Removing CSU patches
* Removed startup code patches in lib/csu regarding kernel to userland
ABI.
* Aligned stack layout on NetBSD stack layout.
* Generate valid stack pointers instead of offsets by taking into account
_minix_kerninfo->kinfo->user_sp.
* Refactored stack generation, by moving part of execve in two
functions {minix_stack_params(), minix_stack_fill()} and using them
in execve(), rs and vm.
* Changed load offset of rtld (ld.so) to:
execi.args.stack_high - execi.args.stack_size - 0xa00000
which is 10MB below the main executable stack.
Change-Id: I839daf3de43321cded44105634102d419cb36cec
This commit is contained in:
+18
-85
@@ -1,6 +1,4 @@
|
||||
/* execve() - basic program execution call Author: Kees J. Bot
|
||||
* 21 Jan 1994
|
||||
*/
|
||||
/* execve() - basic program execution call */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "namespace.h"
|
||||
@@ -9,7 +7,9 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <minix/param.h>
|
||||
#include <sys/exec_elf.h>
|
||||
#include <sys/exec.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(execve, _execve)
|
||||
@@ -17,62 +17,21 @@ __weak_alias(execve, _execve)
|
||||
|
||||
int execve(const char *path, char * const *argv, char * const *envp)
|
||||
{
|
||||
char * const *ap;
|
||||
char * const *ep;
|
||||
char *frame;
|
||||
char **vp;
|
||||
char *sp;
|
||||
size_t argc;
|
||||
int extra;
|
||||
int vectors;
|
||||
size_t frame_size;
|
||||
size_t string_off;
|
||||
size_t n;
|
||||
int ov;
|
||||
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. */
|
||||
|
||||
/* Assumptions: size_t and char *, it's all the same thing. */
|
||||
|
||||
/* Create a stack image that only needs to be patched up slightly
|
||||
* by the kernel to be used for the process to be executed.
|
||||
*/
|
||||
|
||||
ov= 0; /* No overflow yet. */
|
||||
frame_size= 0; /* Size of the new initial stack. */
|
||||
string_off= 0; /* Offset to start of the strings. */
|
||||
argc= 0; /* Argument count. */
|
||||
|
||||
for (ap= argv; *ap != NULL; ap++) {
|
||||
n = sizeof(*ap) + strlen(*ap) + 1;
|
||||
frame_size+= n;
|
||||
if (frame_size < n) ov= 1;
|
||||
string_off+= sizeof(*ap);
|
||||
argc++;
|
||||
}
|
||||
|
||||
for (ep= envp; *ep != NULL; ep++) {
|
||||
n = sizeof(*ep) + strlen(*ep) + 1;
|
||||
frame_size+= n;
|
||||
if (frame_size < n) ov= 1;
|
||||
string_off+= sizeof(*ap);
|
||||
}
|
||||
|
||||
/* Add an argument count, two terminating nulls and
|
||||
* space for the ELF aux vectors, that must come before
|
||||
* (i.e. at a higher address) then the strings.
|
||||
*/
|
||||
vectors = sizeof(argc) + sizeof(*ap) + sizeof(*ep) +
|
||||
sizeof(AuxInfo) * PMEF_AUXVECTORS;
|
||||
extra = vectors + PMEF_EXECNAMELEN1;
|
||||
frame_size+= extra;
|
||||
string_off+= extra;
|
||||
|
||||
/* Align. */
|
||||
frame_size= (frame_size + sizeof(char *) - 1) & ~(sizeof(char *) - 1);
|
||||
minix_stack_params(path, argv, envp, &frame_size, &overflow,
|
||||
&argc, &envc);
|
||||
|
||||
/* The party is off if there is an overflow. */
|
||||
if (ov || frame_size < 3 * sizeof(char *)) {
|
||||
errno= E2BIG;
|
||||
if (overflow) {
|
||||
errno = E2BIG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -82,31 +41,8 @@ int execve(const char *path, char * const *argv, char * const *envp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set arg count, init pointers to vector and string tables. */
|
||||
* (size_t *) frame = argc;
|
||||
vp = (char **) (frame + sizeof(argc));
|
||||
sp = frame + string_off;
|
||||
|
||||
/* Load the argument vector and strings. */
|
||||
for (ap= argv; *ap != NULL; ap++) {
|
||||
*vp++= (char *) (sp - frame);
|
||||
n= strlen(*ap) + 1;
|
||||
memcpy(sp, *ap, n);
|
||||
sp+= n;
|
||||
}
|
||||
*vp++= NULL;
|
||||
|
||||
/* Load the environment vector and strings. */
|
||||
for (ep= envp; *ep != NULL; ep++) {
|
||||
*vp++= (char *) (sp - frame);
|
||||
n= strlen(*ep) + 1;
|
||||
memcpy(sp, *ep, n);
|
||||
sp+= n;
|
||||
}
|
||||
*vp++= NULL;
|
||||
|
||||
/* Padding. */
|
||||
while (sp < frame + frame_size) *sp++= 0;
|
||||
minix_stack_fill(path, argc, argv, envc, envp, frame_size, frame,
|
||||
&vsp, &psp);
|
||||
|
||||
/* Clear unused message fields */
|
||||
memset(&m, 0, sizeof(m));
|
||||
@@ -116,15 +52,12 @@ int execve(const char *path, char * const *argv, char * const *envp)
|
||||
m.m1_i2 = frame_size;
|
||||
m.m1_p1 = (char *) __UNCONST(path);
|
||||
m.m1_p2 = frame;
|
||||
|
||||
/* Tell PM/VFS we have left space for the aux vectors
|
||||
* and executable name
|
||||
*/
|
||||
m.PMEXEC_FLAGS = PMEF_AUXVECTORSPACE | PMEF_EXECNAMESPACE1;
|
||||
m.m1_p4 = (char *)(vsp + ((char *)psp - frame));
|
||||
|
||||
(void) _syscall(PM_PROC_NR, EXEC, &m);
|
||||
|
||||
/* Failure, return the memory used for the frame and exit. */
|
||||
(void) sbrk(-frame_size);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user