1 /* libc/sys/linux/machine/i386/socketcall.h - x86 linux socket system calls */
2 
3 /* Copyright 2002, Red Hat Inc. */
4 
5 #ifndef _SOCKETCALL_H
6 
7 #define _SOCKETCALL_H
8 
9 #include <machine/weakalias.h>
10 #include <sys/errno.h>
11 #include <asm/unistd.h>
12 #include "sockops.h"
13 
14 /*
15  * PIC uses %ebx, so we need to save it during system calls
16  */
17 
18 #ifdef __syscall_return
19 
20 #define __sockcall_base(type, name) \
21 { \
22 long __res; \
23 __asm__ volatile ("push %%ebx; movl %2,%%ebx; lea 8(%%ebp),%%ecx; int $0x80; pop %%ebx" \
24 	: "=a" (__res) \
25 	: "0" (__NR_socketcall),"r" (SOCK_##name)); \
26 __syscall_return(type,__res); \
27 }
28 
29 #else /* !defined(__syscall_return) */
30 
31 /* FIXME: we need to rewrite this for a vsyscall system.  */
32 
33 #define __syscall_return(type, res) \
34 do { \
35   if ((unsigned long)(res) >= (unsigned long)(-125)) { \
36     errno = -(res); \
37     res = -1; \
38   } \
39   return (type) (res); \
40 } while (0)
41 
42 #define __sockcall_base(type, name) \
43 { \
44 long __res; \
45 __asm__ volatile ("push %%ebx; movl %2,%%ebx; lea 8(%%ebp),%%ecx; int $0x80; pop %%ebx" \
46 	: "=a" (__res) \
47 	: "0" (__NR_socketcall),"r" (SOCK_##name)); \
48 __syscall_return(type,__res); \
49 }
50 
51 #endif /* !defined(__syscall_return) */
52 
53 #undef _sockcall1
54 #define _sockcall1(type,name,type1,arg1) \
55 type __libc_##name(type1 arg1) \
56 __sockcall_base(type,name) \
57 weak_alias(__libc_##name,name)
58 
59 #undef _sockcall2
60 #define _sockcall2(type,name,type1,arg1,type2,arg2) \
61 type __libc_##name(type1 arg1, type2 arg2) \
62 __sockcall_base(type,name) \
63 weak_alias(__libc_##name,name)
64 
65 #undef _sockcall3
66 #define _sockcall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
67 type __libc_##name(type1 arg1, type2 arg2, type3 arg3) \
68 __sockcall_base(type,name) \
69 weak_alias(__libc_##name,name)
70 
71 #undef _sockcall4
72 #define _sockcall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
73 type __libc_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
74 __sockcall_base(type,name) \
75 weak_alias(__libc_##name,name)
76 
77 #undef _sockcall5
78 #define _sockcall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
79 type __libc_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
80 __sockcall_base(type,name) \
81 weak_alias(__libc_##name,name)
82 
83 #undef _sockcall6
84 #define _sockcall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
85 type __libc_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
86 __sockcall_base(type,name) \
87 weak_alias(__libc_##name,name)
88 
89 #endif /* _SOCKETCALL_H */
90