Constructors between vsyscall init and libc init Add a region for constructors to be placed between __sysinfo being initialised to sel4_vsyscall and libc_init to allow a user-level implementation to set up virtual memory syscalls use by libc_init whilst depending on a functioning implementation of malloc. Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
diff --git a/libsel4muslcsys/CMakeLists.txt b/libsel4muslcsys/CMakeLists.txt index 336a75c..731bc65 100644 --- a/libsel4muslcsys/CMakeLists.txt +++ b/libsel4muslcsys/CMakeLists.txt
@@ -61,7 +61,7 @@ they occur after external initialisation of the system call dependencies." DEFAULT - "CONSTRUCTOR_MIN_PRIORITY + 1" + "MUSLCSYS_WITH_VSYSCALL_PRIORITY + 10" UNQUOTE ) mark_as_advanced(
diff --git a/libsel4muslcsys/include/muslcsys/vsyscall.h b/libsel4muslcsys/include/muslcsys/vsyscall.h index 722cee7..c96871d 100644 --- a/libsel4muslcsys/include/muslcsys/vsyscall.h +++ b/libsel4muslcsys/include/muslcsys/vsyscall.h
@@ -19,6 +19,8 @@ #include <bits/syscall.h> #include <utils/attribute.h> +#define MUSLCSYS_WITH_VSYSCALL_PRIORITY (CONSTRUCTOR_MIN_PRIORITY + 10) + typedef long (*muslcsys_syscall_t)(va_list); /* Installs a new handler for the given syscall. Any previous handler is returned
diff --git a/libsel4muslcsys/src/vsyscall.c b/libsel4muslcsys/src/vsyscall.c index d48d58b..aa3ce88 100644 --- a/libsel4muslcsys/src/vsyscall.c +++ b/libsel4muslcsys/src/vsyscall.c
@@ -291,6 +291,20 @@ return ret; } +extern void *__sysinfo; + +/* Set the virtual syscall handler so that a portion of muslc will + * function. + * + * This is required for apps using a dynamic heap, which need to make + * use of malloc in order to provide an implementation of brk and mmap + * that are used during the initialisation of muslc. + */ +static void CONSTRUCTOR(MUSLCSYS_WITH_VSYSCALL_PRIORITY - 1) init_vsyscall(void) +{ + __sysinfo = sel4_vsyscall; +} + /* Put a pointer to sel4_vsyscall in a special section so anyone loading us * knows how to configure our syscall table */ uintptr_t VISIBLE SECTION("__vsyscall") __vsyscall_ptr = (uintptr_t) sel4_vsyscall;