xref: /haiku/src/system/libroot/libroot_init.c (revision 372a66634410cf0450e426716c14ad42d40c0da4)
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 void initialize_before(image_id imageID);
23 
24 struct rld_export *__gRuntimeLoader = NULL;
25 	// This little bugger is set to something meaningful by the runtime loader
26 	// Ugly, eh?
27 
28 const void* __gCommPageAddress;
29 
30 char *__progname = NULL;
31 int __libc_argc;
32 char **__libc_argv;
33 
34 int __gABIVersion;
35 
36 char _single_threaded = true;
37 	// determines if I/O locking needed; needed for BeOS compatibility
38 
39 thread_id __main_thread_id;
40 char **argv_save;
41 	// needed for BeOS compatibility - they are set in the startup code
42 	// (have a look at the glue/ directory)
43 
44 int _data_offset_main_;
45 	// this is obviously needed for R4.5 compatiblity
46 
47 
48 void
49 initialize_before(image_id imageID)
50 {
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 	__init_time((addr_t)__gCommPageAddress);
74 	__init_heap();
75 	__init_env(__gRuntimeLoader->program_args);
76 	__init_heap_post_env();
77 	__init_pwd_backend();
78 	__set_stack_protection();
79 }
80 
81 
82 void _init_c_library_(void);
83 void
84 _init_c_library_(void)
85 {
86 	// This function is called from the BeOS start_dyn.o - so it's called once
87 	// for every application that was compiled under BeOS.
88 	// Our libroot functions are already initialized above, so we don't have to
89 	// do anything here.
90 }
91 
92