// // Custom page fault handler - if faulting page is copy-on-write, // map in our own private writable copy. // static void pgfault(struct UTrapframe *utf) { void *addr = (void *) utf->utf_fault_va; uint32_t err = utf->utf_err; int r; pte_t pte; envid_t envid; void *va; // Check that the faulting access was (1) a write, and (2) to a // copy-on-write page. If not, panic. // Hint: // Use the read-only page table mappings at vpt // (see <inc/memlayout.h>). // LAB 4: Your code here. //check # 1 - ren if (!(err & FEC_WR)) panic ("pgfault() - page fault caused not by write!"); //check # 2 - ren pte = (pte_t)vpt[VPN(addr)]; pte &= 0xF00; if (pte != PTE_COW) panic ("pgfault() - access was not to a copy-on-write page!"); // Allocate a new page, map it at a temporary location (PFTEMP), // copy the data from the old page to the new page, then move the new // page to the old page's address. // Hint: // You should make three system calls. // No need to explicitly delete the old page's mapping. // LAB 4: Your code here. envid = sys_getenvid(); va = (void*)ROUNDDOWN(addr, PGSIZE); if ( (r = sys_page_alloc(envid, PFTEMP, PTE_U | PTE_P | PTE_W)) < 0) sys_env_destroy(envid); memcpy(PFTEMP, va, PGSIZE); if ( (r = sys_page_map(envid, PFTEMP, envid, va, PTE_U | PTE_P | PTE_W)) < 0) sys_env_destroy(envid); if ((r = sys_page_unmap(envid, PFTEMP)) < 0) //fourth system call, hm - ren sys_env_destroy(envid); }
// Dispatches to the correct kernel function, passing the arguments. int64_t syscall(uint64_t syscallno, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. //panic("syscall not implemented"); int ret_val = 0; switch (syscallno) { case SYS_cputs: sys_cputs((char *)a1, a2); break; case SYS_cgetc: ret_val = sys_cgetc(); break; case SYS_getenvid: ret_val = sys_getenvid(); break; case SYS_env_destroy: ret_val = sys_env_destroy(a1); break; default: ret_val = -E_INVAL; break; } return ret_val; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. /*stone's solution for lab3-B*/ int32_t ret = -E_INVAL; switch (syscallno){ case SYS_cputs: sys_cputs((char*)a1, a2); ret = 0; break; case SYS_cgetc: ret = sys_cgetc(); break; case SYS_getenvid: ret = sys_getenvid(); break; case SYS_env_destroy: ret = sys_env_destroy(a1); break; case SYS_map_kernel_page: ret = sys_map_kernel_page((void*)a1, (void*)a2); break; case SYS_sbrk: ret = sys_sbrk(a1); break; default: break; } return ret; //panic("syscall not implemented"); }
void umain(int argc, char **argv) { envid_t env; cprintf("I am the parent. Forking the child...\n"); if ((env = fork()) == 0) { cprintf("I am the child. Spinning...\n"); while (1) /* do nothing */; } cprintf("I am the parent. Running the child...\n"); sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); cprintf("I am the parent. Killing the child...\n"); sys_env_destroy(env); }
void umain(int argc, char **argv) { envid_t env; cprintf("Father:%04x", sys_getenvid()); a=1; if ((env = sfork()) == 0) { while (1) { cprintf("child:a=%d\n",a); sys_yield(); } exit(); } sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); cprintf("Father:a changed\n"); a=2; sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); sys_yield(); cprintf("Killing the child\n"); sys_env_destroy(env); }
// // Set the page fault handler function. // If there isn't one yet, _pgfault_handler will be 0. // The first time we register a handler, we need to // allocate an exception stack (one page of memory with its top // at UXSTACKTOP), and tell the kernel to call the assembly-language // _pgfault_upcall routine when a page fault occurs. // void set_pgfault_handler(void (*handler)(struct UTrapframe *utf)) { int r; int re; envid_t envid = sys_getenvid(); if (_pgfault_handler == 0) { // First time through! // LAB 4: Your code here. sys_env_set_pgfault_upcall(envid, _pgfault_upcall); re = sys_page_alloc(envid, (void *)(UXSTACKTOP - PGSIZE),PTE_U | PTE_P |PTE_W); if( re < 0){ cprintf("process %x,sys_page_alloc fail\n",envid); sys_env_destroy(envid); } //panic("set_pgfault_handler not implemented"); } // Save handler pointer for assembly to call. _pgfault_handler = handler; //cprintf("_pgfault_handler = %x\n",(uint32_t)_pgfault_handler); }
// Dispatches to the correct kernel function, passing the arguments. int64_t syscall(uint64_t syscallno, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. // panic("syscall not implemented"); switch (syscallno) { case SYS_cputs: sys_cputs((const char *)a1, (size_t)a2); return 0; case SYS_cgetc: return sys_cgetc(); case SYS_getenvid: return sys_getenvid(); case SYS_env_destroy: return sys_env_destroy(a1); case SYS_yield: sys_yield(); return 0; case SYS_page_alloc: return sys_page_alloc((envid_t)a1, (void *)a2,(int)a3); case SYS_page_map: return sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5); case SYS_page_unmap: return sys_page_unmap((envid_t)a1, (void *)a2); case SYS_exofork: return sys_exofork(); case SYS_env_set_status: return sys_env_set_status((envid_t)a1, a2); case SYS_env_set_pgfault_upcall: return sys_env_set_pgfault_upcall((envid_t)a1,(void *)a2); case SYS_ipc_try_send: return sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void *)a3, a4); case SYS_ipc_recv: return sys_ipc_recv((void *)a1); case SYS_env_set_trapframe: return sys_env_set_trapframe((envid_t)a1, (struct Trapframe *)a2); case SYS_time_msec: return sys_time_msec(); case SYS_packet_transmit: return sys_packet_transmit((char*)a1,(size_t)a2); case SYS_packet_receive: return sys_packet_receive((char *)a1); //lab 7 code from here case SYS_insmod: return sys_insmod((char *)a1, (char *)a2,(char *)a3); case SYS_rmmod: return sys_rmmod((char *)a1); case SYS_lsmod: return sys_lsmod(); case SYS_depmod: return sys_depmod((char *)a1); //lab7 code ends here default: return -E_NO_SYS; } }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. // // TBD: gain 10+ percent of performance improvement // by using goto-label-array. switch(syscallno) { case SYS_cputs: sys_cputs((char *) a1, (size_t) a2); break; case SYS_cgetc: return sys_cgetc(); case SYS_getenvid: return sys_getenvid(); case SYS_env_destroy: sys_env_destroy(a1); break; case SYS_exofork: return sys_exofork(); case SYS_env_set_status: return sys_env_set_status(a1, a2); default: cprintf("Error syscall(%u)\n", syscallno); panic("syscall not implemented"); return -E_INVAL; } return 0; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. curenv->env_syscalls++; switch(syscallno){ case SYS_cputs: sys_cputs((char *)a1, (size_t)a2);break; case SYS_cgetc: sys_cgetc();break; case SYS_getenvid: return sys_getenvid(); case SYS_env_destroy: return sys_env_destroy((envid_t)a1); case SYS_dump_env: sys_dump_env();break; case SYS_page_alloc: return sys_page_alloc((envid_t)a1, (void *)a2, (int)a3); case SYS_page_map: { return sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5); } case SYS_page_unmap: return sys_page_unmap((envid_t)a1, (void *)a2); case SYS_exofork: return sys_exofork(); case SYS_env_set_status: return sys_env_set_status((envid_t)a1,(int)a2); case SYS_env_set_trapframe: return sys_env_set_trapframe((envid_t)a1, (struct Trapframe *)a2); case SYS_env_set_pgfault_upcall: return sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2); case SYS_yield: sys_yield();break;//new add syscall for lab4; case SYS_ipc_try_send: return sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void *)a3, (unsigned)a4); case SYS_ipc_recv: return sys_ipc_recv((void *)a1); case SYS_ide_read: sys_ide_read((uint32_t)a1, (void *)a2, (size_t)a3); break; case SYS_ide_write: sys_ide_write((uint32_t)a1, (void *)a2, (size_t)a3); break; case SYS_time_msec: return sys_time_msec(); case NSYSCALLS: break; default: return -E_INVAL; } return 0; //panic("syscall not implemented"); }
void handler(struct UTrapframe *utf) { cprintf("\n IN FAULT DIE HANDLER \n"); void *addr = (void*)utf->utf_fault_va; uint32_t err = utf->utf_err; cprintf("i faulted at va %x, err %x\n", addr, err & 7); sys_env_destroy(sys_getenvid()); }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. /* lj */ int ret = 0; switch(syscallno) { case SYS_cputs: sys_cputs((const char *)a1, a2); break; case SYS_cgetc: ret = sys_cgetc(); break; case SYS_getenvid: ret = sys_getenvid(); break; case SYS_env_destroy: ret = sys_env_destroy(a1); break; case SYS_yield: sys_yield(); break; case SYS_exofork: ret = sys_exofork(); break; case SYS_env_set_status: ret = sys_env_set_status((envid_t)a1, a2); break; case SYS_page_alloc: ret = sys_page_alloc((envid_t)a1, (void *)a2, a3); break; case SYS_page_map: ret = sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, a5); break; case SYS_page_unmap: ret = sys_page_unmap((envid_t)a1, (void *)a2); break; case SYS_env_set_pgfault_upcall: ret = sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2); break; case SYS_ipc_try_send: ret = sys_ipc_try_send((envid_t)a1, a2, (void *)a3, a4); break; case SYS_ipc_recv: ret = sys_ipc_recv((void *)a1); break; default: ret = -E_INVAL; break; } //panic("syscall not implemented"); //cprintf("%d return to user %d\n", syscallno, ret); return ret; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. int32_t ret = -E_INVAL; switch(syscallno) { case SYS_cputs: sys_cputs((char *)a1, a2); break; case SYS_cgetc: ret = sys_cgetc(); break; case SYS_getenvid: ret = sys_getenvid(); break; case SYS_env_destroy: ret = sys_env_destroy(a1); break; case SYS_yield: sys_yield(); ret = 0; break; case SYS_map_kernel_page: ret = sys_map_kernel_page((void *)a1, (void *)a2); break; case SYS_sbrk: ret = sys_sbrk(a1); break; case SYS_exofork: ret = sys_exofork(); break; case SYS_env_set_status: ret = sys_env_set_status(a1,a2); break; case SYS_page_alloc: ret = sys_page_alloc(a1,(void*)a2,a3); break; case SYS_page_map: ret = sys_page_map(a1,(void*)a2,a3,(void*)a4,a5); break; case SYS_page_unmap: ret = sys_page_unmap(a1,(void*)a2); break; case SYS_env_set_pgfault_upcall: ret = sys_env_set_pgfault_upcall(a1,(void*)a2); break; case SYS_ipc_try_send: ret = sys_ipc_try_send(a1,a2,(void*)a3,a4); break; case SYS_ipc_recv: ret = sys_ipc_recv((void*)a1); } return ret; // panic("syscall not implemented"); }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. int32_t r =0; switch(syscallno){ case SYS_cputs: sys_cputs((const char*)a1,(size_t)a2); break; case SYS_cgetc: r = sys_cgetc(); break; case SYS_getenvid: r = sys_getenvid(); break; case SYS_env_destroy: r = sys_env_destroy((envid_t)a1); break; case SYS_yield: sys_yield(); r =0; break; case SYS_exofork: r = sys_exofork(); break; case SYS_env_set_status: r = sys_env_set_status((envid_t)a1,(int)a2); break; case SYS_page_alloc: r = sys_page_alloc((envid_t)a1 ,(void *)a2, (int)a3); break; case SYS_page_map: r = sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5); break; case SYS_page_unmap: r = sys_page_unmap((envid_t)a1,(void *)a2); break; case SYS_env_set_pgfault_upcall: r = sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2); break; case SYS_ipc_try_send: r = sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void *)a3, (unsigned int)a4); break; case SYS_ipc_recv: r = sys_ipc_recv((void *)a1); break; default: r = -E_INVAL; } return r; panic("syscall not implemented"); }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. switch (syscallno){ case SYS_getenvid: return sys_getenvid(); case SYS_cputs: sys_cputs((const char*)a1, a2); return 0; case SYS_cgetc: return sys_cgetc(); case SYS_env_destroy: return sys_env_destroy(a1); case SYS_map_kernel_page: return sys_map_kernel_page((void*)a1, (void*)a2); case SYS_sbrk: return sys_sbrk(a1); case SYS_yield: sys_yield(); return 0; case SYS_exofork: return sys_exofork(); case SYS_env_set_status: return sys_env_set_status((envid_t)a1, (int)a2); case SYS_page_alloc: return sys_page_alloc((envid_t)a1, (void *)a2, (int)a3); case SYS_page_map: return sys_page_map((envid_t)*((uint32_t*)a1), (void*)*((uint32_t*)a1+1), (envid_t)*((uint32_t*)a1+2), (void*)*((uint32_t*)a1+3), (int)*((uint32_t*)a1+4)); case SYS_page_unmap: return sys_page_unmap((envid_t)a1, (void*)a2); case SYS_env_set_priority: return sys_env_set_priority((envid_t)a1, (int) a2); case SYS_env_set_pgfault_upcall: return sys_env_set_pgfault_upcall((envid_t)a1, (void*)a2); case SYS_ipc_recv: return sys_ipc_recv((void*)a1); case SYS_ipc_try_send: return sys_ipc_try_send((envid_t)a1, a2, (void*)a3, (int)a4); default: return -E_INVAL; } }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. // panic("syscall not implemented"); switch (syscallno) { case SYS_cputs: sys_cputs((char *)a1, a2); break; case SYS_cgetc: return sys_cgetc(); case SYS_env_destroy: return sys_env_destroy(a1); case SYS_getenvid: return sys_getenvid(); case SYS_yield: sys_yield(); break; case SYS_page_alloc: return sys_page_alloc(a1, (void *)a2, a3); case SYS_page_map: return sys_page_map(a1, (void *)a2, a3, (void *)a4, a5); case SYS_page_unmap: return sys_page_unmap(a1, (void *)a2); case SYS_env_set_status: return sys_env_set_status(a1, a2); case SYS_exofork: return sys_exofork(); case SYS_env_set_pgfault_upcall: return sys_env_set_pgfault_upcall(a1, (void *)a2); case SYS_ipc_try_send: return sys_ipc_try_send(a1, a2, (void*)a3, a4); case SYS_ipc_recv: return sys_ipc_recv((void*)a1); case SYS_env_set_trapframe: return sys_env_set_trapframe(a1, (struct Trapframe *)a2); case SYS_time_msec: return sys_time_msec(); case SYS_trans_pkt: return sys_trans_pkt((void*)a1, a2); case SYS_recv_pkt: return sys_recv_pkt((void *)a1, (size_t *)a2); default: return -E_INVAL; } return 0; }
// Dispatches to the correct kernel function, passing the arguments. int64_t syscall(uint64_t syscallno, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. uint64_t retval = 0; switch (syscallno) { case SYS_cputs: sys_cputs((char *) a1, (size_t) a2); return retval; case SYS_cgetc: return (int64_t) sys_cgetc(); case SYS_getenvid: return (int64_t) sys_getenvid(); case SYS_env_destroy: return (int64_t) sys_env_destroy((envid_t) a1); case SYS_yield: sys_yield(); return retval; case SYS_exofork: return (int64_t)sys_exofork(); case SYS_page_alloc: return (int64_t)sys_page_alloc((envid_t)a1, (void *)a2, (int)a3); case SYS_page_map: return (int64_t)sys_page_map((envid_t)a1, (void *)a2, (envid_t)a3, (void *)a4, (int)a5); case SYS_page_unmap: return (int64_t)sys_page_unmap((envid_t)a1, (void *)a2); case SYS_env_set_status: return (int64_t)sys_env_set_status((envid_t)a1, (int)a2); case SYS_env_set_pgfault_upcall: return (int64_t)sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2); case SYS_ipc_try_send: return (int64_t) sys_ipc_try_send((envid_t) a1, (uint32_t) a2, (void *) a3, (unsigned) a4); case SYS_ipc_recv: return (int64_t)sys_ipc_recv((void*)a1); case SYS_env_set_trapframe: return sys_env_set_trapframe((envid_t)a1, (struct Trapframe*)a2); case SYS_time_msec: return sys_time_msec(); case SYS_net_try_send: return sys_net_try_send((char *) a1, (int) a2); case SYS_net_try_receive: return sys_net_try_receive((char *) a1, (int *) a2); default: return -E_INVAL; } panic("syscall not implemented"); }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. switch (syscallno) { case (SYS_cputs): sys_cputs((const char *) a1, a2); return 0; case (SYS_cgetc): return sys_cgetc(); case (SYS_getenvid): return sys_getenvid(); case (SYS_env_destroy): return sys_env_destroy(a1, a2); case (SYS_yield): sys_yield(); return 0; case (SYS_exofork): return sys_exofork(); case (SYS_env_set_status): return sys_env_set_status(a1, a2); case (SYS_page_alloc): return sys_page_alloc(a1, (void *) a2, a3); case (SYS_page_map): return sys_page_map(a1, (void *) a2, a3, (void *) a4, a5); case (SYS_page_unmap): return sys_page_unmap(a1, (void *) a2); case (SYS_env_set_pgfault_upcall): return sys_env_set_pgfault_upcall(a1, (void *) a2); case (SYS_ipc_try_send): return sys_ipc_try_send(a1, a2, (void *) a3, a4); case (SYS_ipc_recv): return sys_ipc_recv((void *) a1); case (SYS_env_set_trapframe): return sys_env_set_trapframe(a1, (struct Trapframe *) a2); case (SYS_time_msec): return sys_time_msec(); case (SYS_e1000_transmit): return sys_e1000_transmit(a1, (char *) a2, a3); default: return -E_INVAL; } }
// Dispatches to the correct kernel function, passing the arguments. uint32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. switch (syscallno){ case SYS_cputs: sys_cputs( (const char *)a1, a2); return 0; case SYS_cgetc: return sys_cgetc(); case SYS_getenvid: return sys_getenvid(); case SYS_env_destroy: return sys_env_destroy(a1); case SYS_yield: sys_yield(); return 0; case SYS_exofork: return sys_exofork(); case SYS_env_set_status: return sys_env_set_status(a1, a2); case SYS_page_alloc: return sys_page_alloc(a1, (void *)a2, a3); case SYS_page_map: return sys_page_map(a1, (void *)a2, a3, (void *)a4, a5); case SYS_env_set_trapframe: return sys_env_set_trapframe(a1, (struct Trapframe *)a2); case SYS_page_unmap: return sys_page_unmap(a1, (void *)a2); case SYS_env_set_pgfault_upcall: return sys_env_set_pgfault_upcall(a1, (void *)a2); case SYS_ipc_try_send: return sys_ipc_try_send(a1, a2, (void *)a3, a4); case SYS_ipc_recv: return sys_ipc_recv((void *)a1); default: panic("this syscall ( %d )is not yet implemented", syscallno); } }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. // My code: gmenghani // An invalid system call if(syscallno >= NSYSCALLS) return -E_INVAL; switch(syscallno) { case SYS_cputs: sys_cputs((char *) a1, (size_t)a2); return 0; case SYS_cgetc: return sys_cgetc(); case SYS_getenvid: return sys_getenvid(); case SYS_env_destroy: return sys_env_destroy((envid_t)a1); case SYS_yield : sys_yield(); break; case SYS_exofork : return sys_exofork(); case SYS_env_set_status : return sys_env_set_status((envid_t)a1, (int)a2); case SYS_page_alloc : return sys_page_alloc((envid_t)a1, (void*)a2, (int)a3); case SYS_page_map : return sys_page_map((envid_t)a1, (void*)a2, (envid_t)a3, (void*)a5, (int)a4); case SYS_page_unmap : return sys_page_unmap((envid_t)a1, (void*)a2); // For Challenge problem 1 Lab 4a case SYS_env_set_nice: sys_env_set_nice(a1); return 0; case SYS_env_set_pgfault_upcall: sys_env_set_pgfault_upcall((envid_t)a1, (void *)a2); return 0; case SYS_ipc_try_send: return sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void*)a3, (unsigned)a5); case SYS_ipc_recv: return sys_ipc_recv((void*)a1); case SYS_env_set_trapframe: return sys_env_set_trapframe((envid_t)a1, (struct Trapframe*)a2); case SYS_time_msec: return sys_time_msec(); case SYS_net_send: return sys_net_send((void*)a1, (uint32_t) a2); case SYS_net_recv: return sys_net_recv((void*)a1, (uint16_t*) a2); } return 0; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. //panic("syscall not implemented"); switch (syscallno) { case SYS_cputs:{ sys_cputs((const char*)a1, a2); return 0; } case SYS_cgetc: return sys_cgetc(); case SYS_getenvid: return sys_getenvid(); case SYS_env_destroy: return sys_env_destroy(curenv->env_id); default: return -E_INVAL; } }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. int32_t ret=0; /* if(syscallno==SYS_cputs||syscallno==SYS_getenvid||syscallno==SYS_env_destroy||syscallno==SYS_cgetc) { if(syscallno==SYS_cputs) sys_cputs((char *)a1,a2); if(syscallno==SYS_getenvid) return sys_getenvid(); if(syscallno==SYS_env_destroy) return sys_env_destroy(a1); if(syscallno==SYS_cgetc) return sys_cgetc(); return ret; }*/ //cprintf("\nNO----%d\n",syscallno); switch (syscallno) { case SYS_cputs: sys_cputs((const char *)a1, (size_t)a2); break; case SYS_cgetc: ret = sys_cgetc(); break; case SYS_getenvid: ret = sys_getenvid(); break; case SYS_env_destroy: ret = sys_env_destroy((envid_t)a1); break; case SYS_yield: sys_yield(); break; case SYS_exofork: ret=sys_exofork(); break; case SYS_env_set_status: ret = sys_env_set_status(a1,a2); break; case SYS_page_alloc: ret = sys_page_alloc(a1,(void *)a2,a3); break; case SYS_page_map: ret = sys_page_map(a1,(void *)a2,a3,(void *)a4,a5); break; case SYS_page_unmap: ret = sys_page_unmap(a1,(void *)a2); break; case SYS_env_set_pgfault_upcall: ret = sys_env_set_pgfault_upcall(a1,(void *)a2); case SYS_ipc_try_send: ret=sys_ipc_try_send(a1,a2,(void *)a3,a4); break; case SYS_ipc_recv: ret=sys_ipc_recv((void *)a1); break; case SYS_env_set_trapframe: ret=sys_env_set_trapframe(a1,(struct Trapframe *)a2); break; case SYS_time_msec: ret=sys_time_msec(); break; case SYS_call_packet_send: ret=sys_call_packet_send((void *)a1,a2); break; case SYS_call_receive_packet: ret=sys_call_receive_packet((void *)a1,(void *)a2); break; default: // NSYSCALLS ret = -E_INVAL; break; } return ret; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. //cprintf("syscallno is %d\n",syscallno); switch (syscallno){ case SYS_getenvid: //cprintf("in kernel SYS_getenvid!\n"); return sys_getenvid(); case SYS_cputs: //cprintf("in kernel SYS_cputs!\n"); sys_cputs((const char*) a1,a2); return 0; case SYS_cgetc: //cprintf("in kernel SYS_cgetc!\n"); return sys_cgetc(); case SYS_env_destroy: //cprintf("in kernel SYS_env_destroy!\n"); return sys_env_destroy(a1); case SYS_map_kernel_page: //cprintf("in kernel SYS_map_kernel_page!\n"); return sys_map_kernel_page((void *)a1, (void *)a2); case SYS_yield: //cprintf("in kernel SYS_yield!\n"); //unlock_kernel(); sys_yield(); return 0; case SYS_page_alloc: //cprintf("in kernel SYS_page_alloc!\n"); //cprintf("in kern sys_page_alloc!\n"); return sys_page_alloc((envid_t) a1, (void *) a2, (int) a3); case SYS_page_map: //cprintf("in kernel SYS_page_map!\n"); //cprintf("in kern sys_page_map!\n"); //cprintf("in kern get arglist is %p\n",a1); //cprintf("value of a1 is %p\n",*((uint32_t *)a1+1)); return sys_page_map((envid_t) *((uint32_t *)a1), (void *) *((uint32_t *)a1+1), (envid_t) *((uint32_t *)a1+2), (void *) *((uint32_t *)a1+3), (int) *((uint32_t *)a1+4)); case SYS_page_unmap: //cprintf("in kernel SYS_page_unmap!\n"); //cprintf("in kern sys_page_unmap!\n"); return sys_page_unmap((envid_t) a1, (void *) a2); case SYS_exofork: //cprintf("in kernel SYS_exofork!\n"); //cprintf("in kern sys_exofork!\n"); return sys_exofork(); case SYS_env_set_status: //cprintf("in kernel SYS_env_set_status!\n"); //cprintf("in kern sys_env_set_status!\n"); //cprintf("syscall in envid %p status %p\n",a1,a2); return sys_env_set_status((envid_t) a1, (int) a2); case SYS_env_set_pgfault_upcall: //cprintf("in kernel SYS_env_set_pgfault_upcall!\n"); return sys_env_set_pgfault_upcall((envid_t) a1, (void *) a2); case SYS_ipc_recv: //cprintf("in syscall recive!\n"); return sys_ipc_recv((void*)a1); case SYS_ipc_try_send: //cprintf("in syscall send!\n"); return sys_ipc_try_send((envid_t)a1,a2,(void*)a3,(int)a4); case SYS_proc_save: return sys_proc_save((envid_t)a1,(struct proc *)a2); case SYS_proc_resume: return sys_proc_resume((envid_t)a1,(struct proc*)a2); default: return -E_INVAL; } // panic("syscall not implemented"); }
// Spawn a child process from a program image loaded from the file system. // prog: the pathname of the program to run. // argv: pointer to null-terminated array of pointers to strings, // which will be passed to the child as its command-line arguments. // Returns child envid on success, < 0 on failure. int spawn(const char *prog, const char **argv) { unsigned char elf_buf[512]; struct Trapframe child_tf; envid_t child; int fd, i, r; struct Elf *elf; struct Proghdr *ph; int perm; // This code follows this procedure: // // - Open the program file. // // - Read the ELF header, as you have before, and sanity check its // magic number. (Check out your load_icode!) // // - Use sys_exofork() to create a new environment. // // - Set child_tf to an initial struct Trapframe for the child. // // - Call the init_stack() function above to set up // the initial stack page for the child environment. // // - Map all of the program's segments that are of p_type // ELF_PROG_LOAD into the new environment's address space. // Use the p_flags field in the Proghdr for each segment // to determine how to map the segment: // // * If the ELF flags do not include ELF_PROG_FLAG_WRITE, // then the segment contains text and read-only data. // Use read_map() to read the contents of this segment, // and map the pages it returns directly into the child // so that multiple instances of the same program // will share the same copy of the program text. // Be sure to map the program text read-only in the child. // Read_map is like read but returns a pointer to the data in // *blk rather than copying the data into another buffer. // // * If the ELF segment flags DO include ELF_PROG_FLAG_WRITE, // then the segment contains read/write data and bss. // As with load_icode() in Lab 3, such an ELF segment // occupies p_memsz bytes in memory, but only the FIRST // p_filesz bytes of the segment are actually loaded // from the executable file - you must clear the rest to zero. // For each page to be mapped for a read/write segment, // allocate a page in the parent temporarily at UTEMP, // read() the appropriate portion of the file into that page // and/or use memset() to zero non-loaded portions. // (You can avoid calling memset(), if you like, if // page_alloc() returns zeroed pages already.) // Then insert the page mapping into the child. // Look at init_stack() for inspiration. // Be sure you understand why you can't use read_map() here. // // Note: None of the segment addresses or lengths above // are guaranteed to be page-aligned, so you must deal with // these non-page-aligned values appropriately. // The ELF linker does, however, guarantee that no two segments // will overlap on the same page; and it guarantees that // PGOFF(ph->p_offset) == PGOFF(ph->p_va). // // - Call sys_env_set_trapframe(child, &child_tf) to set up the // correct initial eip and esp values in the child. // // - Start the child process running with sys_env_set_status(). if ((r = open(prog, O_RDONLY)) < 0) return r; fd = r; // Read elf header elf = (struct Elf*) elf_buf; if (readn(fd, elf_buf, sizeof(elf_buf)) != sizeof(elf_buf) || elf->e_magic != ELF_MAGIC) { close(fd); cprintf("elf magic %08x want %08x\n", elf->e_magic, ELF_MAGIC); return -E_NOT_EXEC; } // Create new child environment if ((r = sys_exofork()) < 0) return r; child = r; // Set up trap frame, including initial stack. child_tf = envs[ENVX(child)].env_tf; child_tf.tf_eip = elf->e_entry; if ((r = init_stack(child, argv, &child_tf.tf_esp)) < 0) return r; // Set up program segments as defined in ELF header. ph = (struct Proghdr*) (elf_buf + elf->e_phoff); for (i = 0; i < elf->e_phnum; i++, ph++) { if (ph->p_type != ELF_PROG_LOAD) continue; perm = PTE_P | PTE_U; if (ph->p_flags & ELF_PROG_FLAG_WRITE) perm |= PTE_W; if ((r = map_segment(child, ph->p_va, ph->p_memsz, fd, ph->p_filesz, ph->p_offset, perm)) < 0) goto error; } close(fd); fd = -1; // Copy shared library state. if ((r = copy_shared_pages(child)) < 0) panic("copy_shared_pages: %e", r); if ((r = sys_env_set_trapframe(child, &child_tf)) < 0) panic("sys_env_set_trapframe: %e", r); if ((r = sys_env_set_status(child, ENV_RUNNABLE)) < 0) panic("sys_env_set_status: %e", r); return child; error: sys_env_destroy(child); close(fd); return r; }
void exit(int retcode) { close_all(); sys_env_destroy(0, retcode); }
// Spawn a child process from a program image. // In Lab 4, the image is loaded from the kernel. // In Lab 5, you will allow images to be loaded from the file system. // prog: the name of the program to run. // argv: pointer to null-terminated array of pointers to strings, // which will be passed to the child as its command-line arguments. // Returns child envid on success, < 0 on failure. envid_t spawn(const char* progname, const char** argv) { uint8_t elf_header_buf[512]; ssize_t elf_size; struct Trapframe child_tf; /* Hint!! */ // Insert your code, following approximately this procedure: // // - Look up the program using sys_program_lookup. // Return an error code if no such program exists. // envid_t child, envid; int pid, err; pid = sys_program_lookup(progname,sizeof(progname)); if(pid < 0) return pid; // - Set 'elf_size' to the program's ELF binary size using // sys_program_size. // elf_size = sys_program_size(pid); // - Map the program's first page at UTEMP using the map_page helper. // envid = sys_getenvid(); map_page(envid, pid, 0, (void *)UTEMP, PTE_U|PTE_P); // - Copy the 512-byte ELF header from UTEMP into elf_header_buf. // memcpy(elf_header_buf, (void *)UTEMP, 512); // - Read the ELF header, as you have before, and sanity check its // magic number. (Check out your load_elf for hints!) // struct Elf *elfbin = (struct Elf *)elf_header_buf; if (elfbin->e_magic != ELF_MAGIC) return -E_INVAL; // - Use sys_exofork() to create a new environment. // child = sys_exofork(); if (child < 0) panic("sys_exofork: %e", child); if (child == 0) { return 0; } // - Set child_tf to an initial struct Trapframe for the child. // Hint: The sys_exofork() system call has already created // a good starting point. It is accessible at // envs[ENVX(child)].env_tf. // Hint: You must do something with the program's entry point. // What? (See load_elf!) // child_tf = envs[ENVX(child)].env_tf; //child_tf.tf_regs = envs[ENVX(child)].env_tf.tf_regs; child_tf.tf_eip = elfbin->e_entry; //sys_env_set_trapframe(child, &child_tf); // - Call the init_stack() function to set up the initial stack // page for the child environment. // if((err = init_stack(child,argv,&(child_tf.tf_esp))) < 0){ sys_env_destroy(child); return err; } // - Map all of the program's segments that are of p_type // ELF_PROG_LOAD into the new environment's address space. // Use the load_segment() helper function below. // All the 'struct Proghdr' structures will be accessible // within the first 512 bytes of the ELF. // // load each program segment (ignores ph flags) struct Proghdr *ph, *eph; ph = (struct Proghdr *) ((uint8_t *) elfbin + elfbin->e_phoff); eph = ph + elfbin->e_phnum; for(; ph < eph; ph++){ if(ph->p_type != ELF_PROG_LOAD){ continue; } assert(ph->p_filesz <= ph->p_memsz); load_segment(child, pid, ph, elfbin, elf_size); } // - Call sys_env_set_trapframe(child, &child_tf) to set up the // correct initial eip and esp values in the child. // if((err = sys_env_set_trapframe(child, &child_tf)) < 0){ sys_env_destroy(child); return err; } // - Start the child process running with sys_env_set_status(). /// if((err = sys_env_set_status(child,ENV_RUNNABLE)) < 0){ sys_env_destroy(child); return err; } //panic("spawn unimplemented!"); return 0; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. uint32_t result = -E_INVAL; //cprintf("syscallno:%08x\n",syscallno); switch(syscallno) { case SYS_cputs: sys_cputs((char *)a1,(size_t)a2); result = SYS_cputs; break; case SYS_getenvid: result = sys_getenvid(); break; case SYS_cgetc: result = sys_cgetc(); break; case SYS_env_destroy: result = sys_env_destroy((envid_t)a1); break; case SYS_env_set_trapframe: result = sys_env_set_trapframe((envid_t)a1, (struct Trapframe *)a2); break; case SYS_yield: sys_yield(); result = SYS_yield; break; case SYS_exofork: result = sys_exofork(); break; case SYS_env_set_status: result = sys_env_set_status((envid_t)a1,(int)a2); break; case SYS_page_alloc: result = sys_page_alloc((envid_t)a1,(void *)a2,(int)a3); break; case SYS_page_map: result = sys_page_map((envid_t)a1,(void *)a2,(envid_t)a3,(void *)a4,(int)a5); break; case SYS_page_unmap: result = sys_page_unmap((envid_t)a1,(void *)a2); break; case SYS_env_set_pgfault_upcall: result = sys_env_set_pgfault_upcall((envid_t)a1,(void*)a2); break; case SYS_ipc_recv: result = sys_ipc_recv((void*)a1); break; case SYS_ipc_try_send: result = sys_ipc_try_send((envid_t)a1, (uint32_t)a2, (void *)a3, (unsigned)a4); break; case SYS_for_fork: result = sys_for_fork((envid_t)a1, (void *)a2, (int)a3); break; case SYS_set_shforkid: result = sys_set_shforkid((envid_t)a1); break; default: result = -E_INVAL; } return result; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. int32_t res; a5 = syscallno >> 8; syscallno -= (a5<<8); //if(a5!=0)cprintf("syscallno %d %x %x\n",syscallno,a1,a5); switch(syscallno) { case SYS_cputs: sys_cputs((const char*)a1,(size_t)a2); res = 0; break; case SYS_cgetc: res = sys_cgetc(); break; case SYS_getenvid: res = sys_getenvid(); break; case SYS_env_destroy: res = sys_env_destroy(a1); break; case SYS_map_kernel_page: res = sys_map_kernel_page((void*)a1,(void*)a2); break; case SYS_yield: res = 0; sys_yield(); break; case SYS_exofork: res = sys_exofork(); break; case SYS_env_set_status: res = sys_env_set_status(a1,a2); break; case SYS_page_alloc: res = sys_page_alloc(a1,(void*)a2,a3); break; case SYS_page_map: res = sys_page_map(a1,(void*)a2,a3,(void*)a4,(int)a5); break; case SYS_page_unmap: res = sys_page_unmap(a1,(void*)a2); break; case SYS_env_set_pgfault_upcall: res = sys_env_set_pgfault_upcall(a1,(void*)a2); break; case SYS_ipc_try_send: res = sys_ipc_try_send(a1,a2,(void*)a3,a4); break; case SYS_ipc_recv: res = sys_ipc_recv((void*)a1); break; case NSYSCALLS: default: res = -E_INVAL; } //cprintf("res %x\n",res); return res; }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. // LAB 3: Your code here. /*stone's solution for lab3-B*/ int32_t ret = -E_INVAL; switch (syscallno){ case SYS_cputs: sys_cputs((char*)a1, a2); ret = 0; break; case SYS_cgetc: ret = sys_cgetc(); break; case SYS_getenvid: ret = sys_getenvid(); break; case SYS_env_destroy: ret = sys_env_destroy(a1); break; case SYS_map_kernel_page: ret = sys_map_kernel_page((void*)a1, (void*)a2); break; case SYS_sbrk: ret = sys_sbrk(a1); break; /*stone's solution for lab4-A*/ case SYS_yield: sys_yield(); ret = 0; break; case SYS_exofork: ret = sys_exofork(); break; case SYS_env_set_status: ret = sys_env_set_status(a1, a2); break; case SYS_env_set_pgfault_upcall: ret = sys_env_set_pgfault_upcall((envid_t)a1, (void*)a2); break; case SYS_page_alloc: ret = sys_page_alloc((envid_t)a1, (void*)a2, (int)a3); break; case SYS_page_map: /*stone: see lib/syscall.c for modification details*/ ret = sys_page_map(*((uint32_t*)a1), (void*)*((uint32_t*)a1 + 1), *((uint32_t*)a1 + 2), (void*)*((uint32_t*)a1 + 3), *((uint32_t*)a1 + 4)); //ret = sys_page_map(a1, (void*)a2, a3, (void*)a4, a5); break; case SYS_page_unmap: ret = sys_page_unmap(a1, (void*)a2); break; case SYS_ipc_recv: ret = sys_ipc_recv((void*)a1); break; case SYS_ipc_try_send: ret = sys_ipc_try_send((envid_t)a1, a2, (void*)a3, (int)a4); break; case SYS_env_set_trapframe: ret = sys_env_set_trapframe((envid_t)a1, (struct Trapframe*)a2); break; default: break; } return ret; //panic("syscall not implemented"); }
// Dispatches to the correct kernel function, passing the arguments. int32_t syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5) { // Call the function corresponding to the 'syscallno' parameter. // Return any appropriate return value. switch(syscallno){ case SYS_cputs: user_mem_assert(curenv, (void *)a1, a2, PTE_U); sys_cputs((char *)a1, a2); return 0; break; case SYS_cgetc: return sys_cgetc(); break; case SYS_getenvid: return sys_getenvid(); break; case SYS_getenv_parent_id: return sys_getenv_parent_id(a1); break; case SYS_env_destroy: return sys_env_destroy(a1); break; case SYS_page_alloc: return sys_page_alloc(a1, (void *)a2, a3); break; case SYS_page_map: return sys_page_map(a1, (void *)a2, a3, (void *)a4, a5); break; case SYS_page_unmap: return sys_page_unmap(a1, (void *)a2); break; case SYS_exofork: return sys_exofork(); break; case SYS_env_set_status: return sys_env_set_status(a1, a2); break; case SYS_env_set_trapframe: return sys_env_set_trapframe(a1, (struct Trapframe *)a2); break; case SYS_env_set_pgfault_upcall: return sys_env_set_pgfault_upcall(a1, (void *)a2); break; case SYS_env_get_curdir: return sys_env_get_curdir((envid_t)a1, (char *)a2); break; case SYS_env_set_curdir: return sys_env_set_curdir((envid_t)a1, (char *)a2); break; case SYS_yield: sys_yield(); break; case SYS_ipc_try_send: return sys_ipc_try_send(a1, a2, (void *)a3, a4); break; case SYS_ipc_recv: return sys_ipc_recv((void *)a1); break; case SYS_time_msec: return sys_time_msec(); break; case SYS_net_send: return sys_net_send((void *)a1, a2); break; case SYS_net_recv: return sys_net_recv((void *)a1, a2); break; case NSYSCALLS: default: return -E_INVAL; break; } return 0; }
void exit(void) { sys_env_destroy(0); }