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