Index: lss/linux_syscall_support.h |
=================================================================== |
--- lss/linux_syscall_support.h (revision 17) |
+++ lss/linux_syscall_support.h (working copy) |
@@ -103,6 +103,7 @@ |
#include <signal.h> |
#include <stdarg.h> |
#include <stddef.h> |
+#include <stdint.h> |
#include <string.h> |
#include <sys/ptrace.h> |
#include <sys/resource.h> |
@@ -1753,6 +1754,36 @@ |
return res; |
} |
#elif defined(__x86_64__) |
+ /* The x32 ABI has 32 bit longs, but the syscall interface is 64 bit. |
+ * We need to explicitly cast to an unsigned 64 bit type to avoid implicit |
+ * sign extension. We can't cast pointers directly because those are |
+ * 32 bits, and gcc will dump ugly warnings about casting from a pointer |
+ * to an integer of a different size. |
+ */ |
+ #ifdef __ILP32__ |
+ #define LSS_SYSCALL_IGNORE_ARG_CASTS() \ |
+ do { \ |
+ _Pragma("GCC diagnostic ignored \"-Wpointer-to-int-cast\""); \ |
Mark Seaborn
2013/03/05 17:05:19
You also need to do "GCC diagnostic push"/"pop" ot
|
+ _Pragma("GCC diagnostic ignored \"-Wint-to-pointer-cast\""); \ |
+ } while (0) |
+ #define LSS_SYSCALL_ARG(a) (sizeof(a) == 8 ? \ |
Mark Seaborn
2013/03/05 17:05:19
If you're disabling the warning, you don't need th
|
+ (uint64_t)(a) : \ |
+ (uint64_t)(uintptr_t)(a)) |
+ #undef LSS_RETURN |
+ #define LSS_RETURN(type, res) \ |
+ do { \ |
+ if ((uint64_t)(res) >= (uint64_t)(-4095)) { \ |
+ LSS_ERRNO = -(res); \ |
+ res = -1; \ |
+ } \ |
+ LSS_SYSCALL_IGNORE_ARG_CASTS(); \ |
+ return (type) (res); \ |
+ } while (0) |
+ #else |
+ #define LSS_SYSCALL_IGNORE_ARG_CASTS() |
+ #define LSS_SYSCALL_ARG(a) ((long)(a)) |
+ #endif |
+ |
/* There are no known problems with any of the _syscallX() macros |
* currently shipping for x86_64, but we still need to be able to define |
* our own version so that we can override the location of the errno |
@@ -1793,7 +1824,8 @@ |
#endif |
#undef LSS_BODY |
#define LSS_BODY(type,name, ...) \ |
- long __res; \ |
+ long long __res; \ |
+ LSS_SYSCALL_IGNORE_ARG_CASTS(); \ |
__asm__ __volatile__(LSS_ENTRYPOINT \ |
: "=a" (__res) : "0" (__NR_##name), \ |
##__VA_ARGS__ : "r11", "rcx", "memory"); \ |
@@ -1806,27 +1838,31 @@ |
#undef _syscall1 |
#define _syscall1(type,name,type1,arg1) \ |
type LSS_NAME(name)(type1 arg1) { \ |
- LSS_BODY(type, name, "D" ((long)(arg1))); \ |
+ LSS_BODY(type, name, "D" (LSS_SYSCALL_ARG(arg1))); \ |
} |
#undef _syscall2 |
#define _syscall2(type,name,type1,arg1,type2,arg2) \ |
type LSS_NAME(name)(type1 arg1, type2 arg2) { \ |
- LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2))); \ |
+ LSS_BODY(type, name, "D" (LSS_SYSCALL_ARG(arg1)), \ |
+ "S" (LSS_SYSCALL_ARG(arg2))); \ |
} |
#undef _syscall3 |
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ |
type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ |
- LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2)), \ |
- "d" ((long)(arg3))); \ |
+ LSS_BODY(type, name, "D" (LSS_SYSCALL_ARG(arg1)), \ |
+ "S" (LSS_SYSCALL_ARG(arg2)), \ |
+ "d" (LSS_SYSCALL_ARG(arg3))); \ |
} |
#undef _syscall4 |
#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ |
type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ |
- long __res; \ |
+ long long __res; \ |
+ LSS_SYSCALL_IGNORE_ARG_CASTS(); \ |
__asm__ __volatile__("movq %5,%%r10;" LSS_ENTRYPOINT : \ |
"=a" (__res) : "0" (__NR_##name), \ |
- "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \ |
- "r" ((long)(arg4)) : "r10", "r11", "rcx", "memory"); \ |
+ "D" (LSS_SYSCALL_ARG(arg1)), "S" (LSS_SYSCALL_ARG(arg2)), \ |
+ "d" (LSS_SYSCALL_ARG(arg3)), "r" (LSS_SYSCALL_ARG(arg4)) \ |
+ : "r10", "r11", "rcx", "memory"); \ |
LSS_RETURN(type, __res); \ |
} |
#undef _syscall5 |
@@ -1834,12 +1870,14 @@ |
type5,arg5) \ |
type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ |
type5 arg5) { \ |
- long __res; \ |
+ long long __res; \ |
+ LSS_SYSCALL_IGNORE_ARG_CASTS(); \ |
__asm__ __volatile__("movq %5,%%r10; movq %6,%%r8;" LSS_ENTRYPOINT :\ |
"=a" (__res) : "0" (__NR_##name), \ |
- "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \ |
- "r" ((long)(arg4)), "r" ((long)(arg5)) : \ |
- "r8", "r10", "r11", "rcx", "memory"); \ |
+ "D" (LSS_SYSCALL_ARG(arg1)), "S" (LSS_SYSCALL_ARG(arg2)), \ |
+ "d" (LSS_SYSCALL_ARG(arg3)), "r" (LSS_SYSCALL_ARG(arg4)), \ |
+ "r" (LSS_SYSCALL_ARG(arg5)) : "r8", "r10", "r11", "rcx", \ |
+ "memory"); \ |
LSS_RETURN(type, __res); \ |
} |
#undef _syscall6 |
@@ -1847,20 +1885,23 @@ |
type5,arg5,type6,arg6) \ |
type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ |
type5 arg5, type6 arg6) { \ |
- long __res; \ |
+ long long __res; \ |
+ LSS_SYSCALL_IGNORE_ARG_CASTS(); \ |
__asm__ __volatile__("movq %5,%%r10; movq %6,%%r8; movq %7,%%r9;" \ |
LSS_ENTRYPOINT : \ |
"=a" (__res) : "0" (__NR_##name), \ |
- "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)), \ |
- "r" ((long)(arg4)), "r" ((long)(arg5)), "r" ((long)(arg6)) : \ |
- "r8", "r9", "r10", "r11", "rcx", "memory"); \ |
+ "D" (LSS_SYSCALL_ARG(arg1)), "S" (LSS_SYSCALL_ARG(arg2)), \ |
+ "d" (LSS_SYSCALL_ARG(arg3)), "r" (LSS_SYSCALL_ARG(arg4)), \ |
+ "r" (LSS_SYSCALL_ARG(arg5)), "r" (LSS_SYSCALL_ARG(arg6)) \ |
+ : "r8", "r9", "r10", "r11", "rcx", "memory"); \ |
LSS_RETURN(type, __res); \ |
} |
LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, |
int flags, void *arg, int *parent_tidptr, |
void *newtls, int *child_tidptr) { |
- long __res; |
+ long long __res; |
{ |
+ LSS_SYSCALL_IGNORE_ARG_CASTS(); |
__asm__ __volatile__(/* if (fn == NULL) |
* return -EINVAL; |
*/ |
@@ -1922,9 +1963,13 @@ |
"1:\n" |
: "=a" (__res) |
: "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit), |
- "r"(fn), "S"(child_stack), "D"(flags), "r"(arg), |
- "d"(parent_tidptr), "r"(newtls), |
- "r"(child_tidptr) |
+ "r"(LSS_SYSCALL_ARG(fn)), |
+ "S"(LSS_SYSCALL_ARG(child_stack)), |
+ "D"(LSS_SYSCALL_ARG(flags)), |
+ "r"(LSS_SYSCALL_ARG(arg)), |
+ "d"(LSS_SYSCALL_ARG(parent_tidptr)), |
+ "r"(LSS_SYSCALL_ARG(newtls)), |
+ "r"(LSS_SYSCALL_ARG(child_tidptr)) |
: "rsp", "memory", "r8", "r10", "r11", "rcx"); |
} |
LSS_RETURN(int, __res); |
@@ -1940,7 +1985,7 @@ |
* Unfortunately, we cannot just reference the glibc version of this |
* function, as glibc goes out of its way to make it inaccessible. |
*/ |
- void (*res)(void); |
+ long long res; |
__asm__ __volatile__("call 2f\n" |
"0:.align 16\n" |
"1:movq %1,%%rax\n" |
@@ -1949,7 +1994,7 @@ |
"addq $(1b-0b),%0\n" |
: "=a" (res) |
: "i" (__NR_rt_sigreturn)); |
- return res; |
+ return (void (*)())(uintptr_t)res; |
} |
#elif defined(__ARM_ARCH_3__) |
/* Most definitions of _syscallX() neglect to mark "memory" as being |