void exec_bootproc(struct vmproc *vmp, struct boot_image *ip) { struct vm_exec_info vmexeci; struct exec_info *execi = &vmexeci.execi; char hdr[VM_PAGE_SIZE]; memset(&vmexeci, 0, sizeof(vmexeci)); if(pt_new(&vmp->vm_pt) != OK) panic("VM: no new pagetable"); if(pt_bind(&vmp->vm_pt, vmp) != OK) panic("VM: pt_bind failed"); if(sys_physcopy(NONE, ip->start_addr, SELF, (vir_bytes) hdr, sizeof(hdr)) != OK) panic("can't look at boot proc header"); execi->stack_high = kernel_boot_info.user_sp; execi->stack_size = DEFAULT_STACK_LIMIT; execi->proc_e = vmp->vm_endpoint; execi->hdr = hdr; execi->hdr_len = sizeof(hdr); strlcpy(execi->progname, ip->proc_name, sizeof(execi->progname)); execi->frame_len = 0; execi->opaque = &vmexeci; execi->filesize = ip->len; vmexeci.ip = ip; vmexeci.vmp = vmp; /* callback functions and data */ execi->copymem = libexec_copy_physcopy; execi->clearproc = NULL; execi->clearmem = libexec_clear_sys_memset; execi->allocmem_prealloc_junk = libexec_alloc_vm_prealloc; execi->allocmem_prealloc_cleared = libexec_alloc_vm_prealloc; execi->allocmem_ondemand = libexec_alloc_vm_ondemand; if(libexec_load_elf(execi) != OK) panic("vm: boot process load of process %s (ep=%d) failed\n", execi->progname,vmp->vm_endpoint); if(sys_exec(vmp->vm_endpoint, (char *) execi->stack_high - 12, (char *) ip->proc_name, execi->pc) != OK) panic("vm: boot process exec of process %s (ep=%d) failed\n", execi->progname,vmp->vm_endpoint); /* make it runnable */ if(sys_vmctl(vmp->vm_endpoint, VMCTL_BOOTINHIBIT_CLEAR, 0) != OK) panic("VMCTL_BOOTINHIBIT_CLEAR failed"); }
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; } }
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; } }