Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

message message

  • Loading branch information...
commit 798d440cd2ec9027be1d60b2077cb3c7c331904b 1 parent 0221c31
@Frankencelery Frankencelery authored
View
2  src/threads/thread.c
@@ -291,7 +291,7 @@ thread_exit (void)
{
ASSERT (!intr_context ());
if (!sema_try_down(&thread_current ()->wait_status->dead)){
- printf("Error! (%s) has not been given permission to die.\n",thread_current ()->name);
+ //printf("Error! (%s) has not been given permission to die.\n",thread_current ()->name);
}
//sema_up(&thread_current ()->wait_status->dead); //Do this for make check if not everything implemented.
#ifdef USERPROG
View
8 src/userprog/process.c
@@ -157,7 +157,6 @@ process_wait (tid_t child_tid)
void
process_exit (void)
{
- //printf(" "); //Having this line causes exit code to print??? Not having it does not.
struct thread *cur = thread_current ();
struct list_elem *e, *next;
uint32_t *pd;
@@ -167,15 +166,12 @@ process_exit (void)
/* Notify parent that we're dead. */
if (cur->wait_status != NULL)
{
- /* add code */
+
struct wait_status *cs = cur->wait_status;
+ printf ("%s: exit(%d)\n", cur->name,cur->wait_status->exit_code);
sema_up(&cur->wait_status->dead);
- printf ("%s: exit(%d)\n", cur->name,cur->wait_status->exit_code);
-
release_child (cs);
}
- //else{printf("something bad..\n");}// Put this in to check. REMOVE
- // Maybe if null make wait_status?
/* Free entries of children list. */
for (e = list_begin (&cur->children); e != list_end (&cur->children);
View
68 src/userprog/syscall.c
@@ -141,7 +141,7 @@ copy_in (void *dst_, const void *usrc_, size_t size)
for (; size > 0; size--, dst++, usrc++)
if (usrc >= (uint8_t *) PHYS_BASE || !get_user (dst, usrc))
- thread_exit ();
+ sys_exit (-1);
}
/* Creates a copy of user string US in kernel memory
@@ -185,7 +185,6 @@ static int
sys_exit (int exit_code)
{
thread_current ()->wait_status->exit_code = exit_code;
- //printf("wait_status->exit_code = %d\n", thread_current ()->wait_status->exit_code);
sema_up(&(thread_current ()->wait_status->dead));
thread_exit ();
NOT_REACHED ();
@@ -195,8 +194,15 @@ sys_exit (int exit_code)
static int
sys_exec (const char *ufile)
{
+
+ if(ufile==NULL || !verify_user(ufile))
+ {
+ sys_exit(-1);
+ NOT_REACHED ();
+ }
char *kfile = copy_in_string(ufile);
return process_execute(kfile);
+ palloc_free_page(kfile);
}
/* Wait system call. */
@@ -218,15 +224,14 @@ sys_create (const char *ufile, unsigned initial_size)
sys_exit(-1);
NOT_REACHED ();
}
- printf("attempting copy\n");
char *kfile = copy_in_string(ufile);
- printf("copy worked!\n");
lock_acquire (&fs_lock);
if (kfile != NULL)
{
sucess = filesys_create (kfile, (off_t)initial_size);
}
lock_release (&fs_lock);
+ palloc_free_page(kfile);
return sucess;
}
@@ -234,6 +239,12 @@ sys_create (const char *ufile, unsigned initial_size)
static int
sys_remove (const char *ufile)
{
+ if(ufile==NULL || !verify_user(ufile))
+ {
+ //close the program
+ sys_exit(-1);
+ NOT_REACHED ();
+ }
bool sucess = false;
char *kfile = copy_in_string(ufile);
lock_acquire (&fs_lock);
@@ -242,7 +253,7 @@ sys_remove (const char *ufile)
sucess = filesys_remove (kfile) ;
}
lock_release (&fs_lock);
-
+ palloc_free_page(kfile);
return sucess;
}
@@ -258,9 +269,14 @@ struct file_descriptor
static int
sys_open (const char *ufile)
{
- if(ufile==NULL){return -1;}
+ if(ufile==NULL || !verify_user(ufile))
+ {
+ //close the program
+ sys_exit(-1);
+ NOT_REACHED ();
+ }
char *kfile = copy_in_string (ufile);
- //if(kfile==NULL){return -1;}
+
struct file_descriptor *fd;
int handle = -1;
@@ -293,18 +309,18 @@ lookup_fd (int handle)
/* Add code to lookup file descriptor in the current thread's fds */
struct thread* cur = thread_current();
+ if (list_empty(&(cur->fds))) sys_exit(-1);
struct list_elem* e = list_front(&(cur->fds));
+
struct file_descriptor * e2;
while(e != NULL){
e2 = list_entry(e, struct file_descriptor, elem);
if (e2->handle == handle){
- lock_release (&fs_lock);
return e2;
}
e = list_next(e);
}
-
- thread_exit ();
+ sys_exit(-1);
}
/* Filesize system call. */
@@ -322,20 +338,35 @@ sys_filesize (int handle)
static int
sys_read (int handle, void *udst_, unsigned size)
{
-/* Add code */
- struct file_descriptor* fd = lookup_fd(handle); // NEED TO FIGURE OUT FILE IO. MAYBE FROM STDOUT_FILENO...
- if (fd != NULL){
+ int read;
+ if(udst_==NULL || !verify_user(udst_))
+ {
+ //close the program
+ sys_exit(-1);
+ NOT_REACHED ();
+ }
+ struct file_descriptor* fd = lookup_fd(handle);
+
+ if(fd == NULL) sys_exit(-1);
+
lock_acquire (&fs_lock);
- int read = file_read(fd->file, udst_, size);
+ read = file_read(fd->file, udst_, size);
lock_release (&fs_lock);
+
return read;
- } else{return -1;}
}
/* Write system call. */
static int
sys_write (int handle, void *usrc_, unsigned size)
{
+ if(usrc_==NULL || !verify_user(usrc_))
+ {
+ //close the program
+ sys_exit(-1);
+ NOT_REACHED ();
+ }
+
uint8_t *usrc = usrc_;
struct file_descriptor *fd = NULL;
int bytes_written = 0;
@@ -352,13 +383,6 @@ sys_write (int handle, void *usrc_, unsigned size)
size_t write_amt = size < page_left ? size : page_left;
off_t retval;
- /* Check that we can touch this user page. */
- if (!verify_user (usrc))
- {
- lock_release (&fs_lock);
- thread_exit ();
- }
-
/* Do the write. */
if (handle == STDOUT_FILENO)
{
Please sign in to comment.
Something went wrong with that request. Please try again.