Rev 1065 | Rev 1081 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1065 | Rev 1079 | ||
|---|---|---|---|
| Line 26... | Line 26... | ||
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
27 | */ |
| 28 | 28 | ||
| 29 | #include <thread.h> |
29 | #include <thread.h> |
| 30 | #include <libc.h> |
30 | #include <libc.h> |
| - | 31 | #include <stdlib.h> |
|
| 31 | #include <arch/faddr.h> |
32 | #include <arch/faddr.h> |
| - | 33 | #include <kernel/proc/uarg.h> |
|
| 32 | 34 | ||
| 33 | typedef void (* voidfunc_t)(void); |
35 | void thread_main(uspace_arg_t *uarg) |
| - | 36 | { |
|
| - | 37 | uarg->uspace_thread_function(uarg->uspace_thread_arg); |
|
| - | 38 | free(uarg->uspace_stack); |
|
| - | 39 | free(uarg); |
|
| - | 40 | thread_exit(0); |
|
| - | 41 | } |
|
| 34 | 42 | ||
| 35 | int thread_create(void (* function)(void *), void *arg, void *stack, char *name) |
43 | int thread_create(void (* function)(void *), void *arg, char *name) |
| 36 | { |
44 | { |
| - | 45 | char *stack; |
|
| - | 46 | uspace_arg_t *uarg; |
|
| - | 47 | ||
| - | 48 | stack = (char *) malloc(getpagesize()); |
|
| - | 49 | if (!stack) |
|
| - | 50 | return -1; |
|
| - | 51 | ||
| - | 52 | uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t)); |
|
| - | 53 | if (!uarg) { |
|
| - | 54 | free(stack); |
|
| - | 55 | return -1; |
|
| - | 56 | } |
|
| - | 57 | uarg->uspace_entry = (void *) FADDR(__thread_entry); |
|
| - | 58 | uarg->uspace_stack = (void *) stack; |
|
| - | 59 | uarg->uspace_thread_function = (void *) FADDR(function); |
|
| - | 60 | uarg->uspace_thread_arg = arg; |
|
| - | 61 | uarg->uspace_uarg = uarg; |
|
| - | 62 | ||
| 37 | return __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) FADDR((voidfunc_t) function), (sysarg_t) arg, (sysarg_t) stack, (sysarg_t) name); |
63 | return __SYSCALL2(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name); |
| 38 | } |
64 | } |
| 39 | 65 | ||
| 40 | void thread_exit(int status) |
66 | void thread_exit(int status) |
| 41 | { |
67 | { |
| 42 | __SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status); |
68 | __SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status); |
| 43 | } |
69 | } |
| 44 | - | ||