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/ipc.h>
17 #include <minix/syslib.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
) {
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
) {
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
);
61 int libexec_clear_memset(struct exec_info
*execi
, off_t vaddr
, size_t len
)
63 memset((char *) vaddr
, 0, len
);
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.
78 flag
= 0; /* counts number of 0-pointers seen */
79 ap
= (char **) stack
; /* points initially to 'nargs' */
80 ap
++; /* now points to argv[0] */
82 if (ap
>= (char **) &stack
[ARG_MAX
]) return; /* too bad */
84 v
= (vir_bytes
) *ap
; /* v is relative pointer */
85 v
+= base
; /* relocate it */
86 *ap
= (char *) v
; /* put it back */
94 int libexec_pm_newexec(endpoint_t proc_e
, struct exec_info
*e
)
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
);