tools/llvm: Do not build with symbols
[minix3.git] / minix / lib / libexec / exec_general.c
blob495913b68454a1028821fe4a5da02819ba62c846
1 #define _SYSTEM 1
3 #include <minix/type.h>
4 #include <minix/const.h>
5 #include <sys/param.h>
6 #include <assert.h>
7 #include <unistd.h>
8 #include <errno.h>
9 #include <libexec.h>
10 #include <string.h>
11 #include <assert.h>
12 #include <minix/ipc.h>
13 #include <minix/com.h>
14 #include <minix/callnr.h>
15 #include <minix/vm.h>
16 #include <minix/ipc.h>
17 #include <minix/syslib.h>
18 #include <sys/mman.h>
19 #include <machine/elf.h>
21 int libexec_alloc_mmap_prealloc_junk(struct exec_info *execi, vir_bytes vaddr, size_t len)
23 if(minix_mmap_for(execi->proc_e, (void *) vaddr, len,
24 PROT_READ|PROT_WRITE|PROT_EXEC,
25 MAP_ANON|MAP_PREALLOC|MAP_UNINITIALIZED|MAP_FIXED, -1, 0) == MAP_FAILED) {
26 return ENOMEM;
29 return OK;
32 int libexec_alloc_mmap_prealloc_cleared(struct exec_info *execi, vir_bytes vaddr, size_t len)
34 if(minix_mmap_for(execi->proc_e, (void *) vaddr, len,
35 PROT_READ|PROT_WRITE|PROT_EXEC,
36 MAP_ANON|MAP_PREALLOC|MAP_FIXED, -1, 0) == MAP_FAILED) {
37 return ENOMEM;
40 return OK;
43 int libexec_alloc_mmap_ondemand(struct exec_info *execi, vir_bytes vaddr, size_t len)
45 if(minix_mmap_for(execi->proc_e, (void *) vaddr, len,
46 PROT_READ|PROT_WRITE|PROT_EXEC,
47 MAP_ANON|MAP_FIXED, -1, 0) == MAP_FAILED) {
48 return ENOMEM;
51 return OK;
54 int libexec_clearproc_vm_procctl(struct exec_info *execi)
56 return vm_procctl_clear(execi->proc_e);
59 int libexec_clear_sys_memset(struct exec_info *execi, vir_bytes vaddr, size_t len)
61 return sys_memset(execi->proc_e, 0, vaddr, len);
64 int libexec_copy_memcpy(struct exec_info *execi,
65 off_t off, vir_bytes vaddr, size_t len)
67 assert(off + len <= execi->hdr_len);
68 memcpy((char *) vaddr, (char *) execi->hdr + off, len);
69 return OK;
72 int libexec_clear_memset(struct exec_info *execi, vir_bytes vaddr, size_t len)
74 memset((char *) vaddr, 0, len);
75 return OK;
78 int libexec_pm_newexec(endpoint_t proc_e, struct exec_info *e)
80 int r;
81 message m;
83 memset(&m, 0, sizeof(m));
84 m.m_type = PM_EXEC_NEW;
85 m.m_lexec_pm_exec_new.endpt = proc_e;
86 m.m_lexec_pm_exec_new.ptr = (vir_bytes)e;
87 if ((r = ipc_sendrec(PM_PROC_NR, &m)) != OK) return(r);
89 e->allow_setuid = !!m.m_pm_lexec_exec_new.suid;
91 return(m.m_type);