blob: 51fd256c75f00f8f268f171f50336fa2db8437bc [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
9#include <asm/ptrace.h>
Jeff Diked67b5692005-07-07 17:56:49 -070010
11#define STUB_SYSCALL_RET EAX
12#define STUB_MMAP_NR __NR_mmap2
Jeff Dike71f926f2007-10-16 01:26:44 -070013#define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT)
Jeff Diked67b5692005-07-07 17:56:49 -070014
Jeff Dike17d46972005-11-21 21:32:09 -080015static inline long stub_syscall0(long syscall)
16{
17 long ret;
18
19 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
20
21 return ret;
22}
23
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080024static inline long stub_syscall1(long syscall, long arg1)
25{
26 long ret;
27
28 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
29
30 return ret;
31}
32
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070033static inline long stub_syscall2(long syscall, long arg1, long arg2)
34{
35 long ret;
36
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080037 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
38 "c" (arg2));
39
40 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070041}
42
43static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
44{
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080045 long ret;
46
47 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
48 "c" (arg2), "d" (arg3));
49
50 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070051}
52
53static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
54 long arg4)
55{
Paolo 'Blaisorblade' Giarrusso4f027242005-11-07 00:58:46 -080056 long ret;
57
58 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
59 "c" (arg2), "d" (arg3), "S" (arg4));
60
61 return ret;
62}
63
64static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
65 long arg4, long arg5)
66{
67 long ret;
68
69 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
70 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
71
72 return ret;
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070073}
74
Bodo Stroesser9786a8f2005-07-07 17:56:50 -070075static inline void trap_myself(void)
76{
77 __asm("int3");
78}
79
Jeff Dike5b7b15af2005-12-18 17:50:39 +010080static inline void remap_stack(int fd, unsigned long offset)
81{
82 __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;"
83 "movl %7, %%ebx ; movl %%eax, (%%ebx)"
Jeff Dike54ae36f2007-10-16 01:27:33 -070084 : : "g" (STUB_MMAP_NR), "b" (STUB_DATA),
85 "c" (UM_KERN_PAGE_SIZE),
Jeff Dike5b7b15af2005-12-18 17:50:39 +010086 "d" (PROT_READ | PROT_WRITE),
Jeff Dike54ae36f2007-10-16 01:27:33 -070087 "S" (MAP_FIXED | MAP_SHARED), "D" (fd),
88 "a" (offset),
89 "i" (&((struct stub_data *) STUB_DATA)->err)
Jeff Dike5b7b15af2005-12-18 17:50:39 +010090 : "memory");
91}
92
Jeff Diked67b5692005-07-07 17:56:49 -070093#endif