this repo has no description
1
fork

Configure Feed

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

Added shell_cmds submodule, building some executables from it. Added initial 'darling' tool. Added sys_getlogin. sysconf(_SC_ARG_MAX) now works.

+860 -44
+4
.gitmodules
··· 45 45 path = src/external/curl 46 46 url = ../darling-curl.git 47 47 branch = darling 48 + [submodule "src/external/shell_cmds"] 49 + path = src/external/shell_cmds 50 + url = ../darling-shell_cmds.git 51 + branch = darling
+20
cmake/darling_exe.cmake
··· 1 + if(COMMAND cmake_policy) 2 + cmake_policy(SET CMP0003 NEW) 3 + cmake_policy(SET CMP0011 NEW) 4 + endif(COMMAND cmake_policy) 5 + 6 + 7 + FUNCTION(add_darling_executable exe) 8 + foreach(f IN LISTS ARGN) 9 + set(files ${files} ${f}) 10 + endforeach(f) 11 + 12 + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") 13 + SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 14 + SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 15 + 16 + add_executable(${exe} ${files}) 17 + target_link_libraries(${exe} system -lpthread csu dyld) 18 + set_target_properties(${exe} PROPERTIES COMPILE_FLAGS "-Denviron=__darwin_environ -Ddlopen=__darwin_dlopen -Ddlclose=__darwin_dlclose -Ddlsym=__darwin_dlsym -Ddladdr=__darwin_dladdr") 19 + ENDFUNCTION(add_darling_executable) 20 +
+1
platform-include/notify.h
··· 30 30 #include <stdint.h> 31 31 #include <mach/message.h> 32 32 #include <Availability.h> 33 + #include <stdbool.h> 33 34 #ifdef __BLOCKS__ 34 35 #include <dispatch/dispatch.h> 35 36 #endif /* __BLOCKS__ */
-30
platform-include/sys/_structs.h
··· 1 - /* 2 - * Copyright (c) 2004-2013 Apple Inc. All rights reserved. 3 - * 4 - * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 - * 6 - * This file contains Original Code and/or Modifications of Original Code 7 - * as defined in and that are subject to the Apple Public Source License 8 - * Version 2.0 (the 'License'). You may not use this file except in 9 - * compliance with the License. The rights granted to you under the License 10 - * may not be used to create, or enable the creation or redistribution of, 11 - * unlawful or unlicensed copies of an Apple operating system, or to 12 - * circumvent, violate, or enable the circumvention or violation of, any 13 - * terms of an Apple operating system software license agreement. 14 - * 15 - * Please obtain a copy of the License at 16 - * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 - * 18 - * The Original Code and all software distributed under the License are 19 - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 - * Please see the License for the specific language governing rights and 24 - * limitations under the License. 25 - * 26 - * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 - */ 28 - 29 - #include <sys/cdefs.h> 30 - #include <sys/_types.h>
+2
src/CMakeLists.txt
··· 107 107 #add_subdirectory(launchd/src) 108 108 add_subdirectory(external/compiler-rt/lib/builtins) 109 109 add_subdirectory(CommonCrypto) 110 + add_subdirectory(csu) 111 + add_subdirectory(external/shell_cmds) 110 112 111 113 ###################### 112 114 # libc++ & libc++abi #
+24
src/csu/CMakeLists.txt
··· 1 + project(csu) 2 + 3 + cmake_minimum_required(VERSION 2.4.0) 4 + 5 + enable_language(C ASM) 6 + 7 + if(COMMAND cmake_policy) 8 + cmake_policy(SET CMP0003 NEW) 9 + endif(COMMAND cmake_policy) 10 + 11 + add_definitions(-DTARGET_OS_MAC=1) 12 + add_definitions(-D__APPLE__ -D__DYNAMIC__) 13 + 14 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w") 15 + 16 + include_directories(${DARLING_TOP_DIRECTORY}/src/libc/include/FreeBSD) 17 + 18 + set(csu_SRCS 19 + crt.c 20 + start.S 21 + ) 22 + 23 + add_library(csu STATIC ${csu_SRCS}) 24 +
+356
src/csu/crt.c
··· 1 + /* 2 + * Copyright (c) 1999-2008 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights 7 + * Reserved. This file contains Original Code and/or Modifications of 8 + * Original Code as defined in and that are subject to the Apple Public 9 + * Source License Version 1.1 (the "License"). You may not use this file 10 + * except in compliance with the License. Please obtain a copy of the 11 + * License at http://www.apple.com/publicsource and read it before using 12 + * this file. 13 + * 14 + * The Original Code and all software distributed under the License are 15 + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the 19 + * License for the specific language governing rights and limitations 20 + * under the License. 21 + * 22 + * @APPLE_LICENSE_HEADER_END@ 23 + */ 24 + /* 25 + * The common startup code. This code is if'ed with the 'C' preprocessor 26 + * macros __DYNAMIC__ and GCRT. It is used to create 27 + * the following files when compiled with the following macros defined: 28 + * 29 + * File Dedined Macros Purpose 30 + * crt1.o __DYNAMIC__ startup for programs compiled -dynamic 31 + * gcrt1.o __DYNAMIC__, GCRT profiling startup, programs compiled -dynamic 32 + * 33 + * crt0.o startup for programs compiled -static 34 + * 35 + */ 36 + 37 + #include <stddef.h> 38 + 39 + /* 40 + * Global data definitions (initialized data). 41 + */ 42 + int NXArgc = 0; 43 + const char** NXArgv = NULL; 44 + const char** environ = NULL; 45 + const char* __progname = NULL; 46 + 47 + #if ADD_PROGRAM_VARS 48 + extern void* __dso_handle; 49 + struct ProgramVars 50 + { 51 + void* mh; 52 + int* NXArgcPtr; 53 + const char*** NXArgvPtr; 54 + const char*** environPtr; 55 + const char** __prognamePtr; 56 + }; 57 + __attribute__((used)) static struct ProgramVars pvars 58 + __attribute__ ((section ("__DATA,__program_vars"))) = { &__dso_handle, &NXArgc, &NXArgv, &environ, &__progname }; 59 + 60 + #endif 61 + 62 + 63 + /* 64 + * This file is not needed for executables targeting 10.5 or later 65 + * start calls main() directly. 66 + */ 67 + #if __DYNAMIC__ && OLD_LIBSYSTEM_SUPPORT 68 + /* 69 + * The following symbols are reference by System Framework symbolicly (instead 70 + * of through undefined references (to allow prebinding). To get strip(1) to 71 + * know these symbols are not to be stripped they need to have the 72 + * REFERENCED_DYNAMICALLY bit (0x10) set. This would have been done automaticly 73 + * by ld(1) if these symbols were referenced through undefined symbols. 74 + * The catch_exception_raise symbol is special in that the Mach API specifically 75 + * requires that the library call into the user program for its implementation. 76 + * Therefore, we need to create a common definition and make sure the symbol 77 + * doesn't get stripped. 78 + */ 79 + asm(".desc _NXArgc, 0x10"); 80 + asm(".desc _NXArgv, 0x10"); 81 + asm(".desc _environ, 0x10"); 82 + asm(".desc __mh_execute_header, 0x10"); 83 + #if defined(__ppc__) || defined(__i386__) 84 + asm(".comm _catch_exception_raise, 4"); 85 + asm(".desc _catch_exception_raise, 0x10"); 86 + asm(".comm _catch_exception_raise_state, 4"); 87 + asm(".desc _catch_exception_raise_state, 0x10"); 88 + asm(".comm _catch_exception_raise_state_identity, 4"); 89 + asm(".desc _catch_exception_raise_state_identity, 0x10"); 90 + asm(".comm _do_mach_notify_dead_name, 4"); 91 + asm(".desc _do_mach_notify_dead_name, 0x10"); 92 + asm(".comm _do_seqnos_mach_notify_dead_name, 4"); 93 + asm(".desc _do_seqnos_mach_notify_dead_name, 0x10"); 94 + asm(".comm _do_mach_notify_no_senders, 4"); 95 + asm(".desc _do_mach_notify_no_senders, 0x10"); 96 + asm(".comm _do_seqnos_mach_notify_no_senders, 4"); 97 + asm(".desc _do_seqnos_mach_notify_no_senders, 0x10"); 98 + asm(".comm _do_mach_notify_port_deleted, 4"); 99 + asm(".desc _do_mach_notify_port_deleted, 0x10"); 100 + asm(".comm _do_seqnos_mach_notify_port_deleted, 4"); 101 + asm(".desc _do_seqnos_mach_notify_port_deleted, 0x10"); 102 + asm(".comm _do_mach_notify_send_once, 4"); 103 + asm(".desc _do_mach_notify_send_once, 0x10"); 104 + asm(".comm _do_seqnos_mach_notify_send_once, 4"); 105 + asm(".desc _do_seqnos_mach_notify_send_once, 0x10"); 106 + asm(".comm _clock_alarm_reply, 4"); 107 + asm(".desc _clock_alarm_reply, 0x10"); 108 + asm(".comm _receive_samples, 4"); 109 + asm(".desc _receive_samples, 0x10"); 110 + #endif /* __ppc__ || __i386__ */ 111 + asm(".desc ___progname, 0x10"); 112 + 113 + /* 114 + * Common data definitions. If the routines in System Framework are not pulled 115 + * into the executable then the static linker will allocate these as common 116 + * symbols. The code in here tests the value of these are non-zero to know if 117 + * the routines in System Framework got pulled in and should be called. The 118 + * first two are pointers to functions. The second two use just the symbol 119 + * itself. In the later case we are using the symbol with two different 'C' 120 + * types. To make it as clean as possible the 'C' type declared is that of the 121 + * external function. The common symbol is declared with an asm() and the code 122 + * casts the function name to a pointer to an int and then indirects through 123 + * the pointer to see if the value is not zero to know the function got linked 124 + * in. Then the code uses a pointer in the data area to the function to call 125 + * the function. The pointer in the data area is needed on various RISC 126 + * architectutes like the PowerPC to avoid a relocation overflow error when 127 + * linking programs with large data area. 128 + */ 129 + extern int (*mach_init_routine)(void); 130 + extern int (*_cthread_init_routine)(void); 131 + #if !__DYNAMIC__ 132 + asm(".comm __cplus_init, 4"); 133 + extern void _cplus_init(void); 134 + #endif 135 + #if __DYNAMIC__ && __ppc__ 136 + asm(".comm ___darwin_gcc3_preregister_frame_info, 4"); 137 + extern void __darwin_gcc3_preregister_frame_info (void); 138 + static void (*pointer_to__darwin_gcc3_preregister_frame_info)(void) = 139 + __darwin_gcc3_preregister_frame_info; 140 + #endif 141 + 142 + /* 143 + * Prototypes for routines that are called. 144 + */ 145 + extern int main(int argc, const char* argv[], const char* envp[], const char* apple[]); 146 + extern void exit(int status) __attribute__ ((noreturn)); 147 + extern int atexit(void (*fcn)(void)); 148 + static const char* crt_basename(const char* path); 149 + 150 + #if GCRT 151 + extern void moninit(void); 152 + static void _mcleanup(void); 153 + extern void monitor(char *lowpc,char *highpc,char *buf,int bufsiz,int nfunc); 154 + #endif /* GCRT */ 155 + 156 + #if __DYNAMIC__ 157 + extern int _dyld_func_lookup(const char *dyld_func_name,unsigned long *address); 158 + extern void __keymgr_dwarf2_register_sections (void); 159 + #endif /* __DYNAMIC__ */ 160 + 161 + #if __DYNAMIC__ && __ppc__ 162 + static void _call_objcInit(void); 163 + #endif 164 + 165 + extern int errno; 166 + 167 + /* 168 + * _start() is called from the machine dependent assembly entry point "start:" . 169 + * It takes care of setting up the stack so 'C' routines can be called and 170 + * passes argc, argv and envp to here. 171 + */ 172 + __private_extern__ 173 + void 174 + _start(int argc, const char* argv[], const char* envp[]) 175 + { 176 + const char** apple; 177 + #if __DYNAMIC__ 178 + void (*term)(void); 179 + void (*init)(void); 180 + #endif 181 + 182 + // initialize global variables 183 + NXArgc = argc; 184 + NXArgv = argv; 185 + environ = envp; 186 + __progname = ((argv[0] != NULL) ? crt_basename(argv[0]) : ""); 187 + // see start.s for how "apple" parameter follow envp 188 + for(apple = envp; *apple != NULL; ++apple) { /* loop */ } 189 + ++apple; 190 + 191 + // initialize libSystem 192 + if ( mach_init_routine != 0 ) 193 + (void) mach_init_routine(); 194 + if ( _cthread_init_routine != 0 ) 195 + (*_cthread_init_routine)(); 196 + 197 + #ifdef __DYNAMIC__ 198 + __keymgr_dwarf2_register_sections (); 199 + #endif 200 + 201 + #if __ppc__ && __DYNAMIC__ 202 + /* Call a ppc GCC 3.3-specific function (in libgcc.a) to 203 + "preregister" exception frame info, meaning to set up the 204 + dyld hooks that do the actual registration. */ 205 + if ( *((int *)pointer_to__darwin_gcc3_preregister_frame_info) != 0 ) 206 + pointer_to__darwin_gcc3_preregister_frame_info (); 207 + #endif 208 + 209 + #if !__DYNAMIC__ 210 + if(*((int *)_cplus_init) != 0) 211 + _cplus_init(); 212 + #endif 213 + 214 + #ifdef __DYNAMIC__ 215 + /* 216 + * Call into dyld to run all initializers. This must be done 217 + * after mach_init() 218 + */ 219 + _dyld_func_lookup("__dyld_make_delayed_module_initializer_calls", 220 + (unsigned long *)&init); 221 + init(); 222 + #endif 223 + 224 + #if __DYNAMIC__ && __ppc__ 225 + _call_objcInit(); 226 + #endif 227 + 228 + #ifdef GCRT 229 + atexit(_mcleanup); 230 + moninit(); 231 + #endif 232 + 233 + #ifdef __DYNAMIC__ 234 + /* 235 + * If the dyld we are running with supports module termination routines 236 + * for all types of images then register the function to call them with 237 + * atexit(). 238 + */ 239 + _dyld_func_lookup("__dyld_mod_term_funcs", (unsigned long *)&term); 240 + if ( term != 0 ) 241 + atexit(term); 242 + #endif 243 + 244 + // clear errno, so main() starts fresh 245 + errno = 0; 246 + 247 + // call main() and return to exit() 248 + exit(main(argc, argv, envp, apple)); 249 + } 250 + 251 + #if GCRT 252 + /* 253 + * For profiling the routine _mcleanup gets registered with atexit so monitor(0) 254 + * gets called. 255 + */ 256 + static 257 + void 258 + _mcleanup( 259 + void) 260 + { 261 + monitor(0,0,0,0,0); 262 + } 263 + #endif /* GCRT */ 264 + 265 + static 266 + const char * 267 + crt_basename(const char *path) 268 + { 269 + const char *s; 270 + const char *last = path; 271 + 272 + for (s = path; *s != '\0'; s++) { 273 + if (*s == '/') last = s+1; 274 + } 275 + 276 + return last; 277 + } 278 + 279 + #if __DYNAMIC__ && __ppc__ 280 + static 281 + int 282 + crt_strbeginswith(const char *s1, const char *s2) 283 + { 284 + int i; 285 + 286 + for (i = 0; ; i++) { 287 + if (s2[i] == '\0') return 1; 288 + else if (s1[i] != s2[i]) return 0; 289 + } 290 + } 291 + 292 + /* 293 + * Look for a function called _objcInit() in any library whose name 294 + * starts with "libobjc", and call it if one exists. This is used to 295 + * initialize the Objective-C runtime on Mac OS X 10.3 and earlier. 296 + * This is completely unnecessary on Mac OS X 10.4 and later. 297 + */ 298 + static 299 + void 300 + _call_objcInit(void) 301 + { 302 + unsigned int i, count; 303 + 304 + unsigned int (*_dyld_image_count_fn)(void); 305 + const char *(*_dyld_get_image_name_fn)(unsigned int image_index); 306 + const void *(*_dyld_get_image_header_fn)(unsigned int image_index); 307 + const void *(*NSLookupSymbolInImage_fn)(const void *image, const char *symbolName, unsigned int options); 308 + void *(*NSAddressOfSymbol_fn)(const void *symbol); 309 + 310 + // Find some dyld functions. 311 + _dyld_func_lookup("__dyld_image_count", 312 + (unsigned long *)&_dyld_image_count_fn); 313 + _dyld_func_lookup("__dyld_get_image_name", 314 + (unsigned long *)&_dyld_get_image_name_fn); 315 + _dyld_func_lookup("__dyld_get_image_header", 316 + (unsigned long *)&_dyld_get_image_header_fn); 317 + _dyld_func_lookup("__dyld_NSLookupSymbolInImage", 318 + (unsigned long *)&NSLookupSymbolInImage_fn); 319 + _dyld_func_lookup("__dyld_NSAddressOfSymbol", 320 + (unsigned long *)&NSAddressOfSymbol_fn); 321 + 322 + // If any of the dyld functions don't exist, assume we're 323 + // on a post-Panther dyld and silently do nothing. 324 + if (!_dyld_image_count_fn) return; 325 + if (!_dyld_get_image_name_fn) return; 326 + if (!_dyld_get_image_header_fn) return; 327 + if (!NSLookupSymbolInImage_fn) return; 328 + if (!NSAddressOfSymbol_fn) return; 329 + 330 + // Search for an image whose library name starts with "libobjc". 331 + count = (*_dyld_image_count_fn)(); 332 + for (i = 0; i < count; i++) { 333 + const void *image; 334 + const char *path = (*_dyld_get_image_name_fn)(i); 335 + const char *base = crt_basename(path); 336 + if (!crt_strbeginswith(base, "libobjc")) continue; 337 + 338 + // Call _objcInit() if library exports it. 339 + if ((image = (*_dyld_get_image_header_fn)(i))) { 340 + const void *symbol; 341 + // 4 == NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 342 + if ((symbol = (*NSLookupSymbolInImage_fn)(image,"__objcInit",4))) { 343 + void (*_objcInit_fn)(void) = 344 + (void(*)(void))(*NSAddressOfSymbol_fn)(symbol); 345 + if (_objcInit_fn) { 346 + (*_objcInit_fn)(); 347 + break; 348 + } 349 + } 350 + } 351 + } 352 + } 353 + 354 + #endif /* __DYNAMIC__ && __ppc__ */ 355 + 356 + #endif /* __DYNAMIC__ && OLD_LIBSYSTEM_SUPPORT */
+269
src/csu/start.S
··· 1 + // Modified by Lubos Dolezel for Darling 2 + /* 3 + * Copyright (c) 1999-2009 Apple Inc. All rights reserved. 4 + * 5 + * @APPLE_LICENSE_HEADER_START@ 6 + * 7 + * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights 8 + * Reserved. This file contains Original Code and/or Modifications of 9 + * Original Code as defined in and that are subject to the Apple Public 10 + * Source License Version 1.1 (the "License"). You may not use this file 11 + * except in compliance with the License. Please obtain a copy of the 12 + * License at http://www.apple.com/publicsource and read it before using 13 + * this file. 14 + * 15 + * The Original Code and all software distributed under the License are 16 + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 17 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 18 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 19 + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the 20 + * License for the specific language governing rights and limitations 21 + * under the License. 22 + * 23 + * @APPLE_LICENSE_HEADER_END@ 24 + */ 25 + 26 + #include <Availability.h> 27 + 28 + #ifdef DARLING 29 + # define start _start 30 + # define _main main 31 + #endif 32 + 33 + #if __ppc__ && __DYNAMIC__ 34 + // 35 + // Force stub section next to __text section to minimize chance that 36 + // a bl to a stub will be out of range. 37 + // 38 + .text 39 + .symbol_stub 40 + .picsymbol_stub 41 + #endif 42 + 43 + /* 44 + * C runtime startup for ppc, ppc64, i386, x86_64 45 + * 46 + * Kernel sets up stack frame to look like: 47 + * 48 + * : 49 + * | STRING AREA | 50 + * +-------------+ 51 + * | 0 | 52 + * +-------------+ 53 + * | exec_path | extra "apple" parameters start after NULL terminating env array 54 + * +-------------+ 55 + * | 0 | 56 + * +-------------+ 57 + * | env[n] | 58 + * +-------------+ 59 + * : 60 + * : 61 + * +-------------+ 62 + * | env[0] | 63 + * +-------------+ 64 + * | 0 | 65 + * +-------------+ 66 + * | arg[argc-1] | 67 + * +-------------+ 68 + * : 69 + * : 70 + * +-------------+ 71 + * | arg[0] | 72 + * +-------------+ 73 + * | argc | argc is always 4 bytes long, even in 64-bit architectures 74 + * +-------------+ <- sp 75 + * 76 + * Where arg[i] and env[i] point into the STRING AREA 77 + */ 78 + 79 + .text 80 + .globl start 81 + .align 2 82 + 83 + #if __ppc__ 84 + start: mr r26,r1 ; save original stack pointer into r26 85 + subi r1,r1,4 ; make space for linkage 86 + clrrwi r1,r1,5 ; align to 32 bytes (good enough for 32- and 64-bit APIs) 87 + li r0,0 ; load 0 into r0 88 + stw r0,0(r1) ; terminate initial stack frame 89 + stwu r1,-64(r1) ; allocate minimal stack frame 90 + lwz r3,0(r26) ; get argc into r3 91 + addi r4,r26,4 ; get argv into r4 92 + addi r27,r3,1 ; calculate argc + 1 into r27 93 + slwi r27,r27,2 ; calculate (argc + 1) * sizeof(char *) into r27 94 + add r5,r4,r27 ; get address of env[0] into r5 95 + #if OLD_LIBSYSTEM_SUPPORT 96 + bl __start ; 24-bt branch to __start. ld64 will make a branch island if needed 97 + trap ; should never return 98 + #else 99 + mr r6,r5 100 + Lapple: lwz r0,0(r6) ; look for NULL ending env[] array 101 + addi r6,r6,4 102 + cmpwi r0,0 103 + bne Lapple ; once found, next pointer is "apple" parameter now in r6 104 + bl _main 105 + b _exit ; pass result from main() to exit() 106 + #endif 107 + #endif // __ppc__ 108 + 109 + 110 + #if __ppc64__ 111 + start: mr r26,r1 ; save original stack pointer into r26 112 + subi r1,r1,8 ; make space for linkage 113 + clrrdi r1,r1,5 ; align to 32 bytes (good enough for 32- and 64-bit APIs) 114 + li r0,0 ; load 0 into r0 115 + std r0,0(r1) ; terminate initial stack frame 116 + stdu r1,-128(r1) ; allocate minimal stack frame 117 + lwz r3,0(r26) ; get argc into r3 118 + addi r4,r26,8 ; get argv into r4 119 + addi r27,r3,1 ; calculate argc + 1 into r27 120 + sldi r27,r27,3 ; calculate (argc + 1) * sizeof(char *) into r27 121 + add r5,r4,r27 ; get address of env[0] into r5 122 + #if OLD_LIBSYSTEM_SUPPORT 123 + bl __start ; 24-bt branch to __start. ld64 will make a branch island if needed 124 + trap ; should never return 125 + #else 126 + mr r6,r5 127 + Lapple: ld r0,0(r6) ; look for NULL ending env[] array 128 + addi r6,r6,8 129 + cmpdi r0,0 130 + bne Lapple ; once found, next pointer is "apple" parameter now in r6 131 + bl _main 132 + b _exit ; pass result from main() to exit() 133 + #endif 134 + #endif // __ppc64__ 135 + 136 + 137 + #if __i386__ 138 + start: pushl $0 # push a zero for debugger end of frames marker 139 + movl %esp,%ebp # pointer to base of kernel frame 140 + andl $-16,%esp # force SSE alignment 141 + subl $16,%esp # room for new argc, argv, & envp, SSE aligned 142 + movl 4(%ebp),%ebx # pickup argc in %ebx 143 + movl %ebx,0(%esp) # argc to reserved stack word 144 + lea 8(%ebp),%ecx # addr of arg[0], argv, into %ecx 145 + movl %ecx,4(%esp) # argv to reserved stack word 146 + addl $1,%ebx # argc + 1 for zero word 147 + sall $2,%ebx # * sizeof(char *) 148 + addl %ecx,%ebx # addr of env[0], envp, into %ebx 149 + movl %ebx,8(%esp) # envp to reserved stack word 150 + #if OLD_LIBSYSTEM_SUPPORT 151 + call __start # call _start(argc, argv, envp) 152 + hlt # should never return 153 + #else 154 + Lapple: movl (%ebx),%eax # look for NULL ending env[] array 155 + add $4,%ebx 156 + testl %eax,%eax 157 + jne Lapple # once found, next pointer is "apple" parameter now in %ebx 158 + movl %ebx,12(%esp) # apple to reserved stack word 159 + call _main 160 + movl %eax, 0(%esp) # pass result from main() to exit() 161 + call _exit # need to use call to keep stack aligned 162 + hlt 163 + #endif 164 + #endif // __i386__ 165 + 166 + 167 + 168 + #if __x86_64__ 169 + start: pushq $0 # push a zero for debugger end of frames marker 170 + movq %rsp,%rbp # pointer to base of kernel frame 171 + andq $-16,%rsp # force SSE alignment 172 + movq 8(%rbp),%rdi # put argc in %rdi 173 + leaq 16(%rbp),%rsi # addr of arg[0], argv, into %rsi 174 + movl %edi,%edx # copy argc into %rdx 175 + addl $1,%edx # argc + 1 for zero word 176 + sall $3,%edx # * sizeof(char *) 177 + addq %rsi,%rdx # addr of env[0], envp, into %rdx 178 + #if OLD_LIBSYSTEM_SUPPORT 179 + call __start # call _start(argc, argv, envp) 180 + hlt # should never return 181 + #else 182 + movq %rdx,%rcx 183 + jmp Lapple2 184 + Lapple: add $8,%rcx 185 + Lapple2:cmpq $0,(%rcx) # look for NULL ending env[] array 186 + jne Lapple 187 + add $8,%rcx # once found, next pointer is "apple" parameter now in %rcx 188 + call _main 189 + movl %eax,%edi # pass result from main() to exit() 190 + call _exit@PLT # need to use call to keep stack aligned 191 + hlt 192 + #endif 193 + #endif // __x86_64__ 194 + 195 + #ifdef __arm__ 196 + start: 197 + ldr r0, [sp] // get argc into r0 198 + add r1, sp, #4 // get argv into r1 199 + add r4, r0, #1 // calculate argc + 1 into r4 200 + add r2, r1, r4, lsl #2 // get address of env[0] into r2 201 + bic sp, sp, #7 // force eight-byte alignment 202 + #if OLD_LIBSYSTEM_SUPPORT 203 + bl __start 204 + .long 0xe1200070 // should never return 205 + #else 206 + mov r3, r2 207 + Lapple: 208 + ldr r4, [r3], #4 // look for NULL ending env[] array 209 + cmp r4, #0 210 + bne Lapple 211 + // "apple" param now in r3 212 + #if __STATIC__ || ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 30100) && !__ARM_ARCH_4T__) 213 + bl _main 214 + b _exit 215 + #else 216 + // use -mlong-branch style call sites so that main executable can be >32MB 217 + ldr ip, L4 218 + L2: add ip, pc, ip 219 + ldr ip, [ip, #0] 220 + #if __ARM_ARCH_4T__ 221 + mov lr, pc // blx not supported, so simulate it in two steps 222 + bx ip 223 + #else 224 + blx ip // call main() 225 + #endif 226 + 227 + ldr ip, L5 228 + L3: add ip, pc, ip 229 + ldr ip, [ip, #0] 230 + bx ip // jmp exit() 231 + 232 + L4: .long L_main$non_lazy_ptr-(L2+8) 233 + L5: .long L_exit$non_lazy_ptr-(L3+8) 234 + 235 + .non_lazy_symbol_pointer 236 + L_main$non_lazy_ptr: 237 + .indirect_symbol _main 238 + .long 0 239 + L_exit$non_lazy_ptr: 240 + .indirect_symbol _exit 241 + .long 0 242 + #endif 243 + 244 + 245 + #endif 246 + #endif /* __arm__ */ 247 + 248 + 249 + #if __arm64__ 250 + 251 + start: 252 + mov x5, sp 253 + ldr x0, [x5] ; get argc into x0 (kernel passes 32-bit int argc as 64-bits on stack to keep alignment) 254 + add x1, x5, #8 ; get argv into x1 255 + add x4, x0, #1 ; argc + 1 256 + add x2, x1, x4, lsl #3 ; &env[0] = (argc+1)*8 257 + and sp, x5, #~15 ; force 16-byte alignment of stack 258 + mov x3, x2 259 + L1: ldr x4, [x3], #8 260 + cmp x4, #0 ; look for NULL ending env[] array 261 + b.ne L1 262 + bl _main ; main(x0=argc, x1=argv, x2=envp, x3=apple) 263 + b _exit 264 + 265 + #endif /* __arm64__ */ 266 + 267 + 268 + // This code has be written to allow dead code stripping 269 + // .subsections_via_symbols
+1 -1
src/duct/src/CMakeLists.txt
··· 24 24 25 25 add_library(system_duct SHARED commpage.c libnotify.c numcpus.c 26 26 CRGetCrashLogMessage.c acl.c bootstrap.c dyld.c dns_sd.c 27 - sa_dst_compare.c) 27 + sa_dst_compare.c asl.c) 28 28 29 29 install(TARGETS system_duct DESTINATION lib${SUFFIX}/darling)
+65
src/duct/src/asl.c
··· 1 + int asl_close() 2 + { 3 + return 0; 4 + } 5 + 6 + int asl_get() 7 + { 8 + return 0; 9 + } 10 + 11 + int asl_open() 12 + { 13 + return 0; 14 + } 15 + 16 + int asl_set_query() 17 + { 18 + return 0; 19 + } 20 + 21 + int asl_store_match_timeout() 22 + { 23 + return 0; 24 + } 25 + 26 + int asl_new() 27 + { 28 + return 0; 29 + } 30 + 31 + int asl_free() 32 + { 33 + return 0; 34 + } 35 + 36 + int aslresponse_free() 37 + { 38 + return 0; 39 + } 40 + 41 + int asl_set() 42 + { 43 + return 0; 44 + } 45 + 46 + int aslresponse_next() 47 + { 48 + return 0; 49 + } 50 + 51 + int asl_store_open_read() 52 + { 53 + return 0; 54 + } 55 + 56 + int asl_send() 57 + { 58 + return 0; 59 + } 60 + 61 + int asl_store_close() 62 + { 63 + return 0; 64 + } 65 +
+16
src/dyld/darling
··· 84 84 >2& echo "Not implemented yet" 85 85 exit 1 86 86 ;; 87 + "load") 88 + if [ "$(id -u)" != 0 ]; then 89 + 2>&1 "You need to be root for this command." 90 + exit 1 91 + fi 92 + 93 + darling_load 94 + ;; 95 + "unload") 96 + if [ "$(id -u)" != 0 ]; then 97 + 2>&1 "You need to be root for this command." 98 + exit 1 99 + fi 100 + 101 + darling_unload 102 + ;; 87 103 *) 88 104 exec "${dyld_path}" "$1" "${@:2}" 89 105 ;;
+1
src/kernel/emulation/linux/CMakeLists.txt
··· 89 89 misc/getrlimit.c 90 90 misc/gethostuuid.c 91 91 misc/getrusage.c 92 + misc/getlogin.c 92 93 fcntl/open.c 93 94 fcntl/fcntl.c 94 95 network/socket.c
+26
src/kernel/emulation/linux/misc/getlogin.c
··· 1 + #include "getlogin.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <asm/unistd.h> 5 + #include <stddef.h> 6 + 7 + extern char *getenv(const char *name); 8 + extern unsigned long strlcpy(char* dst, const char* src, unsigned long size); 9 + 10 + long sys_getlogin(char* buf, unsigned int len) 11 + { 12 + int ret; 13 + char* e; 14 + 15 + e = getenv("USER"); 16 + if (e != NULL) 17 + { 18 + return strlcpy(buf, e, len); 19 + } 20 + else 21 + { 22 + *buf = '\0'; 23 + return 0; 24 + } 25 + } 26 +
+7
src/kernel/emulation/linux/misc/getlogin.h
··· 1 + #ifndef LINUX_GETLOGIN_H 2 + #define LINUX_GETLOGIN_H 3 + 4 + long sys_getlogin(char* buf, unsigned int len); 5 + 6 + #endif 7 +
+1
src/kernel/emulation/linux/misc/getrlimit.h
··· 5 5 { 6 6 unsigned long long rlim_cur; 7 7 unsigned long long rlim_max; 8 + long _dummy[20]; 8 9 }; 9 10 10 11 enum {
+14
src/kernel/emulation/linux/misc/sysctl.c
··· 12 12 #include <limits.h> 13 13 #include "../ext/sys/utsname.h" 14 14 #include "../ext/syslog.h" 15 + #include "getrlimit.h" 15 16 #include "darling-config.h" 16 17 #include <util/IniConfig.h> 17 18 ··· 183 184 default: 184 185 return -ENOTDIR; 185 186 } 187 + } 188 + case KERN_ARGMAX: 189 + { 190 + struct rlimit lim; 191 + int r; 192 + int* ovalue = (int*) old; 193 + 194 + r = sys_getrlimit(BSD_RLIMIT_STACK, &lim); 195 + if (r < 0) 196 + return r; 197 + 198 + *ovalue = lim.rlim_cur / 4; 199 + return 0; 186 200 } 187 201 } 188 202
+2
src/kernel/emulation/linux/syscalls.c
··· 60 60 #include "process/wait4.h" 61 61 #include "process/waitid.h" 62 62 #include "process/execve.h" 63 + #include "misc/getlogin.h" 63 64 #include "misc/ioctl.h" 64 65 #include "misc/getrlimit.h" 65 66 #include "misc/thread_selfid.h" ··· 158 159 [46] = sys_sigaction, 159 160 [47] = sys_getgid, 160 161 [48] = sys_sigprocmask, 162 + [49] = sys_getlogin, 161 163 [53] = sys_sigaltstack, 162 164 [54] = sys_ioctl, 163 165 [57] = sys_symlink,
+2
src/kernel/libsyscall/sys_x86-64/SYS.h
··· 146 146 147 147 #define UNIX_SYSCALL(name, nargs) \ 148 148 .globl cerror ;\ 149 + .type name, @function ;\ 149 150 LEAF(name, 0) ;\ 150 151 movl $ SYS_##name, %eax ;\ 151 152 call __darling_bsd_syscall@PLT ;\ ··· 158 159 159 160 #define UNIX_SYSCALL_NONAME(name, nargs, cerror) \ 160 161 .globl cerror ;\ 162 + .type name, @function ;\ 161 163 movl $ SYS_##name, %eax ;\ 162 164 call __darling_bsd_syscall@PLT ;\ 163 165 cmpq $-4095, %rax ;\
+1
src/kernel/libsyscall/sys_x86-64/__vfork.S
··· 152 152 #error Unsupported architecture 153 153 #endif 154 154 #if defined(__x86_64__) 155 + .type vfork, @function 155 156 .globl vfork 156 157 vfork = __vfork 157 158 #endif
+2 -2
src/libc/gen/CMakeLists.txt
··· 53 53 #syslog.c 54 54 thread_stack_pcs.c 55 55 uname.c 56 - #utmpx-darwin.c 56 + utmpx-darwin.c 57 57 wordexp.c) 58 58 59 59 set(gen_sources ${gen_sources} ··· 169 169 SET_SOURCE_FILES_PROPERTIES(FreeBSD/waitpid.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLIBC_ALIAS_WAITPID") 170 170 171 171 set(gen_sources ${gen_sources} 172 - #NetBSD/utmpx.c 172 + NetBSD/utmpx.c 173 173 ) 174 174 175 175 add_library(libc-gen OBJECT ${gen_sources})
+1 -1
src/libc/gen/utmpx-darwin.c
··· 52 52 #include <mach/mach_types.h> 53 53 #include <servers/bootstrap.h> 54 54 #include <pthread.h> 55 - #include <asl_ipc.h> 55 + //#include <asl_ipc.h> 56 56 57 57 #ifdef UTMP_COMPAT 58 58 #include <ttyent.h>
+2 -1
src/libc/sys/CMakeLists.txt
··· 3 3 cmake_minimum_required(VERSION 2.4.0) 4 4 5 5 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") 6 + include_directories(${DARLING_TOP_DIRECTORY}/src/libnotify) 6 7 7 8 set(sys_sources chmodx_np.c 8 9 crt_externs.c ··· 19 20 #OSThermalNotification.c 20 21 posix_spawn.c 21 22 semctl.c 22 - #settimeofday.c 23 + settimeofday.c 23 24 shmctl.c 24 25 sigaction.c 25 26 sigcatch.c
+2
src/libc/x86_64/string/memcmp.S
··· 44 44 #ifdef DARLING 45 45 # define _memcmp memcmp 46 46 # define _bcmp bcmp 47 + .type memcmp, @function 48 + .type bcmp, @function 47 49 #endif 48 50 49 51 .text
+1
src/libc/x86_64/string/memset.S
··· 49 49 # define _memset_pattern8 memset_pattern8 50 50 # define _memset_pattern16 memset_pattern16 51 51 # define _bzero bzero@PLT 52 + .type memset, @function 52 53 #endif 53 54 54 55 #define kShort 255 // for nonzero memset(), too short for commpage
+1
src/libc/x86_64/string/strcmp.S
··· 37 37 38 38 #ifdef DARLING 39 39 # define _strcmp strcmp 40 + .type strcmp, @function 40 41 #endif 41 42 42 43 .text
+1
src/libc/x86_64/string/strcpy.S
··· 39 39 40 40 #ifdef DARLING 41 41 # define _strcpy strcpy 42 + .type strcpy, @function 42 43 #endif 43 44 44 45 .text
+1
src/libc/x86_64/string/strlcat.S
··· 49 49 50 50 #ifdef DARLING 51 51 # define _strlcat strlcat 52 + .type strlcat, @function 52 53 #endif 53 54 54 55 .text
+1
src/libc/x86_64/string/strlcpy.S
··· 46 46 47 47 #ifdef DARLING 48 48 # define _strlcpy strlcpy 49 + .type strlcpy,@function 49 50 #endif 50 51 51 52 .text
+1
src/libc/x86_64/string/strlen.S
··· 34 34 35 35 #ifdef DARLING 36 36 # define _strlen strlen 37 + .type strlen, @function 37 38 #endif 38 39 39 40 .text
+1
src/libc/x86_64/string/strncmp.S
··· 37 37 38 38 #ifdef DARLING 39 39 # define _strncmp strncmp 40 + .type strncmp, @function 40 41 #endif 41 42 42 43 #define kShort 20 // too short for vectors (must be >16)
+1
src/libc/x86_64/string/strncpy.S
··· 46 46 #ifdef DARLING 47 47 # define _strncpy strncpy 48 48 # define _bzero bzero@PLT 49 + .type strncpy, @function 49 50 #endif 50 51 51 52 #define kShort 31 // too short to bother with vector loop
+3 -2
src/libdyld/dl_public.cpp
··· 314 314 const char*** environPtr; 315 315 const char** __prognamePtr; 316 316 }; 317 + extern "C" char** __darwin_environ; 317 318 void __darling_get_args(int** argc, char**** argv, char**** env, struct ::ProgramVars* vars) 318 319 { 319 320 *argc = &g_argc; 320 321 *argv = &g_argv; 321 - *env = &environ; 322 + *env = &__darwin_environ; 322 323 vars->NXArgcPtr = &g_argc; 323 324 vars->NXArgvPtr = (const char***) &g_argv; 324 - vars->environPtr = (const char***) &environ; 325 + vars->environPtr = (const char***) &__darwin_environ; 325 326 vars->__prognamePtr = (const char**) &g_argv[0]; 326 327 327 328 }
+2
src/libdyld/environ.c
··· 1 1 #ifdef __x86_64__ 2 2 __asm__(".section .bss\n" 3 + ".type __darwin_environ,@common\n" 4 + ".size __darwin_environ, 8\n" 3 5 ".global __darwin_environ\n" 4 6 ".symver __darwin_environ, environ@DARWIN\n" 5 7 "//.comm __darwin_environ, 8\n"
+28 -7
src/libsystem/init.c
··· 94 94 /* 95 95 * libsyscall_initializer() initializes all of libSystem.dylib <rdar://problem/4892197> 96 96 */ 97 - static __attribute__((constructor)) 98 - void libSystem_initializer(/*int argc, const char* argv[], const char* envp[], const char* apple[], const struct ProgramVars* vars*/) 97 + //static 98 + void libSystem_initializer(int argc, const char* argv[], const char* envp[] /*, const char* apple[], const struct ProgramVars* vars*/) 99 99 { 100 100 static const struct _libkernel_functions libkernel_funcs = { 101 101 .version = 1, ··· 106 106 ._pthread_exit_if_canceled = _pthread_exit_if_canceled, 107 107 }; 108 108 109 - int* argc; 110 - char*** argv; 111 - char*** envp; 109 + int* x_argc; 110 + char*** x_argv; 111 + char*** x_envp; 112 112 char** apple = { NULL }; 113 113 struct ProgramVars vars; 114 114 115 115 /* Early initialization - original Apple code assumes pthread_init() doesn't print errors */ 116 - __darling_get_args(&argc, &argv, &envp, &vars); 117 - __darling_set_libc_vars(argc, argv, envp); 116 + __darling_get_args(&x_argc, &x_argv, &x_envp, &vars); 117 + 118 + if (!*x_argc) 119 + { 120 + // Darling libdyld is not being used 121 + // to execute a Mach-O binary. 122 + // Use what the ELF loader gave us. 123 + *x_argc = argc; 124 + *x_argv = argv; 125 + *x_envp = envp; 126 + vars.NXArgcPtr = x_argc; 127 + vars.NXArgvPtr = x_argv; 128 + vars.environPtr = x_envp; 129 + vars.__prognamePtr = &(*x_argv)[0]; 130 + vars.mh = NULL; 131 + } 132 + __darling_set_libc_vars(x_argc, x_argv, x_envp); 118 133 119 134 /* cerror() calls require working pthread_self() */ 120 135 char dummy_self[4096]; ··· 143 158 errno = 0; 144 159 __objc_initialize(); 145 160 } 161 + 162 + void (*const init_array []) (void) 163 + __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) = 164 + { 165 + &libSystem_initializer 166 + }; 146 167 147 168 /* 148 169 * libSystem_atfork_{prepare,parent,child}() are called by libc when we fork, then we deal with running fork handlers