xref: /minix/minix/lib/libexec/libexec.h (revision 7f5f010b)
1 #ifndef _LIBEXEC_H_
2 #define _LIBEXEC_H_ 1
3 
4 #include <sys/exec_elf.h>
5 
6 struct exec_info;
7 
8 typedef int (*libexec_loadfunc_t)(struct exec_info *execi,
9 	off_t offset, vir_bytes vaddr, size_t len);
10 
11 typedef int (*libexec_clearfunc_t)(struct exec_info *execi,
12 	vir_bytes vaddr, size_t len);
13 
14 typedef int (*libexec_allocfunc_t)(struct exec_info *execi,
15 	vir_bytes vaddr, size_t len);
16 
17 typedef int (*libexec_procclearfunc_t)(struct exec_info *execi);
18 
19 typedef int (*libexec_mmap_t)(struct exec_info *execi,
20 	vir_bytes vaddr, vir_bytes len, vir_bytes foffset, u16_t clearend,
21 	int protflags);
22 
23 struct exec_info {
24     /* Filled in by libexec caller */
25     endpoint_t  proc_e;                 /* Process endpoint */
26     char *hdr;                          /* Header or full image */
27     size_t hdr_len;                     /* Size of hdr */
28     vir_bytes frame_len;                /* Stack size */
29     char progname[PROC_NAME_LEN];       /* Program name */
30     uid_t new_uid;                      /* Process UID after exec */
31     gid_t new_gid;                      /* Process GID after exec */
32     int allow_setuid;                   /* Allow set{u,g}id execution? */
33     vir_bytes stack_size;		/* Desired stack size */
34     vir_bytes load_offset;		/* Desired load offset */
35     vir_bytes text_size;		/* Text segment size */
36     vir_bytes data_size;		/* Data segment size */
37     off_t filesize;			/* How big is the file */
38 
39     /* Callback pointers for use by libexec */
40     libexec_loadfunc_t copymem;		/* Copy callback */
41     libexec_clearfunc_t clearmem;	/* Clear callback */
42     libexec_allocfunc_t allocmem_prealloc_cleared; /* Alloc callback */
43     libexec_allocfunc_t allocmem_prealloc_junk; /* Alloc callback */
44     libexec_allocfunc_t allocmem_ondemand; /* Alloc callback */
45     libexec_procclearfunc_t clearproc;	/* Clear process callback */
46     libexec_mmap_t memmap;		/* mmap callback */
47     void *opaque;			/* Callback data */
48 
49     /* Filled in by libexec load function */
50     vir_bytes load_base;		/* Where executable is loaded */
51     vir_bytes pc;                       /* Entry point of exec file */
52     vir_bytes stack_high;		/* High stack addr */
53 };
54 
55 int elf_has_interpreter(char *exec_hdr, int hdr_len, char *interp, int maxsz);
56 int elf_phdr(char *exec_hdr, int hdr_len, vir_bytes *phdr);
57 
58 int libexec_pm_newexec(endpoint_t proc_e, struct exec_info *execi);
59 
60 typedef int (*libexec_exec_loadfunc_t)(struct exec_info *execi);
61 int libexec_load_elf(struct exec_info *execi);
62 
63 /* Default callbacks for kernel. */
64 int libexec_copy_memcpy(struct exec_info *execi, off_t offset, vir_bytes vaddr, size_t len);
65 int libexec_clear_memset(struct exec_info *execi, vir_bytes vaddr, size_t len);
66 
67 /* Default callbacks. */
68 int libexec_alloc_mmap_prealloc_cleared(struct exec_info *execi, vir_bytes vaddr, size_t len);
69 int libexec_alloc_mmap_prealloc_junk(struct exec_info *execi, vir_bytes vaddr, size_t len);
70 int libexec_alloc_mmap_ondemand(struct exec_info *execi, vir_bytes vaddr, size_t len);
71 int libexec_clearproc_vm_procctl(struct exec_info *execi);
72 int libexec_clear_sys_memset(struct exec_info *execi, vir_bytes vaddr, size_t len);
73 
74 #endif /* !_LIBEXEC_H_ */
75