OSDN Git Service

syscall: unify part 2: NCS variety
authorMike Frysinger <vapier@gentoo.org>
Thu, 9 Jul 2009 19:09:29 +0000 (15:09 -0400)
committerMike Frysinger <vapier@gentoo.org>
Thu, 9 Jul 2009 19:11:46 +0000 (15:11 -0400)
Declare common NCS (non-constant syscall) variants and convert the existing
ports over to this.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
14 files changed:
libc/sysdeps/linux/alpha/bits/syscalls.h
libc/sysdeps/linux/arm/bits/syscalls.h
libc/sysdeps/linux/avr32/bits/syscalls.h
libc/sysdeps/linux/bfin/bits/syscalls.h
libc/sysdeps/linux/common/bits/syscalls-common.h
libc/sysdeps/linux/common/bits/syscalls.h
libc/sysdeps/linux/i386/bits/syscalls.h
libc/sysdeps/linux/ia64/bits/syscalls.h
libc/sysdeps/linux/mips/bits/syscalls.h
libc/sysdeps/linux/powerpc/bits/syscalls.h
libc/sysdeps/linux/sh/bits/syscalls.h
libc/sysdeps/linux/sparc/bits/syscalls.h
libc/sysdeps/linux/x86_64/bits/syscalls.h
libc/sysdeps/linux/xtensa/bits/syscalls.h

index 6be2697..ee56788 100644 (file)
 
 #ifndef __ASSEMBLER__
 
-#define INLINE_SYSCALL(name, nr, args...)      \
+#define INLINE_SYSCALL_NCS(name, nr, args...)  \
 ({                                             \
        long _sc_ret, _sc_err;                  \
-       inline_syscall##nr(__NR_##name, args);  \
+       inline_syscall##nr(name, args);         \
        if (__builtin_expect (_sc_err, 0))      \
          {                                     \
            __set_errno (_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;                          \
-       inline_syscall##nr(__NR_##name, args);          \
+       inline_syscall##nr(name, args);                 \
        err_out = _sc_err;                              \
        _sc_ret;                                        \
 })
index 2ad7255..1a854ff 100644 (file)
@@ -30,8 +30,8 @@
 
 #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))        \
        {                                                               \
         __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, ));           \
 
 #if !defined(__thumb__)
 #if defined(__ARM_EABI__)
-#define INTERNAL_SYSCALL(name, err, nr, args...)                       \
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)                   \
   ({unsigned int __sys_result;                                         \
      {                                                                 \
        register int _a1 __asm__ ("r0"), _nr __asm__ ("r7");            \
        LOAD_ARGS_##nr (args)                                           \
-       _nr = SYS_ify(name);                                            \
+       _nr = (name);                                                   \
        __asm__ __volatile__ ("swi      0x0     @ syscall " #name       \
                             : "=r" (_a1)                               \
                             : "r" (_nr) ASM_ARGS_##nr                  \
      (int) __sys_result; })
 #else /* defined(__ARM_EABI__) */
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)                       \
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)                   \
   ({ unsigned int __sys_result;                                                \
      {                                                                 \
        register int _a1 __asm__ ("a1");                                        \
        LOAD_ARGS_##nr (args)                                           \
        __asm__ __volatile__ ("swi      %1      @ syscall " #name       \
                     : "=r" (_a1)                                       \
-                    : "i" (SYS_ify(name)) ASM_ARGS_##nr                \
+                    : "i" (name) ASM_ARGS_##nr                         \
                     : "memory");                                       \
        __sys_result = _a1;                                             \
      }                                                                 \
 /* We can't use push/pop inside the asm because that breaks
    unwinding (ie. thread cancellation).
  */
-#define INTERNAL_SYSCALL(name, err, nr, args...)                       \
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)                   \
   ({ unsigned int __sys_result;                                                \
     {                                                                  \
       int _sys_buf[2];                                                 \
       register int _a1 __asm__ ("a1");                                 \
       register int *_v3 __asm__ ("v3") = _sys_buf;                     \
-      *_v3 = (int) (SYS_ify(name));                                    \
+      *_v3 = (int) (name);                                             \
       LOAD_ARGS_##nr (args)                                            \
       __asm__ __volatile__ ("str       r7, [v3, #4]\n"                 \
                    "\tldr      r7, [v3]\n"                             \
index e473b10..48f15d4 100644 (file)
@@ -8,10 +8,10 @@
 
 #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 _scno __asm__("r8") = SYS_ify(name);       \
+               register int _scno __asm__("r8") = name;                \
                LOAD_ARGS_##nr (args);                                  \
                __asm__ __volatile__("scall     /* syscall " #name " */" \
                              : "=r" (_a1)                              \
index 478ea2d..6230b03 100644 (file)
@@ -6,13 +6,13 @@
 
 #ifndef __ASSEMBLER__
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)       \
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...)   \
 ({                                                     \
        long __res;                                     \
        __asm__ __volatile__ (                          \
                "excpt 0;\n\t"                          \
                : "=q0" (__res)                         \
-               : "qA"  (__NR_##name) ASMFMT_##nr(args) \
+               : "qA"  (name) ASMFMT_##nr(args)        \
                : "memory","CC");                       \
        __res;                                          \
 })
index 81c82c8..2aef89c 100644 (file)
 
 /* Define a macro which expands into the inline wrapper code for a system call */
 #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);                                     \
-       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))) {             \
                __set_errno(INTERNAL_SYSCALL_ERRNO(res, err));          \
                res = -1L;                                              \
 })
 #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
 
 #define C_DECL_ARGS_0()                        void
index e7c6b03..03d08d1 100644 (file)
@@ -6,4 +6,4 @@
  */
 
 #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
index 343b096..8a98a0e 100644 (file)
@@ -96,16 +96,16 @@ __asm__ (".L__X'%ebx = 1\n\t"
      ".endm\n\t");
 #endif
 
-#define INTERNAL_SYSCALL(name, err, nr, args...) \
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({                                                                          \
     register unsigned int resultvar;                                          \
-    __asm__ __volatile__ (                                                            \
+    __asm__ __volatile__ (                                                    \
     LOADARGS_##nr                                                             \
     "movl %1, %%eax\n\t"                                                      \
     "int $0x80\n\t"                                                           \
     RESTOREARGS_##nr                                                          \
     : "=a" (resultvar)                                                        \
-    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");                  \
+    : "i" (name) ASMFMT_##nr(args) : "memory", "cc");                         \
      (int) resultvar; })
 
 #define LOADARGS_0
index 81b2cf4..9fda3d0 100644 (file)
                      : "memory" ASM_CLOBBERS_##nr);            \
     _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)                                    \
       {                                                        \
        __set_errno (_retval);                          \
@@ -81,8 +78,6 @@
     DO_INLINE_SYSCALL_NCS (name, nr, args)             \
     err = _r10;                                                \
     _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)
 
index 07e0fe4..3639913 100644 (file)
@@ -19,9 +19,9 @@
 
 /* Define a macro which expands into the inline wrapper code for a system
    call.  */
-#define INLINE_SYSCALL(name, nr, args...)                               \
+#define INLINE_SYSCALL_NCS(name, nr, args...)                               \
   ({ 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) )                 \
        {                                                               \
         __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err));        \
index e11c362..f689c60 100644 (file)
     (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
    call. This use is for internal calls that do not need to handle errors
    normally. It will never touch errno.
     err = r0;                                                          \
     (int) r3;                                                          \
   })
-# define INTERNAL_SYSCALL(name, err, nr, args...) \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
 
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
   ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
index 6e7ddbb..c69dce5 100644 (file)
        register long int r1 __asm__ ("%r1") = (long int) (_arg6);                    \
        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.  */
 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({                                                                         \
index 5542010..78f1439 100644 (file)
 #define DEBUG_SYSCALL(name) do{} while(0)
 #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...) \
     ({                                                      \
         unsigned int __res;                                 \
index 3aabe67..d16addb 100644 (file)
@@ -76,8 +76,6 @@
     : "=a" (resultvar)                                                       \
     : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");               \
     (long) resultvar; })
-#define INTERNAL_SYSCALL(name, err, nr, args...) \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
 
 #define LOAD_ARGS_0()
 #define LOAD_REGS_0
index 6b87ace..cc6c41e 100644 (file)
@@ -81,8 +81,5 @@
                   : "memory");                                               \
      (long) _a2; })
 
-#define INTERNAL_SYSCALL(name, err, nr, args...)                             \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
-
 #endif /* not __ASSEMBLER__ */
 #endif /* _BITS_SYSCALLS_H */