3 #include <minix/type.h>
4 #include <minix/const.h>
12 #include <minix/ipc.h>
13 #include <minix/com.h>
14 #include <minix/callnr.h>
16 #include <minix/syslib.h>
18 #include <machine/elf.h>
20 int libexec_alloc_mmap_prealloc(struct exec_info
*execi
, off_t vaddr
, size_t len
)
22 if(minix_mmap_for(execi
->proc_e
, (void *) vaddr
, len
,
23 PROT_READ
|PROT_WRITE
|PROT_EXEC
,
24 MAP_ANON
|MAP_PREALLOC
|MAP_UNINITIALIZED
|MAP_FIXED
, -1, 0) == MAP_FAILED
) {
31 int libexec_alloc_mmap_ondemand(struct exec_info
*execi
, off_t vaddr
, size_t len
)
33 if(minix_mmap_for(execi
->proc_e
, (void *) vaddr
, len
,
34 PROT_READ
|PROT_WRITE
|PROT_EXEC
,
35 MAP_ANON
|MAP_FIXED
, -1, 0) == MAP_FAILED
) {
42 int libexec_clearproc_vm_procctl(struct exec_info
*execi
)
44 return vm_procctl(execi
->proc_e
, VMPPARAM_CLEAR
);
47 int libexec_clear_sys_memset(struct exec_info
*execi
, off_t vaddr
, size_t len
)
49 return sys_memset(execi
->proc_e
, 0, vaddr
, len
);
52 int libexec_copy_memcpy(struct exec_info
*execi
,
53 off_t off
, off_t vaddr
, size_t len
)
55 assert(off
+ len
<= execi
->hdr_len
);
56 memcpy((char *) vaddr
, (char *) execi
->hdr
+ off
, len
);
60 int libexec_clear_memset(struct exec_info
*execi
, off_t vaddr
, size_t len
)
62 memset((char *) vaddr
, 0, len
);
66 void libexec_patch_ptr(char stack
[ARG_MAX
], vir_bytes base
)
68 /* When doing an exec(name, argv, envp) call, the user builds up a stack
69 * image with arg and env pointers relative to the start of the stack. Now
70 * these pointers must be relocated, since the stack is not positioned at
71 * address 0 in the user's address space.
77 flag
= 0; /* counts number of 0-pointers seen */
78 ap
= (char **) stack
; /* points initially to 'nargs' */
79 ap
++; /* now points to argv[0] */
81 if (ap
>= (char **) &stack
[ARG_MAX
]) return; /* too bad */
83 v
= (vir_bytes
) *ap
; /* v is relative pointer */
84 v
+= base
; /* relocate it */
85 *ap
= (char *) v
; /* put it back */
93 int libexec_pm_newexec(endpoint_t proc_e
, struct exec_info
*e
)
98 m
.m_type
= PM_NEWEXEC
;
99 m
.EXC_NM_PROC
= proc_e
;
100 m
.EXC_NM_PTR
= (char *)e
;
101 if ((r
= sendrec(PM_PROC_NR
, &m
)) != OK
) return(r
);
103 e
->allow_setuid
= !!(m
.m1_i2
& EXC_NM_RF_ALLOW_SETUID
);