From dcefc713890e6612d1d290c32281cbc66b27eae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alf-Andr=C3=A9=20Walla?= Date: Mon, 17 Jun 2024 14:56:49 +0200 Subject: [PATCH 01/14] musl 1.1.24: prepare for upgrade, import old patches - Copy patches from github.com/IncludeOS/musl, commit 4f331b7. - Copy src/musl/nanosleep.ccp with clock_nanosleep from commit 9ceff78 in this repo. Original author of both patches is fwsGonzo. --- deps/musl/patches/includeos_syscalls.h | 127 ++++++++++++++----------- deps/musl/patches/syscall.h | 126 +++++++++++++++++++++--- src/musl/nanosleep.cpp | 7 ++ 3 files changed, 196 insertions(+), 64 deletions(-) diff --git a/deps/musl/patches/includeos_syscalls.h b/deps/musl/patches/includeos_syscalls.h index d199f40e73..25b16ebffe 100644 --- a/deps/musl/patches/includeos_syscalls.h +++ b/deps/musl/patches/includeos_syscalls.h @@ -1,52 +1,71 @@ #pragma once -#define __includeos(num, ...) extern long syscall_##num(long,...) +#if !defined(SYS_set_thread_area) + #define SYS_set_thread_area +#endif -extern long syscall_n(long,...); -extern long syscall_SYS_brk(void*); -extern long syscall_SYS_close(long,...); -extern long syscall_SYS_epoll_wait(long,...); -extern long syscall_SYS_exit_group(long,...); -extern long syscall_SYS_exit(long,...); -extern long syscall_SYS_fadvise(long,...); -extern long syscall_SYS_fallocate(long,...); -extern long syscall_SYS_fcntl(long,...); -extern long syscall_SYS_flistxattr(long,...); +#if !defined(SYS_fork) + #define SYS_fork +#endif + +#define __includeos(num, ...) extern long syscall_##num() + +extern long syscall_n(); +extern long syscall_nr(); +extern long syscall_SYS_brk(); +extern long syscall_SYS_close(); +extern long syscall_SYS_copy_file_range(); +extern long syscall_SYS_epoll_wait(); +extern long syscall_SYS_execveat(); +extern long syscall_SYS_exit_group(); +extern long syscall_SYS_exit(); +extern long syscall_SYS_fadvise(); +extern long syscall_SYS_fallocate(); +extern long syscall_SYS_fcntl(); +extern long syscall_SYS_flistxattr(); extern long syscall_SYS_fork(); -extern long syscall_SYS_fremovexattr(long,...); -extern long syscall_SYS_fsetxattr(long,...); -extern long syscall_SYS_futex(long, ...); -extern long syscall_SYS_getdents(long,...); +extern long syscall_SYS_fremovexattr(); +extern long syscall_SYS_fsetxattr(); +extern long syscall_SYS_futex(); +extern long syscall_SYS_get_robust_list(); +extern long syscall_SYS_getdents(); extern long syscall_SYS_getegid(); extern long syscall_SYS_geteuid(); extern long syscall_SYS_getgid(); extern long syscall_SYS_getpid(); extern long syscall_SYS_getppid(); +extern long syscall_SYS_getrandom(); extern long syscall_SYS_gettid(); extern long syscall_SYS_getuid(); extern long syscall_SYS_inotify_init(); -extern long syscall_SYS_ioctl(long, long, long, ...); -extern long syscall_SYS_lremovexattr(long,...); -extern long syscall_SYS_mmap2(long,...); -extern long syscall_SYS_msgctl(long,...); -extern long syscall_SYS_msgget(long,...); +extern long syscall_SYS_ioctl(); +extern long syscall_SYS_lremovexattr(); +extern long syscall_SYS_membarrier(); +extern long syscall_SYS_memfd_create(); +extern long syscall_SYS_mmap2(); +extern long syscall_SYS_mlock2(); +extern long syscall_SYS_msgctl(); +extern long syscall_SYS_msgget(); extern long syscall_SYS_munlockall(); +extern long syscall_SYS_name_to_handle_at(); +extern long syscall_SYS_open_by_handle_at(); extern long syscall_SYS_pause(); -extern long syscall_SYS_poll(long,...); -extern long syscall_SYS_removexattr(long,...); -extern long syscall_SYS_rt_sigqueueinfo(long, ...); -extern long syscall_SYS_sched_getaffinity(long, ...); +extern long syscall_SYS_poll(); +extern long syscall_SYS_ppoll(); +extern long syscall_SYS_removexattr(); +extern long syscall_SYS_rt_sigqueueinfo(); +extern long syscall_SYS_sched_getaffinity(); extern long syscall_SYS_sched_yield(); -extern long syscall_SYS_semctl(long,...); -extern long syscall_SYS_semget(long,...); -extern long syscall_SYS_semop(long,...); -extern long syscall_SYS_semtimedop(long,...); +extern long syscall_SYS_semctl(); +extern long syscall_SYS_semget(); +extern long syscall_SYS_semop(); +extern long syscall_SYS_semtimedop(); extern long syscall_SYS_setsid(); -extern long syscall_SYS_set_tid_address(long,...); -extern long syscall_SYS_shmat(long,...); +extern long syscall_SYS_set_tid_address(); +extern long syscall_SYS_shmat(); extern long syscall_SYS_sync(); extern long syscall_SYS_vhangup(); -extern int syscall_SYS_open(const char *path, int oflag, ... ); +extern int syscall_SYS_open(const char *path, int oflag, ...); __includeos(SYS_access); __includeos(SYS_acct); @@ -191,6 +210,7 @@ __includeos(SYS_sched_setparam); __includeos(SYS_sched_setscheduler); __includeos(SYS_select); __includeos(SYS_sendfile); +__includeos(SYS_set_thread_area); __includeos(SYS_setdomainname); __includeos(SYS_setfsgid); __includeos(SYS_setfsuid); @@ -217,6 +237,7 @@ __includeos(SYS_signalfd4); __includeos(SYS_socketcall); __includeos(SYS_splice); __includeos(SYS_stat); +__includeos(SYS_statx); __includeos(SYS_statfs); __includeos(SYS_statfs64); __includeos(SYS_swapoff); @@ -254,25 +275,25 @@ __includeos(SYS_waitid); __includeos(SYS_write); __includeos(SYS_writev); -int socketcall_socket(int,...); -int socketcall_bind(int,...); -int socketcall_connect(int,...); -int socketcall_listen(int,...); -int socketcall_accept(int,...); -int socketcall_getsockname(int,...); -int socketcall_getpeername(int,...); -int socketcall_socketpair(int,...); -int socketcall_send(int,...); -int socketcall_recv(int,...); -int socketcall_sendto(int,...); -int socketcall_recvfrom(int,...); -int socketcall_shutdown(int,...); -int socketcall_setsockopt(int,...); -int socketcall_getsockopt(int,...); -int socketcall_sendmsg(int,...); -int socketcall_recvmsg(int,...); -int socketcall_accept4(int,...); -int socketcall_recvmmsg(int,...); -int syscall_SYS_recvmmsg(int,...); -int syscall_SYS_sendmmsg(int,...); -//int socketcall_sendmmsg(int,...); +int socketcall_socket(); +int socketcall_bind(); +int socketcall_connect(); +int socketcall_listen(); +int socketcall_accept(); +int socketcall_getsockname(); +int socketcall_getpeername(); +int socketcall_socketpair(); +int socketcall_send(); +int socketcall_recv(); +int socketcall_sendto(); +int socketcall_recvfrom(); +int socketcall_shutdown(); +int socketcall_setsockopt(); +int socketcall_getsockopt(); +int socketcall_sendmsg(); +int socketcall_recvmsg(); +int socketcall_accept4(); +int socketcall_recvmmsg(); +int syscall_SYS_recvmmsg(); +int syscall_SYS_sendmmsg(); +//int socketcall_sendmmsg(); diff --git a/deps/musl/patches/syscall.h b/deps/musl/patches/syscall.h index 0846fc0254..e078fd236b 100644 --- a/deps/musl/patches/syscall.h +++ b/deps/musl/patches/syscall.h @@ -1,6 +1,7 @@ #ifndef _INTERNAL_SYSCALL_H #define _INTERNAL_SYSCALL_H +#include #include #include "includeos_syscalls.h" @@ -28,26 +29,21 @@ typedef long syscall_arg_t; #endif -__attribute__((visibility("hidden"))) -long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), +hidden long __syscall_ret(unsigned long), __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t); -#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n -#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,) -#define __SYSCALL_CONCAT_X(a,b) a##b -#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) #define __syscall(a,...) syscall_##a(__VA_ARGS__) #define syscall(a,...) __syscall_ret(syscall_##a(__VA_ARGS__)) - -#define socketcall __socketcall -#define socketcall_cp __socketcall - #define __syscall_cp syscall #define syscall_cp syscall -#define __socketcall(nm, ...) __syscall_ret(socketcall_##nm(__VA_ARGS__)) +#define socketcall __socketcall +#define socketcall_cp __socketcall +#define __socketcall(nm, ...) socketcall_##nm(__VA_ARGS__) +//#define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f)) +//#define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f)) /* fixup legacy 16-bit junk */ @@ -175,6 +171,89 @@ long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), #define SYS_sendfile SYS_sendfile64 #endif + +/* Ensure that the plain syscall names are defined even for "time64-only" + * archs. These facilitate callers passing null time arguments, and make + * tests for establishing which to use/fallback-to more consistent when + * they do need to be called with time arguments. */ + +#ifndef SYS_clock_gettime +#define SYS_clock_gettime SYS_clock_gettime64 +#endif + +#ifndef SYS_clock_settime +#define SYS_clock_settime SYS_clock_settime64 +#endif + +#ifndef SYS_clock_adjtime +#define SYS_clock_adjtime SYS_clock_adjtime64 +#endif + +#ifndef SYS_clock_getres +#define SYS_clock_getres SYS_clock_getres_time64 +#endif + +#ifndef SYS_clock_nanosleep +#define SYS_clock_nanosleep SYS_clock_nanosleep_time64 +#endif + +#ifndef SYS_timer_gettime +#define SYS_timer_gettime SYS_timer_gettime64 +#endif + +#ifndef SYS_timer_settime +#define SYS_timer_settime SYS_timer_settime64 +#endif + +#ifndef SYS_timerfd_gettime +#define SYS_timerfd_gettime SYS_timerfd_gettime64 +#endif + +#ifndef SYS_timerfd_settime +#define SYS_timerfd_settime SYS_timerfd_settime64 +#endif + +#ifndef SYS_utimensat +#define SYS_utimensat SYS_utimensat_time64 +#endif + +#ifndef SYS_pselect6 +#define SYS_pselect6 SYS_pselect6_time64 +#endif + +#ifndef SYS_ppoll +#define SYS_ppoll SYS_ppoll_time64 +#endif + +#ifndef SYS_recvmmsg +#define SYS_recvmmsg SYS_recvmmsg_time64 +#endif + +#ifndef SYS_mq_timedsend +#define SYS_mq_timedsend SYS_mq_timedsend_time64 +#endif + +#ifndef SYS_mq_timedreceive +#define SYS_mq_timedreceive SYS_mq_timedreceive_time64 +#endif + +/* SYS_semtimedop omitted because SYS_ipc may provide it */ + +#ifndef SYS_rt_sigtimedwait +#define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64 +#endif + +#ifndef SYS_futex +#define SYS_futex SYS_futex_time64 +#endif + +#ifndef SYS_sched_rr_get_interval +#define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64 +#endif + + + + /* socketcall calls */ @@ -199,6 +278,27 @@ long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), #define __SC_recvmmsg 19 #define __SC_sendmmsg 20 +#ifndef SO_RCVTIMEO_OLD +#define SO_RCVTIMEO_OLD 20 +#endif +#ifndef SO_SNDTIMEO_OLD +#define SO_SNDTIMEO_OLD 21 +#endif + +#define SO_TIMESTAMP_OLD 29 +#define SO_TIMESTAMPNS_OLD 35 +#define SO_TIMESTAMPING_OLD 37 +#define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD +#define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD +#define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD + +#ifndef SIOCGSTAMP_OLD +#define SIOCGSTAMP_OLD 0x8906 +#endif +#ifndef SIOCGSTAMPNS_OLD +#define SIOCGSTAMPNS_OLD 0x8907 +#endif + #ifdef SYS_open #define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE) #define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo) @@ -217,4 +317,8 @@ long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), #define __sys_open_cp __sys_open #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) +hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); + +hidden void *__vdsosym(const char *, const char *); + #endif diff --git a/src/musl/nanosleep.cpp b/src/musl/nanosleep.cpp index 17be07fb91..ff96e5eafa 100644 --- a/src/musl/nanosleep.cpp +++ b/src/musl/nanosleep.cpp @@ -30,3 +30,10 @@ long syscall_SYS_nanosleep(const struct timespec *req, struct timespec *rem) { return strace(sys_nanosleep, "nanosleep", req, rem); } + +extern "C" +long syscall_SYS_clock_nanosleep(clockid_t, int, + const struct timespec *req, struct timespec *rem) +{ + return strace(sys_nanosleep, "clock_nanosleep", req, rem); +} From 954fad5005524ed1fa9b23458032fb1fa669e3a4 Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Mon, 17 Jun 2024 15:15:51 +0200 Subject: [PATCH 02/14] musl 1.1.24: update nix files --- deps/musl-unpatched/default.nix | 14 +++++--------- deps/musl/default.nix | 14 +++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/deps/musl-unpatched/default.nix b/deps/musl-unpatched/default.nix index 1e2b27ba43..31431f6b74 100644 --- a/deps/musl-unpatched/default.nix +++ b/deps/musl-unpatched/default.nix @@ -1,19 +1,15 @@ -{ nixpkgs ? - builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.11.tar.gz"; - sha256 = "1ndiv385w1qyb3b18vw13991fzb9wg4cl21wglk89grsfsnra41k"; - } -, stdenv -, pkgs ? import nixpkgs { config = {}; overlays = []; crossSystem = { config = stdenv.targetPlatform.config; }; } +{ +stdenv +, pkgs , linuxHeaders ? null }: stdenv.mkDerivation rec { pname = "musl-unpatched"; - version = "1.1.18"; + version = "1.1.24"; src = fetchGit { url = "git://git.musl-libc.org/musl"; - rev = "eb03bde2f24582874cb72b56c7811bf51da0c817"; + rev = "ea9525c8bcf6170df59364c4bcd616de1acf8703"; }; enableParallelBuilding = true; diff --git a/deps/musl/default.nix b/deps/musl/default.nix index aecebebbc0..14bd7d34e6 100644 --- a/deps/musl/default.nix +++ b/deps/musl/default.nix @@ -1,19 +1,15 @@ -{ nixpkgs ? - builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.11.tar.gz"; - sha256 = "1ndiv385w1qyb3b18vw13991fzb9wg4cl21wglk89grsfsnra41k"; - } -, stdenv -, pkgs ? import nixpkgs { config = {}; overlays = []; crossSystem = { config = stdenv.targetPlatform.config; }; } +{ +stdenv +, pkgs , linuxHeaders ? null }: stdenv.mkDerivation rec { pname = "musl-includeos"; - version = "1.1.18"; + version = "1.1.24"; src = fetchGit { url = "git://git.musl-libc.org/musl"; - rev = "eb03bde2f24582874cb72b56c7811bf51da0c817"; + rev = "ea9525c8bcf6170df59364c4bcd616de1acf8703"; }; enableParallelBuilding = true; From 15ed9102b104a05d9cc4aa3e5e43e693ca8d62fe Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Mon, 17 Jun 2024 15:16:44 +0200 Subject: [PATCH 03/14] musl 1.1.24: include _time64 defines needed in 32-bit build --- deps/musl/patches/includeos_syscalls.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/deps/musl/patches/includeos_syscalls.h b/deps/musl/patches/includeos_syscalls.h index 25b16ebffe..d57739859d 100644 --- a/deps/musl/patches/includeos_syscalls.h +++ b/deps/musl/patches/includeos_syscalls.h @@ -27,6 +27,7 @@ extern long syscall_SYS_fork(); extern long syscall_SYS_fremovexattr(); extern long syscall_SYS_fsetxattr(); extern long syscall_SYS_futex(); +extern long syscall_SYS_futex_time64(); extern long syscall_SYS_get_robust_list(); extern long syscall_SYS_getdents(); extern long syscall_SYS_getegid(); @@ -52,6 +53,7 @@ extern long syscall_SYS_open_by_handle_at(); extern long syscall_SYS_pause(); extern long syscall_SYS_poll(); extern long syscall_SYS_ppoll(); +extern long syscall_SYS_ppoll_time64(); extern long syscall_SYS_removexattr(); extern long syscall_SYS_rt_sigqueueinfo(); extern long syscall_SYS_sched_getaffinity(); @@ -60,6 +62,7 @@ extern long syscall_SYS_semctl(); extern long syscall_SYS_semget(); extern long syscall_SYS_semop(); extern long syscall_SYS_semtimedop(); +extern long syscall_SYS_semtimedop_time64(); extern long syscall_SYS_setsid(); extern long syscall_SYS_set_tid_address(); extern long syscall_SYS_shmat(); @@ -80,8 +83,11 @@ __includeos(SYS_chroot); __includeos(SYS_clock_adjtime); __includeos(SYS_clock_getres); __includeos(SYS_clock_gettime); +__includeos(SYS_clock_gettime64); __includeos(SYS_clock_nanosleep); +__includeos(SYS_clock_nanosleep_time64); __includeos(SYS_clock_settime); +__includeos(SYS_clock_settime64); __includeos(SYS_delete_module); __includeos(SYS_dup); __includeos(SYS_dup2); @@ -159,6 +165,8 @@ __includeos(SYS_mq_notify); __includeos(SYS_mq_open); __includeos(SYS_mq_timedreceive); __includeos(SYS_mq_timedsend); +__includeos(SYS_mq_timedreceive_time64); +__includeos(SYS_mq_timedsend_time64); __includeos(SYS_mq_unlink); __includeos(SYS_mremap); __includeos(SYS_msgrcv); @@ -181,6 +189,7 @@ __includeos(SYS_prlimit64); __includeos(SYS_process_vm_readv); __includeos(SYS_process_vm_writev); __includeos(SYS_pselect6); +__includeos(SYS_pselect6_time64); __includeos(SYS_ptrace); __includeos(SYS_pwrite); __includeos(SYS_pwritev); @@ -200,6 +209,7 @@ __includeos(SYS_rt_sigpending); __includeos(SYS_rt_sigprocmask); __includeos(SYS_rt_sigsuspend); __includeos(SYS_rt_sigtimedwait); +__includeos(SYS_rt_sigtimedwait_time64); __includeos(SYS_sched_getparam); __includeos(SYS_sched_get_priority_max); __includeos(SYS_sched_get_priority_min); @@ -255,9 +265,13 @@ __includeos(SYS_timer_delete); __includeos(SYS_timerfd_create); __includeos(SYS_timerfd_gettime); __includeos(SYS_timerfd_settime); +__includeos(SYS_timerfd_gettime64); +__includeos(SYS_timerfd_settime64); __includeos(SYS_timer_getoverrun); __includeos(SYS_timer_gettime); +__includeos(SYS_timer_gettime64); __includeos(SYS_timer_settime); +__includeos(SYS_timer_settime64); __includeos(SYS_times); __includeos(SYS_tkill); __includeos(SYS_truncate); @@ -268,6 +282,7 @@ __includeos(SYS_unlink); __includeos(SYS_unlinkat); __includeos(SYS_unshare); __includeos(SYS_utimensat); +__includeos(SYS_utimensat_time64); __includeos(SYS_utimes); __includeos(SYS_vmsplice); __includeos(SYS_wait4); @@ -296,4 +311,5 @@ int socketcall_accept4(); int socketcall_recvmmsg(); int syscall_SYS_recvmmsg(); int syscall_SYS_sendmmsg(); +int syscall_SYS_recvmmsg_time64(); //int socketcall_sendmmsg(); From 0bbaad99c3d394cfd8bc22812c7cc7391516b0e1 Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Mon, 17 Jun 2024 15:18:04 +0200 Subject: [PATCH 04/14] musl 1.1.24: implement getrandom, stub more syscalls adds getrandom + stubs for fchdir, getrusage, sched_setaffinity, sched_setscheduler, sigaltstack --- src/musl/CMakeLists.txt | 8 ++++++-- src/musl/fchdir.cpp | 13 +++++++++++++ src/musl/getrandom.cpp | 14 ++++++++++++++ src/musl/getrusage.cpp | 12 ++++++++++++ src/musl/sched_setaffinity.cpp | 15 +++++++++++++++ src/musl/sched_setscheduler.cpp | 14 ++++++++++++++ src/musl/sigaltstack.cpp | 14 ++++++++++++++ 7 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/musl/fchdir.cpp create mode 100644 src/musl/getrandom.cpp create mode 100644 src/musl/getrusage.cpp create mode 100644 src/musl/sched_setaffinity.cpp create mode 100644 src/musl/sched_setscheduler.cpp create mode 100644 src/musl/sigaltstack.cpp diff --git a/src/musl/CMakeLists.txt b/src/musl/CMakeLists.txt index ca59cfb218..d5c37697c4 100644 --- a/src/musl/CMakeLists.txt +++ b/src/musl/CMakeLists.txt @@ -2,8 +2,8 @@ set(MUSL_OBJECTS futex.cpp close.cpp fcntl.cpp lseek.cpp ioctl.cpp writev.cpp write.cpp brk.cpp madvise.cpp mmap.cpp mremap.cpp munmap.cpp - lseek.cpp sched_getaffinity.cpp sysinfo.cpp prlimit64.cpp - getrlimit.cpp sched_yield.cpp set_robust_list.cpp + lseek.cpp sched_getaffinity.cpp sched_setaffinity.cpp sysinfo.cpp prlimit64.cpp + getrlimit.cpp getrusage.cpp sched_yield.cpp set_robust_list.cpp nanosleep.cpp open.cpp creat.cpp clock_gettime.cpp gettimeofday.cpp poll.cpp exit.cpp close.cpp set_tid_address.cpp pipe.cpp read.cpp readv.cpp getpid.cpp getuid.cpp mknod.cpp sync.cpp @@ -16,6 +16,7 @@ set(MUSL_OBJECTS cwd.cpp dup3.cpp # also dup, dup2 execve.cpp + fchdir.cpp fchmod.cpp fchmodat.cpp fchown.cpp @@ -25,6 +26,7 @@ set(MUSL_OBJECTS geteuid.cpp getgid.cpp getuid.cpp + getrandom.cpp kill.cpp mkdir.cpp mkdirat.cpp @@ -46,6 +48,8 @@ set(MUSL_OBJECTS uname.cpp utimensat.cpp unlink.cpp + sigaltstack.cpp + sched_setscheduler.cpp ) add_library(musl_syscalls STATIC ${MUSL_OBJECTS}) diff --git a/src/musl/fchdir.cpp b/src/musl/fchdir.cpp new file mode 100644 index 0000000000..e02dce792b --- /dev/null +++ b/src/musl/fchdir.cpp @@ -0,0 +1,13 @@ +#include "common.hpp" +#include + +static long sys_fchdir(int /*fd*/) +{ + return -ENOSYS; +} + +extern "C" +long syscall_SYS_fchdir(int fd) +{ + return strace(sys_fchdir, "fchown", fd); +} diff --git a/src/musl/getrandom.cpp b/src/musl/getrandom.cpp new file mode 100644 index 0000000000..655b4d3f64 --- /dev/null +++ b/src/musl/getrandom.cpp @@ -0,0 +1,14 @@ +#include "common.hpp" +#include + +// TODO Flags are ignored. +static long sys_getrandom(void* buf, size_t len, unsigned int flags) +{ + rng_absorb(buf, len); + return len; +} + +extern "C" +long syscall_SYS_getrandom(void *buf, size_t len, unsigned int flags) { + return strace(sys_getrandom, "getrandom", buf, len, flags); +} diff --git a/src/musl/getrusage.cpp b/src/musl/getrusage.cpp new file mode 100644 index 0000000000..ad38b5f105 --- /dev/null +++ b/src/musl/getrusage.cpp @@ -0,0 +1,12 @@ +#include "common.hpp" + +#include + +static int sys_getrusage(int /*resource*/, struct rusage*) { + return -ENOSYS; +} + +extern "C" +long syscall_SYS_getrusage(int resource, struct rusage *usage) { + return strace(sys_getrusage, "getrusage", resource, usage); +} diff --git a/src/musl/sched_setaffinity.cpp b/src/musl/sched_setaffinity.cpp new file mode 100644 index 0000000000..78060ea03f --- /dev/null +++ b/src/musl/sched_setaffinity.cpp @@ -0,0 +1,15 @@ +#include "common.hpp" +#include + +static long sys_sched_setaffinity(pid_t /*pid*/, size_t /*cpusetsize*/, + cpu_set_t */*mask*/) +{ + return -ENOSYS; +} + +extern "C" +long syscall_SYS_sched_setaffinity(pid_t pid, size_t cpusetsize, + cpu_set_t *mask) +{ + return strace(sys_sched_setaffinity, "sched_setaffinity", pid, cpusetsize, mask); +} diff --git a/src/musl/sched_setscheduler.cpp b/src/musl/sched_setscheduler.cpp new file mode 100644 index 0000000000..69e8b335ec --- /dev/null +++ b/src/musl/sched_setscheduler.cpp @@ -0,0 +1,14 @@ +#include "common.hpp" +#include + +static long sys_sched_setscheduler(pid_t /*pid*/, int /*policy*/, const struct sched_param* /*param*/) +{ + return -ENOSYS; +} + +extern "C" +long syscall_SYS_sched_setscheduler(pid_t pid, int policy, + const struct sched_param *param) +{ + return strace(sys_sched_setscheduler, "sched_setscheduler", pid, policy, param); +} diff --git a/src/musl/sigaltstack.cpp b/src/musl/sigaltstack.cpp new file mode 100644 index 0000000000..d766041ae8 --- /dev/null +++ b/src/musl/sigaltstack.cpp @@ -0,0 +1,14 @@ +#include "common.hpp" +#include + +static long sys_sigaltstack(const stack_t * /*ss*/, stack_t * /*old_ss*/) +{ + return -ENOSYS; +} + +extern "C" +long syscall_SYS_sigaltstack(const stack_t *_Nullable ss, + stack_t *_Nullable old_ss) +{ + return strace(sys_sigaltstack, "sigaltstack", ss, old_ss); +} From b641f1a8f6137a7b1f52f41bb4c11f413e5bc688 Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Mon, 17 Jun 2024 19:52:41 +0200 Subject: [PATCH 05/14] musl 1.2.5: update nix files --- deps/musl-unpatched/default.nix | 4 ++-- deps/musl/default.nix | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deps/musl-unpatched/default.nix b/deps/musl-unpatched/default.nix index 31431f6b74..a2be281598 100644 --- a/deps/musl-unpatched/default.nix +++ b/deps/musl-unpatched/default.nix @@ -5,11 +5,11 @@ stdenv }: stdenv.mkDerivation rec { pname = "musl-unpatched"; - version = "1.1.24"; + version = "1.2.5"; src = fetchGit { url = "git://git.musl-libc.org/musl"; - rev = "ea9525c8bcf6170df59364c4bcd616de1acf8703"; + rev = "0784374d561435f7c787a555aeab8ede699ed298"; }; enableParallelBuilding = true; diff --git a/deps/musl/default.nix b/deps/musl/default.nix index 14bd7d34e6..09a3a74fe5 100644 --- a/deps/musl/default.nix +++ b/deps/musl/default.nix @@ -5,11 +5,11 @@ stdenv }: stdenv.mkDerivation rec { pname = "musl-includeos"; - version = "1.1.24"; + version = "1.2.5"; src = fetchGit { url = "git://git.musl-libc.org/musl"; - rev = "ea9525c8bcf6170df59364c4bcd616de1acf8703"; + rev = "0784374d561435f7c787a555aeab8ede699ed298"; }; enableParallelBuilding = true; From de936302e949e774f19d0eb01ad6d702a02def80 Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Mon, 17 Jun 2024 19:53:19 +0200 Subject: [PATCH 06/14] musl 1.2.5: update patches --- deps/musl/patches/includeos_syscalls.h | 5 +++ deps/musl/patches/musl.patch | 20 ++++----- deps/musl/patches/syscall.h | 58 ++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/deps/musl/patches/includeos_syscalls.h b/deps/musl/patches/includeos_syscalls.h index d57739859d..00016241e9 100644 --- a/deps/musl/patches/includeos_syscalls.h +++ b/deps/musl/patches/includeos_syscalls.h @@ -81,6 +81,7 @@ __includeos(SYS_chmod); __includeos(SYS_chown); __includeos(SYS_chroot); __includeos(SYS_clock_adjtime); +__includeos(SYS_clock_adjtime64); __includeos(SYS_clock_getres); __includeos(SYS_clock_gettime); __includeos(SYS_clock_gettime64); @@ -100,11 +101,13 @@ __includeos(SYS_eventfd); __includeos(SYS_eventfd2); __includeos(SYS_execve); __includeos(SYS_faccessat); +__includeos(SYS_faccessat2); __includeos(SYS_fanotify_init); __includeos(SYS_fanotify_mark); __includeos(SYS_fchdir); __includeos(SYS_fchmod); __includeos(SYS_fchmodat); +__includeos(SYS_fchmodat2); __includeos(SYS_fchown); __includeos(SYS_fchownat); __includeos(SYS_fdatasync); @@ -185,6 +188,7 @@ __includeos(SYS_ppoll); __includeos(SYS_prctl); __includeos(SYS_pread); __includeos(SYS_preadv); +__includeos(SYS_preadv2); __includeos(SYS_prlimit64); __includeos(SYS_process_vm_readv); __includeos(SYS_process_vm_writev); @@ -193,6 +197,7 @@ __includeos(SYS_pselect6_time64); __includeos(SYS_ptrace); __includeos(SYS_pwrite); __includeos(SYS_pwritev); +__includeos(SYS_pwritev2); __includeos(SYS_quotactl); __includeos(SYS_read); __includeos(SYS_readahead); diff --git a/deps/musl/patches/musl.patch b/deps/musl/patches/musl.patch index 726f3bc9f1..2724d083e9 100644 --- a/deps/musl/patches/musl.patch +++ b/deps/musl/patches/musl.patch @@ -9,7 +9,7 @@ index 7d2a48a..0d9fc0f 100644 - __asm__ __volatile__( "hlt" : : : "memory" ); + __asm__ __volatile__( "ud2" : : : "memory" ); } - + #define a_ctz_64 a_ctz_64 diff --git a/arch/x86_64/atomic_arch.h b/arch/x86_64/atomic_arch.h index da4e203..08beb81 100644 @@ -22,31 +22,31 @@ index da4e203..08beb81 100644 - __asm__ __volatile__( "hlt" : : : "memory" ); + __asm__ __volatile__( "ud2" : : : "memory" ); } - + #define a_ctz_64 a_ctz_64 diff --git a/src/thread/pthread_cancel.c b/src/thread/pthread_cancel.c index 3d22922..a560b4f 100644 --- a/src/thread/pthread_cancel.c +++ b/src/thread/pthread_cancel.c @@ -30,7 +30,7 @@ long __syscall_cp_c(syscall_arg_t nr, - + if ((st=(self=__pthread_self())->canceldisable) && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close)) - return __syscall(nr, u, v, w, x, y, z); + return syscall_n(nr, u, v, w, x, y, z); - + r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z); if (r==-EINTR && nr!=SYS_close && self->cancel && diff --git a/src/unistd/setxid.c b/src/unistd/setxid.c -index 0239f8a..75c4165 100644 +index a629ed4b..e83fda99 100644 --- a/src/unistd/setxid.c +++ b/src/unistd/setxid.c -@@ -13,7 +13,7 @@ static void do_setxid(void *p) +@@ -12,7 +12,7 @@ static void do_setxid(void *p) { struct ctx *c = p; - if (c->err>0) return; -- int ret = -__syscall(c->nr, c->id, c->eid, c->sid); -+ int ret = -syscall_n(c->nr, c->id, c->eid, c->sid); - if (ret && !c->err) { + if (c->ret<0) return; +- int ret = __syscall(c->nr, c->id, c->eid, c->sid); ++ int ret = syscall_n(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 diff --git a/deps/musl/patches/syscall.h b/deps/musl/patches/syscall.h index e078fd236b..04fc8700da 100644 --- a/deps/musl/patches/syscall.h +++ b/deps/musl/patches/syscall.h @@ -2,6 +2,7 @@ #define _INTERNAL_SYSCALL_H #include +#include #include #include "includeos_syscalls.h" @@ -171,6 +172,45 @@ hidden long __syscall_ret(unsigned long), #define SYS_sendfile SYS_sendfile64 #endif +#ifdef SYS_timer_settime32 +#define SYS_timer_settime SYS_timer_settime32 +#endif + +#ifdef SYS_timer_gettime32 +#define SYS_timer_gettime SYS_timer_gettime32 +#endif + +#ifdef SYS_timerfd_settime32 +#define SYS_timerfd_settime SYS_timerfd_settime32 +#endif + +#ifdef SYS_timerfd_gettime32 +#define SYS_timerfd_gettime SYS_timerfd_gettime32 +#endif + +#ifdef SYS_clock_settime32 +#define SYS_clock_settime SYS_clock_settime32 +#endif + +#ifdef SYS_clock_gettime32 +#define SYS_clock_gettime SYS_clock_gettime32 +#endif + +#ifdef SYS_clock_getres_time32 +#define SYS_clock_getres SYS_clock_getres_time32 +#endif + +#ifdef SYS_clock_nanosleep_time32 +#define SYS_clock_nanosleep SYS_clock_nanosleep_time32 +#endif + +#ifdef SYS_gettimeofday_time32 +#define SYS_gettimeofday SYS_gettimeofday_time32 +#endif + +#ifdef SYS_settimeofday_time32 +#define SYS_settimeofday SYS_settimeofday_time32 +#endif /* Ensure that the plain syscall names are defined even for "time64-only" * archs. These facilitate callers passing null time arguments, and make @@ -278,6 +318,12 @@ hidden long __syscall_ret(unsigned long), #define __SC_recvmmsg 19 #define __SC_sendmmsg 20 +/* This is valid only because all socket syscalls are made via + * socketcall, which always fills unused argument slots with zeros. */ +#ifndef SYS_accept +#define SYS_accept SYS_accept4 +#endif + #ifndef SO_RCVTIMEO_OLD #define SO_RCVTIMEO_OLD 20 #endif @@ -317,6 +363,18 @@ hidden long __syscall_ret(unsigned long), #define __sys_open_cp __sys_open #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) +#ifdef SYS_wait4 +#define __sys_wait4(a,b,c,d) __syscall(SYS_wait4,a,b,c,d) +#define __sys_wait4_cp(a,b,c,d) __syscall_cp(SYS_wait4,a,b,c,d) +#else +hidden long __emulate_wait4(int, int *, int, void *, int); +#define __sys_wait4(a,b,c,d) __emulate_wait4(a,b,c,d,0) +#define __sys_wait4_cp(a,b,c,d) __emulate_wait4(a,b,c,d,1) +#endif + +#define sys_wait4(a,b,c,d) __syscall_ret(__sys_wait4(a,b,c,d)) +#define sys_wait4_cp(a,b,c,d) __syscall_ret(__sys_wait4_cp(a,b,c,d)) + hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); hidden void *__vdsosym(const char *, const char *); From 61dbb2852ab3ebf9ce19b0315e85b01b9e01afa9 Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Mon, 17 Jun 2024 19:53:50 +0200 Subject: [PATCH 07/14] musl 1.2.5: stub missing syscalls, add time64 versions for 32bit - stub faccessat, faccessat2, fchmodat2, pwritev2, preadv2, statx - include time64 versions of calls to time functions. As it looks like IncludeOS is already using 64 bit time on 32 bit, the *_time64 calls just redirect to the existing calls. On 64 bit systems there should be no change, as the regular calls are 64 bit. --- src/musl/CMakeLists.txt | 4 ++++ src/musl/clock_gettime.cpp | 5 +++++ src/musl/faccessat.cpp | 14 ++++++++++++++ src/musl/faccessat2.cpp | 14 ++++++++++++++ src/musl/fchmodat2.cpp | 14 ++++++++++++++ src/musl/futex.cpp | 7 +++++++ src/musl/nanosleep.cpp | 7 +++++++ src/musl/statx.cpp | 15 +++++++++++++++ 8 files changed, 80 insertions(+) create mode 100644 src/musl/faccessat.cpp create mode 100644 src/musl/faccessat2.cpp create mode 100644 src/musl/fchmodat2.cpp create mode 100644 src/musl/statx.cpp diff --git a/src/musl/CMakeLists.txt b/src/musl/CMakeLists.txt index d5c37697c4..457c9e0faa 100644 --- a/src/musl/CMakeLists.txt +++ b/src/musl/CMakeLists.txt @@ -10,6 +10,7 @@ set(MUSL_OBJECTS msync.cpp mincore.cpp syscall_n.cpp sigmask.cpp gettid.cpp socketcall.cpp rt_sigaction.cpp stat.cpp fstat.cpp fstatat.cpp + statx.cpp access.cpp chmod.cpp chown.cpp @@ -19,7 +20,10 @@ set(MUSL_OBJECTS fchdir.cpp fchmod.cpp fchmodat.cpp + fchmodat2.cpp fchown.cpp + faccessat.cpp + faccessat2.cpp fsync.cpp ftruncate.cpp getdents.cpp diff --git a/src/musl/clock_gettime.cpp b/src/musl/clock_gettime.cpp index 8f4cd31297..cb1ec1c8ef 100644 --- a/src/musl/clock_gettime.cpp +++ b/src/musl/clock_gettime.cpp @@ -21,3 +21,8 @@ extern "C" long syscall_SYS_clock_gettime(clockid_t clk_id, struct timespec* tp) { return strace(sys_clock_gettime, "clock_gettime", clk_id, tp); } + +extern "C" +long syscall_SYS_clock_gettime64(clockid_t clk_id, struct timespec* tp) { + return strace(sys_clock_gettime, "clock_gettime", clk_id, tp); +} diff --git a/src/musl/faccessat.cpp b/src/musl/faccessat.cpp new file mode 100644 index 0000000000..62d57ec503 --- /dev/null +++ b/src/musl/faccessat.cpp @@ -0,0 +1,14 @@ +#include "common.hpp" +#include +#include + +static long sys_faccessat(int /*fd*/, const char* /*path*/, mode_t, int /*flag*/) +{ + // TODO Same as access(), but path is relative to fd + return -EROFS; +} + +extern "C" +long syscall_SYS_faccessat(int fd, const char *path, mode_t mode, int flag) { + return strace(sys_faccessat, "faccessat", fd, path, mode, flag); +} diff --git a/src/musl/faccessat2.cpp b/src/musl/faccessat2.cpp new file mode 100644 index 0000000000..a007f56f10 --- /dev/null +++ b/src/musl/faccessat2.cpp @@ -0,0 +1,14 @@ +#include "common.hpp" +#include +#include + +static long sys_faccessat2(int /*fd*/, const char* /*path*/, mode_t, int /*flag*/) +{ + // TODO Same as access(), but path is relative to fd + return -EROFS; +} + +extern "C" +long syscall_SYS_faccessat2(int fd, const char *path, mode_t mode, int flag) { + return strace(sys_faccessat2, "faccessat2", fd, path, mode, flag); +} diff --git a/src/musl/fchmodat2.cpp b/src/musl/fchmodat2.cpp new file mode 100644 index 0000000000..b7c72d2522 --- /dev/null +++ b/src/musl/fchmodat2.cpp @@ -0,0 +1,14 @@ +#include "common.hpp" +#include +#include + +static long sys_fchmodat2(int /*fd*/, const char* /*path*/, mode_t, int /*flag*/) +{ + // currently makes no sense, especially since we're read-only + return -EROFS; +} + +extern "C" +long syscall_SYS_fchmodat2(int fd, const char *path, mode_t mode, int flag) { + return strace(sys_fchmodat2, "fchmodat2", fd, path, mode, flag); +} diff --git a/src/musl/futex.cpp b/src/musl/futex.cpp index 1b7c46559f..4596811838 100644 --- a/src/musl/futex.cpp +++ b/src/musl/futex.cpp @@ -40,3 +40,10 @@ int syscall_SYS_futex(int *uaddr, int futex_op, int val, { return stubtrace(sys_futex, "futex", uaddr, futex_op, val, timeout, val3); } + +extern "C" +int syscall_SYS_futex_time64(int *uaddr, int futex_op, int val, + const struct timespec *timeout, int val3) +{ + return stubtrace(sys_futex, "futex_time64", uaddr, futex_op, val, timeout, val3); +} diff --git a/src/musl/nanosleep.cpp b/src/musl/nanosleep.cpp index ff96e5eafa..be527aecb4 100644 --- a/src/musl/nanosleep.cpp +++ b/src/musl/nanosleep.cpp @@ -37,3 +37,10 @@ long syscall_SYS_clock_nanosleep(clockid_t, int, { return strace(sys_nanosleep, "clock_nanosleep", req, rem); } + +extern "C" +long syscall_SYS_clock_nanosleep_time64(clockid_t, int, + const struct timespec *req, struct timespec *rem) +{ + return strace(sys_nanosleep, "clock_nanosleep_time64", req, rem); +} diff --git a/src/musl/statx.cpp b/src/musl/statx.cpp new file mode 100644 index 0000000000..b85d44d7df --- /dev/null +++ b/src/musl/statx.cpp @@ -0,0 +1,15 @@ +#include "common.hpp" +#include + +long sys_statx(int /*dirfd*/, const char* /*pathname*/, int /*flags*/, + unsigned int /*mask*/, struct statx* /*statxbuf*/) +{ + return -ENOSYS; +} + +extern "C" +long syscall_SYS_statx(int dirfd, const char *pathname, int flags, + unsigned int mask, struct statx *statxbuf) { + return strace(sys_statx, "statx", dirfd, pathname, flags, mask, statxbuf); +} + From 4ec88b631afc7a03641a027d4a9320cfce6d3902 Mon Sep 17 00:00:00 2001 From: Alfred Bratterud Date: Tue, 2 Jul 2024 10:55:43 +0200 Subject: [PATCH 08/14] Make a_crash emit a message and cli;hlt This makes crash loop detection easier --- deps/musl/patches/musl.patch | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/deps/musl/patches/musl.patch b/deps/musl/patches/musl.patch index 2724d083e9..52120c7d5b 100644 --- a/deps/musl/patches/musl.patch +++ b/deps/musl/patches/musl.patch @@ -2,12 +2,14 @@ diff --git a/arch/i386/atomic_arch.h b/arch/i386/atomic_arch.h index 7d2a48a..0d9fc0f 100644 --- a/arch/i386/atomic_arch.h +++ b/arch/i386/atomic_arch.h -@@ -80,7 +80,7 @@ static inline void a_spin() - #define a_crash a_crash +@@ -80,4 +80,7 @@ static inline void a_spin() ++ extern void kprint(const char*); ++ #define a_crash a_crash static inline void a_crash() { - __asm__ __volatile__( "hlt" : : : "memory" ); -+ __asm__ __volatile__( "ud2" : : : "memory" ); ++ kprint("\n*** Libc crashed 😵 ***\n"); ++ __asm__ __volatile__( "cli;hlt" : : : "memory" ); } #define a_ctz_64 a_ctz_64 @@ -15,12 +17,14 @@ diff --git a/arch/x86_64/atomic_arch.h b/arch/x86_64/atomic_arch.h index da4e203..08beb81 100644 --- a/arch/x86_64/atomic_arch.h +++ b/arch/x86_64/atomic_arch.h -@@ -105,7 +105,7 @@ static inline void a_spin() - #define a_crash a_crash +@@ -105,4 +105,7 @@ static inline void a_spin() ++ extern void kprint(const char*); ++#define a_crash a_crash static inline void a_crash() { - __asm__ __volatile__( "hlt" : : : "memory" ); -+ __asm__ __volatile__( "ud2" : : : "memory" ); ++ kprint("\n*** Libc crashed 😵 ***\n"); ++ __asm__ __volatile__( "cli;hlt" : : : "memory" ); } #define a_ctz_64 a_ctz_64 From 4c154c3eebf0fe569080ab44284b29e7b118b16a Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Tue, 2 Jul 2024 11:03:38 +0200 Subject: [PATCH 09/14] default changed: FOR_PRODUCTION is OFF Missing RDSEED/RDRAND will only emit warning, not terminate --- cmake/os.cmake | 2 +- src/kernel/kernel.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/os.cmake b/cmake/os.cmake index c3cb221c5c..417e77209f 100644 --- a/cmake/os.cmake +++ b/cmake/os.cmake @@ -100,7 +100,7 @@ set(CMAKE_SKIP_RPATH ON) set(BUILD_SHARED_LIBRARIES OFF) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") -option(FOR_PRODUCTION "Stop the OS when conditions not suitable for production" ON) +option(FOR_PRODUCTION "Stop the OS when conditions not suitable for production" OFF) if (FOR_PRODUCTION) set(PROD_USE "--defsym __for_production_use=0x2000") else() diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index bb04d12b05..9992edc3c9 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -160,6 +160,8 @@ void kernel::post_start() printf(" +--> To disable this check, re-run cmake with \"-DFOR_PRODUCTION=OFF\".\n"); os::shutdown(); return; + } else { + printf(" +--> To make this warning fatal, re-compile with FOR_PRODUCTION=ON.\n"); } FILLINE('~'); } From 617565600238b4636270f5b90701cd9f8c56c18c Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Tue, 2 Jul 2024 11:08:26 +0200 Subject: [PATCH 10/14] default changed: SMP now ON Enable SMP by default. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 085accec62..1efc2c8c1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) project (includeos C CXX) -option(SMP "Compile with SMP (multiprocessing)" OFF) +option(SMP "Compile with SMP (multiprocessing)" ON) option(PROFILE "Compile with startup profilers" OFF) include(cmake/includeos.cmake) From 6f565ca12e673848d99c23716cb89ed51a77912f Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Tue, 2 Jul 2024 11:11:09 +0200 Subject: [PATCH 11/14] example: shut down service after last printf --- example/src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example/src/main.cpp b/example/src/main.cpp index 990870bfd4..dabb793620 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -3,5 +3,7 @@ void Service::start(const std::string& args){ printf("Args = %s\n", args.c_str()); - printf("Try giving the service less memory, eg. 5MB in vm.json\n"); + printf("Try giving the service less memory, eg. 10MB in vm.json\n"); + printf("Service done. Shutting down...\n"); + os::shutdown(); } From 7dbb15d3b15a9b8baaaa4b0d2b352b314cd1650b Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Wed, 3 Jul 2024 10:08:53 +0200 Subject: [PATCH 12/14] musl 1.2.5: update __libc struct --- src/platform/x86_pc/smp.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/platform/x86_pc/smp.cpp b/src/platform/x86_pc/smp.cpp index 6e2e6975b6..c154ba4497 100644 --- a/src/platform/x86_pc/smp.cpp +++ b/src/platform/x86_pc/smp.cpp @@ -45,13 +45,13 @@ struct apic_boot { uint32_t stack_base; uint32_t stack_size; }; - struct __libc { - int can_do_threads; - int threaded; - int secure; - volatile int threads_minus_1; - size_t* auxv; + char can_do_threads; + char threaded; + char secure; + volatile signed char need_locks; + int threads_minus_1; + size_t *auxv; }; extern struct __libc __libc; //extern "C" struct __libc *__libc_loc(void) __attribute__((const)); @@ -59,11 +59,14 @@ extern struct __libc __libc; static inline void musl_override_glob_locks() { - printf("__libc.can_do_threads: %d __libc.threaded: %d\n", + printf("__libc.can_do_threads: %d\n__libc.threaded: %d\n", __libc.can_do_threads, __libc.threaded); printf("__libc.threads_minus_1: %d -> %d\n", __libc.threads_minus_1, 1); __libc.threads_minus_1 = 1; + printf("__libc.need_locks: %d -> 1", + __libc.need_locks); + __libc.need_locks = 1; } namespace x86 From bdcf6fd0f9818139b92da234fd275d9189a0e574 Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Fri, 16 Aug 2024 22:50:11 +0200 Subject: [PATCH 13/14] musl: use oldmalloc instead of mallocng --- deps/musl-unpatched/default.nix | 2 +- deps/musl/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/musl-unpatched/default.nix b/deps/musl-unpatched/default.nix index a2be281598..9fbb4e2de4 100644 --- a/deps/musl-unpatched/default.nix +++ b/deps/musl-unpatched/default.nix @@ -17,7 +17,7 @@ stdenv.mkDerivation rec { configurePhase = '' echo "Configuring with musl's configure script" echo "Target platform is ${stdenv.targetPlatform.config}" - ./configure --prefix=$out --disable-shared --enable-debug CROSS_COMPILE=${stdenv.targetPlatform.config}- + ./configure --prefix=$out --with-malloc=oldmalloc --disable-shared --enable-debug CROSS_COMPILE=${stdenv.targetPlatform.config}- ''; # Copy linux headers - taken from upstream nixpkgs musl, needed for libcxx to build diff --git a/deps/musl/default.nix b/deps/musl/default.nix index 09a3a74fe5..c3070d3340 100644 --- a/deps/musl/default.nix +++ b/deps/musl/default.nix @@ -34,7 +34,7 @@ stdenv.mkDerivation rec { configurePhase = '' echo "Configuring with musl's configure script" echo "Target platform is ${stdenv.targetPlatform.config}" - ./configure --prefix=$out --disable-shared --enable-debug CROSS_COMPILE=${stdenv.targetPlatform.config}- + ./configure --prefix=$out --disable-shared --enable-debug --with-malloc=oldmalloc CROSS_COMPILE=${stdenv.targetPlatform.config}- ''; CFLAGS = "-Wno-error=int-conversion -nostdinc"; From d5f6bb5a69a629cd31bb0ee2e37b444b9b8fc22b Mon Sep 17 00:00:00 2001 From: Magnus Skjegstad Date: Sat, 7 Sep 2024 17:59:05 +0200 Subject: [PATCH 14/14] tests: update stacktrace test to match new musl version --- test/kernel/integration/stacktrace/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/kernel/integration/stacktrace/test.py b/test/kernel/integration/stacktrace/test.py index 567ad79412..8f6f692fe2 100755 --- a/test/kernel/integration/stacktrace/test.py +++ b/test/kernel/integration/stacktrace/test.py @@ -19,7 +19,7 @@ def is_good(line): vm.on_output("Service::start()", is_good) vm.on_output("kernel_main", is_good) -vm.on_output("__libc_start_main", is_good) +vm.on_output("libc_start_main", is_good) vm.on_output("long_mode", is_good) vm.boot(20,image_name='kernel_stacktrace')