Browse Source

syscall: unify part 2: NCS variety

Declare common NCS (non-constant syscall) variants and convert the existing
ports over to this.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Mike Frysinger 16 years ago
parent
commit
763bbf9e9a

+ 4 - 4
libc/sysdeps/linux/alpha/bits/syscalls.h

@@ -26,10 +26,10 @@
 
 
 #ifndef __ASSEMBLER__
 #ifndef __ASSEMBLER__
 
 
-#define INLINE_SYSCALL(name, nr, args...)	\
+#define INLINE_SYSCALL_NCS(name, nr, args...)	\
 ({						\
 ({						\
 	long _sc_ret, _sc_err;			\
 	long _sc_ret, _sc_err;			\
-	inline_syscall##nr(__NR_##name, args);	\
+	inline_syscall##nr(name, args);		\
 	if (__builtin_expect (_sc_err, 0))	\
 	if (__builtin_expect (_sc_err, 0))	\
 	  {					\
 	  {					\
 	    __set_errno (_sc_ret);		\
 	    __set_errno (_sc_ret);		\
@@ -38,10 +38,10 @@
 	_sc_ret;				\
 	_sc_ret;				\
 })
 })
 
 
-#define INTERNAL_SYSCALL(name, err_out, nr, args...) \
+#define INTERNAL_SYSCALL_NCS(name, err_out, nr, args...) \
 ({							\
 ({							\
 	long _sc_ret, _sc_err;				\
 	long _sc_ret, _sc_err;				\
-	inline_syscall##nr(__NR_##name, args);		\
+	inline_syscall##nr(name, args);			\
 	err_out = _sc_err;				\
 	err_out = _sc_err;				\
 	_sc_ret;					\
 	_sc_ret;					\
 })
 })

+ 8 - 8
libc/sysdeps/linux/arm/bits/syscalls.h

@@ -30,8 +30,8 @@
 
 
 #include <errno.h>
 #include <errno.h>
 
 
-#define INLINE_SYSCALL(name, nr, args...)				\
-  ({ unsigned int _inline_sys_result = INTERNAL_SYSCALL (name, , nr, args);	\
+#define INLINE_SYSCALL_NCS(name, nr, args...)				\
+  ({ unsigned int _inline_sys_result = INTERNAL_SYSCALL_NCS (name, , nr, args);	\
      if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ), 0))	\
      if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ), 0))	\
        {								\
        {								\
 	 __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, ));		\
 	 __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, ));		\
@@ -41,12 +41,12 @@
 
 
 #if !defined(__thumb__)
 #if !defined(__thumb__)
 #if defined(__ARM_EABI__)
 #if defined(__ARM_EABI__)
-#define INTERNAL_SYSCALL(name, err, nr, args...)			\
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)			\
   ({unsigned int __sys_result;						\
   ({unsigned int __sys_result;						\
      {									\
      {									\
        register int _a1 __asm__ ("r0"), _nr __asm__ ("r7");		\
        register int _a1 __asm__ ("r0"), _nr __asm__ ("r7");		\
        LOAD_ARGS_##nr (args)						\
        LOAD_ARGS_##nr (args)						\
-       _nr = SYS_ify(name);						\
+       _nr = (name);							\
        __asm__ __volatile__ ("swi	0x0	@ syscall " #name	\
        __asm__ __volatile__ ("swi	0x0	@ syscall " #name	\
 			     : "=r" (_a1)				\
 			     : "=r" (_a1)				\
 			     : "r" (_nr) ASM_ARGS_##nr			\
 			     : "r" (_nr) ASM_ARGS_##nr			\
@@ -56,14 +56,14 @@
      (int) __sys_result; })
      (int) __sys_result; })
 #else /* defined(__ARM_EABI__) */
 #else /* defined(__ARM_EABI__) */
 
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)			\
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)			\
   ({ unsigned int __sys_result;						\
   ({ unsigned int __sys_result;						\
      {									\
      {									\
        register int _a1 __asm__ ("a1");					\
        register int _a1 __asm__ ("a1");					\
        LOAD_ARGS_##nr (args)						\
        LOAD_ARGS_##nr (args)						\
        __asm__ __volatile__ ("swi	%1	@ syscall " #name	\
        __asm__ __volatile__ ("swi	%1	@ syscall " #name	\
 		     : "=r" (_a1)					\
 		     : "=r" (_a1)					\
-		     : "i" (SYS_ify(name)) ASM_ARGS_##nr		\
+		     : "i" (name) ASM_ARGS_##nr				\
 		     : "memory");					\
 		     : "memory");					\
        __sys_result = _a1;						\
        __sys_result = _a1;						\
      }									\
      }									\
@@ -73,13 +73,13 @@
 /* We can't use push/pop inside the asm because that breaks
 /* We can't use push/pop inside the asm because that breaks
    unwinding (ie. thread cancellation).
    unwinding (ie. thread cancellation).
  */
  */
-#define INTERNAL_SYSCALL(name, err, nr, args...)			\
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)			\
   ({ unsigned int __sys_result;						\
   ({ unsigned int __sys_result;						\
     {									\
     {									\
       int _sys_buf[2];							\
       int _sys_buf[2];							\
       register int _a1 __asm__ ("a1");					\
       register int _a1 __asm__ ("a1");					\
       register int *_v3 __asm__ ("v3") = _sys_buf;			\
       register int *_v3 __asm__ ("v3") = _sys_buf;			\
-      *_v3 = (int) (SYS_ify(name));					\
+      *_v3 = (int) (name);						\
       LOAD_ARGS_##nr (args)						\
       LOAD_ARGS_##nr (args)						\
       __asm__ __volatile__ ("str	r7, [v3, #4]\n"			\
       __asm__ __volatile__ ("str	r7, [v3, #4]\n"			\
 		    "\tldr	r7, [v3]\n"				\
 		    "\tldr	r7, [v3]\n"				\

+ 2 - 2
libc/sysdeps/linux/avr32/bits/syscalls.h

@@ -8,10 +8,10 @@
 
 
 #include <errno.h>
 #include <errno.h>
 
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)			\
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)			\
 	({								\
 	({								\
 		register int _a1 __asm__("r12");			\
 		register int _a1 __asm__("r12");			\
-		register int _scno __asm__("r8") = SYS_ify(name);	\
+		register int _scno __asm__("r8") = name;		\
 		LOAD_ARGS_##nr (args);					\
 		LOAD_ARGS_##nr (args);					\
 		__asm__ __volatile__("scall	/* syscall " #name " */" \
 		__asm__ __volatile__("scall	/* syscall " #name " */" \
 			      : "=r" (_a1)				\
 			      : "=r" (_a1)				\

+ 2 - 2
libc/sysdeps/linux/bfin/bits/syscalls.h

@@ -6,13 +6,13 @@
 
 
 #ifndef __ASSEMBLER__
 #ifndef __ASSEMBLER__
 
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)	\
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)	\
 ({							\
 ({							\
 	long __res;					\
 	long __res;					\
 	__asm__ __volatile__ (				\
 	__asm__ __volatile__ (				\
 		"excpt 0;\n\t"				\
 		"excpt 0;\n\t"				\
 		: "=q0" (__res)				\
 		: "=q0" (__res)				\
-		: "qA"  (__NR_##name) ASMFMT_##nr(args)	\
+		: "qA"  (name) ASMFMT_##nr(args)	\
 		: "memory","CC");			\
 		: "memory","CC");			\
 	__res;						\
 	__res;						\
 })
 })

+ 16 - 2
libc/sysdeps/linux/common/bits/syscalls-common.h

@@ -31,10 +31,15 @@
 
 
 /* Define a macro which expands into the inline wrapper code for a system call */
 /* Define a macro which expands into the inline wrapper code for a system call */
 #ifndef INLINE_SYSCALL
 #ifndef INLINE_SYSCALL
-# define INLINE_SYSCALL(name, nr, args...)				\
+# define INLINE_SYSCALL(name, nr, args...) INLINE_SYSCALL_NCS(__NR_##name, nr, args)
+#endif
+
+/* Just like INLINE_SYSCALL(), but take a non-constant syscall (NCS) argument */
+#ifndef INLINE_SYSCALL_NCS
+# define INLINE_SYSCALL_NCS(name, nr, args...)				\
 ({									\
 ({									\
 	INTERNAL_SYSCALL_DECL(err);					\
 	INTERNAL_SYSCALL_DECL(err);					\
-	long res = INTERNAL_SYSCALL(name, err, nr, args);		\
+	long res = INTERNAL_SYSCALL_NCS(name, err, nr, args);		\
 	if (unlikely(INTERNAL_SYSCALL_ERROR_P(res, err))) {		\
 	if (unlikely(INTERNAL_SYSCALL_ERROR_P(res, err))) {		\
 		__set_errno(INTERNAL_SYSCALL_ERRNO(res, err));		\
 		__set_errno(INTERNAL_SYSCALL_ERRNO(res, err));		\
 		res = -1L;						\
 		res = -1L;						\
@@ -43,6 +48,15 @@
 })
 })
 #endif
 #endif
 
 
+/* No point in forcing people to implement both when they only need one */
+#ifndef INTERNAL_SYSCALL
+# define INTERNAL_SYSCALL(name, err, nr, args...) INTERNAL_SYSCALL_NCS(__NR_##name, err, nr, args)
+#endif
+
+#ifndef INTERNAL_SYSCALL_NCS
+# error your port needs to define INTERNAL_SYSCALL_NCS in bits/syscalls.h
+#endif
+
 #ifndef _syscall0
 #ifndef _syscall0
 
 
 #define C_DECL_ARGS_0()			void
 #define C_DECL_ARGS_0()			void

+ 1 - 1
libc/sysdeps/linux/common/bits/syscalls.h

@@ -6,4 +6,4 @@
  */
  */
 
 
 #error You have not provided architecture specific bits/syscalls.h
 #error You have not provided architecture specific bits/syscalls.h
-#error You should need to define only INTERNAL_SYSCALL
+#error You should need to define only INTERNAL_SYSCALL_NCS

+ 3 - 3
libc/sysdeps/linux/i386/bits/syscalls.h

@@ -96,16 +96,16 @@ __asm__ (".L__X'%ebx = 1\n\t"
      ".endm\n\t");
      ".endm\n\t");
 #endif
 #endif
 
 
-#define INTERNAL_SYSCALL(name, err, nr, args...) \
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({                                                                          \
   ({                                                                          \
     register unsigned int resultvar;                                          \
     register unsigned int resultvar;                                          \
-    __asm__ __volatile__ (                                                            \
+    __asm__ __volatile__ (                                                    \
     LOADARGS_##nr                                                             \
     LOADARGS_##nr                                                             \
     "movl %1, %%eax\n\t"                                                      \
     "movl %1, %%eax\n\t"                                                      \
     "int $0x80\n\t"                                                           \
     "int $0x80\n\t"                                                           \
     RESTOREARGS_##nr                                                          \
     RESTOREARGS_##nr                                                          \
     : "=a" (resultvar)                                                        \
     : "=a" (resultvar)                                                        \
-    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");                  \
+    : "i" (name) ASMFMT_##nr(args) : "memory", "cc");                         \
      (int) resultvar; })
      (int) resultvar; })
 
 
 #define LOADARGS_0
 #define LOADARGS_0

+ 2 - 7
libc/sysdeps/linux/ia64/bits/syscalls.h

@@ -61,12 +61,9 @@
 		      : "memory" ASM_CLOBBERS_##nr);		\
 		      : "memory" ASM_CLOBBERS_##nr);		\
     _retval = _r8;
     _retval = _r8;
 
 
-#define DO_INLINE_SYSCALL(name, nr, args...)	\
-  DO_INLINE_SYSCALL_NCS (__NR_##name, nr, ##args)
-
-#define INLINE_SYSCALL(name, nr, args...)		\
+#define INLINE_SYSCALL_NCS(name, nr, args...)		\
   ({							\
   ({							\
-    DO_INLINE_SYSCALL_NCS (__NR_##name, nr, args)	\
+    DO_INLINE_SYSCALL_NCS (name, nr, args)	\
     if (_r10 == -1)					\
     if (_r10 == -1)					\
       {							\
       {							\
 	__set_errno (_retval);				\
 	__set_errno (_retval);				\
@@ -81,8 +78,6 @@
     DO_INLINE_SYSCALL_NCS (name, nr, args)		\
     DO_INLINE_SYSCALL_NCS (name, nr, args)		\
     err = _r10;						\
     err = _r10;						\
     _retval; })
     _retval; })
-#define INTERNAL_SYSCALL(name, err, nr, args...)	\
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
 
 
 #define INTERNAL_SYSCALL_ERROR_P(val, err)	(err == -1)
 #define INTERNAL_SYSCALL_ERROR_P(val, err)	(err == -1)
 
 

+ 2 - 2
libc/sysdeps/linux/mips/bits/syscalls.h

@@ -19,9 +19,9 @@
 
 
 /* Define a macro which expands into the inline wrapper code for a system
 /* Define a macro which expands into the inline wrapper code for a system
    call.  */
    call.  */
-#define INLINE_SYSCALL(name, nr, args...)                               \
+#define INLINE_SYSCALL_NCS(name, nr, args...)                               \
   ({ INTERNAL_SYSCALL_DECL(err);					\
   ({ INTERNAL_SYSCALL_DECL(err);					\
-     long result_var = INTERNAL_SYSCALL (name, err, nr, args);		\
+     long result_var = INTERNAL_SYSCALL_NCS (name, err, nr, args);		\
      if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) )			\
      if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) )			\
        {								\
        {								\
 	 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err));	\
 	 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err));	\

+ 0 - 14
libc/sysdeps/linux/powerpc/bits/syscalls.h

@@ -130,18 +130,6 @@
     (int) r3;								      \
     (int) r3;								      \
   })
   })
 
 
-# define INLINE_SYSCALL(name, nr, args...)				\
-  ({									\
-    INTERNAL_SYSCALL_DECL (sc_err);					\
-    long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args);	\
-    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))			\
-      {									\
-	__set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));		\
-	sc_ret = -1L;							\
-      }									\
-    sc_ret;								\
-  })
-
 /* Define a macro which expands inline into the wrapper code for a system
 /* Define a macro which expands inline into the wrapper code for a system
    call. This use is for internal calls that do not need to handle errors
    call. This use is for internal calls that do not need to handle errors
    normally. It will never touch errno.
    normally. It will never touch errno.
@@ -177,8 +165,6 @@
     err = r0;								\
     err = r0;								\
     (int) r3;								\
     (int) r3;								\
   })
   })
-# define INTERNAL_SYSCALL(name, err, nr, args...) \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
 
 
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
   ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
   ((void) (val), __builtin_expect ((err) & (1 << 28), 0))

+ 0 - 23
libc/sysdeps/linux/sh/bits/syscalls.h

@@ -112,29 +112,6 @@
 	register long int r1 __asm__ ("%r1") = (long int) (_arg6);		      \
 	register long int r1 __asm__ ("%r1") = (long int) (_arg6);		      \
 	register long int r2 __asm__ ("%r2") = (long int) (_arg7)
 	register long int r2 __asm__ ("%r2") = (long int) (_arg7)
 
 
-#define INLINE_SYSCALL(name, nr, args...) \
-  ({                                                                          \
-    unsigned int __resultvar = INTERNAL_SYSCALL (name, , nr, args);             \
-    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (__resultvar, ), 0))         \
-      {                                                                       \
-        __set_errno (INTERNAL_SYSCALL_ERRNO (__resultvar, ));                   \
-        __resultvar = 0xffffffff;                                               \
-      }                                                                       \
-    (int) __resultvar; })
-
-#define INTERNAL_SYSCALL(name, err, nr, args...) \
-  ({									      \
-    unsigned long int resultvar;					      \
-    register long int r3 __asm__ ("%r3") = SYS_ify (name);			      \
-    SUBSTITUTE_ARGS_##nr(args);						      \
-									      \
-    __asm__ volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD			      \
-		  : "=z" (resultvar)					      \
-		  : "r" (r3) ASMFMT_##nr				      \
-		  : "memory");						      \
-									      \
-    (int) resultvar; })
-
 /* The _NCS variant allows non-constant syscall numbers.  */
 /* The _NCS variant allows non-constant syscall numbers.  */
 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({									      \
   ({									      \

+ 0 - 5
libc/sysdeps/linux/sparc/bits/syscalls.h

@@ -35,11 +35,6 @@
 #define DEBUG_SYSCALL(name) do{} while(0)
 #define DEBUG_SYSCALL(name) do{} while(0)
 #endif
 #endif
 
 
-
-#define INTERNAL_SYSCALL( name, err, nr, args...) \
-    INTERNAL_SYSCALL_NCS( __NR_##name, err, nr, args )
-
-
 #define INTERNAL_SYSCALL_NCS(sys_num, err, nr, args...) \
 #define INTERNAL_SYSCALL_NCS(sys_num, err, nr, args...) \
     ({                                                      \
     ({                                                      \
         unsigned int __res;                                 \
         unsigned int __res;                                 \

+ 0 - 2
libc/sysdeps/linux/x86_64/bits/syscalls.h

@@ -76,8 +76,6 @@
     : "=a" (resultvar)							      \
     : "=a" (resultvar)							      \
     : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
     : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
     (long) resultvar; })
     (long) resultvar; })
-#define INTERNAL_SYSCALL(name, err, nr, args...) \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
 
 
 #define LOAD_ARGS_0()
 #define LOAD_ARGS_0()
 #define LOAD_REGS_0
 #define LOAD_REGS_0

+ 0 - 3
libc/sysdeps/linux/xtensa/bits/syscalls.h

@@ -81,8 +81,5 @@
 	 	   : "memory");						      \
 	 	   : "memory");						      \
      (long) _a2; })
      (long) _a2; })
 
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)			      \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
-
 #endif /* not __ASSEMBLER__ */
 #endif /* not __ASSEMBLER__ */
 #endif /* _BITS_SYSCALLS_H */
 #endif /* _BITS_SYSCALLS_H */