wip on hw4
This commit is contained in:
parent
947c3a612c
commit
c987ffa0dc
5 changed files with 39 additions and 3 deletions
|
@ -575,6 +575,7 @@ init_thread (struct thread *t, const char *name, int priority)
|
||||||
strlcpy (t->name, name, sizeof t->name);
|
strlcpy (t->name, name, sizeof t->name);
|
||||||
t->stack = (uint8_t *) t + PGSIZE;
|
t->stack = (uint8_t *) t + PGSIZE;
|
||||||
sema_init(&t->waiting_sem, 0);
|
sema_init(&t->waiting_sem, 0);
|
||||||
|
t->waited_on_before = 0;
|
||||||
|
|
||||||
if (thread_mlfqs) {
|
if (thread_mlfqs) {
|
||||||
t->nice_init = priority > 20 || priority < 20 ? 0 : priority;
|
t->nice_init = priority > 20 || priority < 20 ? 0 : priority;
|
||||||
|
|
|
@ -101,6 +101,8 @@ struct thread
|
||||||
int nice_init;
|
int nice_init;
|
||||||
FPReal recent_cpu;
|
FPReal recent_cpu;
|
||||||
struct semaphore waiting_sem;
|
struct semaphore waiting_sem;
|
||||||
|
int exit_status;
|
||||||
|
int waited_on_before;
|
||||||
|
|
||||||
#ifdef USERPROG
|
#ifdef USERPROG
|
||||||
/* Owned by userprog/process.c. */
|
/* Owned by userprog/process.c. */
|
||||||
|
|
BIN
pintos-env/pintos/userprog/filesys.dsk
Normal file
BIN
pintos-env/pintos/userprog/filesys.dsk
Normal file
Binary file not shown.
|
@ -179,13 +179,21 @@ start_process (void *file_name_)
|
||||||
int
|
int
|
||||||
process_wait (tid_t child_tid)
|
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);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printf("child is: %s\n", child->name);
|
||||||
|
|
||||||
sema_down(&child->waiting_sem);
|
sema_down(&child->waiting_sem);
|
||||||
return 0;
|
child->waited_on_before = 1;
|
||||||
|
return child->exit_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the current process's resources. */
|
/* Free the current process's resources. */
|
||||||
|
|
|
@ -4,12 +4,17 @@
|
||||||
#include "threads/interrupt.h"
|
#include "threads/interrupt.h"
|
||||||
#include "threads/thread.h"
|
#include "threads/thread.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "userprog/process.h"
|
||||||
|
#include "threads/vaddr.h"
|
||||||
|
#include "userprog/pagedir.h"
|
||||||
|
|
||||||
typedef int (*handler) (uint32_t, uint32_t, uint32_t);
|
typedef int (*handler) (uint32_t, uint32_t, uint32_t);
|
||||||
static handler syscall_vec[128];
|
static handler syscall_vec[128];
|
||||||
|
|
||||||
static int sys_write (int fd, const void *buffer, unsigned length);
|
static int sys_write (int fd, const void *buffer, unsigned length);
|
||||||
static int sys_exit (int status);
|
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_nop(void);
|
||||||
|
|
||||||
static void syscall_handler (struct intr_frame *);
|
static void syscall_handler (struct intr_frame *);
|
||||||
|
@ -18,9 +23,11 @@ void
|
||||||
syscall_init (void)
|
syscall_init (void)
|
||||||
{
|
{
|
||||||
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
|
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
|
||||||
|
printf("syscall\n");
|
||||||
memset(syscall_vec, (int)&syscall_nop, 128);
|
memset(syscall_vec, (int)&syscall_nop, 128);
|
||||||
syscall_vec[SYS_EXIT] = (handler)sys_exit;
|
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;
|
syscall_vec[SYS_WRITE] = (handler)sys_write;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +65,24 @@ sys_exit (int status)
|
||||||
{
|
{
|
||||||
struct thread* t = thread_current();
|
struct thread* t = thread_current();
|
||||||
printf("%s: exit(%d)\n", t->name, status);
|
printf("%s: exit(%d)\n", t->name, status);
|
||||||
|
t->exit_status = status;
|
||||||
thread_exit ();
|
thread_exit ();
|
||||||
return -1;
|
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);
|
||||||
|
}
|
Reference in a new issue