void arch_boot_proc(struct boot_image *ip, struct proc *rp) { multiboot_module_t *mod; if(rp->p_nr < 0) return; mod = bootmod(rp->p_nr); /* Important special case: we put VM in the bootstrap pagetable * so it can run. */ if(rp->p_nr == VM_PROC_NR) { struct exec_info execi; memset(&execi, 0, sizeof(execi)); /* exec parameters */ execi.stack_high = kinfo.user_sp; 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; strcpy(execi.progname, ip->proc_name); 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_ondemand = libexec_pg_alloc; execi.clearproc = NULL; /* parse VM ELF binary and alloc/map it into bootstrap pagetable */ libexec_load_elf(&execi); /* Initialize the server stack pointer. Take it 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); /* 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; /* Remember them */ kinfo.vm_allocated_bytes = alloc_for_vm; } }
/*===========================================================================* * do_exec * *===========================================================================*/ int do_exec(struct proc * caller, message * m_ptr) { /* Handle sys_exec(). A process has done a successful EXEC. Patch it up. */ register struct proc *rp; int proc_nr; char name[PROC_NAME_LEN]; if(!isokendpt(m_ptr->PR_ENDPT, &proc_nr)) return EINVAL; rp = proc_addr(proc_nr); if(rp->p_misc_flags & MF_DELIVERMSG) { rp->p_misc_flags &= ~MF_DELIVERMSG; } /* Save command name for debugging, ps(1) output, etc. */ if(data_copy(caller->p_endpoint, (vir_bytes) m_ptr->PR_NAME_PTR, KERNEL, (vir_bytes) name, (phys_bytes) sizeof(name) - 1) != OK) strncpy(name, "<unset>", PROC_NAME_LEN); 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); /* No reply to EXEC call */ RTS_UNSET(rp, RTS_RECEIVING); /* Mark fpu_regs contents as not significant, so fpu * will be initialized, when it's used next time. */ rp->p_misc_flags &= ~MF_FPU_INITIALIZED; /* force reloading FPU if the current process is the owner */ release_fpu(rp); return(OK); }
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; mod = bootmod(rp->p_nr); /* Important special case: we put VM in the bootstrap pagetable * so it can run. */ if(rp->p_nr == VM_PROC_NR) { struct exec_info execi; memset(&execi, 0, sizeof(execi)); /* exec parameters */ execi.stack_high = kinfo.user_sp; 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; 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_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 */ if(libexec_load_elf(&execi) != OK) panic("VM loading failed"); /* 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". */ 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; /* Remember them */ kinfo.vm_allocated_bytes = alloc_for_vm; } }