diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-06-05 13:44:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-05 13:44:05 -0400 |
| commit | 3b77f23e760ef46c558ff8d3f45f7e477da644b2 (patch) | |
| tree | 96abadaf7788edfeacdd849d1480ac42c9966afa /lib/libc/musl/src/linux | |
| parent | ac3faa6cb3244a5db26b4fd5b114da23208e2239 (diff) | |
| parent | 46b2f67905e67bab1573f7b72536800bd8f6e669 (diff) | |
| download | zig-3b77f23e760ef46c558ff8d3f45f7e477da644b2.tar.gz zig-3b77f23e760ef46c558ff8d3f45f7e477da644b2.zip | |
Merge pull request #20194 from ziglang/musl-v1.2.5
upgrade musl to v1.2.5
Diffstat (limited to 'lib/libc/musl/src/linux')
| -rw-r--r-- | lib/libc/musl/src/linux/cache.c | 3 | ||||
| -rw-r--r-- | lib/libc/musl/src/linux/clone.c | 56 | ||||
| -rw-r--r-- | lib/libc/musl/src/linux/ppoll.c | 26 | ||||
| -rw-r--r-- | lib/libc/musl/src/linux/preadv2.c | 17 | ||||
| -rw-r--r-- | lib/libc/musl/src/linux/pwritev2.c | 17 | ||||
| -rw-r--r-- | lib/libc/musl/src/linux/statx.c | 42 | ||||
| -rw-r--r-- | lib/libc/musl/src/linux/wait4.c | 2 |
7 files changed, 129 insertions, 34 deletions
diff --git a/lib/libc/musl/src/linux/cache.c b/lib/libc/musl/src/linux/cache.c index 0eb051c2d4..e76f7812e6 100644 --- a/lib/libc/musl/src/linux/cache.c +++ b/lib/libc/musl/src/linux/cache.c @@ -21,7 +21,7 @@ weak_alias(__cachectl, cachectl); #ifdef SYS_riscv_flush_icache #define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache" -#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5" +#define VDSO_FLUSH_ICACHE_VER "LINUX_4.15" static void *volatile vdso_func; @@ -45,6 +45,7 @@ int __riscv_flush_icache(void *start, void *end, unsigned long int flags) if (!r) return r; if (r != -ENOSYS) return __syscall_ret(r); } + return syscall(SYS_riscv_flush_icache, start, end, flags); } weak_alias(__riscv_flush_icache, riscv_flush_icache); #endif diff --git a/lib/libc/musl/src/linux/clone.c b/lib/libc/musl/src/linux/clone.c index 8c1af7d3dc..257c1cecdb 100644 --- a/lib/libc/musl/src/linux/clone.c +++ b/lib/libc/musl/src/linux/clone.c @@ -4,18 +4,62 @@ #include <sched.h> #include "pthread_impl.h" #include "syscall.h" +#include "lock.h" +#include "fork_impl.h" + +struct clone_start_args { + int (*func)(void *); + void *arg; + sigset_t sigmask; +}; + +static int clone_start(void *arg) +{ + struct clone_start_args *csa = arg; + __post_Fork(0); + __restore_sigs(&csa->sigmask); + return csa->func(csa->arg); +} int clone(int (*func)(void *), void *stack, int flags, void *arg, ...) { + struct clone_start_args csa; va_list ap; - pid_t *ptid, *ctid; - void *tls; + pid_t *ptid = 0, *ctid = 0; + void *tls = 0; + + /* Flags that produce an invalid thread/TLS state are disallowed. */ + int badflags = CLONE_THREAD | CLONE_SETTLS | CLONE_CHILD_CLEARTID; + + if ((flags & badflags) || !stack) + return __syscall_ret(-EINVAL); va_start(ap, arg); - ptid = va_arg(ap, pid_t *); - tls = va_arg(ap, void *); - ctid = va_arg(ap, pid_t *); + if (flags & (CLONE_PIDFD | CLONE_PARENT_SETTID | CLONE_CHILD_SETTID)) + ptid = va_arg(ap, pid_t *); + if (flags & CLONE_CHILD_SETTID) { + tls = va_arg(ap, void *); + ctid = va_arg(ap, pid_t *); + } va_end(ap); - return __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid)); + /* If CLONE_VM is used, it's impossible to give the child a consistent + * thread structure. In this case, the best we can do is assume the + * caller is content with an extremely restrictive execution context + * like the one vfork() would provide. */ + if (flags & CLONE_VM) return __syscall_ret( + __clone(func, stack, flags, arg, ptid, tls, ctid)); + + __block_all_sigs(&csa.sigmask); + LOCK(__abort_lock); + + /* Setup the a wrapper start function for the child process to do + * mimic _Fork in producing a consistent execution state. */ + csa.func = func; + csa.arg = arg; + int ret = __clone(clone_start, stack, flags, &csa, ptid, tls, ctid); + + __post_Fork(ret); + __restore_sigs(&csa.sigmask); + return __syscall_ret(ret); } diff --git a/lib/libc/musl/src/linux/ppoll.c b/lib/libc/musl/src/linux/ppoll.c deleted file mode 100644 index e614600ab8..0000000000 --- a/lib/libc/musl/src/linux/ppoll.c +++ /dev/null @@ -1,26 +0,0 @@ -#define _GNU_SOURCE -#include <poll.h> -#include <signal.h> -#include <errno.h> -#include "syscall.h" - -#define IS32BIT(x) !((x)+0x80000000ULL>>32) -#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) - -int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask) -{ - time_t s = to ? to->tv_sec : 0; - long ns = to ? to->tv_nsec : 0; -#ifdef SYS_ppoll_time64 - int r = -ENOSYS; - if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s)) - r = __syscall_cp(SYS_ppoll_time64, fds, n, - to ? ((long long[]){s, ns}) : 0, - mask, _NSIG/8); - if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS) - return __syscall_ret(r); - s = CLAMP(s); -#endif - return syscall_cp(SYS_ppoll, fds, n, - to ? ((long[]){s, ns}) : 0, mask, _NSIG/8); -} diff --git a/lib/libc/musl/src/linux/preadv2.c b/lib/libc/musl/src/linux/preadv2.c new file mode 100644 index 0000000000..5e7ab70f19 --- /dev/null +++ b/lib/libc/musl/src/linux/preadv2.c @@ -0,0 +1,17 @@ +#define _GNU_SOURCE +#include <sys/uio.h> +#include <unistd.h> +#include "syscall.h" + +ssize_t preadv2(int fd, const struct iovec *iov, int count, off_t ofs, int flags) +{ +#ifdef SYS_preadv + if (!flags) { + if (ofs==-1) return readv(fd, iov, count); + return syscall_cp(SYS_preadv, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); + } +#endif + return syscall_cp(SYS_preadv2, fd, iov, count, + (long)(ofs), (long)(ofs>>32), flags); +} diff --git a/lib/libc/musl/src/linux/pwritev2.c b/lib/libc/musl/src/linux/pwritev2.c new file mode 100644 index 0000000000..ece90d7ca2 --- /dev/null +++ b/lib/libc/musl/src/linux/pwritev2.c @@ -0,0 +1,17 @@ +#define _GNU_SOURCE +#include <sys/uio.h> +#include <unistd.h> +#include "syscall.h" + +ssize_t pwritev2(int fd, const struct iovec *iov, int count, off_t ofs, int flags) +{ +#ifdef SYS_pwritev + if (!flags) { + if (ofs==-1) return writev(fd, iov, count); + return syscall_cp(SYS_pwritev, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); + } +#endif + return syscall_cp(SYS_pwritev2, fd, iov, count, + (long)(ofs), (long)(ofs>>32), flags); +} diff --git a/lib/libc/musl/src/linux/statx.c b/lib/libc/musl/src/linux/statx.c new file mode 100644 index 0000000000..4616bff4aa --- /dev/null +++ b/lib/libc/musl/src/linux/statx.c @@ -0,0 +1,42 @@ +#define _GNU_SOURCE +#include <sys/stat.h> +#include <string.h> +#include <syscall.h> +#include <sys/sysmacros.h> +#include <errno.h> + +int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct statx *restrict stx) +{ + int ret = __syscall(SYS_statx, dirfd, path, flags, mask, stx); + +#ifndef SYS_fstatat + return __syscall_ret(ret); +#endif + + if (ret != -ENOSYS) return __syscall_ret(ret); + + struct stat st; + ret = fstatat(dirfd, path, &st, flags); + if (ret) return ret; + + stx->stx_dev_major = major(st.st_dev); + stx->stx_dev_minor = minor(st.st_dev); + stx->stx_ino = st.st_ino; + stx->stx_mode = st.st_mode; + stx->stx_nlink = st.st_nlink; + stx->stx_uid = st.st_uid; + stx->stx_gid = st.st_gid; + stx->stx_size = st.st_size; + stx->stx_blksize = st.st_blksize; + stx->stx_blocks = st.st_blocks; + stx->stx_atime.tv_sec = st.st_atim.tv_sec; + stx->stx_atime.tv_nsec = st.st_atim.tv_nsec; + stx->stx_mtime.tv_sec = st.st_mtim.tv_sec; + stx->stx_mtime.tv_nsec = st.st_mtim.tv_nsec; + stx->stx_ctime.tv_sec = st.st_ctim.tv_sec; + stx->stx_ctime.tv_nsec = st.st_ctim.tv_nsec; + stx->stx_btime = (struct statx_timestamp){.tv_sec=0, .tv_nsec=0}; + stx->stx_mask = STATX_BASIC_STATS; + + return 0; +} diff --git a/lib/libc/musl/src/linux/wait4.c b/lib/libc/musl/src/linux/wait4.c index ff2e3e6649..fb08c0d0b7 100644 --- a/lib/libc/musl/src/linux/wait4.c +++ b/lib/libc/musl/src/linux/wait4.c @@ -26,7 +26,7 @@ pid_t wait4(pid_t pid, int *status, int options, struct rusage *ru) } #endif char *dest = ru ? (char *)&ru->ru_maxrss - 4*sizeof(long) : 0; - r = __syscall(SYS_wait4, pid, status, options, dest); + r = __sys_wait4(pid, status, options, dest); if (r>0 && ru && sizeof(time_t) > sizeof(long)) { long kru[4]; memcpy(kru, dest, 4*sizeof(long)); |
