this repo has no description
1
fork

Configure Feed

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

Adding: - a couple of xlocale functions - malloc_zone fake functions on top of malloc/free - some missing stdio functions - improved (configurable) uname - full posix_spawn implementation

+639 -199
+2
config.h.in
··· 6 6 #define LIB_DIR_NAME "lib@SUFFIX@" 7 7 #define INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" 8 8 9 + #define ETC_DARLING_PATH "/etc/darling" 10 + 9 11 #cmakedefine MULTILIB 10 12 11 13 /*
+5
etc/version.conf
··· 1 + [uname] 2 + sysname=Darwin 3 + release=12.0.0 4 + version=Darwin Kernel Version 12.0.0 5 +
+4
src/dyld/keymgr.cpp
··· 46 46 pthread_mutex_unlock(&m_keymgr[key].mutex); 47 47 } 48 48 49 + void __keymgr_dwarf2_register_sections() 50 + { 51 + } 52 +
+1
src/dyld/keymgr.h
··· 7 7 void* _keymgr_get_and_lock_processwide_ptr(unsigned key); 8 8 void _keymgr_set_and_unlock_processwide_ptr(unsigned key, void* ptr); 9 9 void _keymgr_unlock_processwide_ptr(unsigned key); 10 + void __keymgr_dwarf2_register_sections(); 10 11 11 12 } 12 13
+1 -1
src/dyld/ld.cpp
··· 87 87 88 88 try 89 89 { 90 - g_iniConfig = new IniConfig("/etc/darling/dylib.conf"); 90 + g_iniConfig = new IniConfig(ETC_DARLING_PATH "/dylib.conf"); 91 91 } 92 92 catch (const std::exception& e) 93 93 {
+4
src/libSystem/CMakeLists.txt
··· 67 67 libc/signals.cpp 68 68 libc/termios.cpp 69 69 libc/attrlist.cpp 70 + libc/spawn.cpp 71 + libc/xlocale.cpp 72 + libc/malloc_zone.cpp 70 73 common/auto.cpp 71 74 common/path.cpp 72 75 ) ··· 91 94 kernel-mach/error.cpp 92 95 kernel-mach/Futex.cpp 93 96 kernel-mach/FutexSemaphore.cpp 97 + kernel-mach/compat.cpp 94 98 ) 95 99 96 100 add_library(System.B.dylib SHARED ${libc_SRCS} ${bsdkern_SRCS} ${machkern_SRCS})
+8
src/libSystem/common/auto.h
··· 36 36 return rv; 37 37 } 38 38 39 + template<typename Func, typename... Params> int AutoErrnoPosix(Func f, Params... params) 40 + { 41 + int rv = f(params...); 42 + if (rv != 0) 43 + rv = errnoLinuxToDarwin(rv); 44 + return rv; 45 + } 46 + 39 47 namespace Darling 40 48 { 41 49 struct MappedFlag
+7 -7
src/libSystem/libc/exec.cpp
··· 18 18 19 19 extern char g_loader_path[PATH_MAX]; 20 20 21 - static const char* findInPath(const char* file) 21 + const char* Darling::findInPath(const char* file) 22 22 { 23 23 static __thread char buffer[DARWIN_MAXPATHLEN]; 24 24 ··· 67 67 return 0; 68 68 } 69 69 70 - static char* const* prependLoaderPath(char *const argv[], const char* fullMachoPath) 70 + char* const* Darling::prependLoaderPath(char *const argv[], const char* fullMachoPath) 71 71 { 72 72 int count = 0; 73 73 const char** rv; ··· 156 156 } 157 157 else 158 158 { 159 - argv = prependLoaderPath(argv, path); 160 - int rv = execvp(g_loader_path, argv); 159 + argv = Darling::prependLoaderPath(argv, path); 160 + int rv = execvp(g_loader_path, argv); // TODO: change to execv? 161 161 162 162 std::cout << "Executing with loader at " << g_loader_path << std::endl; 163 163 ··· 172 172 { 173 173 TRACE1(file); 174 174 175 - const char* path = findInPath(file); 175 + const char* path = Darling::findInPath(file); 176 176 if (!path) 177 177 { 178 178 std::cout << "Path failed to be located: " << file << std::endl; ··· 187 187 { 188 188 TRACE1(file); 189 189 190 - const char* path = findInPath(file); 190 + const char* path = Darling::findInPath(file); 191 191 if (!path) 192 192 { 193 193 errno = DARWIN_ENOENT; ··· 202 202 } 203 203 else 204 204 { 205 - argv = prependLoaderPath(argv, path); 205 + argv = Darling::prependLoaderPath(argv, path); 206 206 int rv = execvpe(g_loader_path, argv, envp); 207 207 errnoOut(); 208 208
+6
src/libSystem/libc/exec.h
··· 15 15 16 16 #ifdef __cplusplus 17 17 } 18 + 19 + namespace Darling 20 + { 21 + const char* findInPath(const char* file); 22 + char* const* prependLoaderPath(char *const argv[], const char* fullMachoPath); 23 + } 18 24 #endif 19 25 20 26 #endif
-182
src/libSystem/libc/mac.c
··· 70 70 return __maskrune(_c, _f); 71 71 } 72 72 73 - size_t mbstowcs_l(wchar_t* pwcs, const char* s, size_t n, void* l) { 74 - return mbstowcs(pwcs, s, n); 75 - } 76 - 77 - size_t wcswidth_l(wchar_t* pwcs, size_t n, void* l) { 78 - return wcswidth(pwcs, n); 79 - } 80 - 81 73 void libiconv_set_relocation_prefix(const char* orig, const char* curr) { 82 74 // TODO: What should we do? 83 75 abort(); ··· 101 93 return mmap(addr, length, prot, flags, fd, offset); 102 94 } 103 95 104 - extern char* __loader_path; 105 - 106 - static char** add_loader_to_argv(char* argv[]) { 107 - int i, argc; 108 - for (argc = 0; argv[argc]; argc++); 109 - LOGF("\n"); 110 - char** new_argv = malloc(sizeof(char*) * (argc + 2)); 111 - new_argv[0] = __loader_path; 112 - for (i = 0; i < argc + 1; i++) { 113 - new_argv[i + 1] = argv[i]; 114 - } 115 - return new_argv; 116 - } 117 - 118 - // It seems the size of posix_spawn_file_actions_t of Mac is smaller 119 - // than Linux so modifying posix_spawn_file_actions_t allocated in 120 - // Mac's stack would cause stack overflow. Let's wrap it. 121 - 122 - int __darwin_posix_spawn(pid_t* pid, 123 - const char* path, 124 - const posix_spawn_file_actions_t** file_actions, 125 - const posix_spawnattr_t* attrp, 126 - char* argv[], 127 - char* const envp[]) { 128 - char** new_argv = add_loader_to_argv(argv); 129 - const posix_spawn_file_actions_t* fa = NULL; 130 - if (file_actions) 131 - fa = *file_actions; 132 - int r = posix_spawn(pid, 133 - __loader_path, 134 - fa, 135 - attrp, 136 - new_argv, 137 - envp); 138 - free(new_argv); 139 - return r; 140 - } 141 - 142 - int __darwin_posix_spawnp(pid_t *pid, 143 - const char* file, 144 - const posix_spawn_file_actions_t* file_actions, 145 - const posix_spawnattr_t* attrp, 146 - char* const argv[], 147 - char* const envp[]) { 148 - err(1, "posix_spawnp is not implemented yet\n"); 149 - return 0; 150 - } 151 - 152 - int __darwin_posix_spawn_file_actions_init(posix_spawn_file_actions_t** p) { 153 - *p = (posix_spawn_file_actions_t*)malloc(sizeof(posix_spawn_file_actions_t)); 154 - return posix_spawn_file_actions_init(*p); 155 - } 156 - 157 - int __darwin_posix_spawn_file_actions_destroy(posix_spawn_file_actions_t** p) { 158 - int r = posix_spawn_file_actions_destroy(*p); 159 - free(*p); 160 - return r; 161 - } 162 - 163 - int __darwin_posix_spawn_file_actions_addopen( 164 - posix_spawn_file_actions_t** file_actions, 165 - int fd, 166 - const char* path, 167 - int oflag, 168 - int mode) { 169 - return posix_spawn_file_actions_addopen( 170 - *file_actions, fd, path, oflag, mode); 171 - } 172 - 173 - int __darwin_posix_spawn_file_actions_addclose( 174 - posix_spawn_file_actions_t** file_actions, 175 - int fd) { 176 - return posix_spawn_file_actions_addclose(*file_actions, fd); 177 - } 178 - 179 - int __darwin_posix_spawn_file_actions_adddup2( 180 - posix_spawn_file_actions_t** file_actions, 181 - int fd, 182 - int newfd) { 183 - return posix_spawn_file_actions_adddup2(*file_actions, fd, newfd); 184 - } 185 - 186 - typedef struct { 187 - void* ss_sp; 188 - size_t ss_size; 189 - int ss_flags; 190 - } __darwin_stack_t; 191 - 192 - int __darwin_sigaltstack(const __darwin_stack_t* ss, __darwin_stack_t* oss) { 193 - return 0; 194 - 195 - #if 0 196 - stack_t linux_ss; 197 - stack_t linux_oss; 198 - linux_ss.ss_sp = ss->ss_sp; 199 - linux_ss.ss_size = ss->ss_size; 200 - linux_ss.ss_flags = ss->ss_flags; 201 - if (oss) { 202 - linux_oss.ss_sp = oss->ss_sp; 203 - linux_oss.ss_size = oss->ss_size; 204 - linux_oss.ss_flags = oss->ss_flags; 205 - } 206 - int r = sigaltstack(&linux_ss, &linux_oss); 207 - if (oss) { 208 - oss->ss_sp = linux_oss.ss_sp; 209 - oss->ss_size = linux_oss.ss_size; 210 - oss->ss_flags = linux_oss.ss_flags; 211 - } 212 - return r; 213 - #endif 214 - } 215 - 216 - typedef struct malloc_statistics_t { 217 - unsigned blocks_in_use; 218 - size_t size_in_use; 219 - size_t max_size_in_use; 220 - size_t size_allocated; 221 - } __darwin_malloc_statistics_t; 222 - 223 - void* malloc_default_zone() { 224 - return NULL; 225 - } 226 - 227 - // TODO: implement via mallinfo 228 - void malloc_zone_statistics(void* zone, __darwin_malloc_statistics_t* stats) { 229 - fprintf(stderr, "malloc_zone_statistics\n"); 230 - memset(stats, 0, sizeof(*stats)); 231 - } 232 96 233 97 int task_get_exception_ports() { 234 98 fprintf(stderr, "task_get_exception_ports\n"); ··· 238 102 int task_set_exception_ports() { 239 103 fprintf(stderr, "task_set_exception_ports\n"); 240 104 return 0; 241 - } 242 - 243 - 244 - 245 - static void do_nothing(void) { 246 - } 247 - static void* do_nothing2(void) { 248 - return 0; 249 - } 250 - static void do_nothing3(int status) { 251 - } 252 - 253 - void (*mach_init_routine)(void) = do_nothing; 254 - void* (*_cthread_init_routine)(void) = do_nothing2; 255 - void (*_cthread_exit_routine) (int) = do_nothing3; 256 - 257 - void __keymgr_dwarf2_register_sections() { 258 - } 259 - 260 - #define __DARWIN_SYS_NAMELEN 256 261 - typedef struct { 262 - char sysname[__DARWIN_SYS_NAMELEN]; 263 - char nodename[__DARWIN_SYS_NAMELEN]; 264 - char release[__DARWIN_SYS_NAMELEN]; 265 - char version[__DARWIN_SYS_NAMELEN]; 266 - char machine[__DARWIN_SYS_NAMELEN]; 267 - } __darwin_utsname; 268 - 269 - int __darwin_uname(__darwin_utsname* buf) { 270 - struct utsname linux_buf; 271 - int r = uname(&linux_buf); 272 - if (r) 273 - return r; 274 - 275 - // Linux's buf size is currently much smaller, only 65, so strcpy() is safe 276 - //strcpy(buf->sysname, linux_buf.sysname); 277 - //strcpy(buf->nodename, linux_buf.nodename); 278 - //strcpy(buf->release, linux_buf.release); 279 - //strcpy(buf->version, linux_buf.version); 280 - //strcpy(buf->machine, linux_buf.machine); 281 - strcpy(buf->sysname, "Darwin"); 282 - strcpy(buf->nodename, linux_buf.nodename); 283 - strcpy(buf->release, "12.0.0"); 284 - strcpy(buf->version, "Darwin Kernel Version 12.0.0"); 285 - strcpy(buf->machine, linux_buf.machine); 286 - return 0; 287 105 } 288 106 289 107 #define __DARWIN_LC_ALL_MASK ( __DARWIN_LC_COLLATE_MASK \
+65
src/libSystem/libc/malloc_zone.cpp
··· 1 + #include "malloc_zone.h" 2 + #include <malloc.h> 3 + 4 + static uint32_t dummy = 0xbaadf00d; 5 + 6 + malloc_zone_t* malloc_create_zone(vm_size_t start_size, unsigned flags) 7 + { 8 + return malloc_default_zone(); 9 + } 10 + 11 + void malloc_destroy_zone(malloc_zone_t *zone) 12 + { 13 + } 14 + 15 + malloc_zone_t* malloc_default_zone() 16 + { 17 + return &dummy; 18 + } 19 + 20 + malloc_zone_t* malloc_zone_from_ptr(const void *ptr) 21 + { 22 + return malloc_default_zone(); 23 + } 24 + 25 + void* malloc_zone_malloc(malloc_zone_t *zone, size_t size) 26 + { 27 + return malloc(size); 28 + } 29 + 30 + void* malloc_zone_calloc(malloc_zone_t *zone, size_t num_items, size_t size) 31 + { 32 + return calloc(num_items, size); 33 + } 34 + 35 + void* malloc_zone_valloc(malloc_zone_t *zone, size_t size) 36 + { 37 + return valloc(size); 38 + } 39 + 40 + void* malloc_zone_realloc(malloc_zone_t *zone, void *ptr, size_t size) 41 + { 42 + return realloc(ptr, size); 43 + } 44 + 45 + void* malloc_zone_memalign(malloc_zone_t *zone, size_t alignment, size_t size) 46 + { 47 + return memalign(alignment, size); 48 + } 49 + 50 + void malloc_zone_free(malloc_zone_t *zone, void *ptr) 51 + { 52 + return free(ptr); 53 + } 54 + 55 + void malloc_zone_statistics(malloc_zone_t* zone, __darwin_malloc_statistics_t* stats) 56 + { 57 + struct mallinfo info = mallinfo(); 58 + 59 + // No idea if this is even nearly correct 60 + stats->size_allocated = info.uordblks; 61 + stats->size_in_use = info.hblkhd; 62 + stats->max_size_in_use = info.usmblks; 63 + stats->blocks_in_use = stats->size_in_use; 64 + } 65 +
+36
src/libSystem/libc/malloc_zone.h
··· 1 + #ifndef LIBC_MALLOC_ZONE_H 2 + #define LIBC_MALLOC_ZONE_H 3 + #include <stdint.h> 4 + #include <stdlib.h> 5 + 6 + typedef uint32_t malloc_zone_t; 7 + typedef uintptr_t vm_size_t; 8 + 9 + struct __darwin_malloc_statistics_t 10 + { 11 + unsigned blocks_in_use; 12 + size_t size_in_use; 13 + size_t max_size_in_use; 14 + size_t size_allocated; 15 + }; 16 + 17 + 18 + extern "C" { 19 + 20 + malloc_zone_t* malloc_create_zone(vm_size_t start_size, unsigned flags); 21 + void malloc_destroy_zone(malloc_zone_t *zone); 22 + malloc_zone_t* malloc_default_zone(); 23 + malloc_zone_t* malloc_zone_from_ptr(const void *ptr); 24 + void* malloc_zone_malloc(malloc_zone_t *zone, size_t size); 25 + void* malloc_zone_calloc(malloc_zone_t *zone, size_t num_items, size_t size); 26 + void* malloc_zone_valloc(malloc_zone_t *zone, size_t size); 27 + void* malloc_zone_realloc(malloc_zone_t *zone, void *ptr, size_t size); 28 + void* malloc_zone_memalign(malloc_zone_t *zone, size_t alignment, size_t size); 29 + void malloc_zone_free(malloc_zone_t *zone, void *ptr); 30 + 31 + void malloc_zone_statistics(malloc_zone_t* zone, __darwin_malloc_statistics_t* stats); 32 + 33 + } 34 + 35 + #endif 36 +
+9 -9
src/libSystem/libc/signals.cpp
··· 89 89 return signal(signum, handler); 90 90 } 91 91 92 - static sigset_t sigsetDarwinToLinux(const __darwin_sigset_t* set) 92 + sigset_t Darling::sigsetDarwinToLinux(const __darwin_sigset_t* set) 93 93 { 94 94 sigset_t rv; 95 95 ··· 104 104 return rv; 105 105 } 106 106 107 - static __darwin_sigset_t sigsetLinuxToDarwin(const sigset_t* set) 107 + __darwin_sigset_t Darling::sigsetLinuxToDarwin(const sigset_t* set) 108 108 { 109 109 __darwin_sigset_t rv = 0; 110 110 ··· 136 136 nact->sa_flags = Darling::flagsDarwinToNative(g_sigactionFlags, sizeof(g_sigactionFlags)/sizeof(g_sigactionFlags[0]), act->sa_flags); 137 137 nact->sa_handler = act->xsa_handler; 138 138 nact->sa_sigaction = act->xsa_sigaction; 139 - nact->sa_mask = sigsetDarwinToLinux(&act->sa_mask); 139 + nact->sa_mask = Darling::sigsetDarwinToLinux(&act->sa_mask); 140 140 oldhdl = g_darwinHandlers[signum]; 141 141 142 142 // defer a user-supplied function to a wrapper that will translate the signal number ··· 159 159 else 160 160 oldact->xsa_handler = noldact->sa_handler; 161 161 oldact->xsa_sigaction = oldhdl; 162 - oldact->sa_mask = sigsetLinuxToDarwin(&noldact->sa_mask); 162 + oldact->sa_mask = Darling::sigsetLinuxToDarwin(&noldact->sa_mask); 163 163 } 164 164 if (rv == -1) 165 165 errnoOut(); ··· 228 228 if (set) 229 229 { 230 230 nset.reset(new sigset_t); 231 - *nset = sigsetDarwinToLinux(set); 231 + *nset = Darling::sigsetDarwinToLinux(set); 232 232 } 233 233 if (oldset) 234 234 noldset.reset(new sigset_t); ··· 239 239 if (rv == -1) 240 240 errnoOut(); 241 241 else if (oldset) 242 - *oldset = sigsetLinuxToDarwin(noldset.get()); 242 + *oldset = Darling::sigsetLinuxToDarwin(noldset.get()); 243 243 244 244 return rv; 245 245 } 246 246 247 247 int __darwin_sigsuspend(const __darwin_sigset_t *mask) 248 248 { 249 - sigset_t set = sigsetDarwinToLinux(mask); 249 + sigset_t set = Darling::sigsetDarwinToLinux(mask); 250 250 int rv = sigsuspend(&set); 251 251 if (rv == -1) 252 252 errnoOut(); ··· 255 255 256 256 int __darwin_sigwait(const __darwin_sigset_t *set, int *sig) 257 257 { 258 - sigset_t nset = sigsetDarwinToLinux(set); 258 + sigset_t nset = Darling::sigsetDarwinToLinux(set); 259 259 int rv = sigwait(&nset, sig); 260 260 if (rv == -1) 261 261 errnoOut(); ··· 271 271 if (rv == -1) 272 272 errnoOut(); 273 273 else 274 - *set = sigsetLinuxToDarwin(&nset); 274 + *set = Darling::sigsetLinuxToDarwin(&nset); 275 275 return rv; 276 276 } 277 277
+3
src/libSystem/libc/signals.h
··· 77 77 { 78 78 int signalLinuxToDarwin(int sig); 79 79 int signalDarwinToLinux(int sig); 80 + 81 + sigset_t sigsetDarwinToLinux(const __darwin_sigset_t* set); 82 + __darwin_sigset_t sigsetLinuxToDarwin(const sigset_t* set); 80 83 } 81 84 82 85 #endif
+196
src/libSystem/libc/spawn.cpp
··· 1 + #include "spawn.h" 2 + #include "errno.h" 3 + #include "../common/auto.h" 4 + #include "../kernel-bsd/io.h" 5 + #include "darwin_errno_codes.h" 6 + #include "exec.h" 7 + #include <type_traits> 8 + #include "MachO.h" 9 + #include "trace.h" 10 + 11 + template<typename NativeInit, typename T> int GenericInit(T* t, NativeInit nativeInit) 12 + { 13 + int err; 14 + 15 + if (!t) 16 + return DARWIN_EINVAL; 17 + 18 + t->native = new typename std::remove_reference<decltype(*t->native)>::type; 19 + err = AutoErrnoPosix(nativeInit, t->native); 20 + 21 + if (err) 22 + delete t->native; 23 + return err; 24 + } 25 + 26 + template<typename NativeDestroy, typename T> int GenericDestroy(T* t, NativeDestroy nativeDestroy) 27 + { 28 + if (t != nullptr) 29 + { 30 + int err = AutoErrnoPosix(nativeDestroy, t->native); 31 + delete t->native; 32 + return err; 33 + } 34 + else 35 + return DARWIN_EINVAL; 36 + } 37 + 38 + int __darwin_posix_spawn_file_actions_destroy(__darwin_posix_spawn_file_actions_t* file_actions) 39 + { 40 + return GenericDestroy(file_actions, posix_spawn_file_actions_destroy); 41 + } 42 + 43 + int __darwin_posix_spawn_file_actions_init(__darwin_posix_spawn_file_actions_t* file_actions) 44 + { 45 + return GenericInit(file_actions, posix_spawn_file_actions_init); 46 + } 47 + 48 + int __darwin_posix_spawn_file_actions_addclose(__darwin_posix_spawn_file_actions_t* file_actions, int filedes) 49 + { 50 + return AutoErrnoPosix(posix_spawn_file_actions_addclose, file_actions->native, filedes); 51 + } 52 + 53 + int __darwin_posix_spawn_file_actions_addopen(__darwin_posix_spawn_file_actions_t* file_actions, int filedes, const char* path, int oflag, mode_t mode) 54 + { 55 + return AutoErrnoPosix(posix_spawn_file_actions_addopen, file_actions->native, filedes, translatePathCI(path), Darling::openflagsDarwinToNative(oflag), mode); 56 + } 57 + 58 + int __darwin_posix_spawn_file_actions_adddup2(__darwin_posix_spawn_file_actions_t* file_actions, int filedes, int newfiledes) 59 + { 60 + return AutoErrnoPosix(posix_spawn_file_actions_adddup2, file_actions->native, filedes, newfiledes); 61 + } 62 + 63 + int __darwin_posix_spawn_file_actions_addinherit_np(__darwin_posix_spawn_file_actions_t* file_actions, int filedes) 64 + { 65 + return DARWIN_ENOTSUP; 66 + } 67 + 68 + int __darwin_posix_spawnattr_destroy(__darwin_posix_spawnattr_t* attr) 69 + { 70 + return GenericDestroy(attr, posix_spawnattr_destroy); 71 + } 72 + 73 + int __darwin_posix_spawnattr_init(__darwin_posix_spawnattr_t* attr) 74 + { 75 + return GenericInit(attr, posix_spawnattr_init); 76 + } 77 + 78 + int __darwin_posix_spawnattr_getsigdefault(const __darwin_posix_spawnattr_t* attr, __darwin_sigset_t* sigdefault) 79 + { 80 + sigset_t ns; 81 + int err = AutoErrnoPosix(posix_spawnattr_getsigdefault, attr->native, &ns); 82 + 83 + if (!err) 84 + *sigdefault = Darling::sigsetLinuxToDarwin(&ns); 85 + 86 + return err; 87 + } 88 + 89 + int __darwin_posix_spawnattr_setsigdefault(__darwin_posix_spawnattr_t* attr, const __darwin_sigset_t* sigdefault) 90 + { 91 + sigset_t ns; 92 + ns = Darling::sigsetDarwinToLinux(sigdefault); 93 + 94 + return AutoErrnoPosix(posix_spawnattr_setsigdefault, attr->native, &ns); 95 + } 96 + 97 + int __darwin_posix_spawnattr_getsigmask(const __darwin_posix_spawnattr_t* attr, __darwin_sigset_t* sigmask) 98 + { 99 + sigset_t ns; 100 + int err = AutoErrnoPosix(posix_spawnattr_getsigmask, attr->native, &ns); 101 + 102 + if (!err) 103 + *sigmask = Darling::sigsetLinuxToDarwin(&ns); 104 + 105 + return err; 106 + } 107 + 108 + int __darwin_posix_spawnattr_setsigmask(__darwin_posix_spawnattr_t* attr, const __darwin_sigset_t* sigmask) 109 + { 110 + sigset_t ns; 111 + ns = Darling::sigsetDarwinToLinux(sigmask); 112 + 113 + return AutoErrnoPosix(posix_spawnattr_setsigmask, attr->native, &ns); 114 + } 115 + 116 + 117 + // flag values are compatible 118 + int __darwin_posix_spawnattr_getflags(const __darwin_posix_spawnattr_t* attr, short* flags) 119 + { 120 + return AutoErrnoPosix(posix_spawnattr_getflags, attr->native, flags); 121 + } 122 + 123 + int __darwin_posix_spawnattr_setflags(__darwin_posix_spawnattr_t* attr, short flags) 124 + { 125 + return AutoErrnoPosix(posix_spawnattr_setflags, attr->native, flags); 126 + } 127 + 128 + int __darwin_posix_spawnattr_getpgroup(const __darwin_posix_spawnattr_t* attr, pid_t* pgroup) 129 + { 130 + return AutoErrnoPosix(posix_spawnattr_getpgroup, attr->native, pgroup); 131 + } 132 + 133 + int __darwin_posix_spawnattr_setpgroup(__darwin_posix_spawnattr_t *attr, pid_t pgroup) 134 + { 135 + return AutoErrnoPosix(posix_spawnattr_setpgroup, attr->native, pgroup); 136 + } 137 + 138 + int __darwin_posix_spawnattr_getschedparam(const __darwin_posix_spawnattr_t* attr, struct sched_param* schedparam) 139 + { 140 + return AutoErrnoPosix(posix_spawnattr_getschedparam, attr->native, schedparam); 141 + } 142 + 143 + int __darwin_posix_spawnattr_setschedparam(__darwin_posix_spawnattr_t* attr, const struct sched_param* schedparam) 144 + { 145 + return AutoErrnoPosix(posix_spawnattr_setschedparam, attr->native, schedparam); 146 + } 147 + 148 + int __darwin_posix_spawnattr_getschedpolicy(const __darwin_posix_spawnattr_t* attr, int* schedpolicy) 149 + { 150 + return AutoErrnoPosix(posix_spawnattr_getschedpolicy, attr->native, schedpolicy); 151 + } 152 + 153 + int __darwin_posix_spawnattr_setschedpolicy(__darwin_posix_spawnattr_t *attr, int schedpolicy) 154 + { 155 + return AutoErrnoPosix(posix_spawnattr_setschedpolicy, attr->native, schedpolicy); 156 + } 157 + 158 + int __darwin_posix_spawn(pid_t* pid, const char* path, const __darwin_posix_spawn_file_actions_t* file_actions, const __darwin_posix_spawnattr_t* attrp, 159 + char* const argv[], char* const envp[]) 160 + { 161 + TRACE6(pid, path, file_actions, attrp, argv, envp); 162 + char* const* argv_copy = nullptr; 163 + int err; 164 + 165 + path = translatePathCI(path); 166 + 167 + if (MachO::isMachO(path)) 168 + argv = argv_copy = Darling::prependLoaderPath(argv, path); 169 + 170 + err = AutoErrnoPosix(posix_spawn, pid, path, file_actions->native, attrp->native, argv, envp); 171 + 172 + delete [] argv_copy; 173 + return err; 174 + } 175 + 176 + int __darwin_posix_spawnp(pid_t* pid, const char* file, const __darwin_posix_spawn_file_actions_t* file_actions,const __darwin_posix_spawnattr_t* attrp, 177 + char* const argv[], char* const envp[]) 178 + { 179 + TRACE6(pid, file, file_actions, attrp, argv, envp); 180 + char* const* argv_copy = nullptr; 181 + int err; 182 + 183 + const char* path = Darling::findInPath(file); 184 + if (!path) 185 + return DARWIN_ENOENT; 186 + 187 + if (MachO::isMachO(path)) 188 + argv = argv_copy = Darling::prependLoaderPath(argv, path); 189 + 190 + err = AutoErrnoPosix(posix_spawn, pid, path, file_actions->native, attrp->native, argv, envp); 191 + 192 + delete [] argv_copy; 193 + return err; 194 + } 195 + 196 +
+52
src/libSystem/libc/spawn.h
··· 1 + #ifndef LIBC_SPAWN_H 2 + #define LIBC_SPAWN_H 3 + #include <spawn.h> 4 + #include "signals.h" 5 + 6 + extern "C" { 7 + 8 + // sizeof on Darwin: ptr size 9 + // sizeof on Linux (x86-64): 80 bytes 10 + struct __darwin_posix_spawn_file_actions_t 11 + { 12 + posix_spawn_file_actions_t* native; 13 + }; 14 + 15 + struct __darwin_posix_spawnattr_t 16 + { 17 + posix_spawnattr_t* native; 18 + }; 19 + 20 + int __darwin_posix_spawn_file_actions_destroy(__darwin_posix_spawn_file_actions_t* file_actions); 21 + int __darwin_posix_spawn_file_actions_init(__darwin_posix_spawn_file_actions_t* file_actions); 22 + 23 + int __darwin_posix_spawn_file_actions_addclose(__darwin_posix_spawn_file_actions_t* file_actions, int filedes); 24 + int __darwin_posix_spawn_file_actions_addopen(__darwin_posix_spawn_file_actions_t* file_actions, int filedes, const char* path, int oflag, mode_t mode); 25 + int __darwin_posix_spawn_file_actions_adddup2(__darwin_posix_spawn_file_actions_t* file_actions, int filedes, int newfiledes); 26 + int __darwin_posix_spawn_file_actions_addinherit_np(__darwin_posix_spawn_file_actions_t* file_actions, int filedes); 27 + 28 + int __darwin_posix_spawnattr_destroy(__darwin_posix_spawnattr_t* attr); 29 + int __darwin_posix_spawnattr_init(__darwin_posix_spawnattr_t* attr); 30 + 31 + int __darwin_posix_spawnattr_getsigdefault(const __darwin_posix_spawnattr_t* attr, __darwin_sigset_t* sigdefault); 32 + int __darwin_posix_spawnattr_setsigdefault(__darwin_posix_spawnattr_t* attr, const __darwin_sigset_t* sigdefault); 33 + int __darwin_posix_spawnattr_getsigmask(const __darwin_posix_spawnattr_t* attr, __darwin_sigset_t* sigmask); 34 + int __darwin_posix_spawnattr_setsigmask(__darwin_posix_spawnattr_t* attr, const __darwin_sigset_t* sigmask); 35 + int __darwin_posix_spawnattr_getflags(const __darwin_posix_spawnattr_t* attr, short* flags); 36 + int __darwin_posix_spawnattr_setflags(__darwin_posix_spawnattr_t* attr, short flags); 37 + int __darwin_posix_spawnattr_getpgroup(const __darwin_posix_spawnattr_t* attr, pid_t* pgroup); 38 + int __darwin_posix_spawnattr_setpgroup(__darwin_posix_spawnattr_t *attr, pid_t pgroup); 39 + int __darwin_posix_spawnattr_getschedparam(const __darwin_posix_spawnattr_t* attr, struct sched_param* schedparam); 40 + int __darwin_posix_spawnattr_setschedparam(__darwin_posix_spawnattr_t* attr, const struct sched_param* schedparam); 41 + int __darwin_posix_spawnattr_getschedpolicy(const __darwin_posix_spawnattr_t* attr, int* schedpolicy); 42 + int __darwin_posix_spawnattr_setschedpolicy(__darwin_posix_spawnattr_t *attr, int schedpolicy); 43 + 44 + int __darwin_posix_spawn(pid_t* pid, const char* path, const __darwin_posix_spawn_file_actions_t* file_actions, const __darwin_posix_spawnattr_t* attrp, 45 + char* const argv[], char* const envp[]); 46 + int __darwin_posix_spawnp(pid_t* pid, const char* file, const __darwin_posix_spawn_file_actions_t* file_actions,const __darwin_posix_spawnattr_t* attrp, 47 + char* const argv[], char* const envp[]); 48 + 49 + } 50 + 51 + #endif 52 +
+10
src/libSystem/libc/stdio.cpp
··· 149 149 return fseek(fp->linux_fp, offset, whence); 150 150 } 151 151 152 + int __darwin_fseeko(__darwin_FILE* fp, off_t offset, int whence) 153 + { 154 + return fseeko(fp->linux_fp, offset, whence); 155 + } 156 + 152 157 long __darwin_ftell(__darwin_FILE* fp) 153 158 { 154 159 return ftell(fp->linux_fp); 160 + } 161 + 162 + off_t __darwin_ftello(__darwin_FILE* fp) 163 + { 164 + return ftello(fp->linux_fp); 155 165 } 156 166 157 167 void __darwin_rewind(__darwin_FILE* fp)
+2
src/libSystem/libc/stdio.h
··· 65 65 size_t __darwin_fread(void* ptr, size_t size, size_t nmemb, __darwin_FILE* fp); 66 66 size_t __darwin_fwrite(void* ptr, size_t size, size_t nmemb, __darwin_FILE* fp); 67 67 int __darwin_fseek(__darwin_FILE* fp, long offset, int whence); 68 + int __darwin_fseeko(__darwin_FILE* fp, off_t offset, int whence); 68 69 long __darwin_ftell(__darwin_FILE* fp); 70 + off_t __darwin_ftello(__darwin_FILE* fp); 69 71 void __darwin_rewind(__darwin_FILE* fp); 70 72 int __darwin_getc(__darwin_FILE* fp); 71 73 int __darwin_fgetc(__darwin_FILE* fp);
+68
src/libSystem/libc/uname.cpp
··· 1 + #include "config,h" 2 + #include "uname.h" 3 + #include "errno.h" 4 + #include <errno.h> 5 + #include <cstring> 6 + #include "darwin_errno_codes.h" 7 + #include <sys/utsname.h> 8 + #ifndef NO_DARWIN_UNAME 9 + # include "IniConfig.h" 10 + #endif 11 + #include <bsd/string.h> 12 + 13 + int __darwin_uname(__darwin_utsname* buf) 14 + { 15 + if (!buf) 16 + { 17 + errno = DARWIN_EINVAL; 18 + return -1; 19 + } 20 + 21 + struct utsname nbuf; 22 + int rv = uname(&nbuf); 23 + 24 + if (rv == -1) 25 + { 26 + errnoOut(); 27 + return rv; 28 + } 29 + 30 + strcpy(buf->nodename, nbuf.nodename); 31 + strcpy(buf->machine, nbuf.machine); 32 + 33 + #ifdef NO_DARWIN_UNAME 34 + strcpy(buf->sysname, nbuf.sysname); 35 + strcpy(buf->release, nbuf.release); 36 + strcpy(buf->version, nbuf.version); 37 + #else 38 + static IniConfig iniConfig(ETC_DARWIN_PATH "/version.conf"); 39 + const char *sysname = nullptr, *release = nullptr, *version = nullptr; 40 + 41 + if (iniConfig.hasSection("uname")) 42 + { 43 + const IniConfig::ValueMap* map = iniConfig.getSection("uname"); 44 + sysname = map->find("sysname")->second.c_str(); 45 + release = map->find("release")->second.c_str(); 46 + version = map->find("version")->second.c_str(); 47 + } 48 + 49 + if (!sysname || !*sysname) 50 + strcpy(buf->sysname, "Darwin"); 51 + else 52 + strlcpy(buf->sysname, sysname, __DARWIN_SYS_NAMELEN); 53 + 54 + if (!release || !*release) 55 + strcpy(buf->release, "12.0.0"); 56 + else 57 + strlcpy(buf->release, release, __DARWIN_SYS_NAMELEN); 58 + 59 + if (!version || !*version) 60 + strcpy(buf->version, "Darwin Kernel Version 12.0.0"); 61 + else 62 + strlcpy(buf->version, version, __DARWIN_SYS_NAMELEN); 63 + #endif 64 + 65 + return 0; 66 + } 67 + 68 +
+19
src/libSystem/libc/uname.h
··· 1 + #ifndef LIBC_UNAME_H 2 + #define LIBC_UNAME_H 3 + 4 + #define __DARWIN_SYS_NAMELEN 256 5 + 6 + struct __darwin_utsname 7 + { 8 + char sysname[__DARWIN_SYS_NAMELEN]; 9 + char nodename[__DARWIN_SYS_NAMELEN]; 10 + char release[__DARWIN_SYS_NAMELEN]; 11 + char version[__DARWIN_SYS_NAMELEN]; 12 + char machine[__DARWIN_SYS_NAMELEN]; 13 + }; 14 + 15 + 16 + extern "C" int __darwin_uname(__darwin_utsname* buf); 17 + 18 + #endif 19 +
+59
src/libSystem/libc/xlocale.cpp
··· 1 + #include "xlocale.h" 2 + 3 + #define WRAP_TRIVIAL(name, type) int name ## _l (wint_t wc, locale_t l) throw() { return UseLocale<int>(name, l, wc); } 4 + 5 + template<typename T, typename Func, typename... Params> T UseLocale(Func func, locale_t l, Params... params) 6 + { 7 + locale_t oldLoc = uselocale(l); 8 + 9 + T rv = func(params...); 10 + 11 + uselocale(oldLoc); 12 + return rv; 13 + } 14 + 15 + size_t mbstowcs_l(wchar_t* pwcs, const char* s, size_t n, locale_t l) 16 + { 17 + return UseLocale<size_t>(mbstowcs, l, pwcs, s, n); 18 + } 19 + 20 + size_t wcswidth_l(wchar_t* pwcs, size_t n, locale_t l) 21 + { 22 + return UseLocale<size_t>(wcswidth, l, pwcs, n); 23 + } 24 + 25 + int iswnumber(wint_t wc) throw() 26 + { 27 + return iswdigit(wc); 28 + } 29 + 30 + WRAP_TRIVIAL(iswalnum, WCTYPE_ALNUM); 31 + WRAP_TRIVIAL(iswalpha, WCTYPE_ALPHA); 32 + // WRAP_TRIVIAL(iswascii); 33 + WRAP_TRIVIAL(iswblank, WCTYPE_BLANK); 34 + WRAP_TRIVIAL(iswcntrl, WCTYPE_CNTRL); 35 + WRAP_TRIVIAL(iswdigit, WCTYPE_DIGIT); 36 + WRAP_TRIVIAL(iswgraph, WCTYPE_GRAPH); 37 + // WRAP_TRIVIAL(iswhexnumber); 38 + // WRAP_TRIVIAL(iswideogram); 39 + WRAP_TRIVIAL(iswlower, WCTYPE_LOWER); 40 + WRAP_TRIVIAL(iswnumber, WCTYPE_DIGIT); 41 + // WRAP_TRIVIAL(iswphonogram); 42 + WRAP_TRIVIAL(iswprint, WCTYPE_PRINT); 43 + WRAP_TRIVIAL(iswpunct, WCTYPE_PUNCT); 44 + // WRAP_TRIVIAL(iswrune); 45 + WRAP_TRIVIAL(iswspace, WCTYPE_SPACE); 46 + // WRAP_TRIVIAL(iswspecial); 47 + WRAP_TRIVIAL(iswupper, WCTYPE_UPPER); 48 + WRAP_TRIVIAL(iswxdigit, WCTYPE_XDIGIT); 49 + 50 + int iswctype_l(wint_t wc, wctype_t charclass, locale_t loc) throw() 51 + { 52 + return UseLocale<int>(iswctype, loc, wc, charclass); 53 + } 54 + 55 + wctype_t wctype_l(const char *property, locale_t loc) throw() 56 + { 57 + return UseLocale<int>(wctype, loc, property); 58 + } 59 +
+82
src/libSystem/libc/xlocale.h
··· 1 + #ifndef LIBC_MULTIBYTE_H 2 + #define LIBC_MULTIBYTE_H 3 + #include <stdlib.h> 4 + #include <locale.h> 5 + #include <wchar.h> 6 + #include <wctype.h> 7 + 8 + extern "C" { 9 + 10 + size_t mbstowcs_l(wchar_t* pwcs, const char* s, size_t n, locale_t l); 11 + size_t wcswidth_l(wchar_t* pwcs, size_t n, locale_t l); 12 + int mbtowc_l(wchar_t * pwc, const char * s, size_t n, locale_t loc); 13 + size_t mbrtowc_l(wchar_t * pwc, const char * s, size_t n, mbstate_t * ps, locale_t loc); 14 + int mblen_l(const char *s, size_t n, locale_t loc); 15 + size_t wcrtomb_l(char * s, wchar_t wc, mbstate_t * ps, locale_t loc); 16 + 17 + int iswalnum_l(wint_t wc, locale_t loc) throw(); 18 + int iswalpha_l(wint_t wc, locale_t loc) throw(); 19 + int iswascii_l(wint_t wc, locale_t loc) throw(); 20 + int iswblank_l(wint_t wc, locale_t loc) throw(); 21 + int iswcntrl_l(wint_t wc, locale_t loc) throw(); 22 + int iswdigit_l(wint_t wc, locale_t loc) throw(); 23 + int iswgraph_l(wint_t wc, locale_t loc) throw(); 24 + int iswhexnumber_l(wint_t wc, locale_t loc) throw(); 25 + int iswideogram_l(wint_t wc, locale_t loc) throw(); 26 + int iswlower_l(wint_t wc, locale_t loc) throw(); 27 + int iswnumber_l(wint_t wc, locale_t loc) throw(); 28 + int iswphonogram_l(wint_t wc, locale_t loc) throw(); 29 + int iswprint_l(wint_t wc, locale_t loc) throw(); 30 + int iswpunct_l(wint_t wc, locale_t loc) throw(); 31 + int iswrune_l(wint_t wc, locale_t loc) throw(); 32 + int iswspace_l(wint_t wc, locale_t loc) throw(); 33 + int iswspecial_l(wint_t wc, locale_t loc) throw(); 34 + int iswupper_l(wint_t wc, locale_t loc) throw(); 35 + int iswxdigit_l(wint_t wc, locale_t loc) throw(); 36 + int iswnumber(wint_t wc) throw(); 37 + 38 + int iswctype_l(wint_t wc, wctype_t charclass, locale_t loc) throw(); 39 + wctype_t wctype_l(const char *property, locale_t loc) throw(); 40 + 41 + 42 + /* 43 + TODO: 44 + 45 + <ctype.h> digittoint_l(3), isalnum_l(3), isalpha_l(3), isblank_l(3), iscntrl_l(3), isdigit_l(3), isgraph_l(3), ishexnumber_l(3), isideogram_l(3), islower_l(3), isnumber_l(3), 46 + isphonogram_l(3), isprint_l(3), ispunct_l(3), isrune_l(3), isspace_l(3), isspecial_l(3), isupper_l(3), isxdigit_l(3), tolower_l(3), toupper_l(3) 47 + 48 + <inttypes.h> 49 + strtoimax_l(3), strtoumax_l(3), wcstoimax_l(3), wcstoumax_l(3) 50 + 51 + <langinfo.h> 52 + nl_langinfo_l(3) 53 + 54 + <monetary.h> 55 + strfmon_l(3) 56 + 57 + <stdio.h> asprintf_l(3), fprintf_l(3), fscanf_l(3), printf_l(3), scanf_l(3), snprintf_l(3), sprintf_l(3), sscanf_l(3), vasprintf_l(3), vfprintf_l(3), vfscanf_l(3), vprintf_l(3), 58 + vscanf_l(3), vsnprintf_l(3), vsprintf_l(3), vsscanf_l(3) 59 + 60 + <stdlib.h> atof_l(3), atoi_l(3), atol_l(3), atoll_l(3), mblen_l(3), mbstowcs_l(3), mbtowc_l(3), strtod_l(3), strtof_l(3), strtol_l(3), strtold_l(3), strtoll_l(3), strtoq_l(3), 61 + strtoul_l(3), strtoull_l(3), strtouq_l(3), wcstombs_l(3), wctomb_l(3) 62 + 63 + <string.h> strcoll_l(3), strxfrm_l(3), strcasecmp_l(3), strcasestr_l(3), strncasecmp_l(3) 64 + 65 + <time.h> strftime_l(3), strptime_l(3) 66 + 67 + <wchar.h> btowc_l(3), fgetwc_l(3), *fgetws_l(3), fputwc_l(3), fputws_l(3), fwprintf_l(3), fwscanf_l(3), getwc_l(3), getwchar_l(3), mbrlen_l(3), mbrtowc_l(3), mbsinit_l(3), 68 + mbsnrtowcs_l(3), mbsrtowcs_l(3), putwc_l(3), putwchar_l(3), swprintf_l(3), swscanf_l(3), ungetwc_l(3), vfwprintf_l(3), vfwscanf_l(3), vswprintf_l(3), vswscanf_l(3), 69 + vwprintf_l(3), vwscanf_l(3), wcrtomb_l(3), wcscoll_l(3), wcsftime_l(3), wcsnrtombs_l(3), wcsrtombs_l(3), wcstod_l(3), wcstof_l(3), wcstol_l(3), wcstold_l(3), 70 + wcstoll_l(3), wcstoul_l(3), wcstoull_l(3), wcswidth_l(3), wcsxfrm_l(3), wctob_l(3), wcwidth_l(3), wprintf_l(3), wscanf_l(3) 71 + 72 + <wctype.h> iswblank_l(3), iswhexnumber_l(3), iswideogram_l(3), iswnumber_l(3), iswphonogram_l(3), iswrune_l(3), iswspecial_l(3), nextwctype_l(3), towctrans_l(3), wctrans_l(3) 73 + 74 + <xlocale.h> 75 + localeconv_l(3) 76 + 77 + */ 78 + 79 + } 80 + 81 + #endif 82 +