minix/lib/libc/sys-minix/execve.c
Lionel Sambuc 84d9c625bf Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC)
- Fix for possible unset uid/gid in toproto
 - Fix for default mtree style
 - Update libelf
 - Importing libexecinfo
 - Resynchronize GCC, mpc, gmp, mpfr
 - build.sh: Replace params with show-params.
     This has been done as the make target has been renamed in the same
     way, while a new target named params has been added. This new
     target generates a file containing all the parameters, instead of
     printing it on the console.
 - Update test48 with new etc/services (Fix by Ben Gras <ben@minix3.org)
     get getservbyport() out of the inner loop

Change-Id: Ie6ad5226fa2621ff9f0dee8782ea48f9443d2091
2014-07-28 17:05:06 +02:00

60 lines
1.4 KiB
C

/* execve() - basic program execution call */
#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <minix/param.h>
#include <sys/exec_elf.h>
#include <sys/exec.h>
int execve(const char *path, char * const *argv, char * const *envp)
{
message m;
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. */
minix_stack_params(path, argv, envp, &frame_size, &overflow,
&argc, &envc);
/* The party is off if there is an overflow. */
if (overflow) {
errno = E2BIG;
return -1;
}
/* Allocate space for the stack frame. */
if ((frame = (char *) sbrk(frame_size)) == (char *) -1) {
errno = E2BIG;
return -1;
}
minix_stack_fill(path, argc, argv, envc, envp, frame_size, frame,
&vsp, &psp);
/* Clear unused message fields */
memset(&m, 0, sizeof(m));
/* We can finally make the system call. */
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));
(void) _syscall(PM_PROC_NR, PM_EXEC, &m);
/* Failure, return the memory used for the frame and exit. */
(void) sbrk(-frame_size);
return -1;
}