From 8c1ab65c0f548d20b7f177bdb736daaf603340e1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 15:54:38 +0200 Subject: Adding upstream version 0.0~git20221206.8b7148f. Signed-off-by: Daniel Baumann --- libc-top-half/musl/src/unistd/_exit.c | 7 +++ libc-top-half/musl/src/unistd/access.c | 12 ++++++ libc-top-half/musl/src/unistd/acct.c | 8 ++++ libc-top-half/musl/src/unistd/alarm.c | 10 +++++ libc-top-half/musl/src/unistd/chdir.c | 7 +++ libc-top-half/musl/src/unistd/chown.c | 12 ++++++ libc-top-half/musl/src/unistd/close.c | 19 +++++++++ libc-top-half/musl/src/unistd/ctermid.c | 7 +++ libc-top-half/musl/src/unistd/dup.c | 7 +++ libc-top-half/musl/src/unistd/dup2.c | 20 +++++++++ libc-top-half/musl/src/unistd/dup3.c | 24 +++++++++++ libc-top-half/musl/src/unistd/faccessat.c | 61 +++++++++++++++++++++++++++ libc-top-half/musl/src/unistd/fchdir.c | 15 +++++++ libc-top-half/musl/src/unistd/fchown.c | 20 +++++++++ libc-top-half/musl/src/unistd/fchownat.c | 7 +++ libc-top-half/musl/src/unistd/fdatasync.c | 7 +++ libc-top-half/musl/src/unistd/fsync.c | 7 +++ libc-top-half/musl/src/unistd/ftruncate.c | 9 ++++ libc-top-half/musl/src/unistd/getcwd.c | 25 +++++++++++ libc-top-half/musl/src/unistd/getegid.c | 7 +++ libc-top-half/musl/src/unistd/geteuid.c | 7 +++ libc-top-half/musl/src/unistd/getgid.c | 7 +++ libc-top-half/musl/src/unistd/getgroups.c | 7 +++ libc-top-half/musl/src/unistd/gethostname.c | 13 ++++++ libc-top-half/musl/src/unistd/getlogin.c | 7 +++ libc-top-half/musl/src/unistd/getlogin_r.c | 12 ++++++ libc-top-half/musl/src/unistd/getpgid.c | 7 +++ libc-top-half/musl/src/unistd/getpgrp.c | 7 +++ libc-top-half/musl/src/unistd/getpid.c | 7 +++ libc-top-half/musl/src/unistd/getppid.c | 7 +++ libc-top-half/musl/src/unistd/getsid.c | 7 +++ libc-top-half/musl/src/unistd/getuid.c | 7 +++ libc-top-half/musl/src/unistd/isatty.c | 13 ++++++ libc-top-half/musl/src/unistd/lchown.c | 12 ++++++ libc-top-half/musl/src/unistd/link.c | 12 ++++++ libc-top-half/musl/src/unistd/linkat.c | 7 +++ libc-top-half/musl/src/unistd/lseek.c | 23 ++++++++++ libc-top-half/musl/src/unistd/mips/pipe.s | 20 +++++++++ libc-top-half/musl/src/unistd/mips64/pipe.s | 19 +++++++++ libc-top-half/musl/src/unistd/mipsn32/lseek.c | 20 +++++++++ libc-top-half/musl/src/unistd/mipsn32/pipe.s | 19 +++++++++ libc-top-half/musl/src/unistd/nice.c | 23 ++++++++++ libc-top-half/musl/src/unistd/pause.c | 11 +++++ libc-top-half/musl/src/unistd/pipe.c | 11 +++++ libc-top-half/musl/src/unistd/pipe2.c | 22 ++++++++++ libc-top-half/musl/src/unistd/posix_close.c | 6 +++ libc-top-half/musl/src/unistd/pread.c | 9 ++++ libc-top-half/musl/src/unistd/preadv.c | 12 ++++++ libc-top-half/musl/src/unistd/pwrite.c | 9 ++++ libc-top-half/musl/src/unistd/pwritev.c | 12 ++++++ libc-top-half/musl/src/unistd/read.c | 7 +++ libc-top-half/musl/src/unistd/readlink.c | 19 +++++++++ libc-top-half/musl/src/unistd/readlinkat.c | 14 ++++++ libc-top-half/musl/src/unistd/readv.c | 7 +++ libc-top-half/musl/src/unistd/renameat.c | 11 +++++ libc-top-half/musl/src/unistd/rmdir.c | 12 ++++++ libc-top-half/musl/src/unistd/setegid.c | 8 ++++ libc-top-half/musl/src/unistd/seteuid.c | 8 ++++ libc-top-half/musl/src/unistd/setgid.c | 8 ++++ libc-top-half/musl/src/unistd/setpgid.c | 7 +++ libc-top-half/musl/src/unistd/setpgrp.c | 6 +++ libc-top-half/musl/src/unistd/setregid.c | 8 ++++ libc-top-half/musl/src/unistd/setresgid.c | 9 ++++ libc-top-half/musl/src/unistd/setresuid.c | 9 ++++ libc-top-half/musl/src/unistd/setreuid.c | 8 ++++ libc-top-half/musl/src/unistd/setsid.c | 7 +++ libc-top-half/musl/src/unistd/setuid.c | 8 ++++ libc-top-half/musl/src/unistd/setxid.c | 34 +++++++++++++++ libc-top-half/musl/src/unistd/sh/pipe.s | 27 ++++++++++++ libc-top-half/musl/src/unistd/sleep.c | 10 +++++ libc-top-half/musl/src/unistd/symlink.c | 12 ++++++ libc-top-half/musl/src/unistd/symlinkat.c | 7 +++ libc-top-half/musl/src/unistd/sync.c | 7 +++ libc-top-half/musl/src/unistd/tcgetpgrp.c | 11 +++++ libc-top-half/musl/src/unistd/tcsetpgrp.c | 9 ++++ libc-top-half/musl/src/unistd/truncate.c | 9 ++++ libc-top-half/musl/src/unistd/ttyname.c | 14 ++++++ libc-top-half/musl/src/unistd/ttyname_r.c | 28 ++++++++++++ libc-top-half/musl/src/unistd/ualarm.c | 13 ++++++ libc-top-half/musl/src/unistd/unlink.c | 12 ++++++ libc-top-half/musl/src/unistd/unlinkat.c | 7 +++ libc-top-half/musl/src/unistd/usleep.c | 12 ++++++ libc-top-half/musl/src/unistd/write.c | 7 +++ libc-top-half/musl/src/unistd/writev.c | 7 +++ libc-top-half/musl/src/unistd/x32/lseek.c | 15 +++++++ 85 files changed, 1043 insertions(+) create mode 100644 libc-top-half/musl/src/unistd/_exit.c create mode 100644 libc-top-half/musl/src/unistd/access.c create mode 100644 libc-top-half/musl/src/unistd/acct.c create mode 100644 libc-top-half/musl/src/unistd/alarm.c create mode 100644 libc-top-half/musl/src/unistd/chdir.c create mode 100644 libc-top-half/musl/src/unistd/chown.c create mode 100644 libc-top-half/musl/src/unistd/close.c create mode 100644 libc-top-half/musl/src/unistd/ctermid.c create mode 100644 libc-top-half/musl/src/unistd/dup.c create mode 100644 libc-top-half/musl/src/unistd/dup2.c create mode 100644 libc-top-half/musl/src/unistd/dup3.c create mode 100644 libc-top-half/musl/src/unistd/faccessat.c create mode 100644 libc-top-half/musl/src/unistd/fchdir.c create mode 100644 libc-top-half/musl/src/unistd/fchown.c create mode 100644 libc-top-half/musl/src/unistd/fchownat.c create mode 100644 libc-top-half/musl/src/unistd/fdatasync.c create mode 100644 libc-top-half/musl/src/unistd/fsync.c create mode 100644 libc-top-half/musl/src/unistd/ftruncate.c create mode 100644 libc-top-half/musl/src/unistd/getcwd.c create mode 100644 libc-top-half/musl/src/unistd/getegid.c create mode 100644 libc-top-half/musl/src/unistd/geteuid.c create mode 100644 libc-top-half/musl/src/unistd/getgid.c create mode 100644 libc-top-half/musl/src/unistd/getgroups.c create mode 100644 libc-top-half/musl/src/unistd/gethostname.c create mode 100644 libc-top-half/musl/src/unistd/getlogin.c create mode 100644 libc-top-half/musl/src/unistd/getlogin_r.c create mode 100644 libc-top-half/musl/src/unistd/getpgid.c create mode 100644 libc-top-half/musl/src/unistd/getpgrp.c create mode 100644 libc-top-half/musl/src/unistd/getpid.c create mode 100644 libc-top-half/musl/src/unistd/getppid.c create mode 100644 libc-top-half/musl/src/unistd/getsid.c create mode 100644 libc-top-half/musl/src/unistd/getuid.c create mode 100644 libc-top-half/musl/src/unistd/isatty.c create mode 100644 libc-top-half/musl/src/unistd/lchown.c create mode 100644 libc-top-half/musl/src/unistd/link.c create mode 100644 libc-top-half/musl/src/unistd/linkat.c create mode 100644 libc-top-half/musl/src/unistd/lseek.c create mode 100644 libc-top-half/musl/src/unistd/mips/pipe.s create mode 100644 libc-top-half/musl/src/unistd/mips64/pipe.s create mode 100644 libc-top-half/musl/src/unistd/mipsn32/lseek.c create mode 100644 libc-top-half/musl/src/unistd/mipsn32/pipe.s create mode 100644 libc-top-half/musl/src/unistd/nice.c create mode 100644 libc-top-half/musl/src/unistd/pause.c create mode 100644 libc-top-half/musl/src/unistd/pipe.c create mode 100644 libc-top-half/musl/src/unistd/pipe2.c create mode 100644 libc-top-half/musl/src/unistd/posix_close.c create mode 100644 libc-top-half/musl/src/unistd/pread.c create mode 100644 libc-top-half/musl/src/unistd/preadv.c create mode 100644 libc-top-half/musl/src/unistd/pwrite.c create mode 100644 libc-top-half/musl/src/unistd/pwritev.c create mode 100644 libc-top-half/musl/src/unistd/read.c create mode 100644 libc-top-half/musl/src/unistd/readlink.c create mode 100644 libc-top-half/musl/src/unistd/readlinkat.c create mode 100644 libc-top-half/musl/src/unistd/readv.c create mode 100644 libc-top-half/musl/src/unistd/renameat.c create mode 100644 libc-top-half/musl/src/unistd/rmdir.c create mode 100644 libc-top-half/musl/src/unistd/setegid.c create mode 100644 libc-top-half/musl/src/unistd/seteuid.c create mode 100644 libc-top-half/musl/src/unistd/setgid.c create mode 100644 libc-top-half/musl/src/unistd/setpgid.c create mode 100644 libc-top-half/musl/src/unistd/setpgrp.c create mode 100644 libc-top-half/musl/src/unistd/setregid.c create mode 100644 libc-top-half/musl/src/unistd/setresgid.c create mode 100644 libc-top-half/musl/src/unistd/setresuid.c create mode 100644 libc-top-half/musl/src/unistd/setreuid.c create mode 100644 libc-top-half/musl/src/unistd/setsid.c create mode 100644 libc-top-half/musl/src/unistd/setuid.c create mode 100644 libc-top-half/musl/src/unistd/setxid.c create mode 100644 libc-top-half/musl/src/unistd/sh/pipe.s create mode 100644 libc-top-half/musl/src/unistd/sleep.c create mode 100644 libc-top-half/musl/src/unistd/symlink.c create mode 100644 libc-top-half/musl/src/unistd/symlinkat.c create mode 100644 libc-top-half/musl/src/unistd/sync.c create mode 100644 libc-top-half/musl/src/unistd/tcgetpgrp.c create mode 100644 libc-top-half/musl/src/unistd/tcsetpgrp.c create mode 100644 libc-top-half/musl/src/unistd/truncate.c create mode 100644 libc-top-half/musl/src/unistd/ttyname.c create mode 100644 libc-top-half/musl/src/unistd/ttyname_r.c create mode 100644 libc-top-half/musl/src/unistd/ualarm.c create mode 100644 libc-top-half/musl/src/unistd/unlink.c create mode 100644 libc-top-half/musl/src/unistd/unlinkat.c create mode 100644 libc-top-half/musl/src/unistd/usleep.c create mode 100644 libc-top-half/musl/src/unistd/write.c create mode 100644 libc-top-half/musl/src/unistd/writev.c create mode 100644 libc-top-half/musl/src/unistd/x32/lseek.c (limited to 'libc-top-half/musl/src/unistd') diff --git a/libc-top-half/musl/src/unistd/_exit.c b/libc-top-half/musl/src/unistd/_exit.c new file mode 100644 index 0000000..7699482 --- /dev/null +++ b/libc-top-half/musl/src/unistd/_exit.c @@ -0,0 +1,7 @@ +#include +#include + +_Noreturn void _exit(int status) +{ + _Exit(status); +} diff --git a/libc-top-half/musl/src/unistd/access.c b/libc-top-half/musl/src/unistd/access.c new file mode 100644 index 0000000..d6eed68 --- /dev/null +++ b/libc-top-half/musl/src/unistd/access.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int access(const char *filename, int amode) +{ +#ifdef SYS_access + return syscall(SYS_access, filename, amode); +#else + return syscall(SYS_faccessat, AT_FDCWD, filename, amode, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/acct.c b/libc-top-half/musl/src/unistd/acct.c new file mode 100644 index 0000000..308ffc3 --- /dev/null +++ b/libc-top-half/musl/src/unistd/acct.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int acct(const char *filename) +{ + return syscall(SYS_acct, filename); +} diff --git a/libc-top-half/musl/src/unistd/alarm.c b/libc-top-half/musl/src/unistd/alarm.c new file mode 100644 index 0000000..a5e0c82 --- /dev/null +++ b/libc-top-half/musl/src/unistd/alarm.c @@ -0,0 +1,10 @@ +#include +#include +#include "syscall.h" + +unsigned alarm(unsigned seconds) +{ + struct itimerval it = { .it_value.tv_sec = seconds }, old = { 0 }; + setitimer(ITIMER_REAL, &it, &old); + return old.it_value.tv_sec + !!old.it_value.tv_usec; +} diff --git a/libc-top-half/musl/src/unistd/chdir.c b/libc-top-half/musl/src/unistd/chdir.c new file mode 100644 index 0000000..5ba78b6 --- /dev/null +++ b/libc-top-half/musl/src/unistd/chdir.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int chdir(const char *path) +{ + return syscall(SYS_chdir, path); +} diff --git a/libc-top-half/musl/src/unistd/chown.c b/libc-top-half/musl/src/unistd/chown.c new file mode 100644 index 0000000..14b0325 --- /dev/null +++ b/libc-top-half/musl/src/unistd/chown.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int chown(const char *path, uid_t uid, gid_t gid) +{ +#ifdef SYS_chown + return syscall(SYS_chown, path, uid, gid); +#else + return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/close.c b/libc-top-half/musl/src/unistd/close.c new file mode 100644 index 0000000..a2105f5 --- /dev/null +++ b/libc-top-half/musl/src/unistd/close.c @@ -0,0 +1,19 @@ +#include +#include +#include "aio_impl.h" +#include "syscall.h" + +static int dummy(int fd) +{ + return fd; +} + +weak_alias(dummy, __aio_close); + +int close(int fd) +{ + fd = __aio_close(fd); + int r = __syscall_cp(SYS_close, fd); + if (r == -EINTR) r = 0; + return __syscall_ret(r); +} diff --git a/libc-top-half/musl/src/unistd/ctermid.c b/libc-top-half/musl/src/unistd/ctermid.c new file mode 100644 index 0000000..1612770 --- /dev/null +++ b/libc-top-half/musl/src/unistd/ctermid.c @@ -0,0 +1,7 @@ +#include +#include + +char *ctermid(char *s) +{ + return s ? strcpy(s, "/dev/tty") : "/dev/tty"; +} diff --git a/libc-top-half/musl/src/unistd/dup.c b/libc-top-half/musl/src/unistd/dup.c new file mode 100644 index 0000000..7fee012 --- /dev/null +++ b/libc-top-half/musl/src/unistd/dup.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int dup(int fd) +{ + return syscall(SYS_dup, fd); +} diff --git a/libc-top-half/musl/src/unistd/dup2.c b/libc-top-half/musl/src/unistd/dup2.c new file mode 100644 index 0000000..8f43c6d --- /dev/null +++ b/libc-top-half/musl/src/unistd/dup2.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "syscall.h" + +int dup2(int old, int new) +{ + int r; +#ifdef SYS_dup2 + while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); +#else + if (old==new) { + r = __syscall(SYS_fcntl, old, F_GETFD); + if (r >= 0) return old; + } else { + while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY); + } +#endif + return __syscall_ret(r); +} diff --git a/libc-top-half/musl/src/unistd/dup3.c b/libc-top-half/musl/src/unistd/dup3.c new file mode 100644 index 0000000..f919f79 --- /dev/null +++ b/libc-top-half/musl/src/unistd/dup3.c @@ -0,0 +1,24 @@ +#define _GNU_SOURCE +#include +#include +#include +#include "syscall.h" + +int __dup3(int old, int new, int flags) +{ + int r; +#ifdef SYS_dup2 + if (old==new) return __syscall_ret(-EINVAL); + if (flags & O_CLOEXEC) { + while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); + if (r!=-ENOSYS) return __syscall_ret(r); + } + while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); + if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC); +#else + while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); +#endif + return __syscall_ret(r); +} + +weak_alias(__dup3, dup3); diff --git a/libc-top-half/musl/src/unistd/faccessat.c b/libc-top-half/musl/src/unistd/faccessat.c new file mode 100644 index 0000000..557503e --- /dev/null +++ b/libc-top-half/musl/src/unistd/faccessat.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include "syscall.h" +#include "pthread_impl.h" + +struct ctx { + int fd; + const char *filename; + int amode; + int p; +}; + +static int checker(void *p) +{ + struct ctx *c = p; + int ret; + if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1) + || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1)) + __syscall(SYS_exit, 1); + ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0); + __syscall(SYS_write, c->p, &ret, sizeof ret); + return 0; +} + +int faccessat(int fd, const char *filename, int amode, int flag) +{ + if (flag) { + int ret = __syscall(SYS_faccessat2, fd, filename, amode, flag); + if (ret != -ENOSYS) return __syscall_ret(ret); + } + + if (flag & ~AT_EACCESS) + return __syscall_ret(-EINVAL); + + if (!flag || (getuid()==geteuid() && getgid()==getegid())) + return syscall(SYS_faccessat, fd, filename, amode); + + char stack[1024]; + sigset_t set; + pid_t pid; + int status; + int ret, p[2]; + + if (pipe2(p, O_CLOEXEC)) return __syscall_ret(-EBUSY); + struct ctx c = { .fd = fd, .filename = filename, .amode = amode, .p = p[1] }; + + __block_all_sigs(&set); + + pid = __clone(checker, stack+sizeof stack, 0, &c); + __syscall(SYS_close, p[1]); + + if (pid<0 || __syscall(SYS_read, p[0], &ret, sizeof ret) != sizeof(ret)) + ret = -EBUSY; + __syscall(SYS_close, p[0]); + __syscall(SYS_wait4, pid, &status, __WCLONE, 0); + + __restore_sigs(&set); + + return __syscall_ret(ret); +} diff --git a/libc-top-half/musl/src/unistd/fchdir.c b/libc-top-half/musl/src/unistd/fchdir.c new file mode 100644 index 0000000..dee45ba --- /dev/null +++ b/libc-top-half/musl/src/unistd/fchdir.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include "syscall.h" + +int fchdir(int fd) +{ + int ret = __syscall(SYS_fchdir, fd); + if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) + return __syscall_ret(ret); + + char buf[15+3*sizeof(int)]; + __procfdname(buf, fd); + return syscall(SYS_chdir, buf); +} diff --git a/libc-top-half/musl/src/unistd/fchown.c b/libc-top-half/musl/src/unistd/fchown.c new file mode 100644 index 0000000..737b367 --- /dev/null +++ b/libc-top-half/musl/src/unistd/fchown.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "syscall.h" + +int fchown(int fd, uid_t uid, gid_t gid) +{ + int ret = __syscall(SYS_fchown, fd, uid, gid); + if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) + return __syscall_ret(ret); + + char buf[15+3*sizeof(int)]; + __procfdname(buf, fd); +#ifdef SYS_chown + return syscall(SYS_chown, buf, uid, gid); +#else + return syscall(SYS_fchownat, AT_FDCWD, buf, uid, gid, 0); +#endif + +} diff --git a/libc-top-half/musl/src/unistd/fchownat.c b/libc-top-half/musl/src/unistd/fchownat.c new file mode 100644 index 0000000..62457a3 --- /dev/null +++ b/libc-top-half/musl/src/unistd/fchownat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag) +{ + return syscall(SYS_fchownat, fd, path, uid, gid, flag); +} diff --git a/libc-top-half/musl/src/unistd/fdatasync.c b/libc-top-half/musl/src/unistd/fdatasync.c new file mode 100644 index 0000000..3895ae5 --- /dev/null +++ b/libc-top-half/musl/src/unistd/fdatasync.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fdatasync(int fd) +{ + return syscall_cp(SYS_fdatasync, fd); +} diff --git a/libc-top-half/musl/src/unistd/fsync.c b/libc-top-half/musl/src/unistd/fsync.c new file mode 100644 index 0000000..7a1c80b --- /dev/null +++ b/libc-top-half/musl/src/unistd/fsync.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fsync(int fd) +{ + return syscall_cp(SYS_fsync, fd); +} diff --git a/libc-top-half/musl/src/unistd/ftruncate.c b/libc-top-half/musl/src/unistd/ftruncate.c new file mode 100644 index 0000000..b41be0f --- /dev/null +++ b/libc-top-half/musl/src/unistd/ftruncate.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" + +int ftruncate(int fd, off_t length) +{ + return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length)); +} + +weak_alias(ftruncate, ftruncate64); diff --git a/libc-top-half/musl/src/unistd/getcwd.c b/libc-top-half/musl/src/unistd/getcwd.c new file mode 100644 index 0000000..f407ffe --- /dev/null +++ b/libc-top-half/musl/src/unistd/getcwd.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include "syscall.h" + +char *getcwd(char *buf, size_t size) +{ + char tmp[buf ? 1 : PATH_MAX]; + if (!buf) { + buf = tmp; + size = sizeof tmp; + } else if (!size) { + errno = EINVAL; + return 0; + } + long ret = syscall(SYS_getcwd, buf, size); + if (ret < 0) + return 0; + if (ret == 0 || buf[0] != '/') { + errno = ENOENT; + return 0; + } + return buf == tmp ? strdup(buf) : buf; +} diff --git a/libc-top-half/musl/src/unistd/getegid.c b/libc-top-half/musl/src/unistd/getegid.c new file mode 100644 index 0000000..6287490 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getegid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +gid_t getegid(void) +{ + return __syscall(SYS_getegid); +} diff --git a/libc-top-half/musl/src/unistd/geteuid.c b/libc-top-half/musl/src/unistd/geteuid.c new file mode 100644 index 0000000..88f2cd5 --- /dev/null +++ b/libc-top-half/musl/src/unistd/geteuid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +uid_t geteuid(void) +{ + return __syscall(SYS_geteuid); +} diff --git a/libc-top-half/musl/src/unistd/getgid.c b/libc-top-half/musl/src/unistd/getgid.c new file mode 100644 index 0000000..1c9fe71 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getgid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +gid_t getgid(void) +{ + return __syscall(SYS_getgid); +} diff --git a/libc-top-half/musl/src/unistd/getgroups.c b/libc-top-half/musl/src/unistd/getgroups.c new file mode 100644 index 0000000..0e6e63a --- /dev/null +++ b/libc-top-half/musl/src/unistd/getgroups.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int getgroups(int count, gid_t list[]) +{ + return syscall(SYS_getgroups, count, list); +} diff --git a/libc-top-half/musl/src/unistd/gethostname.c b/libc-top-half/musl/src/unistd/gethostname.c new file mode 100644 index 0000000..633ef57 --- /dev/null +++ b/libc-top-half/musl/src/unistd/gethostname.c @@ -0,0 +1,13 @@ +#include +#include + +int gethostname(char *name, size_t len) +{ + size_t i; + struct utsname uts; + if (uname(&uts)) return -1; + if (len > sizeof uts.nodename) len = sizeof uts.nodename; + for (i=0; i +#include + +char *getlogin(void) +{ + return getenv("LOGNAME"); +} diff --git a/libc-top-half/musl/src/unistd/getlogin_r.c b/libc-top-half/musl/src/unistd/getlogin_r.c new file mode 100644 index 0000000..53866c6 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getlogin_r.c @@ -0,0 +1,12 @@ +#include +#include +#include + +int getlogin_r(char *name, size_t size) +{ + char *logname = getlogin(); + if (!logname) return ENXIO; /* or...? */ + if (strlen(logname) >= size) return ERANGE; + strcpy(name, logname); + return 0; +} diff --git a/libc-top-half/musl/src/unistd/getpgid.c b/libc-top-half/musl/src/unistd/getpgid.c new file mode 100644 index 0000000..d295bfd --- /dev/null +++ b/libc-top-half/musl/src/unistd/getpgid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getpgid(pid_t pid) +{ + return syscall(SYS_getpgid, pid); +} diff --git a/libc-top-half/musl/src/unistd/getpgrp.c b/libc-top-half/musl/src/unistd/getpgrp.c new file mode 100644 index 0000000..90e9bb0 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getpgrp.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getpgrp(void) +{ + return __syscall(SYS_getpgid, 0); +} diff --git a/libc-top-half/musl/src/unistd/getpid.c b/libc-top-half/musl/src/unistd/getpid.c new file mode 100644 index 0000000..a6d4e6d --- /dev/null +++ b/libc-top-half/musl/src/unistd/getpid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getpid(void) +{ + return __syscall(SYS_getpid); +} diff --git a/libc-top-half/musl/src/unistd/getppid.c b/libc-top-half/musl/src/unistd/getppid.c new file mode 100644 index 0000000..05cade5 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getppid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getppid(void) +{ + return __syscall(SYS_getppid); +} diff --git a/libc-top-half/musl/src/unistd/getsid.c b/libc-top-half/musl/src/unistd/getsid.c new file mode 100644 index 0000000..93ba690 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getsid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getsid(pid_t pid) +{ + return syscall(SYS_getsid, pid); +} diff --git a/libc-top-half/musl/src/unistd/getuid.c b/libc-top-half/musl/src/unistd/getuid.c new file mode 100644 index 0000000..61309d1 --- /dev/null +++ b/libc-top-half/musl/src/unistd/getuid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +uid_t getuid(void) +{ + return __syscall(SYS_getuid); +} diff --git a/libc-top-half/musl/src/unistd/isatty.c b/libc-top-half/musl/src/unistd/isatty.c new file mode 100644 index 0000000..75a9c18 --- /dev/null +++ b/libc-top-half/musl/src/unistd/isatty.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include "syscall.h" + +int isatty(int fd) +{ + struct winsize wsz; + unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz); + if (r == 0) return 1; + if (errno != EBADF) errno = ENOTTY; + return 0; +} diff --git a/libc-top-half/musl/src/unistd/lchown.c b/libc-top-half/musl/src/unistd/lchown.c new file mode 100644 index 0000000..ccd5ee0 --- /dev/null +++ b/libc-top-half/musl/src/unistd/lchown.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int lchown(const char *path, uid_t uid, gid_t gid) +{ +#ifdef SYS_lchown + return syscall(SYS_lchown, path, uid, gid); +#else + return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW); +#endif +} diff --git a/libc-top-half/musl/src/unistd/link.c b/libc-top-half/musl/src/unistd/link.c new file mode 100644 index 0000000..feec18e --- /dev/null +++ b/libc-top-half/musl/src/unistd/link.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int link(const char *existing, const char *new) +{ +#ifdef SYS_link + return syscall(SYS_link, existing, new); +#else + return syscall(SYS_linkat, AT_FDCWD, existing, AT_FDCWD, new, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/linkat.c b/libc-top-half/musl/src/unistd/linkat.c new file mode 100644 index 0000000..6a9a0b7 --- /dev/null +++ b/libc-top-half/musl/src/unistd/linkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int linkat(int fd1, const char *existing, int fd2, const char *new, int flag) +{ + return syscall(SYS_linkat, fd1, existing, fd2, new, flag); +} diff --git a/libc-top-half/musl/src/unistd/lseek.c b/libc-top-half/musl/src/unistd/lseek.c new file mode 100644 index 0000000..48a638a --- /dev/null +++ b/libc-top-half/musl/src/unistd/lseek.c @@ -0,0 +1,23 @@ +#include +#include "syscall.h" + +off_t __lseek(int fd, off_t offset, int whence) +{ +#ifdef SYS__llseek + off_t result; +#ifdef __wasilibc_unmodified_upstream // WASI has no syscall + return syscall(SYS__llseek, fd, offset>>32, offset, &result, whence) ? -1 : result; +#else + return llseek(fd, offset>>32, offset, &result, whence) ? -1 : result; +#endif +#else +#ifdef __wasilibc_unmodified_upstream // WASI has no syscall + return syscall(SYS_lseek, fd, offset, whence); +#else + return lseek(fd, offset, whence); +#endif +#endif +} + +weak_alias(__lseek, lseek); +weak_alias(__lseek, lseek64); diff --git a/libc-top-half/musl/src/unistd/mips/pipe.s b/libc-top-half/musl/src/unistd/mips/pipe.s new file mode 100644 index 0000000..ba2c39a --- /dev/null +++ b/libc-top-half/musl/src/unistd/mips/pipe.s @@ -0,0 +1,20 @@ +.set noreorder + +.global pipe +.type pipe,@function +pipe: + lui $gp, %hi(_gp_disp) + addiu $gp, %lo(_gp_disp) + addu $gp, $gp, $25 + li $2, 4042 + syscall + beq $7, $0, 1f + nop + lw $25, %call16(__syscall_ret)($gp) + jr $25 + subu $4, $0, $2 +1: sw $2, 0($4) + sw $3, 4($4) + move $2, $0 + jr $ra + nop diff --git a/libc-top-half/musl/src/unistd/mips64/pipe.s b/libc-top-half/musl/src/unistd/mips64/pipe.s new file mode 100644 index 0000000..f8a27dc --- /dev/null +++ b/libc-top-half/musl/src/unistd/mips64/pipe.s @@ -0,0 +1,19 @@ +.set noreorder +.global pipe +.type pipe,@function +pipe: + lui $3, %hi(%neg(%gp_rel(pipe))) + daddiu $3, $3, %lo(%neg(%gp_rel(pipe))) + daddu $3, $3, $25 + li $2, 5021 + syscall + beq $7, $0, 1f + nop + ld $25, %got_disp(__syscall_ret)($3) + jr $25 + dsubu $4, $0, $2 +1: sw $2, 0($4) + sw $3, 4($4) + move $2, $0 + jr $ra + nop diff --git a/libc-top-half/musl/src/unistd/mipsn32/lseek.c b/libc-top-half/musl/src/unistd/mipsn32/lseek.c new file mode 100644 index 0000000..60e74a5 --- /dev/null +++ b/libc-top-half/musl/src/unistd/mipsn32/lseek.c @@ -0,0 +1,20 @@ +#include +#include "syscall.h" + +off_t __lseek(int fd, off_t offset, int whence) +{ + register long long r4 __asm__("$4") = fd; + register long long r5 __asm__("$5") = offset; + register long long r6 __asm__("$6") = whence; + register long long r7 __asm__("$7"); + register long long r2 __asm__("$2") = SYS_lseek; + __asm__ __volatile__ ( + "syscall" + : "+&r"(r2), "=r"(r7) + : "r"(r4), "r"(r5), "r"(r6) + : SYSCALL_CLOBBERLIST); + return r7 ? __syscall_ret(-r2) : r2; +} + +weak_alias(__lseek, lseek); +weak_alias(__lseek, lseek64); diff --git a/libc-top-half/musl/src/unistd/mipsn32/pipe.s b/libc-top-half/musl/src/unistd/mipsn32/pipe.s new file mode 100644 index 0000000..80f882e --- /dev/null +++ b/libc-top-half/musl/src/unistd/mipsn32/pipe.s @@ -0,0 +1,19 @@ +.set noreorder +.global pipe +.type pipe,@function +pipe: + lui $3, %hi(%neg(%gp_rel(pipe))) + addiu $3, $3, %lo(%neg(%gp_rel(pipe))) + addu $3, $3, $25 + li $2, 6021 + syscall + beq $7, $0, 1f + nop + lw $25, %got_disp(__syscall_ret)($3) + jr $25 + subu $4, $0, $2 +1: sw $2, 0($4) + sw $3, 4($4) + move $2, $0 + jr $ra + nop diff --git a/libc-top-half/musl/src/unistd/nice.c b/libc-top-half/musl/src/unistd/nice.c new file mode 100644 index 0000000..1c2295f --- /dev/null +++ b/libc-top-half/musl/src/unistd/nice.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include "syscall.h" + +int nice(int inc) +{ + int prio = inc; + // Only query old priority if it can affect the result. + // This also avoids issues with integer overflow. + if (inc > -2*NZERO && inc < 2*NZERO) + prio += getpriority(PRIO_PROCESS, 0); + if (prio > NZERO-1) prio = NZERO-1; + if (prio < -NZERO) prio = -NZERO; + if (setpriority(PRIO_PROCESS, 0, prio)) { + if (errno == EACCES) + errno = EPERM; + return -1; + } else { + return prio; + } +} diff --git a/libc-top-half/musl/src/unistd/pause.c b/libc-top-half/musl/src/unistd/pause.c new file mode 100644 index 0000000..90bbf4c --- /dev/null +++ b/libc-top-half/musl/src/unistd/pause.c @@ -0,0 +1,11 @@ +#include +#include "syscall.h" + +int pause(void) +{ +#ifdef SYS_pause + return syscall_cp(SYS_pause); +#else + return syscall_cp(SYS_ppoll, 0, 0, 0, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/pipe.c b/libc-top-half/musl/src/unistd/pipe.c new file mode 100644 index 0000000..d07b8d2 --- /dev/null +++ b/libc-top-half/musl/src/unistd/pipe.c @@ -0,0 +1,11 @@ +#include +#include "syscall.h" + +int pipe(int fd[2]) +{ +#ifdef SYS_pipe + return syscall(SYS_pipe, fd); +#else + return syscall(SYS_pipe2, fd, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/pipe2.c b/libc-top-half/musl/src/unistd/pipe2.c new file mode 100644 index 0000000..f24f74f --- /dev/null +++ b/libc-top-half/musl/src/unistd/pipe2.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include "syscall.h" + +int pipe2(int fd[2], int flag) +{ + if (!flag) return pipe(fd); + int ret = __syscall(SYS_pipe2, fd, flag); + if (ret != -ENOSYS) return __syscall_ret(ret); + ret = pipe(fd); + if (ret) return ret; + if (flag & O_CLOEXEC) { + __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); + __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); + } + if (flag & O_NONBLOCK) { + __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); + __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); + } + return 0; +} diff --git a/libc-top-half/musl/src/unistd/posix_close.c b/libc-top-half/musl/src/unistd/posix_close.c new file mode 100644 index 0000000..90f51a8 --- /dev/null +++ b/libc-top-half/musl/src/unistd/posix_close.c @@ -0,0 +1,6 @@ +#include + +int posix_close(int fd, int flags) +{ + return close(fd); +} diff --git a/libc-top-half/musl/src/unistd/pread.c b/libc-top-half/musl/src/unistd/pread.c new file mode 100644 index 0000000..5681b04 --- /dev/null +++ b/libc-top-half/musl/src/unistd/pread.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" + +ssize_t pread(int fd, void *buf, size_t size, off_t ofs) +{ + return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs)); +} + +weak_alias(pread, pread64); diff --git a/libc-top-half/musl/src/unistd/preadv.c b/libc-top-half/musl/src/unistd/preadv.c new file mode 100644 index 0000000..8376d60 --- /dev/null +++ b/libc-top-half/musl/src/unistd/preadv.c @@ -0,0 +1,12 @@ +#define _BSD_SOURCE +#include +#include +#include "syscall.h" + +ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs) +{ + return syscall_cp(SYS_preadv, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); +} + +weak_alias(preadv, preadv64); diff --git a/libc-top-half/musl/src/unistd/pwrite.c b/libc-top-half/musl/src/unistd/pwrite.c new file mode 100644 index 0000000..ca37657 --- /dev/null +++ b/libc-top-half/musl/src/unistd/pwrite.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" + +ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) +{ + return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs)); +} + +weak_alias(pwrite, pwrite64); diff --git a/libc-top-half/musl/src/unistd/pwritev.c b/libc-top-half/musl/src/unistd/pwritev.c new file mode 100644 index 0000000..f5a612c --- /dev/null +++ b/libc-top-half/musl/src/unistd/pwritev.c @@ -0,0 +1,12 @@ +#define _BSD_SOURCE +#include +#include +#include "syscall.h" + +ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) +{ + return syscall_cp(SYS_pwritev, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); +} + +weak_alias(pwritev, pwritev64); diff --git a/libc-top-half/musl/src/unistd/read.c b/libc-top-half/musl/src/unistd/read.c new file mode 100644 index 0000000..f3589c0 --- /dev/null +++ b/libc-top-half/musl/src/unistd/read.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t read(int fd, void *buf, size_t count) +{ + return syscall_cp(SYS_read, fd, buf, count); +} diff --git a/libc-top-half/musl/src/unistd/readlink.c b/libc-top-half/musl/src/unistd/readlink.c new file mode 100644 index 0000000..32f4537 --- /dev/null +++ b/libc-top-half/musl/src/unistd/readlink.c @@ -0,0 +1,19 @@ +#include +#include +#include "syscall.h" + +ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) +{ + char dummy[1]; + if (!bufsize) { + buf = dummy; + bufsize = 1; + } +#ifdef SYS_readlink + int r = __syscall(SYS_readlink, path, buf, bufsize); +#else + int r = __syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize); +#endif + if (buf == dummy && r > 0) r = 0; + return __syscall_ret(r); +} diff --git a/libc-top-half/musl/src/unistd/readlinkat.c b/libc-top-half/musl/src/unistd/readlinkat.c new file mode 100644 index 0000000..f79d3d1 --- /dev/null +++ b/libc-top-half/musl/src/unistd/readlinkat.c @@ -0,0 +1,14 @@ +#include +#include "syscall.h" + +ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) +{ + char dummy[1]; + if (!bufsize) { + buf = dummy; + bufsize = 1; + } + int r = __syscall(SYS_readlinkat, fd, path, buf, bufsize); + if (buf == dummy && r > 0) r = 0; + return __syscall_ret(r); +} diff --git a/libc-top-half/musl/src/unistd/readv.c b/libc-top-half/musl/src/unistd/readv.c new file mode 100644 index 0000000..91e6de8 --- /dev/null +++ b/libc-top-half/musl/src/unistd/readv.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t readv(int fd, const struct iovec *iov, int count) +{ + return syscall_cp(SYS_readv, fd, iov, count); +} diff --git a/libc-top-half/musl/src/unistd/renameat.c b/libc-top-half/musl/src/unistd/renameat.c new file mode 100644 index 0000000..c3b40a2 --- /dev/null +++ b/libc-top-half/musl/src/unistd/renameat.c @@ -0,0 +1,11 @@ +#include +#include "syscall.h" + +int renameat(int oldfd, const char *old, int newfd, const char *new) +{ +#ifdef SYS_renameat + return syscall(SYS_renameat, oldfd, old, newfd, new); +#else + return syscall(SYS_renameat2, oldfd, old, newfd, new, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/rmdir.c b/libc-top-half/musl/src/unistd/rmdir.c new file mode 100644 index 0000000..6825ffc --- /dev/null +++ b/libc-top-half/musl/src/unistd/rmdir.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int rmdir(const char *path) +{ +#ifdef SYS_rmdir + return syscall(SYS_rmdir, path); +#else + return syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); +#endif +} diff --git a/libc-top-half/musl/src/unistd/setegid.c b/libc-top-half/musl/src/unistd/setegid.c new file mode 100644 index 0000000..e6da257 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setegid.c @@ -0,0 +1,8 @@ +#include +#include "libc.h" +#include "syscall.h" + +int setegid(gid_t egid) +{ + return __setxid(SYS_setresgid, -1, egid, -1); +} diff --git a/libc-top-half/musl/src/unistd/seteuid.c b/libc-top-half/musl/src/unistd/seteuid.c new file mode 100644 index 0000000..ef8b9df --- /dev/null +++ b/libc-top-half/musl/src/unistd/seteuid.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" +#include "libc.h" + +int seteuid(uid_t euid) +{ + return __setxid(SYS_setresuid, -1, euid, -1); +} diff --git a/libc-top-half/musl/src/unistd/setgid.c b/libc-top-half/musl/src/unistd/setgid.c new file mode 100644 index 0000000..bae4616 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setgid.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setgid(gid_t gid) +{ + return __setxid(SYS_setgid, gid, 0, 0); +} diff --git a/libc-top-half/musl/src/unistd/setpgid.c b/libc-top-half/musl/src/unistd/setpgid.c new file mode 100644 index 0000000..0616069 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setpgid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int setpgid(pid_t pid, pid_t pgid) +{ + return syscall(SYS_setpgid, pid, pgid); +} diff --git a/libc-top-half/musl/src/unistd/setpgrp.c b/libc-top-half/musl/src/unistd/setpgrp.c new file mode 100644 index 0000000..a2a37f6 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setpgrp.c @@ -0,0 +1,6 @@ +#include + +pid_t setpgrp(void) +{ + return setpgid(0, 0); +} diff --git a/libc-top-half/musl/src/unistd/setregid.c b/libc-top-half/musl/src/unistd/setregid.c new file mode 100644 index 0000000..f5a8972 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setregid.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setregid(gid_t rgid, gid_t egid) +{ + return __setxid(SYS_setregid, rgid, egid, 0); +} diff --git a/libc-top-half/musl/src/unistd/setresgid.c b/libc-top-half/musl/src/unistd/setresgid.c new file mode 100644 index 0000000..b9af540 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setresgid.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" +#include "libc.h" + +int setresgid(gid_t rgid, gid_t egid, gid_t sgid) +{ + return __setxid(SYS_setresgid, rgid, egid, sgid); +} diff --git a/libc-top-half/musl/src/unistd/setresuid.c b/libc-top-half/musl/src/unistd/setresuid.c new file mode 100644 index 0000000..83692b4 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setresuid.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" +#include "libc.h" + +int setresuid(uid_t ruid, uid_t euid, uid_t suid) +{ + return __setxid(SYS_setresuid, ruid, euid, suid); +} diff --git a/libc-top-half/musl/src/unistd/setreuid.c b/libc-top-half/musl/src/unistd/setreuid.c new file mode 100644 index 0000000..3fcc59e --- /dev/null +++ b/libc-top-half/musl/src/unistd/setreuid.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setreuid(uid_t ruid, uid_t euid) +{ + return __setxid(SYS_setreuid, ruid, euid, 0); +} diff --git a/libc-top-half/musl/src/unistd/setsid.c b/libc-top-half/musl/src/unistd/setsid.c new file mode 100644 index 0000000..609bbe4 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setsid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t setsid(void) +{ + return syscall(SYS_setsid); +} diff --git a/libc-top-half/musl/src/unistd/setuid.c b/libc-top-half/musl/src/unistd/setuid.c new file mode 100644 index 0000000..602ecbb --- /dev/null +++ b/libc-top-half/musl/src/unistd/setuid.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setuid(uid_t uid) +{ + return __setxid(SYS_setuid, uid, 0, 0); +} diff --git a/libc-top-half/musl/src/unistd/setxid.c b/libc-top-half/musl/src/unistd/setxid.c new file mode 100644 index 0000000..487c1a1 --- /dev/null +++ b/libc-top-half/musl/src/unistd/setxid.c @@ -0,0 +1,34 @@ +#include +#include +#include "syscall.h" +#include "libc.h" + +struct ctx { + int id, eid, sid; + int nr, ret; +}; + +static void do_setxid(void *p) +{ + struct ctx *c = p; + if (c->ret<0) return; + int ret = __syscall(c->nr, c->id, c->eid, c->sid); + if (ret && !c->ret) { + /* If one thread fails to set ids after another has already + * succeeded, forcibly killing the process is the only safe + * thing to do. State is inconsistent and dangerous. Use + * SIGKILL because it is uncatchable. */ + __block_all_sigs(0); + __syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL); + } + c->ret = ret; +} + +int __setxid(int nr, int id, int eid, int sid) +{ + /* ret is initially nonzero so that failure of the first thread does not + * trigger the safety kill above. */ + struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .ret = 1 }; + __synccall(do_setxid, &c); + return __syscall_ret(c.ret); +} diff --git a/libc-top-half/musl/src/unistd/sh/pipe.s b/libc-top-half/musl/src/unistd/sh/pipe.s new file mode 100644 index 0000000..46c4908 --- /dev/null +++ b/libc-top-half/musl/src/unistd/sh/pipe.s @@ -0,0 +1,27 @@ +.global pipe +.type pipe, @function +pipe: + mov #42, r3 + trapa #31 + + ! work around hardware bug + or r0, r0 + or r0, r0 + or r0, r0 + or r0, r0 + or r0, r0 + + cmp/pz r0 + bt 1f + + mov.l L1, r1 + braf r1 + mov r0, r4 + +1: mov.l r0, @(0,r4) + mov.l r1, @(4,r4) + rts + mov #0, r0 + +.align 2 +L1: .long __syscall_ret@PLT-(1b-.) diff --git a/libc-top-half/musl/src/unistd/sleep.c b/libc-top-half/musl/src/unistd/sleep.c new file mode 100644 index 0000000..d645094 --- /dev/null +++ b/libc-top-half/musl/src/unistd/sleep.c @@ -0,0 +1,10 @@ +#include +#include + +unsigned sleep(unsigned seconds) +{ + struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 }; + if (nanosleep(&tv, &tv)) + return tv.tv_sec; + return 0; +} diff --git a/libc-top-half/musl/src/unistd/symlink.c b/libc-top-half/musl/src/unistd/symlink.c new file mode 100644 index 0000000..0973d78 --- /dev/null +++ b/libc-top-half/musl/src/unistd/symlink.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int symlink(const char *existing, const char *new) +{ +#ifdef SYS_symlink + return syscall(SYS_symlink, existing, new); +#else + return syscall(SYS_symlinkat, existing, AT_FDCWD, new); +#endif +} diff --git a/libc-top-half/musl/src/unistd/symlinkat.c b/libc-top-half/musl/src/unistd/symlinkat.c new file mode 100644 index 0000000..d1c59b4 --- /dev/null +++ b/libc-top-half/musl/src/unistd/symlinkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int symlinkat(const char *existing, int fd, const char *new) +{ + return syscall(SYS_symlinkat, existing, fd, new); +} diff --git a/libc-top-half/musl/src/unistd/sync.c b/libc-top-half/musl/src/unistd/sync.c new file mode 100644 index 0000000..f18765a --- /dev/null +++ b/libc-top-half/musl/src/unistd/sync.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +void sync(void) +{ + __syscall(SYS_sync); +} diff --git a/libc-top-half/musl/src/unistd/tcgetpgrp.c b/libc-top-half/musl/src/unistd/tcgetpgrp.c new file mode 100644 index 0000000..50080c7 --- /dev/null +++ b/libc-top-half/musl/src/unistd/tcgetpgrp.c @@ -0,0 +1,11 @@ +#include +#include +#include + +pid_t tcgetpgrp(int fd) +{ + int pgrp; + if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) + return -1; + return pgrp; +} diff --git a/libc-top-half/musl/src/unistd/tcsetpgrp.c b/libc-top-half/musl/src/unistd/tcsetpgrp.c new file mode 100644 index 0000000..67c38cb --- /dev/null +++ b/libc-top-half/musl/src/unistd/tcsetpgrp.c @@ -0,0 +1,9 @@ +#include +#include +#include + +int tcsetpgrp(int fd, pid_t pgrp) +{ + int pgrp_int = pgrp; + return ioctl(fd, TIOCSPGRP, &pgrp_int); +} diff --git a/libc-top-half/musl/src/unistd/truncate.c b/libc-top-half/musl/src/unistd/truncate.c new file mode 100644 index 0000000..9729680 --- /dev/null +++ b/libc-top-half/musl/src/unistd/truncate.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" + +int truncate(const char *path, off_t length) +{ + return syscall(SYS_truncate, path, __SYSCALL_LL_O(length)); +} + +weak_alias(truncate, truncate64); diff --git a/libc-top-half/musl/src/unistd/ttyname.c b/libc-top-half/musl/src/unistd/ttyname.c new file mode 100644 index 0000000..0f3e114 --- /dev/null +++ b/libc-top-half/musl/src/unistd/ttyname.c @@ -0,0 +1,14 @@ +#include +#include +#include + +char *ttyname(int fd) +{ + static char buf[TTY_NAME_MAX]; + int result; + if ((result = ttyname_r(fd, buf, sizeof buf))) { + errno = result; + return NULL; + } + return buf; +} diff --git a/libc-top-half/musl/src/unistd/ttyname_r.c b/libc-top-half/musl/src/unistd/ttyname_r.c new file mode 100644 index 0000000..82acb75 --- /dev/null +++ b/libc-top-half/musl/src/unistd/ttyname_r.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include "syscall.h" + +int ttyname_r(int fd, char *name, size_t size) +{ + struct stat st1, st2; + char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; + ssize_t l; + + if (!isatty(fd)) return errno; + + __procfdname(procname, fd); + l = readlink(procname, name, size); + + if (l < 0) return errno; + else if (l == size) return ERANGE; + + name[l] = 0; + + if (stat(name, &st1) || fstat(fd, &st2)) + return errno; + if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) + return ENODEV; + + return 0; +} diff --git a/libc-top-half/musl/src/unistd/ualarm.c b/libc-top-half/musl/src/unistd/ualarm.c new file mode 100644 index 0000000..2985855 --- /dev/null +++ b/libc-top-half/musl/src/unistd/ualarm.c @@ -0,0 +1,13 @@ +#define _GNU_SOURCE +#include +#include + +unsigned ualarm(unsigned value, unsigned interval) +{ + struct itimerval it = { + .it_interval.tv_usec = interval, + .it_value.tv_usec = value + }, it_old; + setitimer(ITIMER_REAL, &it, &it_old); + return it_old.it_value.tv_sec*1000000 + it_old.it_value.tv_usec; +} diff --git a/libc-top-half/musl/src/unistd/unlink.c b/libc-top-half/musl/src/unistd/unlink.c new file mode 100644 index 0000000..c40c28d --- /dev/null +++ b/libc-top-half/musl/src/unistd/unlink.c @@ -0,0 +1,12 @@ +#include +#include +#include "syscall.h" + +int unlink(const char *path) +{ +#ifdef SYS_unlink + return syscall(SYS_unlink, path); +#else + return syscall(SYS_unlinkat, AT_FDCWD, path, 0); +#endif +} diff --git a/libc-top-half/musl/src/unistd/unlinkat.c b/libc-top-half/musl/src/unistd/unlinkat.c new file mode 100644 index 0000000..e0e25d2 --- /dev/null +++ b/libc-top-half/musl/src/unistd/unlinkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int unlinkat(int fd, const char *path, int flag) +{ + return syscall(SYS_unlinkat, fd, path, flag); +} diff --git a/libc-top-half/musl/src/unistd/usleep.c b/libc-top-half/musl/src/unistd/usleep.c new file mode 100644 index 0000000..6c96652 --- /dev/null +++ b/libc-top-half/musl/src/unistd/usleep.c @@ -0,0 +1,12 @@ +#define _GNU_SOURCE +#include +#include + +int usleep(unsigned useconds) +{ + struct timespec tv = { + .tv_sec = useconds/1000000, + .tv_nsec = (useconds%1000000)*1000 + }; + return nanosleep(&tv, &tv); +} diff --git a/libc-top-half/musl/src/unistd/write.c b/libc-top-half/musl/src/unistd/write.c new file mode 100644 index 0000000..8fd5bc5 --- /dev/null +++ b/libc-top-half/musl/src/unistd/write.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t write(int fd, const void *buf, size_t count) +{ + return syscall_cp(SYS_write, fd, buf, count); +} diff --git a/libc-top-half/musl/src/unistd/writev.c b/libc-top-half/musl/src/unistd/writev.c new file mode 100644 index 0000000..5a46c95 --- /dev/null +++ b/libc-top-half/musl/src/unistd/writev.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t writev(int fd, const struct iovec *iov, int count) +{ + return syscall_cp(SYS_writev, fd, iov, count); +} diff --git a/libc-top-half/musl/src/unistd/x32/lseek.c b/libc-top-half/musl/src/unistd/x32/lseek.c new file mode 100644 index 0000000..3263642 --- /dev/null +++ b/libc-top-half/musl/src/unistd/x32/lseek.c @@ -0,0 +1,15 @@ +#include +#include "syscall.h" + +off_t __lseek(int fd, off_t offset, int whence) +{ + off_t ret; + __asm__ __volatile__ ("syscall" + : "=a"(ret) + : "a"(SYS_lseek), "D"(fd), "S"(offset), "d"(whence) + : "rcx", "r11", "memory"); + return ret < 0 ? __syscall_ret(ret) : ret; +} + +weak_alias(__lseek, lseek); +weak_alias(__lseek, lseek64); -- cgit v1.2.3