void root( void ) { /****************************/ int i, j; kprintf("Root has been called\n"); sysyield(); sysyield(); syscreate( &producer, 4096 ); syscreate( &consumer, 4096 ); for( ;; ) { sysyield(); } }
/* read a message into a temp file, return an open fd to it in mp->fd */ static int m_read_to_file(Biobuf *fp, message *mp) { int fd; int n; String *file; char buf[4*1024]; file = s_new(); /* * create temp file to be removed on close */ abspath("mtXXXXXX", UPASTMP, file); mktemp(s_to_c(file)); if((fd = syscreate(s_to_c(file), ORDWR|ORCLOSE, 0600))<0){ s_free(file); return -1; } mp->tmp = file; /* * read the rest into the temp file */ while((n = Bread(fp, buf, sizeof(buf))) > 0){ if(write(fd, buf, n) != n){ close(fd); return -1; } mp->size += n; if(mp->size > MSGLIMIT){ mp->size = -1; break; } } mp->fd = fd; return 0; }
static void syscall_handler (struct intr_frame* frame) { // -------- System Call Handler Overview -------- // Get system call number // switch statement using system call number // collect arguments for system call function if necessary // call system call function // set frame->eax to return value if necessary // ---------------------------------------------- uintptr_t* kpaddr_sp = (uintptr_t*) frame->esp; int syscall_num = -1; if(check_uptr(kpaddr_sp)) syscall_num = next_value(&kpaddr_sp); else sysexit(-1); switch(syscall_num) { case SYS_HALT: { // Terminates Pintos shutdown_power_off(); } break; case SYS_EXIT: { uintptr_t status = -1; if(check_uptr(kpaddr_sp)) status = next_value(&kpaddr_sp); sysexit(status); } break; case SYS_EXEC: //pid_t exec (const char *file); { const char* file = next_charptr(&kpaddr_sp); if(file == NULL) sysexit(-1); unsigned len = strlen(file); if(!check_buffer(file, len)) sysexit(-1); else sysexec(frame, file); } break; case SYS_WAIT: //int wait (pid_t); { uintptr_t childid = -1; if(check_uptr(kpaddr_sp)) childid = next_value(&kpaddr_sp); else sysexit(childid); int retval = process_wait((tid_t) childid); frame->eax = retval; } break; case SYS_CREATE: //bool create (const char *file, unsigned initial_size); { const char* file = next_charptr(&kpaddr_sp); if(file == NULL) sysexit(-1); unsigned len = strlen(file); if(!check_buffer(file, len)) sysexit(-1); uintptr_t size = 0; if(check_uptr(kpaddr_sp)) size = next_value(&kpaddr_sp); else sysexit(-1); syscreate(frame, file, size); } break; case SYS_REMOVE: //bool remove (const char *file); { const char* file = next_charptr(&kpaddr_sp); if(file == NULL) sysexit(-1); unsigned len = strlen(file); if(!check_buffer(file, len)) sysexit(-1); sysremove(frame, file); } break; case SYS_OPEN: { //int open (const char *file); const char* file = next_charptr(&kpaddr_sp); if(file == NULL) sysexit(-1); unsigned len = strlen(file); if(!check_buffer(file, len)) sysexit(-1); sysopen(frame, file); } break; case SYS_FILESIZE: { //int filesize (int fd); int fd = 0; if (check_uptr(kpaddr_sp)) fd = (int) next_value(&kpaddr_sp); else sysexit(-1); sysfilesize(frame, fd); } break; case SYS_READ: { //int read (int fd, void *buffer, unsigned length); int fd = 0; if (check_uptr(kpaddr_sp)) fd = (int) next_value(&kpaddr_sp); else sysexit(-1); const char* file = next_charptr(&kpaddr_sp); if(file == NULL) sysexit(-1); unsigned len = strlen(file); if(!check_buffer(file, len)) sysexit(-1); unsigned length = 0; if (check_uptr(kpaddr_sp)) length = (unsigned) next_value(&kpaddr_sp); else sysexit(-1); sysread(frame, fd, (void*) file, length); } break; case SYS_WRITE: { //int write (int fd, const void *buffer, unsigned length); uintptr_t fd = 0; if(check_uptr(kpaddr_sp)) fd = next_value(&kpaddr_sp); else sysexit(-1); const char* file = next_charptr(&kpaddr_sp); if(file == NULL) sysexit(-1); unsigned len = strlen(file); if(!check_buffer(file, len)) sysexit(-1); uintptr_t length = 0; if(check_uptr(kpaddr_sp)) length = next_value(&kpaddr_sp); else sysexit(-1); if(fd == CONSOLEWRITE) // Write to Console { while(length > 0) { if(length > MAX_SIZE) { putbuf (file, MAX_SIZE); file += MAX_SIZE; length -= MAX_SIZE; } else { putbuf (file, length); length = 0; } } } else { syswrite(frame, fd, file, length); } } break; case SYS_SEEK: { //void seek (int fd, unsigned position); int fd = 0; if (check_uptr(kpaddr_sp)) fd = (int) next_value(&kpaddr_sp); else sysexit(-1); unsigned position = 0; if (check_uptr(kpaddr_sp)) position = (unsigned) next_value(&kpaddr_sp); else sysexit(-1); sysseek(fd, position); } break; case SYS_TELL: { //unsigned tell (int fd); int fd = 0; if (check_uptr(kpaddr_sp)) fd = (int) next_value(&kpaddr_sp); else sysexit(-1); systell(frame, fd); } break; case SYS_CLOSE: { //void close (int fd); int fd = 0; if (check_uptr(kpaddr_sp)) fd = (int) next_value(&kpaddr_sp); else sysexit(-1); sysclose(fd); } break; default: { printf("Unrecognized System Call\n"); sysexit(-1); } break; } }