Updated to be a bit more BeOS compatible (now calls B_INIT_BEFORE/AFTER_FUNCTION_NAME

instead of "INIT_BEFORE/AFTER_CTORS".
Uses the new runtime linker exports.
Note, this is not yet BeOS compatible (will need to have init/fini sections)!


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2441 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-01-12 17:22:45 +00:00
parent e6e5ebbc10
commit 75b2a820de
2 changed files with 30 additions and 21 deletions

View File

@ -17,7 +17,7 @@ extern void (*__ctor_end)(void);
extern int main(int argc,char **argv);
int _start(struct uspace_prog_args_t *);
int _start(struct uspace_program_args *);
void _call_ctors(void);
static char empty[1];
@ -25,7 +25,9 @@ char *__progname = empty;
char **environ = NULL;
int _start(struct uspace_prog_args_t *uspa)
int
_start(struct uspace_program_args *args)
{
int retcode;
register char *ap;
@ -33,27 +35,29 @@ int _start(struct uspace_prog_args_t *uspa)
// __stdio_init();
if ((ap = uspa->argv[0])) {
if ((ap = args->argv[0])) {
if ((__progname = strrchr(ap, '/')) == NULL)
__progname = ap;
else
++__progname;
}
environ = uspa->envp;
retcode = main(uspa->argc, uspa->argv);
environ = args->envp;
retcode = main(args->argc, args->argv);
// __stdio_deinit();
sys_exit(retcode);
return 0;
}
void _call_ctors(void)
void
_call_ctors(void)
{
void (**f)(void);
for(f = &__ctor_list; f < &__ctor_end; f++) {
for (f = &__ctor_list; f < &__ctor_end; f++) {
(**f)();
}
}

View File

@ -4,39 +4,44 @@
** Distributed under the terms of the NewOS License.
*/
#include <user_runtime.h>
#include <image.h>
#include <syscalls.h>
extern void sys_exit(int retcode);
extern void (*__ctor_list)(void);
extern void (*__ctor_end)(void);
int _start(unsigned image_id, struct uspace_prog_args_t *);
int _start(image_id image_id, struct uspace_program_args *);
static void _call_ctors(void);
int
_start(unsigned imid, struct uspace_prog_args_t *uspa)
_start(image_id imageID, struct uspace_program_args *args)
{
// int i;
// int retcode;
void *ibc;
void *iac;
void *initBefore = NULL;
void *initAfter = NULL;
ibc= uspa->rld_export->dl_sym(imid, "INIT_BEFORE_CTORS", 0);
iac= uspa->rld_export->dl_sym(imid, "INIT_AFTER_CTORS", 0);
args->rld_export->get_image_symbol(imageID, B_INIT_BEFORE_FUNCTION_NAME, B_SYMBOL_TYPE_TEXT, (void **)&initBefore);
args->rld_export->get_image_symbol(imageID, B_INIT_AFTER_FUNCTION_NAME, B_SYMBOL_TYPE_TEXT, (void **)&initAfter);
if (initBefore)
((libinit_f *)(initBefore))(imageID, args);
if(ibc) {
((libinit_f*)(ibc))(imid, uspa);
}
_call_ctors();
if(iac) {
((libinit_f*)(iac))(imid, uspa);
}
if (initAfter)
((libinit_f *)(initAfter))(imageID, args);
return 0;
}
static
void _call_ctors(void)
{