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 <image.h> 11 12 #include <user_runtime.h> 13 14 #include <runtime_loader.h> 15 16 #include <fork.h> 17 #include <libroot_private.h> 18 #include <pthread_private.h> 19 20 21 void initialize_before(image_id imageID); 22 23 struct rld_export *__gRuntimeLoader = NULL; 24 // This little bugger is set to something meaningful by the runtime loader 25 // Ugly, eh? 26 27 char *__progname = NULL; 28 int __libc_argc; 29 char **__libc_argv; 30 31 char _single_threaded = true; 32 // determines if I/O locking needed; needed for BeOS compatibility 33 34 thread_id __main_thread_id; 35 char **argv_save; 36 // needed for BeOS compatibility - they are set in the startup code 37 // (have a look at the glue/ directory) 38 39 int _data_offset_main_; 40 // this is obviously needed for R4.5 compatiblity 41 42 43 void 44 initialize_before(image_id imageID) 45 { 46 char *programPath = __gRuntimeLoader->program_args->args[0]; 47 if (programPath) { 48 if ((__progname = strrchr(programPath, '/')) == NULL) 49 __progname = programPath; 50 else 51 __progname++; 52 } 53 54 __libc_argc = __gRuntimeLoader->program_args->arg_count; 55 __libc_argv = __gRuntimeLoader->program_args->args; 56 57 __gRuntimeLoader->call_atexit_hooks_for_range 58 = _call_atexit_hooks_for_range; 59 60 if (__gRuntimeLoader->program_args->umask != (mode_t)-1) 61 umask(__gRuntimeLoader->program_args->umask); 62 63 pthread_self()->id = find_thread(NULL); 64 65 __init_time(); 66 __init_heap(); 67 __init_env(__gRuntimeLoader->program_args); 68 __init_heap_post_env(); 69 __init_pwd_backend(); 70 } 71 72 73 void _init_c_library_(void); 74 void 75 _init_c_library_(void) 76 { 77 // This function is called from the BeOS start_dyn.o - so it's called once 78 // for every application that was compiled under BeOS. 79 // Our libroot functions are already initialized above, so we don't have to 80 // do anything here. 81 } 82 83