summaryrefslogtreecommitdiff
path: root/src/user/lib/_start2.c
blob: f55feab53dd3b1b4dfc464ba1236cf30f23684dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <_proc.h>
#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <elfload.h>

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(_libc_psdata, 1, MEMFLAG_PRESENT);
	if (ed->argv[0]) {
		strcpy(_libc_psdata, ed->argv[0]);
	} else {
		strcpy(_libc_psdata, "?");
	}

	_sys_intr_set(intr_trampoline);
	intr_set(intr_default);
	__setinitialcwd(ed->cwd);

	progname = shortname(ed->argv[0]);
	setprogname(progname);
	_klogf("_start2 %s %p", progname, __executable_start);

	exit(main(ed->argc, ed->argv, ed->envp));
}