Skip to content

Commit 7cd79ec

Browse files
committed
syscallmacros.h created online with Bitbucket
1 parent a40721f commit 7cd79ec

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#ifdef __KERNEL__
2+
#define MAX_ERRNO 4095
3+
/*
4+
* user-visible error numbers are in the range -1 - -MAX_ERRNO: see
5+
* <asm-i386/errno.h>
6+
*/
7+
#define __syscall_return(type, res) \
8+
do { \
9+
if ((unsigned long)(res) >= (unsigned long)(-MAX_ERRNO)) { \
10+
errno = -(res); \
11+
res = -1; \
12+
} \
13+
return (type) (res); \
14+
} while (0)
15+
16+
/* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
17+
#define _syscall0(type,name) \
18+
type name(void) \
19+
{ \
20+
long __res; \
21+
__asm__ volatile ("int $0x80" \
22+
: "=a" (__res) \
23+
: "0" (__NR_##name)); \
24+
__syscall_return(type,__res); \
25+
}
26+
27+
#define _syscall1(type,name,type1,arg1) \
28+
type name(type1 arg1) \
29+
{ \
30+
long __res; \
31+
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
32+
: "=a" (__res) \
33+
: "0" (__NR_##name),"ri" ((long)(arg1)) : "memory"); \
34+
__syscall_return(type,__res); \
35+
}
36+
37+
#define _syscall2(type,name,type1,arg1,type2,arg2) \
38+
type name(type1 arg1,type2 arg2) \
39+
{ \
40+
long __res; \
41+
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
42+
: "=a" (__res) \
43+
: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)) \
44+
: "memory"); \
45+
__syscall_return(type,__res); \
46+
}
47+
48+
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
49+
type name(type1 arg1,type2 arg2,type3 arg3) \
50+
{ \
51+
long __res; \
52+
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
53+
: "=a" (__res) \
54+
: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
55+
"d" ((long)(arg3)) : "memory"); \
56+
__syscall_return(type,__res); \
57+
}
58+
59+
#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
60+
type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
61+
{ \
62+
long __res; \
63+
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
64+
: "=a" (__res) \
65+
: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
66+
"d" ((long)(arg3)),"S" ((long)(arg4)) : "memory"); \
67+
__syscall_return(type,__res); \
68+
}
69+
70+
#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
71+
type5,arg5) \
72+
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
73+
{ \
74+
long __res; \
75+
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; movl %1,%%eax ; " \
76+
"int $0x80 ; pop %%ebx" \
77+
: "=a" (__res) \
78+
: "i" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
79+
"d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) \
80+
: "memory"); \
81+
__syscall_return(type,__res); \
82+
}
83+
84+
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
85+
type5,arg5,type6,arg6) \
86+
type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
87+
{ \
88+
long __res; \
89+
struct { long __a1; long __a6; } __s = { (long)arg1, (long)arg6 }; \
90+
__asm__ volatile ("push %%ebp ; push %%ebx ; movl 4(%2),%%ebp ; " \
91+
"movl 0(%2),%%ebx ; movl %1,%%eax ; int $0x80 ; " \
92+
"pop %%ebx ; pop %%ebp" \
93+
: "=a" (__res) \
94+
: "i" (__NR_##name),"0" ((long)(&__s)),"c" ((long)(arg2)), \
95+
"d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) \
96+
: "memory"); \
97+
__syscall_return(type,__res); \
98+
}
99+
100+
#define __ARCH_WANT_IPC_PARSE_VERSION
101+
#define __ARCH_WANT_OLD_READDIR
102+
#define __ARCH_WANT_OLD_STAT
103+
#define __ARCH_WANT_STAT64
104+
#define __ARCH_WANT_SYS_ALARM
105+
#define __ARCH_WANT_SYS_GETHOSTNAME
106+
#define __ARCH_WANT_SYS_PAUSE
107+
#define __ARCH_WANT_SYS_SGETMASK
108+
#define __ARCH_WANT_SYS_SIGNAL
109+
#define __ARCH_WANT_SYS_TIME
110+
#define __ARCH_WANT_SYS_UTIME
111+
#define __ARCH_WANT_SYS_WAITPID
112+
#define __ARCH_WANT_SYS_SOCKETCALL
113+
#define __ARCH_WANT_SYS_FADVISE64
114+
#define __ARCH_WANT_SYS_GETPGRP
115+
#define __ARCH_WANT_SYS_LLSEEK
116+
#define __ARCH_WANT_SYS_NICE
117+
#define __ARCH_WANT_SYS_OLD_GETRLIMIT
118+
#define __ARCH_WANT_SYS_OLDUMOUNT
119+
#define __ARCH_WANT_SYS_SIGPENDING
120+
#define __ARCH_WANT_SYS_SIGPROCMASK
121+
#define __ARCH_WANT_SYS_RT_SIGACTION
122+
#define __ARCH_WANT_SYS_RT_SIGSUSPEND
123+
124+
/*
125+
* "Conditional" syscalls
126+
*
127+
* What we want is __attribute__((weak,alias("sys_ni_syscall"))),
128+
* but it doesn't work on all toolchains, so we just do it by hand
129+
*/
130+
#ifndef cond_syscall
131+
#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall")
132+
#endif
133+
134+
#endif /* __KERNEL__ */

0 commit comments

Comments
 (0)