提交 2cdfb7ca 编写于 作者: R Rich Felker

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
上级 978ca016
......@@ -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
#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);
}
......@@ -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);
......
......@@ -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;
......
......@@ -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);
}
......@@ -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);
}
......@@ -3,5 +3,5 @@
gid_t getegid(void)
{
return syscall0(__NR_getegid32);
return syscall0(__NR_getegid);
}
......@@ -3,5 +3,5 @@
uid_t geteuid(void)
{
return syscall0(__NR_geteuid32);
return syscall0(__NR_geteuid);
}
......@@ -3,5 +3,5 @@
gid_t getgid(void)
{
return syscall0(__NR_getgid32);
return syscall0(__NR_getgid);
}
......@@ -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);
}
......@@ -3,5 +3,5 @@
uid_t getuid(void)
{
return syscall0(__NR_getuid32);
return syscall0(__NR_getuid);
}
......@@ -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);
}
......@@ -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);
#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
}
......@@ -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);
}
......@@ -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);
}
......@@ -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);
}
......@@ -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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册