2013-09-13 20:12:22 +02:00
|
|
|
/* execve() - basic program execution call */
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <lib.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stddef.h>
|
2013-09-13 20:12:22 +02:00
|
|
|
#include <minix/param.h>
|
2012-04-03 15:52:25 +02:00
|
|
|
#include <sys/exec_elf.h>
|
2013-09-13 20:12:22 +02:00
|
|
|
#include <sys/exec.h>
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
int execve(const char *path, char * const *argv, char * const *envp)
|
|
|
|
{
|
|
|
|
message m;
|
2013-09-13 20:12:22 +02:00
|
|
|
size_t frame_size = 0; /* Size of the new initial stack. */
|
|
|
|
int argc = 0; /* Argument count. */
|
|
|
|
int envc = 0; /* Environment count */
|
|
|
|
char overflow = 0; /* No overflow yet. */
|
|
|
|
char *frame;
|
|
|
|
struct ps_strings *psp;
|
|
|
|
int vsp = 0; /* (virtual) Stack pointer in new address space. */
|
2011-02-17 18:11:09 +01:00
|
|
|
|
2013-09-13 20:12:22 +02:00
|
|
|
minix_stack_params(path, argv, envp, &frame_size, &overflow,
|
|
|
|
&argc, &envc);
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
/* The party is off if there is an overflow. */
|
2013-09-13 20:12:22 +02:00
|
|
|
if (overflow) {
|
|
|
|
errno = E2BIG;
|
2011-02-17 18:11:09 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate space for the stack frame. */
|
|
|
|
if ((frame = (char *) sbrk(frame_size)) == (char *) -1) {
|
|
|
|
errno = E2BIG;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-13 20:12:22 +02:00
|
|
|
minix_stack_fill(path, argc, argv, envc, envp, frame_size, frame,
|
|
|
|
&vsp, &psp);
|
2011-02-17 18:11:09 +01:00
|
|
|
|
2012-04-03 15:52:25 +02:00
|
|
|
/* Clear unused message fields */
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
|
2011-02-17 18:11:09 +01:00
|
|
|
/* We can finally make the system call. */
|
2013-11-04 22:48:08 +01:00
|
|
|
m.PM_EXEC_NAME = (char *) __UNCONST(path);
|
|
|
|
m.PM_EXEC_NAMELEN = strlen(path) + 1;
|
|
|
|
m.PM_EXEC_FRAME = frame;
|
|
|
|
m.PM_EXEC_FRAMELEN = frame_size;
|
|
|
|
m.PM_EXEC_PS_STR = (char *)(vsp + ((char *)psp - frame));
|
2011-02-17 18:11:09 +01:00
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
(void) _syscall(PM_PROC_NR, PM_EXEC, &m);
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
/* Failure, return the memory used for the frame and exit. */
|
|
|
|
(void) sbrk(-frame_size);
|
2013-09-13 20:12:22 +02:00
|
|
|
|
2011-02-17 18:11:09 +01:00
|
|
|
return -1;
|
|
|
|
}
|