Skip to content

Instantly share code, notes, and snippets.

@petrhosek
Created July 4, 2013 00:14
Show Gist options
  • Save petrhosek/5923952 to your computer and use it in GitHub Desktop.
Save petrhosek/5923952 to your computer and use it in GitHub Desktop.
--- lss.h 2013-04-10 01:28:04.000000000 +0100
+++ linux_syscall_support.h 2013-03-28 15:53:11.131754894 +0000
@@ -103,8 +103,11 @@
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
-#include <stdint.h>
+#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <string.h>
+#else
+#include <libkern.h>
+#endif
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/time.h>
@@ -112,7 +115,213 @@
#include <sys/syscall.h>
#include <unistd.h>
#include <linux/unistd.h>
-#include <endian.h>
+//#include <endian.h>
+//#include <machine/types.h>
+
+/* include/bits/sigstack.h */
+struct kernel_stack_t {
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+};
+
+//typedef __uint32_t uintptr_t;
+//#if !defined(__off64_t)
+//typedef _off64_t __off64_t;
+//#endif
+//typedef __loff_t loff_t;
+
+#ifndef PROT_READ
+#define PROT_READ 0x1 /* page can be read */
+#endif
+#ifndef PROT_WRITE
+#define PROT_WRITE 0x2 /* page can be written */
+#endif
+#ifndef PROT_EXEC
+#define PROT_EXEC 0x4 /* page can be executed */
+#endif
+#ifndef PROT_SEM
+#define PROT_SEM 0x8 /* page may be used for atomic ops */
+#endif
+#ifndef PROT_NONE
+#define PROT_NONE 0x0 /* page can not be accessed */
+#endif
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *) -1)
+#endif
+#ifndef MAP_SHARED
+#define MAP_SHARED 0x01 /* Share changes */
+#endif
+#ifndef MAP_PRIVATE
+#define MAP_PRIVATE 0x02 /* Changes are private */
+#endif
+#ifndef MAP_TYPE
+#define MAP_TYPE 0x0f /* Mask for type of mapping */
+#endif
+#ifndef MAP_FIXED
+#define MAP_FIXED 0x10 /* Interpret addr exactly */
+#endif
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS 0x20 /* don't use a file */
+#endif
+
+#ifndef RLIMIT_CPU
+#define RLIMIT_CPU 0
+#endif
+#ifndef RLIMIT_FSIZE
+#define RLIMIT_FSIZE 1
+#endif
+#ifndef RLIMIT_DATA
+#define RLIMIT_DATA 2
+#endif
+#ifndef RLIMIT_STACK
+#define RLIMIT_STACK 3
+#endif
+#ifndef RLIMIT_CORE
+#define RLIMIT_CORE 4
+#endif
+#ifndef RLIMIT_RSS
+#define RLIMIT_RSS 5
+#endif
+#ifndef RLIMIT_NPROC
+#define RLIMIT_NPROC 6
+#endif
+#ifndef RLIMIT_NOFILE
+#define RLIMIT_NOFILE 7
+#endif
+#ifndef RLIMIT_MEMLOCK
+#define RLIMIT_MEMLOCK 8
+#endif
+#ifndef RLIMIT_AS
+#define RLIMIT_AS 9
+#endif
+#ifndef RLIMIT_LOCKS
+#define RLIMIT_LOCKS 10
+#endif
+#ifndef RLIMIT_SIGPENDING
+#define RLIMIT_SIGPENDING 11
+#endif
+#ifndef RLIMIT_MSGQUEUE
+#define RLIMIT_MSGQUEUE 12
+#endif
+#ifndef RLIMIT_NICE
+#define RLIMIT_NICE 13
+#endif
+#ifndef RLIMIT_RTPRIO
+#define RLIMIT_RTPRIO 14
+#endif
+#ifndef RLIMIT_RTTIME
+#define RLIMIT_RTTIME 15
+#endif
+#ifndef RLIM_NLIMITS
+#define RLIM_NLIMITS 16
+#endif
+#ifndef RLIM_INFINITY
+# define RLIM_INFINITY (~0UL)
+#endif
+
+#ifndef AF_UNSPEC
+#define AF_UNSPEC 0
+#endif
+#ifndef AF_LOCAL
+#define AF_LOCAL 1
+#endif
+#ifndef AF_UNIX
+#define AF_UNIX AF_LOCAL
+#endif
+#ifndef AF_FILE
+#define AF_FILE AF_LOCAL
+#endif
+#ifndef AF_INET
+#define AF_INET 2
+#endif
+
+#ifndef SOCK_STREAM
+#define SOCK_STREAM 1
+#endif
+#ifndef SOCK_DGRAM
+#define SOCK_DGRAM 2
+#endif
+#ifndef SOCK_RAW
+#define SOCK_RAW 3
+#endif
+
+#ifndef MSG_TRUNC
+#define MSG_TRUNC 0x20
+#endif
+#ifndef MSG_CTRUNC
+#define MSG_CTRUNC 0x08
+#endif
+
+#ifndef SA_NOCLDSTOP
+#define SA_NOCLDSTOP 0x00000001u
+#endif
+#ifndef SA_NOCLDWAIT
+#define SA_NOCLDWAIT 0x00000002u
+#endif
+#ifndef SA_SIGINFO
+#define SA_SIGINFO 0x00000004u
+#endif
+#ifndef SA_RESTORER
+#define SA_RESTORER 0x04000000u
+#endif
+#ifndef SA_ONSTACK
+#define SA_ONSTACK 0x08000000u
+#endif
+#ifndef SA_RESTART
+#define SA_RESTART 0x10000000u
+#endif
+#ifndef SA_NODEFER
+#define SA_NODEFER 0x40000000u
+#endif
+#ifndef SA_RESETHAND
+#define SA_RESETHAND 0x80000000u
+#endif
+
+#ifndef __socklen_t_defined
+typedef unsigned int socklen_t;
+#define __socklen_t_defined
+#endif
+
+#ifndef SOL_SOCKET
+#define SOL_SOCKET 1
+#endif
+
+#ifndef SCM_RIGHTS
+#define SCM_RIGHTS 0x01
+#endif
+#ifndef SCM_CREDENTIALS
+#define SCM_CREDENTIALS 0x02
+#endif
+
+#ifndef CMSG_DATA
+#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
+ CMSG_ALIGN(sizeof(struct kernel_cmsghdr)))
+#endif
+#ifndef CMSG_NXTHDR
+#define CMSG_NXTHDR(mhdr, cmsg) \
+ (((unsigned char *)cmsg + CMSG_ALIGN(cmsg)->cmsg_len) + \
+ CMSG_ALIGN(sizeof(struct kernel_cmsghdr)) > \
+ (unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen ? \
+ (struct kernel_cmsghdr *)NULL : \
+ (struct kernel_cmsghdr *)((unsigned char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len)))
+#endif
+#ifndef CMSG_FIRSTHDR
+#define CMSG_FIRSTHDR(mhdr) ((struct kernel_cmsghdr *)(mhdr)->msg_control)
+#endif
+#ifndef CMSG_ALIGN
+#define CMSG_ALIGN(len) (((len) + sizeof(unsigned long) - 1) \
+ & (unsigned long) ~(sizeof(unsigned long) - 1))
+#endif
+#ifndef CMSG_SPACE
+#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct kernel_cmsghdr)) + \
+ CMSG_ALIGN(len))
+#endif
+#ifndef CMSG_LEN
+#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct kernel_cmsghdr)) + (len))
+#endif
+////
#ifdef __mips__
/* Include definitions of the ABI currently in use. */
@@ -196,6 +405,14 @@
unsigned msg_flags;
};
+/* include/bits/socket.h */
+struct kernel_cmsghdr {
+ unsigned long cmsg_len;
+ int cmsg_level;
+ int cmsg_type;
+ unsigned char *cmsg_data;
+};
+
/* include/asm-generic/poll.h */
struct kernel_pollfd {
int fd;
@@ -409,24 +626,24 @@
};
#elif defined(__x86_64__)
struct kernel_stat {
- uint64_t st_dev;
- uint64_t st_ino;
- uint64_t st_nlink;
+ unsigned long st_dev;
+ unsigned long st_ino;
+ unsigned long st_nlink;
unsigned st_mode;
unsigned st_uid;
unsigned st_gid;
unsigned __pad0;
- uint64_t st_rdev;
- int64_t st_size;
- int64_t st_blksize;
- int64_t st_blocks;
- uint64_t st_atime_;
- uint64_t st_atime_nsec_;
- uint64_t st_mtime_;
- uint64_t st_mtime_nsec_;
- uint64_t st_ctime_;
- uint64_t st_ctime_nsec_;
- int64_t __unused[3];
+ unsigned long st_rdev;
+ long st_size;
+ long st_blksize;
+ long st_blocks;
+ unsigned long st_atime_;
+ unsigned long st_atime_nsec_;
+ unsigned long st_mtime_;
+ unsigned long st_mtime_nsec_;
+ unsigned long st_ctime_;
+ unsigned long st_ctime_nsec_;
+ long __unused[3];
};
#elif defined(__PPC__)
struct kernel_stat {
@@ -523,25 +740,11 @@
long f_namelen;
long f_spare[6];
};
-#elif defined(__x86_64__)
+#else
struct kernel_statfs {
/* x86_64 actually defines all these fields as signed, whereas all other */
/* platforms define them as unsigned. Leaving them at unsigned should not */
- /* cause any problems. Make sure these are 64-bit even on x32. */
- uint64_t f_type;
- uint64_t f_bsize;
- uint64_t f_blocks;
- uint64_t f_bfree;
- uint64_t f_bavail;
- uint64_t f_files;
- uint64_t f_ffree;
- struct { int val[2]; } f_fsid;
- uint64_t f_namelen;
- uint64_t f_frsize;
- uint64_t f_spare[5];
-};
-#else
-struct kernel_statfs {
+ /* cause any problems. */
unsigned long f_type;
unsigned long f_bsize;
unsigned long f_blocks;
@@ -592,6 +795,9 @@
#ifndef AT_REMOVEDIR
#define AT_REMOVEDIR 0x200
#endif
+#ifndef MREMAP_MAYMOVE
+#define MREMAP_MAYMOVE 1
+#endif
#ifndef MREMAP_FIXED
#define MREMAP_FIXED 2
#endif
@@ -1600,8 +1806,8 @@
struct { long __a1; long __a6; } __s = { (long)arg1, (long) arg6 }; \
__asm__ __volatile__("push %%ebp\n" \
"push %%ebx\n" \
- "movl 4(%2),%%ebp\n" \
- "movl 0(%2), %%ebx\n" \
+ "leal 4(%2),%%ebp\n" \
+ "movl 0(%2),%%ebx\n" \
"movl %1,%%eax\n" \
LSS_ENTRYPOINT \
"pop %%ebx\n" \
@@ -1805,139 +2011,75 @@
#else
#define LSS_ENTRYPOINT "syscall\n"
#endif
-
- /* 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.
- */
- #undef LSS_SYSCALL_ARG
- #define LSS_SYSCALL_ARG(a) ((uint64_t)(uintptr_t)(a))
- #undef _LSS_RETURN
- #define _LSS_RETURN(type, res, cast) \
- do { \
- if ((uint64_t)(res) >= (uint64_t)(-4095)) { \
- LSS_ERRNO = -(res); \
- res = -1; \
- } \
- return (type)(cast)(res); \
- } while (0)
- #undef LSS_RETURN
- #define LSS_RETURN(type, res) _LSS_RETURN(type, res, uintptr_t)
-
- #undef _LSS_BODY
- #define _LSS_BODY(nr, type, name, cast, ...) \
- long long __res; \
- __asm__ __volatile__(LSS_BODY_ASM##nr LSS_ENTRYPOINT \
- : "=a" (__res) \
- : "0" (__NR_##name) LSS_BODY_ARG##nr(__VA_ARGS__) \
- : LSS_BODY_CLOBBER##nr "r11", "rcx", "memory"); \
- _LSS_RETURN(type, __res, cast)
#undef LSS_BODY
- #define LSS_BODY(nr, type, name, args...) \
- _LSS_BODY(nr, type, name, uintptr_t, ## args)
-
- #undef LSS_BODY_ASM0
- #undef LSS_BODY_ASM1
- #undef LSS_BODY_ASM2
- #undef LSS_BODY_ASM3
- #undef LSS_BODY_ASM4
- #undef LSS_BODY_ASM5
- #undef LSS_BODY_ASM6
- #define LSS_BODY_ASM0
- #define LSS_BODY_ASM1 LSS_BODY_ASM0
- #define LSS_BODY_ASM2 LSS_BODY_ASM1
- #define LSS_BODY_ASM3 LSS_BODY_ASM2
- #define LSS_BODY_ASM4 LSS_BODY_ASM3 "movq %5,%%r10;"
- #define LSS_BODY_ASM5 LSS_BODY_ASM4 "movq %6,%%r8;"
- #define LSS_BODY_ASM6 LSS_BODY_ASM5 "movq %7,%%r9;"
-
- #undef LSS_BODY_CLOBBER0
- #undef LSS_BODY_CLOBBER1
- #undef LSS_BODY_CLOBBER2
- #undef LSS_BODY_CLOBBER3
- #undef LSS_BODY_CLOBBER4
- #undef LSS_BODY_CLOBBER5
- #undef LSS_BODY_CLOBBER6
- #define LSS_BODY_CLOBBER0
- #define LSS_BODY_CLOBBER1 LSS_BODY_CLOBBER0
- #define LSS_BODY_CLOBBER2 LSS_BODY_CLOBBER1
- #define LSS_BODY_CLOBBER3 LSS_BODY_CLOBBER2
- #define LSS_BODY_CLOBBER4 LSS_BODY_CLOBBER3 "r10",
- #define LSS_BODY_CLOBBER5 LSS_BODY_CLOBBER4 "r8",
- #define LSS_BODY_CLOBBER6 LSS_BODY_CLOBBER5 "r9",
-
- #undef LSS_BODY_ARG0
- #undef LSS_BODY_ARG1
- #undef LSS_BODY_ARG2
- #undef LSS_BODY_ARG3
- #undef LSS_BODY_ARG4
- #undef LSS_BODY_ARG5
- #undef LSS_BODY_ARG6
- #define LSS_BODY_ARG0()
- #define LSS_BODY_ARG1(arg1) \
- LSS_BODY_ARG0(), "D" (arg1)
- #define LSS_BODY_ARG2(arg1, arg2) \
- LSS_BODY_ARG1(arg1), "S" (arg2)
- #define LSS_BODY_ARG3(arg1, arg2, arg3) \
- LSS_BODY_ARG2(arg1, arg2), "d" (arg3)
- #define LSS_BODY_ARG4(arg1, arg2, arg3, arg4) \
- LSS_BODY_ARG3(arg1, arg2, arg3), "r" (arg4)
- #define LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5) \
- LSS_BODY_ARG4(arg1, arg2, arg3, arg4), "r" (arg5)
- #define LSS_BODY_ARG6(arg1, arg2, arg3, arg4, arg5, arg6) \
- LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5), "r" (arg6)
-
+ #define LSS_BODY(type,name, ...) \
+ long __res; \
+ __asm__ __volatile__(LSS_ENTRYPOINT \
+ : "=a" (__res) : "0" (__NR_##name), \
+ ##__VA_ARGS__ : "r11", "rcx", "memory"); \
+ LSS_RETURN(type, __res)
#undef _syscall0
#define _syscall0(type,name) \
- type LSS_NAME(name)(void) { \
- LSS_BODY(0, type, name); \
+ type LSS_NAME(name)() { \
+ LSS_BODY(type, name); \
}
#undef _syscall1
#define _syscall1(type,name,type1,arg1) \
type LSS_NAME(name)(type1 arg1) { \
- LSS_BODY(1, type, name, LSS_SYSCALL_ARG(arg1)); \
+ LSS_BODY(type, name, "D" ((long)(arg1))); \
}
#undef _syscall2
#define _syscall2(type,name,type1,arg1,type2,arg2) \
type LSS_NAME(name)(type1 arg1, type2 arg2) { \
- LSS_BODY(2, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2));\
+ LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(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(3, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
- LSS_SYSCALL_ARG(arg3)); \
+ LSS_BODY(type, name, "D" ((long)(arg1)), "S" ((long)(arg2)), \
+ "d" ((long)(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) { \
- LSS_BODY(4, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
- LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4));\
+ long __res; \
+ __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"); \
+ LSS_RETURN(type, __res); \
}
#undef _syscall5
#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5) \
type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
type5 arg5) { \
- LSS_BODY(5, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
- LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \
- LSS_SYSCALL_ARG(arg5)); \
+ long __res; \
+ __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"); \
+ LSS_RETURN(type, __res); \
}
#undef _syscall6
#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
type5,arg5,type6,arg6) \
type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
type5 arg5, type6 arg6) { \
- LSS_BODY(6, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \
- LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \
- LSS_SYSCALL_ARG(arg5), LSS_SYSCALL_ARG(arg6));\
+ long __res; \
+ __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"); \
+ 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 long __res;
+ long __res;
{
__asm__ __volatile__(/* if (fn == NULL)
* return -EINVAL;
@@ -2000,25 +2142,16 @@
"1:\n"
: "=a" (__res)
: "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
- "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))
+ "r"(fn), "S"(child_stack), "D"(flags), "r"(arg),
+ "d"(parent_tidptr), "r"(newtls),
+ "r"(child_tidptr)
: "rsp", "memory", "r8", "r10", "r11", "rcx");
}
LSS_RETURN(int, __res);
}
LSS_INLINE _syscall2(int, arch_prctl, int, c, void *, a)
-
- /* Need to make sure loff_t isn't truncated to 32-bits under x32. */
- LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset, loff_t len,
- int advice) {
- LSS_BODY(4, int, fadvise64, LSS_SYSCALL_ARG(fd), (uint64_t)(offset),
- (uint64_t)(len), LSS_SYSCALL_ARG(advice));
- }
+ LSS_INLINE _syscall4(int, fadvise64, int, fd, loff_t, offset, loff_t, len,
+ int, advice)
LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) {
/* On x86-64, the kernel does not know how to return from
@@ -2027,7 +2160,7 @@
* Unfortunately, we cannot just reference the glibc version of this
* function, as glibc goes out of its way to make it inaccessible.
*/
- long long res;
+ void (*res)(void);
__asm__ __volatile__("call 2f\n"
"0:.align 16\n"
"1:movq %1,%%rax\n"
@@ -2036,7 +2169,7 @@
"addq $(1b-0b),%0\n"
: "=a" (res)
: "i" (__NR_rt_sigreturn));
- return (void (*)(void))(uintptr_t)res;
+ return res;
}
#elif defined(__ARM_ARCH_3__)
/* Most definitions of _syscallX() neglect to mark "memory" as being
@@ -2056,7 +2189,7 @@
LSS_RETURN(type, __res)
#undef _syscall0
#define _syscall0(type, name) \
- type LSS_NAME(name)(void) { \
+ type LSS_NAME(name)() { \
LSS_BODY(type, name); \
}
#undef _syscall1
@@ -2182,7 +2315,7 @@
LSS_RETURN(type, __res)
#undef _syscall0
#define _syscall0(type, name) \
- type LSS_NAME(name)(void) { \
+ type LSS_NAME(name)() { \
LSS_BODY(type, name); \
}
#undef _syscall1
@@ -2332,7 +2465,7 @@
LSS_RETURN(type, __v0, __r7)
#undef _syscall0
#define _syscall0(type, name) \
- type LSS_NAME(name)(void) { \
+ type LSS_NAME(name)() { \
register unsigned long __r7 __asm__("$7"); \
LSS_BODY(type, name, "=r"); \
}
@@ -2525,7 +2658,7 @@
#else
"daddu $29,16\n"
#endif
- : "+r" (__v0), "+r" (__r7)
+ : "=&r" (__v0), "+r" (__r7)
: "i"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),
"r"(fn), "r"(__stack), "r"(__flags), "r"(arg),
"r"(__ptid), "r"(__r7), "r"(__ctid)
@@ -2721,7 +2854,7 @@
#define __NR__exit __NR_exit
#define __NR__gettid __NR_gettid
#define __NR__mremap __NR_mremap
- LSS_INLINE _syscall1(int, brk, void *, e)
+ LSS_INLINE _syscall1(void *, brk, void *, e)
LSS_INLINE _syscall1(int, chdir, const char *,p)
LSS_INLINE _syscall1(int, close, int, f)
LSS_INLINE _syscall2(int, clock_getres, int, c,
@@ -2742,15 +2875,8 @@
struct kernel_stat*, b)
LSS_INLINE _syscall2(int, fstatfs, int, f,
struct kernel_statfs*, b)
- #if defined(__x86_64__)
- /* Need to make sure off_t isn't truncated to 32-bits under x32. */
- LSS_INLINE int LSS_NAME(ftruncate)(int f, off_t l) {
- LSS_BODY(2, int, ftruncate, LSS_SYSCALL_ARG(f), (uint64_t)(l));
- }
- #else
- LSS_INLINE _syscall2(int, ftruncate, int, f,
- off_t, l)
- #endif
+ LSS_INLINE _syscall2(int, ftruncate, int, f,
+ off_t, l)
LSS_INLINE _syscall4(int, futex, int*, a,
int, o, int, v,
struct kernel_timespec*, t)
@@ -2799,16 +2925,8 @@
int, who, int, ioprio)
LSS_INLINE _syscall2(int, kill, pid_t, p,
int, s)
- #if defined(__x86_64__)
- /* Need to make sure off_t isn't truncated to 32-bits under x32. */
- LSS_INLINE off_t LSS_NAME(lseek)(int f, off_t o, int w) {
- _LSS_BODY(3, off_t, lseek, off_t, LSS_SYSCALL_ARG(f), (uint64_t)(o),
- LSS_SYSCALL_ARG(w));
- }
- #else
- LSS_INLINE _syscall3(off_t, lseek, int, f,
- off_t, o, int, w)
- #endif
+ LSS_INLINE _syscall3(off_t, lseek, int, f,
+ off_t, o, int, w)
LSS_INLINE _syscall2(int, munmap, void*, s,
size_t, l)
LSS_INLINE _syscall6(long, move_pages, pid_t, p,
@@ -2867,8 +2985,9 @@
LSS_INLINE _syscall2(int, setrlimit, int, r,
const struct kernel_rlimit*, l)
LSS_INLINE _syscall0(pid_t, setsid)
- LSS_INLINE _syscall2(int, sigaltstack, const stack_t*, s,
- const stack_t*, o)
+ LSS_INLINE _syscall2(int, sigaltstack,
+ const struct kernel_stack_t*, s,
+ const struct kernel_stack_t*, o)
#if defined(__NR_sigreturn)
LSS_INLINE _syscall1(int, sigreturn, unsigned long, u)
#endif
@@ -2907,12 +3026,8 @@
int, t, int, p, int*, s)
#endif
#if defined(__x86_64__)
- /* Need to make sure loff_t isn't truncated to 32-bits under x32. */
- LSS_INLINE int LSS_NAME(fallocate)(int f, int mode, loff_t offset,
- loff_t len) {
- LSS_BODY(4, int, fallocate, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(mode),
- (uint64_t)(offset), (uint64_t)(len));
- }
+ LSS_INLINE _syscall4(int, fallocate, int, fd, int, mode,
+ loff_t, offset, loff_t, len)
LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid,
gid_t *egid,
@@ -2926,13 +3041,10 @@
return LSS_NAME(getresuid)(ruid, euid, suid);
}
- /* Need to make sure __off64_t isn't truncated to 32-bits under x32. */
- LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d,
- __off64_t o) {
- LSS_BODY(6, void*, mmap, LSS_SYSCALL_ARG(s), LSS_SYSCALL_ARG(l),
- LSS_SYSCALL_ARG(p), LSS_SYSCALL_ARG(f),
- LSS_SYSCALL_ARG(d), (uint64_t)(o));
- }
+ LSS_INLINE _syscall6(void*, mmap, void*, s,
+ size_t, l, int, p,
+ int, f, int, d,
+ __off64_t, o)
LSS_INLINE _syscall4(int, newfstatat, int, d,
const char *, p,
@@ -3505,7 +3617,7 @@
return LSS_NAME(execve)(path, argv, (const char *const *)environ);
}
- LSS_INLINE pid_t LSS_NAME(gettid)(void) {
+ LSS_INLINE pid_t LSS_NAME(gettid)() {
pid_t tid = LSS_NAME(_gettid)();
if (tid != -1) {
return tid;
@@ -3552,7 +3664,7 @@
return LSS_NAME(kill)(LSS_NAME(getpid)(), sig);
}
- LSS_INLINE int LSS_NAME(setpgrp)(void) {
+ LSS_INLINE int LSS_NAME(setpgrp)() {
return LSS_NAME(setpgid)(0, 0);
}
@@ -3576,24 +3688,8 @@
return -1;
}
}
- #if defined(__x86_64__)
- /* Need to make sure loff_t isn't truncated to 32-bits under x32. */
- LSS_INLINE ssize_t LSS_NAME(pread64)(int f, void *b, size_t c, loff_t o) {
- LSS_BODY(4, ssize_t, pread64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b),
- LSS_SYSCALL_ARG(c), (uint64_t)(o));
- }
-
- LSS_INLINE ssize_t LSS_NAME(pwrite64)(int f, const void *b, size_t c,
- loff_t o) {
- LSS_BODY(4, ssize_t, pwrite64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b),
- LSS_SYSCALL_ARG(c), (uint64_t)(o));
- }
-
- LSS_INLINE int LSS_NAME(readahead)(int f, loff_t o, unsigned c) {
- LSS_BODY(3, int, readahead, LSS_SYSCALL_ARG(f), (uint64_t)(o),
- LSS_SYSCALL_ARG(c));
- }
- #elif defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64
+ #if defined(__x86_64__) || \
+ (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64)
LSS_INLINE _syscall4(ssize_t, pread64, int, f,
void *, b, size_t, c,
loff_t, o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment