diff --git a/CMakeLists.txt b/CMakeLists.txt index 085accec6..1efc2c8c1 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) diff --git a/cmake/os.cmake b/cmake/os.cmake index c3cb221c5..417e77209 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/deps/musl-unpatched/default.nix b/deps/musl-unpatched/default.nix index 1e2b27ba4..9fbb4e2de 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.2.5"; src = fetchGit { url = "git://git.musl-libc.org/musl"; - rev = "eb03bde2f24582874cb72b56c7811bf51da0c817"; + rev = "0784374d561435f7c787a555aeab8ede699ed298"; }; enableParallelBuilding = true; @@ -21,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 aecebebbc..c3070d334 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.2.5"; src = fetchGit { url = "git://git.musl-libc.org/musl"; - rev = "eb03bde2f24582874cb72b56c7811bf51da0c817"; + rev = "0784374d561435f7c787a555aeab8ede699ed298"; }; enableParallelBuilding = true; @@ -38,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"; diff --git a/deps/musl/patches/includeos_syscalls.h b/deps/musl/patches/includeos_syscalls.h index d199f40e7..00016241e 100644 --- a/deps/musl/patches/includeos_syscalls.h +++ b/deps/musl/patches/includeos_syscalls.h @@ -1,52 +1,74 @@ #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_futex_time64(); +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_ppoll_time64(); +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_semtimedop_time64(); 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); @@ -59,10 +81,14 @@ __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); __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); @@ -75,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); @@ -140,6 +168,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); @@ -158,13 +188,16 @@ __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); __includeos(SYS_pselect6); +__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); @@ -181,6 +214,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); @@ -191,6 +225,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 +252,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); @@ -234,9 +270,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); @@ -247,6 +287,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); @@ -254,25 +295,26 @@ __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 syscall_SYS_recvmmsg_time64(); +//int socketcall_sendmmsg(); diff --git a/deps/musl/patches/musl.patch b/deps/musl/patches/musl.patch index 726f3bc9f..52120c7d5 100644 --- a/deps/musl/patches/musl.patch +++ b/deps/musl/patches/musl.patch @@ -2,51 +2,55 @@ 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 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 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 0846fc025..04fc8700d 100644 --- a/deps/musl/patches/syscall.h +++ b/deps/musl/patches/syscall.h @@ -1,6 +1,8 @@ #ifndef _INTERNAL_SYSCALL_H #define _INTERNAL_SYSCALL_H +#include +#include #include #include "includeos_syscalls.h" @@ -28,26 +30,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 +172,128 @@ long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), #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 + * 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 +318,33 @@ long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...), #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 +#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 +363,20 @@ 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__)) +#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 *); + #endif diff --git a/example/src/main.cpp b/example/src/main.cpp index 990870bfd..dabb79362 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(); } diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index bb04d12b0..9992edc3c 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('~'); } diff --git a/src/musl/CMakeLists.txt b/src/musl/CMakeLists.txt index ca59cfb21..457c9e0fa 100644 --- a/src/musl/CMakeLists.txt +++ b/src/musl/CMakeLists.txt @@ -2,29 +2,35 @@ 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 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 cwd.cpp dup3.cpp # also dup, dup2 execve.cpp + fchdir.cpp fchmod.cpp fchmodat.cpp + fchmodat2.cpp fchown.cpp + faccessat.cpp + faccessat2.cpp fsync.cpp ftruncate.cpp getdents.cpp geteuid.cpp getgid.cpp getuid.cpp + getrandom.cpp kill.cpp mkdir.cpp mkdirat.cpp @@ -46,6 +52,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/clock_gettime.cpp b/src/musl/clock_gettime.cpp index 8f4cd3129..cb1ec1c8e 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 000000000..62d57ec50 --- /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 000000000..a007f56f1 --- /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/fchdir.cpp b/src/musl/fchdir.cpp new file mode 100644 index 000000000..e02dce792 --- /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/fchmodat2.cpp b/src/musl/fchmodat2.cpp new file mode 100644 index 000000000..b7c72d252 --- /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 1b7c46559..459681183 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/getrandom.cpp b/src/musl/getrandom.cpp new file mode 100644 index 000000000..655b4d3f6 --- /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 000000000..ad38b5f10 --- /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/nanosleep.cpp b/src/musl/nanosleep.cpp index 17be07fb9..be527aecb 100644 --- a/src/musl/nanosleep.cpp +++ b/src/musl/nanosleep.cpp @@ -30,3 +30,17 @@ 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); +} + +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/sched_setaffinity.cpp b/src/musl/sched_setaffinity.cpp new file mode 100644 index 000000000..78060ea03 --- /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 000000000..69e8b335e --- /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 000000000..d766041ae --- /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); +} diff --git a/src/musl/statx.cpp b/src/musl/statx.cpp new file mode 100644 index 000000000..b85d44d7d --- /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); +} + diff --git a/src/platform/x86_pc/smp.cpp b/src/platform/x86_pc/smp.cpp index 6e2e6975b..c154ba449 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 diff --git a/test/kernel/integration/stacktrace/test.py b/test/kernel/integration/stacktrace/test.py index 567ad7941..8f6f692fe 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')