blob: 977dedd9221bf44cd97a0611febb727486f823a3 [file] [log] [blame]
Jeff Diked67b5692005-07-07 17:56:49 -07001/*
2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_STUB_H
7#define __SYSDEP_STUB_H
8
Jeff Dike5b7b15a2005-12-18 17:50:39 +01009#include <sys/mman.h>
Jeff Diked67b5692005-07-07 17:56:49 -070010#include <asm/ptrace.h>
11#include <asm/unistd.h>
Jeff Dike54ae36f2007-10-16 01:27:33 -070012#include "as-layout.h"
Jeff Dike5b7b15a2005-12-18 17:50:39 +010013#include "stub-data.h"
14#include "kern_constants.h"
Jeff Diked67b5692005-07-07 17:56:49 -070015
16extern void stub_segv_handler(int sig);
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070017extern void stub_clone_handler(void);
Jeff Diked67b5692005-07-07 17:56:49 -070018
19#define STUB_SYSCALL_RET EAX
20#define STUB_MMAP_NR __NR_mmap2
Jeff Dike71f926f2007-10-16 01:26:44 -070021#define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT)
Jeff Diked67b5692005-07-07 17:56:49 -070022
Jeff Dike17d46972005-11-21 21:32:09 -080023static inline long stub_syscall0(long syscall)
24{
25 long ret;
26
27 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
28
29 return ret;
30}
31
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080032static inline long stub_syscall1(long syscall, long arg1)
33{
34 long ret;
35
36 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
37
38 return ret;
39}
40
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070041static inline long stub_syscall2(long syscall, long arg1, long arg2)
42{
43 long ret;
44
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080045 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
46 "c" (arg2));
47
48 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070049}
50
51static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
52{
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080053 long ret;
54
55 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
56 "c" (arg2), "d" (arg3));
57
58 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070059}
60
61static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
62 long arg4)
63{
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080064 long ret;
65
66 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
67 "c" (arg2), "d" (arg3), "S" (arg4));
68
69 return ret;
70}
71
72static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
73 long arg4, long arg5)
74{
75 long ret;
76
77 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
78 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
79
80 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070081}
82
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070083static inline void trap_myself(void)
84{
85 __asm("int3");
86}
87
Jeff Dike5b7b15a2005-12-18 17:50:39 +010088static inline void remap_stack(int fd, unsigned long offset)
89{
90 __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;"
91 "movl %7, %%ebx ; movl %%eax, (%%ebx)"
Jeff Dike54ae36f2007-10-16 01:27:33 -070092 : : "g" (STUB_MMAP_NR), "b" (STUB_DATA),
93 "c" (UM_KERN_PAGE_SIZE),
Jeff Dike5b7b15a2005-12-18 17:50:39 +010094 "d" (PROT_READ | PROT_WRITE),
Jeff Dike54ae36f2007-10-16 01:27:33 -070095 "S" (MAP_FIXED | MAP_SHARED), "D" (fd),
96 "a" (offset),
97 "i" (&((struct stub_data *) STUB_DATA)->err)
Jeff Dike5b7b15a2005-12-18 17:50:39 +010098 : "memory");
99}
100
Jeff Diked67b5692005-07-07 17:56:49 -0700101#endif