From 642b5fb0007b64c77d186fcb018d571152ee1d47 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 14 Aug 2023 18:51:07 +0200 Subject: reorganization: first steps --- src/libc/_start2.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/libc/_start2.c (limited to 'src/libc/_start2.c') diff --git a/src/libc/_start2.c b/src/libc/_start2.c new file mode 100644 index 0000000..b4eb76a --- /dev/null +++ b/src/libc/_start2.c @@ -0,0 +1,42 @@ +#include <_proc.h> +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv, char **envp); + +__attribute__((visibility("hidden"))) +extern char __executable_start[]; + +const char *shortname(const char *path) { + if (!path) return "unknown program"; + const char *slash = strrchr(path, '/'); + if (slash) return slash + 1; + return path; +} + +void intr_trampoline(void); /* intr.s */ + +_Noreturn void _start2(struct execdata *ed) { + const char *progname; + elf_selfreloc(); + + /* done first so it isn't allocated elsewhere by accident */ + _sys_memflag(_psdata_loc, 1, MEMFLAG_PRESENT); + _psdata_loc->base = __executable_start; + /* sets ->desc */ + progname = shortname(ed->argv[0]); + setprogname(progname); + + _klogf("_start2 %s %p", progname, __executable_start); + + _sys_intr_set(intr_trampoline); + intr_set(intr_default); + __setinitialcwd(ed->cwd); + + exit(main(ed->argc, ed->argv, ed->envp)); +} -- cgit v1.2.3