diff --git a/pintos-env/pintos/threads/thread.c b/pintos-env/pintos/threads/thread.c index 62424df..e3ff6b6 100644 --- a/pintos-env/pintos/threads/thread.c +++ b/pintos-env/pintos/threads/thread.c @@ -575,6 +575,7 @@ init_thread (struct thread *t, const char *name, int priority) strlcpy (t->name, name, sizeof t->name); t->stack = (uint8_t *) t + PGSIZE; sema_init(&t->waiting_sem, 0); + t->waited_on_before = 0; if (thread_mlfqs) { t->nice_init = priority > 20 || priority < 20 ? 0 : priority; diff --git a/pintos-env/pintos/threads/thread.h b/pintos-env/pintos/threads/thread.h index dcebaaf..8d61d67 100755 --- a/pintos-env/pintos/threads/thread.h +++ b/pintos-env/pintos/threads/thread.h @@ -101,6 +101,8 @@ struct thread int nice_init; FPReal recent_cpu; struct semaphore waiting_sem; + int exit_status; + int waited_on_before; #ifdef USERPROG /* Owned by userprog/process.c. */ diff --git a/pintos-env/pintos/userprog/filesys.dsk b/pintos-env/pintos/userprog/filesys.dsk new file mode 100644 index 0000000..14f36e6 Binary files /dev/null and b/pintos-env/pintos/userprog/filesys.dsk differ diff --git a/pintos-env/pintos/userprog/process.c b/pintos-env/pintos/userprog/process.c index 3f0bf7d..63b1286 100755 --- a/pintos-env/pintos/userprog/process.c +++ b/pintos-env/pintos/userprog/process.c @@ -179,13 +179,21 @@ start_process (void *file_name_) int process_wait (tid_t child_tid) { + //printf("process wait for: %s on: %ul\n", thread_current()->name, child_tid); + + // TODO: check if tid is child + struct thread* child = thread_get_by_tid(child_tid); - if (child == NULL) { + if (child == NULL || child->waited_on_before) { + //printf("child not found\n"); return -1; } + //printf("child is: %s\n", child->name); + sema_down(&child->waiting_sem); - return 0; + child->waited_on_before = 1; + return child->exit_status; } /* Free the current process's resources. */ diff --git a/pintos-env/pintos/userprog/syscall.c b/pintos-env/pintos/userprog/syscall.c index 2885f78..a0deea0 100755 --- a/pintos-env/pintos/userprog/syscall.c +++ b/pintos-env/pintos/userprog/syscall.c @@ -4,12 +4,17 @@ #include "threads/interrupt.h" #include "threads/thread.h" #include +#include "userprog/process.h" +#include "threads/vaddr.h" +#include "userprog/pagedir.h" typedef int (*handler) (uint32_t, uint32_t, uint32_t); static handler syscall_vec[128]; static int sys_write (int fd, const void *buffer, unsigned length); static int sys_exit (int status); +static int sys_wait (tid_t tid); +static tid_t sys_exec (const char* file_name); static void syscall_nop(void); static void syscall_handler (struct intr_frame *); @@ -18,9 +23,11 @@ void syscall_init (void) { intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); - +printf("syscall\n"); memset(syscall_vec, (int)&syscall_nop, 128); syscall_vec[SYS_EXIT] = (handler)sys_exit; + syscall_vec[SYS_WAIT] = (handler)sys_wait; + syscall_vec[SYS_EXEC] = (handler)sys_exec; syscall_vec[SYS_WRITE] = (handler)sys_write; } @@ -58,6 +65,24 @@ sys_exit (int status) { struct thread* t = thread_current(); printf("%s: exit(%d)\n", t->name, status); + t->exit_status = status; thread_exit (); return -1; +} + +int +sys_wait (tid_t tid) +{ + printf("system call wait\n"); + return process_wait(tid); +} + +tid_t +sys_exec (const char* file_name) { + if (file_name == NULL || is_kernel_vaddr(file_name) || + pagedir_get_page(thread_current()->pagedir, file_name) == NULL) { + return -1; + } + + return process_execute(file_name); } \ No newline at end of file