This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add LOAD_ARG[1-6]_TYPE and x32 posix_fallocate.c


On Tue, May 22, 2012 at 11:46 AM, Roland McGrath <roland@hack.frob.com> wrote:
>> ? ? ? * sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c
>> ? ? ? (posix_fallocate): Replace INTERNAL_SYSCALL with
>> ? ? ? INTERNAL_SYSCALL_TYPES.
>
> Oops, sorry. ?This part is not OK as it is, since not everybody defines
> INTERNAL_SYSCALL_TYPES. ?I think it would be fine if you could get the
> other linux/wordsize-64 machines to define it (powerpc64, s390x, sparc64).
> But since they don't actually need it, it would be enough for now just to
> use #ifdef INTERNAL_SYSCALL_TYEPS in posix_fallocate.c instead.
>

How about this?

Thanks.

-- 
H.J.
---
	* sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c
	(posix_fallocate): Use INTERNAL_SYSCALL_TYPES if it is defined.

	* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INLINE_SYSCALL_TYPES):
	New macro.
	(INTERNAL_SYSCALL_NCS_TYPES): Likewise.
	(INTERNAL_SYSCALL_TYPES): Likewise.
	(LOAD_ARGS_TYPES_[1-6]): Likewise.
	(LOAD_REGS_TYPES_[1-6]): Likewise.
	(LOAD_ARGS_[1-6]): Use LOAD_ARGS_TYPES_[1-6].
	(LOAD_REGS_[1-6]): Use LOAD_REGS_TYPES_[1-6].

diff --git a/sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c
b/sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c
index 906b5c2..f791422 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c
+++ b/sysdeps/unix/sysv/linux/wordsize-64/posix_fallocate.c
@@ -38,7 +38,13 @@ posix_fallocate (int fd, __off_t offset, __off_t len)
 # endif
     {
       INTERNAL_SYSCALL_DECL (err);
+# ifdef INTERNAL_SYSCALL_TYPES
+      int res = INTERNAL_SYSCALL_TYPES (fallocate, err, 4, int, fd,
+					int, 0, off_t, offset,
+					off_t, len);
+# else
       int res = INTERNAL_SYSCALL (fallocate, err, 4, fd, 0, offset, len);
+# endif

       if (! INTERNAL_SYSCALL_ERROR_P (res, err))
 	return 0;
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index 396345e..cde8652 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -203,6 +203,20 @@
       }									      \
     (long int) resultvar; })

+/* Define a macro with explicit types for arguments, which expands inline
+   into the wrapper code for a system call.  It should be used when size
+   of any argument > size of long int.  */
+# undef INLINE_SYSCALL_TYPES
+# define INLINE_SYSCALL_TYPES(name, nr, args...) \
+  ({									      \
+    unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args);  \
+    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
+      {									      \
+	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
+	resultvar = (unsigned long int) -1;				      \
+      }									      \
+    (long int) resultvar; })
+
 # undef INTERNAL_SYSCALL_DECL
 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)

@@ -220,6 +234,20 @@
 # define INTERNAL_SYSCALL(name, err, nr, args...) \
   INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)

+# define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
+  ({									      \
+    unsigned long int resultvar;					      \
+    LOAD_ARGS_TYPES_##nr (args)						      \
+    LOAD_REGS_TYPES_##nr (args)						      \
+    asm volatile (							      \
+    "syscall\n\t"							      \
+    : "=a" (resultvar)							      \
+    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
+    (long int) resultvar; })
+# undef INTERNAL_SYSCALL_TYPES
+# define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \
+  INTERNAL_SYSCALL_NCS_TYPES (__NR_##name, err, nr, ##args)
+
 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
   ((unsigned long int) (long int) (val) >= -4095L)
@@ -286,53 +314,83 @@
 # define LOAD_REGS_0
 # define ASM_ARGS_0

-# define LOAD_ARGS_1(a1)				\
-  long int __arg1 = (long int) (a1);			\
+# define LOAD_ARGS_TYPES_1(t1, a1)					   \
+  t1 __arg1 = (t1) (a1);						   \
   LOAD_ARGS_0 ()
-# define LOAD_REGS_1					\
-  register long int _a1 asm ("rdi") = __arg1;		\
+# define LOAD_REGS_TYPES_1(t1, a1)					   \
+  register t1 _a1 asm ("rdi") = __arg1;					   \
   LOAD_REGS_0
 # define ASM_ARGS_1	ASM_ARGS_0, "r" (_a1)
-
-# define LOAD_ARGS_2(a1, a2)				\
-  long int __arg2 = (long int) (a2);			\
-  LOAD_ARGS_1 (a1)
-# define LOAD_REGS_2					\
-  register long int _a2 asm ("rsi") = __arg2;		\
-  LOAD_REGS_1
+# define LOAD_ARGS_1(a1)						   \
+  LOAD_ARGS_TYPES_1 (long int, a1)
+# define LOAD_REGS_1							   \
+  LOAD_REGS_TYPES_1 (long int, a1)
+
+# define LOAD_ARGS_TYPES_2(t1, a1, t2, a2)				   \
+  t2 __arg2 = (t2) (a2);						   \
+  LOAD_ARGS_TYPES_1 (t1, a1)
+# define LOAD_REGS_TYPES_2(t1, a1, t2, a2)				   \
+  register t2 _a2 asm ("rsi") = __arg2;					   \
+  LOAD_REGS_TYPES_1(t1, a1)
 # define ASM_ARGS_2	ASM_ARGS_1, "r" (_a2)
-
-# define LOAD_ARGS_3(a1, a2, a3)			\
-  long int __arg3 = (long int) (a3);			\
-  LOAD_ARGS_2 (a1, a2)
-# define LOAD_REGS_3					\
-  register long int _a3 asm ("rdx") = __arg3;		\
-  LOAD_REGS_2
+# define LOAD_ARGS_2(a1, a2)						   \
+  LOAD_ARGS_TYPES_2 (long int, a1, long int, a2)
+# define LOAD_REGS_2							   \
+  LOAD_REGS_TYPES_2 (long int, a1, long int, a2)
+
+# define LOAD_ARGS_TYPES_3(t1, a1, t2, a2, t3, a3)			   \
+  t3 __arg3 = (t3) (a3);						   \
+  LOAD_ARGS_TYPES_2 (t1, a1, t2, a2)
+# define LOAD_REGS_TYPES_3(t1, a1, t2, a2, t3, a3)			   \
+  register t3 _a3 asm ("rdx") = __arg3;					   \
+  LOAD_REGS_TYPES_2(t1, a1, t2, a2)
 # define ASM_ARGS_3	ASM_ARGS_2, "r" (_a3)
-
-# define LOAD_ARGS_4(a1, a2, a3, a4)			\
-  long int __arg4 = (long int) (a4);			\
-  LOAD_ARGS_3 (a1, a2, a3)
-# define LOAD_REGS_4					\
-  register long int _a4 asm ("r10") = __arg4;		\
-  LOAD_REGS_3
+# define LOAD_ARGS_3(a1, a2, a3)					   \
+  LOAD_ARGS_TYPES_3 (long int, a1, long int, a2, long int, a3)
+# define LOAD_REGS_3							   \
+  LOAD_REGS_TYPES_3 (long int, a1, long int, a2, long int, a3)
+
+# define LOAD_ARGS_TYPES_4(t1, a1, t2, a2, t3, a3, t4, a4)		   \
+  t4 __arg4 = (t4) (a4);						   \
+  LOAD_ARGS_TYPES_3 (t1, a1, t2, a2, t3, a3)
+# define LOAD_REGS_TYPES_4(t1, a1, t2, a2, t3, a3, t4, a4)		   \
+  register t4 _a4 asm ("r10") = __arg4;					   \
+  LOAD_REGS_TYPES_3(t1, a2, t2, a2, t3, a3)
 # define ASM_ARGS_4	ASM_ARGS_3, "r" (_a4)
-
-# define LOAD_ARGS_5(a1, a2, a3, a4, a5)		\
-  long int __arg5 = (long int) (a5);			\
-  LOAD_ARGS_4 (a1, a2, a3, a4)
-# define LOAD_REGS_5					\
-  register long int _a5 asm ("r8") = __arg5;		\
-  LOAD_REGS_4
+# define LOAD_ARGS_4(a1, a2, a3, a4)					   \
+  LOAD_ARGS_TYPES_4 (long int, a1, long int, a2, long int, a3,		   \
+		     long int, a4)
+# define LOAD_REGS_4							   \
+  LOAD_REGS_TYPES_4 (long int, a1, long int, a2, long int, a3,		   \
+		     long int, a4)
+
+# define LOAD_ARGS_TYPES_5(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)	   \
+  t5 __arg5 = (t5) (a5);						   \
+  LOAD_ARGS_TYPES_4 (t1, a1, t2, a2, t3, a3, t4, a4)
+# define LOAD_REGS_TYPES_5(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)	   \
+  register t5 _a5 asm ("r8") = __arg5;					   \
+  LOAD_REGS_TYPES_4 (t1, a1, t2, a2, t3, a3, t4, a4)
 # define ASM_ARGS_5	ASM_ARGS_4, "r" (_a5)
-
-# define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6)		\
-  long int __arg6 = (long int) (a6);			\
-  LOAD_ARGS_5 (a1, a2, a3, a4, a5)
-# define LOAD_REGS_6					\
-  register long int _a6 asm ("r9") = __arg6;		\
-  LOAD_REGS_5
+# define LOAD_ARGS_5(a1, a2, a3, a4, a5)				   \
+  LOAD_ARGS_TYPES_5 (long int, a1, long int, a2, long int, a3,		   \
+		     long int, a4, long int, a5)
+# define LOAD_REGS_5							   \
+  LOAD_REGS_TYPES_5 (long int, a1, long int, a2, long int, a3,		   \
+		     long int, a4, long int, a5)
+
+# define LOAD_ARGS_TYPES_6(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
+  t6 __arg6 = (t6) (a6);						   \
+  LOAD_ARGS_TYPES_5 (t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)
+# define LOAD_REGS_TYPES_6(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
+  register t6 _a6 asm ("r9") = __arg6;					   \
+  LOAD_REGS_TYPES_5 (t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)
 # define ASM_ARGS_6	ASM_ARGS_5, "r" (_a6)
+# define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6)				   \
+  LOAD_ARGS_TYPES_6 (long int, a1, long int, a2, long int, a3,		   \
+		     long int, a4, long int, a5, long int, a6)
+# define LOAD_REGS_6							   \
+  LOAD_REGS_TYPES_6 (long int, a1, long int, a2, long int, a3,		   \
+		     long int, a4, long int, a5, long int, a6)

 #endif	/* __ASSEMBLER__ */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]