Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jleong/change exit behavior #114

Merged
merged 12 commits into from
Feb 22, 2017
Prev Previous commit
Next Next commit
Refactor list_remove
Refactor so we know when an element is removed by checking that
element.

All tests pass on qemu. syn-read has an assertion fail in list_next
and multi-oom hangs on bochs.
  • Loading branch information
omegaphoenix committed Feb 21, 2017
commit c6ef9629072ed8d2e3daa1306f7c1327b0ff1e9c
14 changes: 13 additions & 1 deletion src/lib/kernel/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,19 @@ list_remove (struct list_elem *elem)
ASSERT (is_interior (elem));
elem->prev->next = elem->next;
elem->next->prev = elem->prev;
return elem->next;
struct list_elem *ret = elem->next;
elem->prev = NULL;
elem->next = NULL;
return ret;
}

struct list_elem *
try_remove (struct list_elem *elem)
{
if (is_interior(elem)) {
return list_remove(elem);
}
return NULL;
}

/* Removes the front element from LIST and returns it.
Expand Down
1 change: 1 addition & 0 deletions src/lib/kernel/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void list_push_back (struct list *, struct list_elem *);

/* List removal. */
struct list_elem *list_remove (struct list_elem *);
struct list_elem *try_remove (struct list_elem *);
struct list_elem *list_pop_front (struct list *);
struct list_elem *list_pop_back (struct list *);

Expand Down
9 changes: 9 additions & 0 deletions src/threads/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ void thread_exit(void) {

/* Let kids know that parent is dead so that their page is freed without
waiting for the parent. Will be freed in thread_schedule_tail().*/

while (!list_empty(&cur->kids)) {
e = list_pop_front(&cur->kids);
struct thread *kid = list_entry(e, struct thread, kid_elem);
Expand Down Expand Up @@ -847,6 +848,14 @@ void thread_schedule_tail(struct thread *prev) {
if (prev != NULL && prev->status == THREAD_DYING &&
prev != initial_thread) {
ASSERT(prev != cur);
ASSERT(try_remove(&prev->allelem) == NULL);
ASSERT(try_remove(&prev->sleep_elem) == NULL);
ASSERT(try_remove(&prev->elem) == NULL);
ASSERT(try_remove(&prev->lock_elem) == NULL);
ASSERT(try_remove(&prev->kid_elem) == NULL);
ASSERT(list_empty(&prev->locks_acquired));
ASSERT(list_empty(&prev->open_files));
ASSERT(list_empty(&prev->kids));
palloc_free_page(prev);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/userprog/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ void sys_exit(int status) {
printf("%s: exit(%d)\n", cur->name, status);
cur->exit_status = status;

if (lock_held_by_current_thread(&filesys_lock)) {
release_file_lock();
}

/* Free all file buffers. */
struct list_elem *e;
while (!list_empty(&cur->open_files)) {
Expand All @@ -199,6 +195,8 @@ pid_t sys_exec(const char *cmd_line) {
return ERR;
}
struct thread *cur = thread_current();

/* File system call */
acquire_file_lock();
pid_t new_process_pid = process_execute(cmd_line);

Expand Down