use the -newos toolchain even if -elf is present.
[newos.git] / lib / glue / lib0.c
blob80a3ff9756a4a808e7ecc9c5a335dbe0a90c55ce
1 /*
2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Copyright 2002, Manuel J. Petit. All rights reserved.
4 ** Distributed under the terms of the NewOS License.
5 */
7 #include <newos/user_runtime.h>
8 #include <sys/syscalls.h>
10 extern void sys_exit(int retcode);
12 extern void (*__ctor_list)(void);
13 extern void (*__ctor_end)(void);
15 int _start(unsigned image_id, struct uspace_prog_args_t *);
16 static void _call_ctors(void);
18 int
19 _start(unsigned imid, struct uspace_prog_args_t *uspa)
21 void *ibc;
22 void *iac;
24 ibc= uspa->rld_export->dl_sym(imid, "INIT_BEFORE_CTORS", 0);
25 iac= uspa->rld_export->dl_sym(imid, "INIT_AFTER_CTORS", 0);
27 if(ibc) {
28 ((libinit_f*)(ibc))(imid, uspa);
30 _call_ctors();
31 if(iac) {
32 ((libinit_f*)(iac))(imid, uspa);
35 return 0;
38 static
39 void _call_ctors(void)
41 void (**f)(void);
43 for(f = &__ctor_list; f < &__ctor_end; f++) {
44 (**f)();