Linux syscalls can clobber any input register, thanks to gcc and

the lack of a Linux kernel ABI.
	linux.hh

committer: jreiser <jreiser> 1144967342 +0000
This commit is contained in:
John Reiser
2006-04-13 22:29:02 +00:00
parent f700273624
commit 6a4db2ecab
+46 -57
View File
@@ -188,13 +188,13 @@ type name(void) \
{ \ { \
long __res; \ long __res; \
if (Z1(__NR_##name)) { \ if (Z1(__NR_##name)) { \
__asm__ __volatile__ ("push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name)); \ : [sysN] "g" (__NR_##name)); \
} else { \ } else { \
__asm__ __volatile__ ("int $0x80" \ __asm__ __volatile__ ("int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "a" (__NR_##name)); \ : [sysN] "a" (__NR_##name)); \
} \ } \
return (type) __res; \ return (type) __res; \
} }
@@ -202,26 +202,26 @@ type name(void) \
#define _syscall1(type,name,type1,arg1) \ #define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \ type name(type1 arg1) \
{ \ { \
long __res; \ long __res, junk; \
if (Z1(__NR_##name)) { \ if (Z1(__NR_##name)) { \
if (Z0(arg1)) { \ if (Z0(arg1)) { \
__asm__ __volatile__ ("xorl %%ebx,%%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("xorl %%ebx,%%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name) \ : [sysN] "g" (__NR_##name) \
: "ebx"); \ : "ebx"); \
} else if (Z1(arg1)) { \ } else if (Z1(arg1)) { \
__asm__ __volatile__ ("push %2; popl %%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[a1]; popl %%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name),"g" ((long)(arg1)) \ : [sysN] "g" (__NR_##name), [a1] "g" ((long)(arg1)) \
: "ebx"); \ : "ebx"); \
} else { \ } else { \
__asm__ __volatile__ ("push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junk) \
: "g" (__NR_##name),"b" ((long)(arg1))); \ : [sysN] "g" (__NR_##name),"b" ((long)(arg1))); \
} \ } \
} else { \ } else { \
__asm__ __volatile__ ("int $0x80" \ __asm__ __volatile__ ("int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junk) \
: "a" (__NR_##name),"b" ((long)(arg1))); \ : "a" (__NR_##name),"b" ((long)(arg1))); \
} \ } \
return (type) __res; \ return (type) __res; \
@@ -235,8 +235,8 @@ void __attribute__((__noreturn__)) name(type1 arg1) \
__asm__ __volatile__ ("xorl %%ebx,%%ebx; push %0; popl %%eax; int $0x80" \ __asm__ __volatile__ ("xorl %%ebx,%%ebx; push %0; popl %%eax; int $0x80" \
: : "g" (__NR_##name) ); \ : : "g" (__NR_##name) ); \
} else if (Z1(arg1)) { \ } else if (Z1(arg1)) { \
__asm__ __volatile__ ("push %1; popl %%ebx; push %0; popl %%eax; int $0x80" \ __asm__ __volatile__ ("push %[a1]; popl %%ebx; push %[sysN]; popl %%eax; int $0x80" \
: : "g" (__NR_##name),"g" ((long)(arg1)) ); \ : : [sysN] "g" (__NR_##name), [a1] "g" ((long)(arg1)) ); \
} else { \ } else { \
__asm__ __volatile__ ("push %0; popl %%eax; int $0x80" \ __asm__ __volatile__ ("push %0; popl %%eax; int $0x80" \
: : "g" (__NR_##name),"b" ((long)(arg1))); \ : : "g" (__NR_##name),"b" ((long)(arg1))); \
@@ -248,71 +248,60 @@ void __attribute__((__noreturn__)) name(type1 arg1) \
for(;;) ; \ for(;;) ; \
} }
// special for mmap; somehow Z0(arg1) and Z1(arg1) do not work
#define _syscall1m(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
long __res; \
__asm__ __volatile__ ("push %1; popl %0; int $0x80" \
: "=a" (__res) \
: "g" (__NR_##name),"b" ((long)(arg1))); \
return (type) __res; \
}
#define _syscall2(type,name,type1,arg1,type2,arg2) \ #define _syscall2(type,name,type1,arg1,type2,arg2) \
type name(type1 arg1,type2 arg2) \ type name(type1 arg1,type2 arg2) \
{ \ { \
long __res; \ long __res, junkb, junkc; \
if (Z1(__NR_##name)) { \ if (Z1(__NR_##name)) { \
if (Z0(arg1) && Z0(arg2)) { \ if (Z0(arg1) && Z0(arg2)) { \
__asm__ __volatile__ ("xorl %%ecx,%%ecx; xorl %%ebx,%%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("xorl %%ecx,%%ecx; xorl %%ebx,%%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name) \ : [sysN] "g" (__NR_##name) \
: "ebx", "ecx"); \ : "ebx", "ecx"); \
} else if (Z0(arg1) && Z1(arg2)) { \ } else if (Z0(arg1) && Z1(arg2)) { \
__asm__ __volatile__ ("push %2; popl %%ecx; xorl %%ebx,%%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[a2]; popl %%ecx; xorl %%ebx,%%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name),"g" ((long)(arg2)) \ : [sysN] "g" (__NR_##name), [a2] "g" ((long)(arg2)) \
: "ebx", "ecx"); \ : "ebx", "ecx"); \
} else if (Z1(arg1) && Z0(arg2)) { \ } else if (Z1(arg1) && Z0(arg2)) { \
__asm__ __volatile__ ("xorl %%ecx,%%ecx; push %2; popl %%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("xorl %%ecx,%%ecx; push %[a1]; popl %%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name),"g" ((long)(arg1)) \ : [sysN] "g" (__NR_##name), [a1] "g" ((long)(arg1)) \
: "ebx", "ecx"); \ : "ebx", "ecx"); \
} else if (Z1(arg1) && Z1(arg2)) { \ } else if (Z1(arg1) && Z1(arg2)) { \
__asm__ __volatile__ ("push %3; popl %%ecx; push %2; popl %%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[a2]; popl %%ecx; push %[a1]; popl %%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res) \
: "g" (__NR_##name),"g" ((long)(arg1)),"g" ((long)(arg2)) \ : [sysN] "g" (__NR_##name), [a1] "g" ((long)(arg1)), [a2] "g" ((long)(arg2)) \
: "ebx", "ecx"); \ : "ebx", "ecx"); \
} else if (Z0(arg1)) { \ } else if (Z0(arg1)) { \
__asm__ __volatile__ ("xorl %%ebx,%%ebx; push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("xorl %%ebx,%%ebx; push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=c" (junkc) \
: "g" (__NR_##name),"c" ((long)(arg2)) \ : [sysN] "g" (__NR_##name),"c" ((long)(arg2)) \
: "ebx"); \ : "ebx"); \
} else if (Z0(arg2)) { \ } else if (Z0(arg2)) { \
__asm__ __volatile__ ("push %1; popl %0; xorl %%ecx,%%ecx; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; xorl %%ecx,%%ecx; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junkb) \
: "g" (__NR_##name),"b" ((long)(arg1)) \ : [sysN] "g" (__NR_##name),"b" ((long)(arg1)) \
: "ecx"); \ : "ecx"); \
} else if (Z1(arg1)) { \ } else if (Z1(arg1)) { \
__asm__ __volatile__ ("push %1; popl %0; push %2; popl %%ebx; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; push %[a1]; popl %%ebx; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=c" (junkc) \
: "g" (__NR_##name),"g" ((long)(arg1)),"c" ((long)(arg2)) \ : [sysN] "g" (__NR_##name), [a1] "g" ((long)(arg1)),"c" ((long)(arg2)) \
: "ebx"); \ : "ebx"); \
} else if (Z1(arg2)) { \ } else if (Z1(arg2)) { \
__asm__ __volatile__ ("push %1; popl %0; push %3; popl %%ecx; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; push %[a2]; popl %%ecx; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junkb) \
: "g" (__NR_##name),"b" ((long)(arg1)),"g" ((long)(arg2)) \ : [sysN] "g" (__NR_##name),"b" ((long)(arg1)), [a2] "g" ((long)(arg2)) \
: "ecx"); \ : "ecx"); \
} else { \ } else { \
__asm__ __volatile__ ("push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junkb), "=c" (junkc) \
: "g" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ : [sysN] "g" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \
} \ } \
} else { \ } else { \
__asm__ __volatile__ ("int $0x80" \ __asm__ __volatile__ ("int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junkb), "=c" (junkc) \
: "a" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ : [sysN] "a" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \
} \ } \
return (type) __res; \ return (type) __res; \
} }
@@ -320,16 +309,16 @@ type name(type1 arg1,type2 arg2) \
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \ type name(type1 arg1,type2 arg2,type3 arg3) \
{ \ { \
long __res; \ long __res, junkb, junkc, junkd; \
if (Z1(__NR_##name)) { \ if (Z1(__NR_##name)) { \
__asm__ __volatile__ ("push %1; popl %0; int $0x80" \ __asm__ __volatile__ ("push %[sysN]; popl %0; int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junkb), "=c" (junkc), "=d" (junkd) \
: "g" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ : [sysN] "g" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3))); \ "d" ((long)(arg3))); \
} else { \ } else { \
__asm__ __volatile__ ("int $0x80" \ __asm__ __volatile__ ("int $0x80" \
: "=a" (__res) \ : "=a" (__res), "=b" (junkb), "=c" (junkc), "=d" (junkd) \
: "a" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ : [sysN] "a" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
"d" ((long)(arg3))); \ "d" ((long)(arg3))); \
} \ } \
return (type) __res; \ return (type) __res; \