refactor: elf parsing utility and exec related
[lunaix-os.git] / lunaix-os / includes / lunaix / exec.h
1 #ifndef __LUNAIX_EXEC_H
2 #define __LUNAIX_EXEC_H
3
4 #include <lunaix/elf.h>
5 #include <lunaix/fs.h>
6 #include <lunaix/process.h>
7 #include <lunaix/types.h>
8
9 #define NO_LOADER 0
10 #define DEFAULT_LOADER "usr/ld"
11
12 #define MAX_VAR_PAGES 8
13 #define DEFAULT_HEAP_PAGES 16
14
15 struct exec_context;
16
17 struct load_context
18 {
19     struct exec_container* container;
20     ptr_t base;
21     ptr_t end;
22     ptr_t mem_sz;
23
24     ptr_t entry;
25 };
26
27 struct exec_container
28 {
29     struct proc_info* proc;
30     ptr_t vms_mnt;
31
32     struct load_context executable;
33
34     ptr_t stack_top;
35     ptr_t entry; // mapped to one of {executable|loader}.entry
36
37     int status;
38 };
39
40 struct uexec_param
41 {
42     int argc;
43     char** argv;
44     int envc;
45     char** envp;
46 } PACKED;
47
48 #ifndef __USR_WRAPPER__
49
50 int
51 exec_load_byname(struct exec_container* container,
52                  const char* filename,
53                  const char** argv,
54                  const char** envp);
55
56 int
57 exec_load(struct exec_container* container,
58           struct v_file* executable,
59           const char** argv,
60           const char** envp);
61
62 int
63 exec_kexecve(const char* filename, const char* argv[], const char* envp);
64
65 #endif
66
67 #endif /* __LUNAIX_LOADER_H */