this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[kernel/libsyscall] Restore darling specific changes

Thomas A fc97b2ad 73761f1c

+202 -2
+30 -1
src/kernel/libsyscall/custom/SYS.h
··· 59 59 * for the majority of syscalls which just return a value in %eax. 60 60 */ 61 61 62 - #define UNIX_SYSCALL_SYSENTER call __sysenter_trap 62 + #ifdef DARLING 63 + #define UNIX_SYSCALL_SYSENTER call __darling_bsd_syscall 64 + #else 65 + #define UNIX_SYSCALL_SYSENTER call __sysenter_trap 66 + #endif 63 67 #define UNIX_SYSCALL(name, nargs) \ 64 68 .globl tramp_cerror ;\ 65 69 LEAF(_##name, 0) ;\ ··· 127 131 #include <architecture/i386/asm_help.h> 128 132 #include <mach/i386/syscall_sw.h> 129 133 134 + #ifdef DARLING 135 + #define UNIX_SYSCALL(name, nargs) \ 136 + .globl cerror ;\ 137 + LEAF(_#name, 0) ;\ 138 + movl $ SYS_##name, %eax ;\ 139 + call __darling_bsd_syscall ;\ 140 + cmpq $-4095, %rax ;\ 141 + jb 2f ;\ 142 + movq %rax, %rdi ;\ 143 + negq %rdi ;\ 144 + BRANCH_EXTERN(_cerror) ;\ 145 + 2: 146 + 147 + #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ 148 + .globl cerror ;\ 149 + movl $ SYS_##name, %eax ;\ 150 + call __darling_bsd_syscall ;\ 151 + cmpq $-4095, %rax ;\ 152 + jb 2f ;\ 153 + movq %rax, %rdi ;\ 154 + negq %rdi ;\ 155 + BRANCH_EXTERN(_##cerror) ;\ 156 + 2: 157 + #else 130 158 #define UNIX_SYSCALL_SYSCALL \ 131 159 movq %rcx, %r10 ;\ 132 160 syscall ··· 149 177 movq %rax, %rdi ;\ 150 178 BRANCH_EXTERN(_##cerror) ;\ 151 179 2: 180 + #endif 152 181 153 182 #define PSEUDO(pseudo, name, nargs, cerror) \ 154 183 LEAF(pseudo, 0) ;\
+19 -1
src/kernel/libsyscall/custom/__fork.S
··· 52 52 subl $28, %esp // Align the stack, with 16 bytes of extra padding that we'll need 53 53 54 54 movl $ SYS_fork,%eax; // code for fork -> eax 55 + #ifdef DARLING 56 + call __darling_bsd_syscall 57 + cmpl $0, %eax 58 + jnb L1 59 + #else 55 60 UNIX_SYSCALL_TRAP // do the system call 56 61 jnc L1 // jump if CF==0 62 + #endif 57 63 58 64 CALL_EXTERN(tramp_cerror) 59 65 movl $-1,%eax ··· 77 83 LEAF(___fork, 0) 78 84 subq $24, %rsp // Align the stack, plus room for local storage 79 85 86 + #ifdef DARLING 87 + movl $ SYS_fork, %eax 88 + call __darling_bsd_syscall 89 + cmpq $0, %rax 90 + jnb L1 91 + #else 80 92 movl $ SYSCALL_CONSTRUCT_UNIX(SYS_fork),%eax; // code for fork -> rax 81 93 UNIX_SYSCALL_TRAP // do the system call 82 94 jnc L1 // jump if CF==0 95 + #endif 83 96 84 97 movq %rax, %rdi 85 98 CALL_EXTERN(_cerror) ··· 88 101 ret 89 102 90 103 L1: 104 + #ifdef DARLING 105 + testl %eax, %eax 106 + jnz L2 107 + #else 91 108 orl %edx,%edx // CF=OF=0, ZF set if zero result 92 109 jz L2 // parent, since r1 == 0 in parent, 1 in child 93 - 110 + #endif 111 + 94 112 //child here... 95 113 xorq %rax, %rax 96 114 PICIFY(__current_pid)
+20
src/kernel/libsyscall/custom/__vfork.S
··· 105 105 lock 106 106 cmpxchgl %ecx, (%rdx) 107 107 jne 0b 108 + #ifdef DARLING 109 + movl $ SYS_vfork, %eax 110 + call __darling_bsd_syscall 111 + cmpq $0, %rax 112 + jnb L1 113 + #else 108 114 popq %rdi // return address in %rdi 109 115 movq $ SYSCALL_CONSTRUCT_UNIX(SYS_vfork), %rax // code for vfork -> rax 110 116 UNIX_SYSCALL_TRAP // do the system call 111 117 jnb L1 // jump if CF==0 112 118 pushq %rdi // put return address back on stack for cerror 119 + #endif 113 120 movq __current_pid@GOTPCREL(%rip), %rcx 114 121 lock 115 122 addl $1, (%rcx) ··· 117 124 BRANCH_EXTERN(_cerror) 118 125 119 126 L1: 127 + #ifdef DARLING 128 + testl %eax, %eax 129 + jnz L2 130 + #else 120 131 testl %edx, %edx // CF=OF=0, ZF set if zero result 121 132 jz L2 // parent, since r1 == 0 in parent, 1 in child 133 + #endif 122 134 xorq %rax, %rax // zero rax 135 + #ifdef DARLING 136 + ret 137 + #else 123 138 jmp *%rdi 139 + #endif 124 140 125 141 L2: 126 142 movq __current_pid@GOTPCREL(%rip), %rdx 127 143 lock 128 144 addl $1, (%rdx) 145 + #ifdef DARLING 146 + ret 147 + #else 129 148 jmp *%rdi 149 + #endif 130 150 131 151 #elif defined(__arm__) 132 152
+57
src/kernel/libsyscall/mach/mach_init.c
··· 62 62 #include <stdbool.h> 63 63 #include "externs.h" 64 64 65 + #ifdef DARLING 66 + #include <darlingserver/rpc.h> 67 + #include "../../emulation/linux/duct_errno.h" 68 + #endif 69 + 65 70 mach_port_t bootstrap_port = MACH_PORT_NULL; 66 71 mach_port_t mach_task_self_ = MACH_PORT_NULL; 67 72 #ifdef __i386__ ··· 77 82 vm_size_t vm_page_mask = 0; 78 83 int vm_page_shift = 0; 79 84 85 + #ifdef DARLING 86 + int mach_init(const char** applep); 87 + #else 80 88 int mach_init(void); 89 + #endif 81 90 int _mach_fork_child(void); 91 + #ifdef DARLING 92 + int _mach_fork_parent(void); 93 + #endif 82 94 95 + #ifdef DARLING 96 + static void mach_init_doit(const char** applep); 97 + #else 83 98 static void mach_init_doit(void); 99 + #endif 84 100 85 101 extern void _pthread_set_self(void *); 86 102 extern void _init_cpu_capabilities(void); ··· 97 113 * called by libSystem_initializer() in dynamic executables 98 114 */ 99 115 int 116 + #ifdef DARLING 117 + mach_init(const char** applep) 118 + #else 100 119 mach_init(void) 120 + #endif 101 121 { 102 122 static bool mach_init_inited = false; 103 123 if (!mach_init_inited) { 124 + #ifdef DARLING 125 + mach_init_doit(applep); 126 + #else 104 127 mach_init_doit(); 128 + #endif 105 129 mach_init_inited = true; 106 130 } 107 131 return 0; ··· 111 135 int 112 136 _mach_fork_child(void) 113 137 { 138 + #ifdef DARLING 139 + mach_init_doit(NULL); 140 + #else 114 141 mach_init_doit(); 142 + #endif 115 143 return 0; 116 144 } 117 145 146 + #ifdef DARLING 147 + int _mach_fork_parent(void) { 148 + int result; 149 + 150 + retry: 151 + result = dserver_rpc_fork_wait_for_child(); 152 + if (result < 0) { 153 + if (result == -LINUX_EINTR) { 154 + goto retry; 155 + } 156 + __builtin_unreachable(); 157 + } 158 + return 0; 159 + }; 160 + #endif 161 + 118 162 #if defined(__arm__) || defined(__arm64__) 119 163 #if !defined(_COMM_PAGE_USER_PAGE_SHIFT_64) && defined(_COMM_PAGE_UNUSED0) 120 164 #define _COMM_PAGE_USER_PAGE_SHIFT_32 (_COMM_PAGE_UNUSED0) ··· 128 172 #define COMM_PAGE_KERNEL_PAGE_SHIFT_MIN_VERSION 3 129 173 #endif 130 174 175 + #ifdef DARLING 176 + extern void mach_driver_init(const char** applep); 177 + extern void mach_driver_init_pthread(void); 178 + #endif 179 + 131 180 void 181 + #ifdef DARLING 182 + mach_init_doit(const char** applep) 183 + #else 132 184 mach_init_doit(void) 185 + #endif 133 186 { 187 + #ifdef DARLING 188 + mach_driver_init(applep); 189 + #endif 190 + 134 191 // Initialize cached mach ports defined in mach_init.h 135 192 mach_task_self_ = task_self_trap(); 136 193 _task_reply_port = mach_reply_port();
+4
src/kernel/libsyscall/nolegacy.h
··· 1 + #ifndef __i386__ 2 + # define NO_SYSCALL_LEGACY 3 + #endif 4 +
+28
src/kernel/libsyscall/os/tsd.h
··· 52 52 #include <arm/arch.h> 53 53 #endif 54 54 55 + #ifdef DARLING 56 + #include <darling/emulation/linux-syscalls.h> 57 + #endif 58 + 55 59 extern void _thread_set_tsd_base(void *tsd_base); 56 60 57 61 __attribute__((always_inline)) 58 62 static __inline__ unsigned int 59 63 _os_cpu_number(void) 60 64 { 65 + #ifdef DARLING 66 + extern int __linux_syscall(int nr, ...); 67 + 68 + unsigned int cpu_num = 0; 69 + int status = __linux_syscall(__NR_getcpu, &cpu_num, 0, 0, 0, 0, 0); 70 + // should we even check? i don't think it's possible for it to fail with these arguments 71 + if (status < 0) { 72 + return 0; // i guess? 73 + } 74 + 75 + return cpu_num; 76 + #else // !DARLING 61 77 #if defined(__arm__) 62 78 uintptr_t p; 63 79 __asm__("mrc p15, 0, %[p], c13, c0, 3" : [p] "=&r" (p)); ··· 73 89 #else 74 90 #error _os_cpu_number not implemented on this architecture 75 91 #endif 92 + #endif // !DARLING 76 93 } 77 94 78 95 #if defined(__i386__) || defined(__x86_64__) ··· 80 97 #if defined(__has_attribute) 81 98 #if __has_attribute(address_space) 82 99 #define OS_GS_RELATIVE __attribute__((address_space(256))) 100 + 101 + #if defined(DARLING) && defined(__i386__) && !defined(__x86_64__) 102 + #undef OS_GS_RELATIVE 103 + #define OS_GS_RELATIVE __attribute__((address_space(257))) 104 + #endif 105 + 83 106 #endif 84 107 #endif 85 108 ··· 176 199 177 200 #if defined(__i386__) || defined(__x86_64__) 178 201 202 + #if defined(DARLING) && defined(__i386__) && !defined(__x86_64__) 203 + #define _OS_PTR_MUNGE(_reg) \ 204 + xor %fs:_OS_TSD_OFFSET(__TSD_PTR_MUNGE), _reg 205 + #else 179 206 #define _OS_PTR_MUNGE(_reg) \ 180 207 xor %gs:_OS_TSD_OFFSET(__TSD_PTR_MUNGE), _reg 208 + #endif 181 209 182 210 #define _OS_PTR_UNMUNGE(_reg) \ 183 211 _OS_PTR_MUNGE(_reg)
+5
src/kernel/libsyscall/wrappers/_libc_funcptr.c
··· 113 113 .strcpy = _libkernel_strcpy, 114 114 .strlcpy = _libkernel_strlcpy, 115 115 .strlen = _libkernel_strlen, 116 + #ifdef DARLING 117 + .strncmp = _darling_libkernel_strncmp, 118 + #endif 116 119 }; 117 120 static _libkernel_string_functions_t _libkernel_string_functions = 118 121 &_libkernel_generic_string_functions; ··· 273 276 return KERN_SUCCESS; 274 277 } 275 278 279 + #ifndef DARLING 276 280 boolean_t 277 281 voucher_mach_msg_set(mach_msg_header_t *msg) 278 282 { ··· 306 310 return _libkernel_voucher_functions->voucher_mach_msg_revert(state); 307 311 } 308 312 } 313 + #endif
+11
src/kernel/libsyscall/wrappers/_libkernel_init.c
··· 33 33 #include <mach/vm_page_size.h> 34 34 #include "_libkernel_init.h" 35 35 36 + #ifdef DARLING 37 + extern int mach_init(const char** applep); 38 + extern void sigexc_setup(void); 39 + #else 36 40 extern int mach_init(void); 41 + #endif 37 42 38 43 #if TARGET_OS_OSX 39 44 ··· 81 86 if (fns->dlsym) { 82 87 _dlsym = fns->dlsym; 83 88 } 89 + 90 + #ifdef DARLING 91 + mach_init(apple); 92 + sigexc_setup(); 93 + #else 84 94 mach_init(); 95 + #endif 85 96 #if TARGET_OS_OSX 86 97 for (size_t i = 0; envp[i]; i++) { 87 98
+3
src/kernel/libsyscall/wrappers/_libkernel_init.h
··· 69 69 int (*pthread_current_stack_contains_np)(const void *, size_t); 70 70 71 71 /* Subsequent versions must only add pointers! */ 72 + #ifdef DARLING 73 + void (*dyld_func_lookup)(const char*,void**); 74 + #endif 72 75 } *_libkernel_functions_t; 73 76 74 77 typedef const struct _libkernel_string_functions {
+22
src/kernel/libsyscall/wrappers/string/strcmp.c
··· 46 46 } 47 47 return *(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1); 48 48 } 49 + 50 + #ifdef DARLING 51 + __attribute__((visibility("hidden"))) 52 + int _darling_libkernel_strncmp(const char* str1, const char* str2, size_t max) { 53 + while (max > 0) { 54 + if (*str1 == '\0') { 55 + if (*str2 == '\0') 56 + return 0; 57 + return -1; 58 + } 59 + if (*str2 == '\0') 60 + return 1; 61 + if (*str1 != *str2) { 62 + return *str1 - *str2; 63 + } 64 + ++str1; 65 + ++str2; 66 + --max; 67 + } 68 + return 0; 69 + }; 70 + #endif
+3
src/kernel/libsyscall/wrappers/string/strings.h
··· 89 89 size_t _libkernel_strlcpy(char *, const char *, size_t); 90 90 void _libkernel_bzero(void *, size_t); 91 91 char *_libkernel_strchr(const char *, int); 92 + #ifdef DARLING 93 + int _darling_libkernel_strncmp(const char *, const char *, size_t); 94 + #endif 92 95 93 96 #endif /* _STRINGS_H_ */