ldivmod, uldivmod: fix qdivrem calls
[minix.git] / lib / libexec / exec_general.c
blob2ac942df958b34ba49d3254ece41c262f4893c13
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(struct exec_info *execi, off_t 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_ondemand(struct exec_info *execi, off_t 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_FIXED, -1, 0) == MAP_FAILED) {
37 return ENOMEM;
40 return OK;
43 int libexec_clearproc_vm_procctl(struct exec_info *execi)
45 return vm_procctl(execi->proc_e, VMPPARAM_CLEAR);
48 int libexec_clear_sys_memset(struct exec_info *execi, off_t vaddr, size_t len)
50 return sys_memset(execi->proc_e, 0, vaddr, len);
53 int libexec_copy_memcpy(struct exec_info *execi,
54 off_t off, off_t vaddr, size_t len)
56 assert(off + len <= execi->hdr_len);
57 memcpy((char *) vaddr, (char *) execi->hdr + off, len);
58 return OK;
61 int libexec_clear_memset(struct exec_info *execi, off_t vaddr, size_t len)
63 memset((char *) vaddr, 0, len);
64 return OK;
67 void libexec_patch_ptr(char stack[ARG_MAX], vir_bytes base)
69 /* When doing an exec(name, argv, envp) call, the user builds up a stack
70 * image with arg and env pointers relative to the start of the stack. Now
71 * these pointers must be relocated, since the stack is not positioned at
72 * address 0 in the user's address space.
75 char **ap, flag;
76 vir_bytes v;
78 flag = 0; /* counts number of 0-pointers seen */
79 ap = (char **) stack; /* points initially to 'nargs' */
80 ap++; /* now points to argv[0] */
81 while (flag < 2) {
82 if (ap >= (char **) &stack[ARG_MAX]) return; /* too bad */
83 if (*ap != NULL) {
84 v = (vir_bytes) *ap; /* v is relative pointer */
85 v += base; /* relocate it */
86 *ap = (char *) v; /* put it back */
87 } else {
88 flag++;
90 ap++;
94 int libexec_pm_newexec(endpoint_t proc_e, struct exec_info *e)
96 int r;
97 message m;
99 m.m_type = PM_NEWEXEC;
100 m.EXC_NM_PROC = proc_e;
101 m.EXC_NM_PTR = (char *)e;
102 if ((r = sendrec(PM_PROC_NR, &m)) != OK) return(r);
104 e->allow_setuid = !!(m.m1_i2 & EXC_NM_RF_ALLOW_SETUID);
106 return(m.m_type);