diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-02-13 22:45:42 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-02-13 22:45:42 -0500 |
commit | 2cdfb7ca26f46f151afbc23d5d94fc68597137f5 (patch) | |
tree | 0baa2cd0776f2a44997950e0bc8ab646dc2067b2 /src | |
parent | 978ca016593077d27cc2a828f21c5e45e57074aa (diff) | |
download | musl-2cdfb7ca26f46f151afbc23d5d94fc68597137f5.tar.gz musl-2cdfb7ca26f46f151afbc23d5d94fc68597137f5.tar.bz2 musl-2cdfb7ca26f46f151afbc23d5d94fc68597137f5.tar.xz musl-2cdfb7ca26f46f151afbc23d5d94fc68597137f5.zip |
cleaning up syscalls in preparation for x86_64 port
- hide all the legacy xxxxxx32 name cruft in syscall.h so the actual
source files can be clean and uniform across all archs.
- cleanup llseek/lseek and mmap2/mmap handling for 32/64 bit systems
- alternate implementation for nice if the target lacks nice syscall
Diffstat (limited to 'src')
-rw-r--r-- | src/internal/syscall.h | 49 | ||||
-rw-r--r-- | src/linux/setgroups.c | 4 | ||||
-rw-r--r-- | src/mman/mmap.c | 4 | ||||
-rw-r--r-- | src/stdio/__stdio_seek.c | 8 | ||||
-rw-r--r-- | src/unistd/chown.c | 2 | ||||
-rw-r--r-- | src/unistd/fchown.c | 2 | ||||
-rw-r--r-- | src/unistd/getegid.c | 2 | ||||
-rw-r--r-- | src/unistd/geteuid.c | 2 | ||||
-rw-r--r-- | src/unistd/getgid.c | 2 | ||||
-rw-r--r-- | src/unistd/getgroups.c | 3 | ||||
-rw-r--r-- | src/unistd/getuid.c | 2 | ||||
-rw-r--r-- | src/unistd/lchown.c | 2 | ||||
-rw-r--r-- | src/unistd/lseek.c | 13 | ||||
-rw-r--r-- | src/unistd/nice.c | 5 | ||||
-rw-r--r-- | src/unistd/setgid.c | 4 | ||||
-rw-r--r-- | src/unistd/setregid.c | 4 | ||||
-rw-r--r-- | src/unistd/setreuid.c | 4 | ||||
-rw-r--r-- | src/unistd/setuid.c | 4 |
18 files changed, 79 insertions, 37 deletions
diff --git a/src/internal/syscall.h b/src/internal/syscall.h index 4b3c0a73..901263ba 100644 --- a/src/internal/syscall.h +++ b/src/internal/syscall.h @@ -439,6 +439,46 @@ static inline long syscall6(long n, long a1, long a2, long a3, long a4, long a5, #define __NR_preadv 333 #define __NR_pwritev 334 +/* fixup legacy 16-bit junk */ +#undef __NR_lchown +#undef __NR_getuid +#undef __NR_getgid +#undef __NR_geteuid +#undef __NR_getegid +#undef __NR_setreuid +#undef __NR_setregid +#undef __NR_getgroups +#undef __NR_setgroups +#undef __NR_fchown +#undef __NR_setresuid +#undef __NR_getresuid +#undef __NR_setresgid +#undef __NR_getresgid +#undef __NR_chown +#undef __NR_setuid +#undef __NR_setgid +#undef __NR_setfsuid +#undef __NR_setfsgid +#define __NR_lchown __NR_lchown32 +#define __NR_getuid __NR_getuid32 +#define __NR_getgid __NR_getgid32 +#define __NR_geteuid __NR_geteuid32 +#define __NR_getegid __NR_getegid32 +#define __NR_setreuid __NR_setreuid32 +#define __NR_setregid __NR_setregid32 +#define __NR_getgroups __NR_getgroups32 +#define __NR_setgroups __NR_setgroups32 +#define __NR_fchown __NR_fchown32 +#define __NR_setresuid __NR_setresuid32 +#define __NR_getresuid __NR_getresuid32 +#define __NR_setresgid __NR_setresgid32 +#define __NR_getresgid __NR_getresgid32 +#define __NR_chown __NR_chown32 +#define __NR_setuid __NR_setuid32 +#define __NR_setgid __NR_setgid32 +#define __NR_setfsuid __NR_setfsuid32 +#define __NR_setfsgid __NR_setfsgid32 + #undef O_LARGEFILE #define O_LARGEFILE 0100000 @@ -457,13 +497,4 @@ static inline long syscall6(long n, long a1, long a2, long a3, long a4, long a5, #define __syscall_ioctl(fd,ioc,arg) syscall3(__NR_ioctl, (fd), (ioc), (long)(arg)) #define __syscall_exit(code) syscall1(__NR_exit, code) -#define __NEED_off_t -#include <bits/alltypes.h> - -static inline off_t __syscall_lseek(int fd, off_t offset, int whence) -{ - off_t result; - return syscall5(__NR__llseek, fd, offset>>32, offset, (long)&result, whence) ? -1 : result; -} - #endif diff --git a/src/linux/setgroups.c b/src/linux/setgroups.c index 2368aa0d..4d578013 100644 --- a/src/linux/setgroups.c +++ b/src/linux/setgroups.c @@ -1,9 +1,7 @@ #include <unistd.h> -#define SYSCALL_STANDALONE #include "syscall.h" int setgroups(int count, const gid_t list[]) { - /* this depends on our gid_t being 32bit */ - return syscall2(__NR_setgroups32, count, (long)list); + return syscall2(__NR_setgroups, count, (long)list); } diff --git a/src/mman/mmap.c b/src/mman/mmap.c index 93c76582..5be6e12d 100644 --- a/src/mman/mmap.c +++ b/src/mman/mmap.c @@ -10,7 +10,11 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) if (sizeof(off_t) > sizeof(long)) if (((long)off & 0xfff) | ((long)((unsigned long long)off>>(12 + 8*(sizeof(off_t)-sizeof(long)))))) start = (void *)-1; +#ifdef __NR_mmap2 return (void *)syscall6(__NR_mmap2, (long)start, len, prot, flags, fd, off>>12); +#else + return (void *)syscall6(__NR_mmap, (long)start, len, prot, flags, fd, off); +#endif } weak_alias(__mmap, mmap); diff --git a/src/stdio/__stdio_seek.c b/src/stdio/__stdio_seek.c index fdb9fe7f..c7a5b730 100644 --- a/src/stdio/__stdio_seek.c +++ b/src/stdio/__stdio_seek.c @@ -7,7 +7,13 @@ static off_t retneg1(FILE *f, off_t off, int whence) off_t __stdio_seek(FILE *f, off_t off, int whence) { - off_t ret = __syscall_lseek(f->fd, off, whence); + off_t ret; +#ifdef __NR__llseek + if (syscall5(__NR__llseek, f->fd, off>>32, off, (long)&ret, whence)<0) + ret = -1; +#else + ret = syscall3(__NR_lseek, f->fd, off, whence); +#endif /* Detect unseekable files and optimize future failures out */ if (ret < 0 && off == 0 && whence == SEEK_CUR) f->seek = retneg1; diff --git a/src/unistd/chown.c b/src/unistd/chown.c index 6069a2fe..b89b1735 100644 --- a/src/unistd/chown.c +++ b/src/unistd/chown.c @@ -3,5 +3,5 @@ int chown(const char *path, uid_t uid, gid_t gid) { - return syscall3(__NR_chown32, (long)path, uid, gid); + return syscall3(__NR_chown, (long)path, uid, gid); } diff --git a/src/unistd/fchown.c b/src/unistd/fchown.c index 990f006d..6050b774 100644 --- a/src/unistd/fchown.c +++ b/src/unistd/fchown.c @@ -3,5 +3,5 @@ int fchown(int fd, uid_t uid, gid_t gid) { - return syscall3(__NR_fchown32, fd, uid, gid); + return syscall3(__NR_fchown, fd, uid, gid); } diff --git a/src/unistd/getegid.c b/src/unistd/getegid.c index 0e626b75..33ee2057 100644 --- a/src/unistd/getegid.c +++ b/src/unistd/getegid.c @@ -3,5 +3,5 @@ gid_t getegid(void) { - return syscall0(__NR_getegid32); + return syscall0(__NR_getegid); } diff --git a/src/unistd/geteuid.c b/src/unistd/geteuid.c index 39d6ac7b..cdec631a 100644 --- a/src/unistd/geteuid.c +++ b/src/unistd/geteuid.c @@ -3,5 +3,5 @@ uid_t geteuid(void) { - return syscall0(__NR_geteuid32); + return syscall0(__NR_geteuid); } diff --git a/src/unistd/getgid.c b/src/unistd/getgid.c index 186635a2..8a4590be 100644 --- a/src/unistd/getgid.c +++ b/src/unistd/getgid.c @@ -3,5 +3,5 @@ gid_t getgid(void) { - return syscall0(__NR_getgid32); + return syscall0(__NR_getgid); } diff --git a/src/unistd/getgroups.c b/src/unistd/getgroups.c index 6f19870e..37619b9a 100644 --- a/src/unistd/getgroups.c +++ b/src/unistd/getgroups.c @@ -3,6 +3,5 @@ int getgroups(int count, gid_t list[]) { - /* this depends on our gid_t being 32bit */ - return syscall2(__NR_getgroups32, count, (long)list); + return syscall2(__NR_getgroups, count, (long)list); } diff --git a/src/unistd/getuid.c b/src/unistd/getuid.c index 9d4e53f5..cd7233d1 100644 --- a/src/unistd/getuid.c +++ b/src/unistd/getuid.c @@ -3,5 +3,5 @@ uid_t getuid(void) { - return syscall0(__NR_getuid32); + return syscall0(__NR_getuid); } diff --git a/src/unistd/lchown.c b/src/unistd/lchown.c index 30e83916..a8402132 100644 --- a/src/unistd/lchown.c +++ b/src/unistd/lchown.c @@ -3,5 +3,5 @@ int lchown(const char *path, uid_t uid, gid_t gid) { - return syscall3(__NR_lchown32, (long)path, uid, gid); + return syscall3(__NR_lchown, (long)path, uid, gid); } diff --git a/src/unistd/lseek.c b/src/unistd/lseek.c index 0dab2679..0152866f 100644 --- a/src/unistd/lseek.c +++ b/src/unistd/lseek.c @@ -4,13 +4,12 @@ off_t lseek(int fd, off_t offset, int whence) { - /* optimized away at compiletime */ - if (sizeof(long) == 8) - return syscall3(__NR_lseek, fd, offset, whence); - else { - off_t result; - return syscall5(__NR__llseek, fd, offset>>32, offset, (long)&result, whence) ? -1 : result; - } +#ifdef __NR__llseek + off_t result; + return syscall5(__NR__llseek, fd, offset>>32, offset, (long)&result, whence) ? -1 : result; +#else + return syscall3(__NR_lseek, fd, offset, whence); +#endif } LFS64(lseek); diff --git a/src/unistd/nice.c b/src/unistd/nice.c index 4b28ef41..f38db678 100644 --- a/src/unistd/nice.c +++ b/src/unistd/nice.c @@ -1,7 +1,12 @@ #include <unistd.h> +#include <sys/resource.h> #include "syscall.h" int nice(int inc) { +#ifdef __NR_nice return syscall1(__NR_nice, inc); +#else + return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc); +#endif } diff --git a/src/unistd/setgid.c b/src/unistd/setgid.c index 00c7a03a..42976d95 100644 --- a/src/unistd/setgid.c +++ b/src/unistd/setgid.c @@ -4,6 +4,6 @@ int setgid(gid_t gid) { - if (libc.rsyscall) return libc.rsyscall(__NR_setgid32, gid, 0, 0, 0, 0, 0); - return syscall1(__NR_setgid32, gid); + if (libc.rsyscall) return libc.rsyscall(__NR_setgid, gid, 0, 0, 0, 0, 0); + return syscall1(__NR_setgid, gid); } diff --git a/src/unistd/setregid.c b/src/unistd/setregid.c index d25dab76..158753be 100644 --- a/src/unistd/setregid.c +++ b/src/unistd/setregid.c @@ -4,6 +4,6 @@ int setregid(gid_t rgid, gid_t egid) { - if (libc.rsyscall) return libc.rsyscall(__NR_setregid32, rgid, egid, 0, 0, 0, 0); - return syscall2(__NR_setregid32, rgid, egid); + if (libc.rsyscall) return libc.rsyscall(__NR_setregid, rgid, egid, 0, 0, 0, 0); + return syscall2(__NR_setregid, rgid, egid); } diff --git a/src/unistd/setreuid.c b/src/unistd/setreuid.c index 0ba2277b..47c67306 100644 --- a/src/unistd/setreuid.c +++ b/src/unistd/setreuid.c @@ -4,6 +4,6 @@ int setreuid(uid_t ruid, uid_t euid) { - if (libc.rsyscall) return libc.rsyscall(__NR_setreuid32, ruid, euid, 0, 0, 0, 0); - return syscall2(__NR_setreuid32, ruid, euid); + if (libc.rsyscall) return libc.rsyscall(__NR_setreuid, ruid, euid, 0, 0, 0, 0); + return syscall2(__NR_setreuid, ruid, euid); } diff --git a/src/unistd/setuid.c b/src/unistd/setuid.c index 53b74d88..9e9da61f 100644 --- a/src/unistd/setuid.c +++ b/src/unistd/setuid.c @@ -4,6 +4,6 @@ int setuid(uid_t uid) { - if (libc.rsyscall) return libc.rsyscall(__NR_setuid32, uid, 0, 0, 0, 0, 0); - return syscall1(__NR_setuid32, uid); + if (libc.rsyscall) return libc.rsyscall(__NR_setuid, uid, 0, 0, 0, 0, 0); + return syscall1(__NR_setuid, uid); } |