xref: /haiku/src/system/libroot/libroot_init.c (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <string.h>
7 
8 #include <fork.h>
9 #include <image.h>
10 #include <libroot_private.h>
11 #include <runtime_loader.h>
12 #include <user_runtime.h>
13 
14 
15 void initialize_before(image_id imageID);
16 void _call_atexit_hooks_for_range(addr_t start, addr_t size);
17 void __init_exit_stack_lock();
18 
19 struct rld_export *__gRuntimeLoader = NULL;
20 	// This little bugger is set to something meaningful by the runtime loader
21 	// Ugly, eh?
22 
23 char *__progname = NULL;
24 int __libc_argc;
25 char **__libc_argv;
26 
27 char _single_threaded = true;
28 	// determines if I/O locking needed; needed for BeOS compatibility
29 
30 thread_id __main_thread_id;
31 char **argv_save;
32 	// needed for BeOS compatibility - they are set in the startup code
33 	// (have a look at the glue/ directory)
34 
35 int _data_offset_main_;
36 	// this is obviously needed for R4.5 compatiblity
37 
38 
39 void
40 initialize_before(image_id imageID)
41 {
42 	char *programPath = __gRuntimeLoader->program_args->args[0];
43 	if (programPath) {
44 		if ((__progname = strrchr(programPath, '/')) == NULL)
45 			__progname = programPath;
46 		else
47 			__progname++;
48 	}
49 
50 	__libc_argc = __gRuntimeLoader->program_args->arg_count;
51 	__libc_argv = __gRuntimeLoader->program_args->args;
52 
53 	__gRuntimeLoader->call_atexit_hooks_for_range
54 		= _call_atexit_hooks_for_range;
55 
56 	__init_exit_stack_lock();
57 	__init_time();
58 	__init_fork();
59 	__init_heap();
60 	__init_env(__gRuntimeLoader->program_args);
61 	__init_pwd_backend();
62 }
63 
64 
65 void _init_c_library_(void);
66 void
67 _init_c_library_(void)
68 {
69 	// This function is called from the BeOS start_dyn.o - so it's called once
70 	// for every application that was compiled under BeOS.
71 	// Our libroot functions are already initialized above, so we don't have to
72 	// do anything here.
73 }
74 
75