1 /* 2 * Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <pthread.h> 8 #include <string.h> 9 10 #include <OS.h> 11 #include <image.h> 12 13 #include <user_runtime.h> 14 15 #include <runtime_loader.h> 16 17 #include <fork.h> 18 #include <libroot_private.h> 19 #include <pthread_private.h> 20 21 22 struct rld_export *__gRuntimeLoader = NULL; 23 // This little bugger is set to something meaningful by the runtime loader 24 // Ugly, eh? 25 26 const void* __gCommPageAddress; 27 28 char *__progname = NULL; 29 int __libc_argc; 30 char **__libc_argv; 31 32 int __gABIVersion; 33 int32 __gCPUCount; 34 35 char _single_threaded = true; 36 // determines if I/O locking needed; needed for BeOS compatibility 37 38 thread_id __main_thread_id; 39 char **argv_save; 40 // needed for BeOS compatibility - they are set in the startup code 41 // (have a look at the glue/ directory) 42 43 int _data_offset_main_; 44 // this is obviously needed for R4.5 compatiblity 45 46 47 void 48 initialize_before(image_id imageID) 49 { 50 system_info info; 51 char *programPath = __gRuntimeLoader->program_args->args[0]; 52 __gCommPageAddress = __gRuntimeLoader->commpage_address; 53 __gABIVersion = __gRuntimeLoader->abi_version; 54 55 if (programPath) { 56 if ((__progname = strrchr(programPath, '/')) == NULL) 57 __progname = programPath; 58 else 59 __progname++; 60 } 61 62 __libc_argc = __gRuntimeLoader->program_args->arg_count; 63 __libc_argv = __gRuntimeLoader->program_args->args; 64 65 __gRuntimeLoader->call_atexit_hooks_for_range 66 = _call_atexit_hooks_for_range; 67 68 if (__gRuntimeLoader->program_args->umask != (mode_t)-1) 69 umask(__gRuntimeLoader->program_args->umask); 70 71 pthread_self()->id = find_thread(NULL); 72 73 get_system_info(&info); 74 __gCPUCount = info.cpu_count; 75 76 __init_time((addr_t)__gCommPageAddress); 77 __init_env(__gRuntimeLoader->program_args); 78 __init_heap(); 79 __init_env_post_heap(); 80 __init_pwd_backend(); 81 __set_stack_protection(); 82 } 83 84 85 void _init_c_library_(void); 86 void 87 _init_c_library_(void) 88 { 89 // This function is called from the BeOS start_dyn.o - so it's called once 90 // for every application that was compiled under BeOS. 91 // Our libroot functions are already initialized above, so we don't have to 92 // do anything here. 93 } 94 95 96 void 97 terminate_after(image_id id) 98 { 99 __heap_terminate_after(); 100 } 101