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:
@@ -672,7 +672,8 @@ void memory_init(void)
|
||||
/*===========================================================================*
|
||||
* arch_proc_init *
|
||||
*===========================================================================*/
|
||||
void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp, char *name)
|
||||
void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp,
|
||||
const u32_t ps_str, char *name)
|
||||
{
|
||||
arch_proc_reset(pr);
|
||||
strcpy(pr->p_name, name);
|
||||
@@ -680,6 +681,7 @@ void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp, char *name)
|
||||
/* set custom state we know */
|
||||
pr->p_reg.pc = ip;
|
||||
pr->p_reg.sp = sp;
|
||||
pr->p_reg.retreg = ps_str; /* a.k.a r0*/
|
||||
}
|
||||
|
||||
/* TODO keesj: rewrite the free running clock to use callbacks
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
* for local descriptors in the process table.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <machine/multiboot.h>
|
||||
|
||||
#include "kernel/kernel.h"
|
||||
#include "kernel/proc.h"
|
||||
#include "archconst.h"
|
||||
|
||||
#include "archconst.h"
|
||||
#include "arch_proto.h"
|
||||
|
||||
#include <sys/exec.h>
|
||||
#include <libexec.h>
|
||||
|
||||
struct tss_s tss[CONFIG_MAX_CPUS];
|
||||
@@ -114,6 +115,8 @@ static int libexec_pg_alloc(struct exec_info *execi, vir_bytes vaddr, size_t len
|
||||
void arch_boot_proc(struct boot_image *ip, struct proc *rp)
|
||||
{
|
||||
multiboot_module_t *mod;
|
||||
struct ps_strings *psp;
|
||||
char *sp;
|
||||
|
||||
if(rp->p_nr < 0) return;
|
||||
|
||||
@@ -134,24 +137,41 @@ void arch_boot_proc(struct boot_image *ip, struct proc *rp)
|
||||
execi.proc_e = ip->endpoint;
|
||||
execi.hdr = (char *) mod->mod_start; /* phys mem direct */
|
||||
execi.filesize = execi.hdr_len = mod->mod_end - mod->mod_start;
|
||||
strcpy(execi.progname, ip->proc_name);
|
||||
strlcpy(execi.progname, ip->proc_name, sizeof(execi.progname));
|
||||
execi.frame_len = 0;
|
||||
|
||||
/* callbacks for use in the kernel */
|
||||
execi.copymem = libexec_copy_memcpy;
|
||||
execi.clearmem = libexec_clear_memset;
|
||||
execi.allocmem_prealloc_cleared = libexec_pg_alloc;
|
||||
execi.allocmem_prealloc_junk = libexec_pg_alloc;
|
||||
execi.allocmem_prealloc_cleared = libexec_pg_alloc;
|
||||
execi.allocmem_ondemand = libexec_pg_alloc;
|
||||
execi.clearproc = NULL;
|
||||
|
||||
/* parse VM ELF binary and alloc/map it into bootstrap pagetable */
|
||||
libexec_load_elf(&execi);
|
||||
if(libexec_load_elf(&execi) != OK)
|
||||
panic("VM loading failed");
|
||||
|
||||
/* Initialize the server stack pointer. Take it down three words
|
||||
* to give startup code something to use as "argc", "argv" and "envp".
|
||||
/* Setup a ps_strings struct on the stack, pointing to the
|
||||
* following argv, envp. */
|
||||
sp = (char *)execi.stack_high;
|
||||
sp -= sizeof(struct ps_strings);
|
||||
psp = (struct ps_strings *) sp;
|
||||
|
||||
/* Take the stack pointer down three words to give startup code
|
||||
* something to use as "argc", "argv" and "envp".
|
||||
*/
|
||||
arch_proc_init(rp, execi.pc, kinfo.user_sp - 3*4, ip->proc_name);
|
||||
sp -= (sizeof(void *) + sizeof(void *) + sizeof(int));
|
||||
|
||||
// linear address space, so it is available.
|
||||
psp->ps_argvstr = (char **)(sp + sizeof(int));
|
||||
psp->ps_nargvstr = 0;
|
||||
psp->ps_envstr = psp->ps_argvstr + sizeof(void *);
|
||||
psp->ps_nenvstr = 0;
|
||||
|
||||
arch_proc_init(rp, execi.pc, (vir_bytes)sp,
|
||||
execi.stack_high - sizeof(struct ps_strings),
|
||||
ip->proc_name);
|
||||
|
||||
/* Free VM blob that was just copied into existence. */
|
||||
add_memmap(&kinfo, mod->mod_start, mod->mod_end-mod->mod_start);
|
||||
|
||||
@@ -770,7 +770,8 @@ void memory_init(void)
|
||||
/*===========================================================================*
|
||||
* arch_proc_init *
|
||||
*===========================================================================*/
|
||||
void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp, char *name)
|
||||
void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp,
|
||||
const u32_t ps_str, char *name)
|
||||
{
|
||||
arch_proc_reset(pr);
|
||||
strlcpy(pr->p_name, name, sizeof(pr->p_name));
|
||||
@@ -778,6 +779,7 @@ void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp, char *name)
|
||||
/* set custom state we know */
|
||||
pr->p_reg.pc = ip;
|
||||
pr->p_reg.sp = sp;
|
||||
pr->p_reg.bx = ps_str;
|
||||
}
|
||||
|
||||
static int oxpcie_mapping_index = -1,
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
* for local descriptors in the process table.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <minix/cpufeature.h>
|
||||
#include <machine/multiboot.h>
|
||||
|
||||
#include "kernel/kernel.h"
|
||||
#include "archconst.h"
|
||||
|
||||
#include "archconst.h"
|
||||
#include "arch_proto.h"
|
||||
|
||||
#include <sys/exec.h>
|
||||
#include <libexec.h>
|
||||
|
||||
#define INT_GATE_TYPE (INT_286_GATE | DESC_386_BIT)
|
||||
@@ -388,6 +389,8 @@ static int libexec_pg_alloc(struct exec_info *execi, vir_bytes vaddr, size_t len
|
||||
void arch_boot_proc(struct boot_image *ip, struct proc *rp)
|
||||
{
|
||||
multiboot_module_t *mod;
|
||||
struct ps_strings *psp;
|
||||
char *sp;
|
||||
|
||||
if(rp->p_nr < 0) return;
|
||||
|
||||
@@ -404,7 +407,7 @@ void arch_boot_proc(struct boot_image *ip, struct proc *rp)
|
||||
|
||||
/* exec parameters */
|
||||
execi.stack_high = kinfo.user_sp;
|
||||
execi.stack_size = 64 * 1024; /* not too crazy as it must be preallocated */
|
||||
execi.stack_size = 64 * 1024; /* not too crazy as it must be preallocated */
|
||||
execi.proc_e = ip->endpoint;
|
||||
execi.hdr = (char *) mod->mod_start; /* phys mem direct */
|
||||
execi.filesize = execi.hdr_len = mod->mod_end - mod->mod_start;
|
||||
@@ -423,14 +426,30 @@ void arch_boot_proc(struct boot_image *ip, struct proc *rp)
|
||||
if(libexec_load_elf(&execi) != OK)
|
||||
panic("VM loading failed");
|
||||
|
||||
/* Initialize the server stack pointer. Take it down three words
|
||||
* to give startup code something to use as "argc", "argv" and "envp".
|
||||
/* Setup a ps_strings struct on the stack, pointing to the
|
||||
* following argv, envp. */
|
||||
sp = (char *)execi.stack_high;
|
||||
sp -= sizeof(struct ps_strings);
|
||||
psp = (struct ps_strings *) sp;
|
||||
|
||||
/* Take the stack pointer down three words to give startup code
|
||||
* something to use as "argc", "argv" and "envp".
|
||||
*/
|
||||
arch_proc_init(rp, execi.pc, kinfo.user_sp - 3*4, ip->proc_name);
|
||||
sp -= (sizeof(void *) + sizeof(void *) + sizeof(int));
|
||||
|
||||
// linear address space, so it is available.
|
||||
psp->ps_argvstr = (char **)(sp + sizeof(int));
|
||||
psp->ps_nargvstr = 0;
|
||||
psp->ps_envstr = psp->ps_argvstr + sizeof(void *);
|
||||
psp->ps_nenvstr = 0;
|
||||
|
||||
arch_proc_init(rp, execi.pc, (vir_bytes)sp,
|
||||
execi.stack_high - sizeof(struct ps_strings),
|
||||
ip->proc_name);
|
||||
|
||||
/* Free VM blob that was just copied into existence. */
|
||||
add_memmap(&kinfo, mod->mod_start, mod->mod_end-mod->mod_start);
|
||||
mod->mod_end = mod->mod_start = 0;
|
||||
mod->mod_end = mod->mod_start = 0;
|
||||
|
||||
/* Remember them */
|
||||
kinfo.vm_allocated_bytes = alloc_for_vm;
|
||||
|
||||
@@ -192,7 +192,7 @@ void do_ser_debug(void);
|
||||
int arch_get_params(char *parm, int max);
|
||||
void memory_init(void);
|
||||
void mem_clear_mapcache(void);
|
||||
void arch_proc_init(struct proc *pr, u32_t, u32_t, char *);
|
||||
void arch_proc_init(struct proc *pr, u32_t, u32_t, u32_t, char *);
|
||||
int arch_do_vmctl(message *m_ptr, struct proc *p);
|
||||
int vm_contiguous(const struct proc *targetproc, vir_bytes vir_buf,
|
||||
size_t count);
|
||||
|
||||
@@ -41,7 +41,8 @@ int do_exec(struct proc * caller, message * m_ptr)
|
||||
name[sizeof(name)-1] = '\0';
|
||||
|
||||
/* Set process state. */
|
||||
arch_proc_init(rp, (u32_t) m_ptr->PR_IP_PTR, (u32_t) m_ptr->PR_STACK_PTR, name);
|
||||
arch_proc_init(rp, (u32_t) m_ptr->PR_IP_PTR, (u32_t) m_ptr->PR_STACK_PTR,
|
||||
(u32_t) m_ptr->PR_PS_STR_PTR, name);
|
||||
|
||||
/* No reply to EXEC call */
|
||||
RTS_UNSET(rp, RTS_RECEIVING);
|
||||
|
||||
Reference in New Issue
Block a user