Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
Date: 2005-04-19
Initial Package Version: 2.4.30
Upstream Status: Not submitted
Origin: Gentoo - unistd.h-i386-pic.patch
Description: This patch adds position independent assembly for syscalls.
This fixes problems with llseek(), util-linux, vsftpd, proftpd, and more.

Also see:
http://www.linuxfromscratch.org/hlfs/

diff -Naur linux-2.4.30.orig/include/asm-i386/unistd.h linux-2.4.30/include/asm-i386/unistd.h
--- linux-2.4.30.orig/include/asm-i386/unistd.h	2004-11-17 11:54:22.000000000 +0000
+++ linux-2.4.30/include/asm-i386/unistd.h	2005-04-19 19:35:39.000000000 +0000
@@ -280,6 +280,21 @@
 __syscall_return(type,__res); \
 }
 
+#ifdef __PIC__
+#define _syscall1(type,name,type1,arg1) \
+type name(type1 arg1) \
+{ \
+long __res; \
+__asm__ volatile (\
+	"pushl %%ebx\n\t" \
+	"movl %2,%%ebx\n\t" \
+	"int $0x80\n\t" \
+	"popl %%ebx\n\t" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"r" ((long)(arg1))); \
+__syscall_return(type,__res); \
+}
+#else
 #define _syscall1(type,name,type1,arg1) \
 type name(type1 arg1) \
 { \
@@ -289,7 +304,23 @@
 	: "0" (__NR_##name),"b" ((long)(arg1))); \
 __syscall_return(type,__res); \
 }
+#endif
 
+#ifdef __PIC__
+#define _syscall2(type,name,type1,arg1,type2,arg2) \
+type name(type1 arg1,type2 arg2) \
+{ \
+long __res; \
+__asm__ volatile (\
+	"pushl %%ebx\n\t" \
+	"movl %2,%%ebx\n\t" \
+	"int $0x80\n\t" \
+	"popl %%ebx\n\t" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \
+__syscall_return(type,__res); \
+}
+#else
 #define _syscall2(type,name,type1,arg1,type2,arg2) \
 type name(type1 arg1,type2 arg2) \
 { \
@@ -299,7 +330,24 @@
 	: "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \
 __syscall_return(type,__res); \
 }
+#endif
 
+#ifdef __PIC__
+#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
+type name(type1 arg1,type2 arg2,type3 arg3) \
+{ \
+long __res; \
+__asm__ volatile (\
+	"pushl %%ebx\n\t" \
+	"movl %2,%%ebx\n\t" \
+	"int $0x80\n\t" \
+	"popl %%ebx\n\t" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
+		  "d" ((long)(arg3))); \
+__syscall_return(type,__res); \
+}
+#else
 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
 type name(type1 arg1,type2 arg2,type3 arg3) \
 { \
@@ -310,7 +358,24 @@
 		  "d" ((long)(arg3))); \
 __syscall_return(type,__res); \
 }
+#endif
 
+#ifdef __PIC__
+#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
+type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
+{ \
+long __res; \
+__asm__ volatile (\
+	"pushl %%ebx\n\t" \
+	"movl %2,%%ebx\n\t" \
+	"int $0x80\n\t" \
+	"popl %%ebx\n\t" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
+	  "d" ((long)(arg3)),"S" ((long)(arg4))); \
+__syscall_return(type,__res); \
+} 
+#else
 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
 { \
@@ -321,7 +386,25 @@
 	  "d" ((long)(arg3)),"S" ((long)(arg4))); \
 __syscall_return(type,__res); \
 } 
+#endif
 
+#ifdef __PIC__
+#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
+	  type5,arg5) \
+type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
+{ \
+long __res; \
+__asm__ volatile (\
+	"pushl %%ebx\n\t" \
+	"movl %2,%%ebx\n\t" \
+	"int $0x80\n\t" \
+	"popl %%ebx\n\t" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
+	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
+__syscall_return(type,__res); \
+}
+#else
 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
 	  type5,arg5) \
 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
@@ -333,7 +416,30 @@
 	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
 __syscall_return(type,__res); \
 }
+#endif
 
+#ifdef __PIC__
+#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
+	  type5,arg5,type6,arg6) \
+type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
+{ \
+long __res; \
+__asm__ volatile (\
+	"pushl %%ebp\n\t" \
+	"movl %%eax,%%ebp\n\t" \
+	"movl %1,%%eax\n\t" \
+	"pushl %%ebx\n\t" \
+	"movl %2,%%ebx\n\t" \
+	"int $0x80\n\t" \
+	"popl %%ebx\n\t" \
+	"popl %%ebp\n\t" \
+	: "=a" (__res) \
+	: "i" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
+	  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \
+	  "0" ((long)(arg6))); \
+__syscall_return(type,__res); \
+}
+#else
 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
 	  type5,arg5,type6,arg6) \
 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
@@ -346,6 +452,7 @@
 	  "0" ((long)(arg6))); \
 __syscall_return(type,__res); \
 }
+#endif
 
 #ifdef __KERNEL_SYSCALLS__
 
