From c128ce938e85c908d1f71923d5ec90a8b6f1f193 Mon Sep 17 00:00:00 2001 From: Thomas A Date: Fri, 19 May 2023 09:48:55 -0700 Subject: [PATCH] Partially Restore Darling-Specific Changes Since we don't build the kernel module anymore, I want to take the opportunity to only include changes that are needed for Darling to function (build and sucessfully bring up `bash`). --- EXTERNAL_HEADERS/stdatomic.h | 2 +- libkern/os/trace.h | 2 ++ osfmk/mach/i386/syscall_sw.h | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/EXTERNAL_HEADERS/stdatomic.h b/EXTERNAL_HEADERS/stdatomic.h index 2ce9fa5..4bde893 100644 --- a/EXTERNAL_HEADERS/stdatomic.h +++ b/EXTERNAL_HEADERS/stdatomic.h @@ -31,7 +31,7 @@ /* If we're hosted, fall back to the system's stdatomic.h. FreeBSD, for * example, already has a Clang-compatible stdatomic.h header. */ -#if __STDC_HOSTED__ && __has_include_next() +#if !defined(DARLING) && __STDC_HOSTED__ && __has_include_next() # include_next #else diff --git a/libkern/os/trace.h b/libkern/os/trace.h index 318c21c..be17768 100644 --- a/libkern/os/trace.h +++ b/libkern/os/trace.h @@ -42,7 +42,9 @@ typedef void *xpc_object_t; __BEGIN_DECLS +#ifndef DARLING extern void *__dso_handle; +#endif OS_ALWAYS_INLINE static inline void diff --git a/osfmk/mach/i386/syscall_sw.h b/osfmk/mach/i386/syscall_sw.h index abef968..175b892 100644 --- a/osfmk/mach/i386/syscall_sw.h +++ b/osfmk/mach/i386/syscall_sw.h @@ -74,20 +74,39 @@ /* * Syscall entry macros for use in libc: */ +#ifndef DARLING + #define UNIX_SYSCALL_TRAP \ int $(UNIX_INT) #define MACHDEP_SYSCALL_TRAP \ int $(MACHDEP_INT) +#else // DARLING + +#define UNIX_SYSCALL_TRAP \ + call __darling_bsd_syscall +#define MACHDEP_SYSCALL_TRAP \ + call __darling_machdep_syscall + +#endif + /* * Macro to generate Mach call stubs in libc: */ +#ifndef DARLING #define kernel_trap(trap_name,trap_number,number_args) \ LEAF(_##trap_name,0) ;\ movl $##trap_number, %eax ;\ call __sysenter_trap ;\ END(_##trap_name) +#else // DARLING +#define kernel_trap(trap_name,trap_number,number_args) \ +LEAF(_##trap_name,0) ;\ + movl $##trap_number, %eax ;\ + call __darling_mach_syscall ;\ +END(_##trap_name) +#endif #endif /* !KERNEL */ @@ -97,10 +116,17 @@ END(_##trap_name) #ifndef KERNEL +#ifndef DARLING #define UNIX_SYSCALL_TRAP \ syscall #define MACHDEP_SYSCALL_TRAP \ syscall +#else // DARLING +#define UNIX_SYSCALL_TRAP \ + call __darling_bsd_syscall +#define MACHDEP_SYSCALL_TRAP \ + call __darling_machdep_syscall +#endif /* * Macro to generate Mach call stubs in Libc. @@ -109,13 +135,20 @@ END(_##trap_name) * macro above, we negate those numbers here for the 64-bit * code path. */ +#ifndef DARLING #define kernel_trap(trap_name,trap_number,number_args) \ LEAF(_##trap_name,0) ;\ movq %rcx, %r10 ;\ movl $ SYSCALL_CONSTRUCT_MACH(-##trap_number), %eax ;\ syscall ;\ END(_##trap_name) - +#else // DARLING +#define kernel_trap(trap_name,trap_number,number_args) \ +LEAF(_##trap_name,0) ;\ + movl $##trap_number, %eax ;\ + call __darling_mach_syscall;\ +END(_##trap_name) +#endif #endif /* !KERNEL */ #endif /* defined(__x86_64__) */