Operating Systems Homework

1. Kernel Threads
In this project, you’ll be adding real kernel threads to xv6. Sound like fun? Well, it
should. Because you are on your way to becoming a real kernel hacker. And what
could be more fun than that?
Specifically, you’ll do three things. First, you’ll define a new system call to create a
kernel thread, called clone(), as well as one to wait for a thread called join(). Then,
you’ll use clone() to build a little thread library, with a thread_create() call
and lock_acquire()
2. Overview
Your new clone system call should look like this:
int clone(void(*fcn)(void*, void *), void *arg1, void *arg2,
void *stack)
This call creates a new kernel thread which shares the calling process’s address space.
File descriptors are copied as in fork(). The new process uses stack as its user stack,
which is passed with two arguments (arg1 and arg2) and uses a fake return PC
(0xffffffff); a proper thread will simply call exit() page-aligned. The new thread starts
executing at the address specified by fcn. As with fork(), the PID of the new thread is
returned to the parent (for simplicity, threads each have their own process ID).



Powered by WordPress