/kernel/trunk/generic/src/proc/task.c |
---|
115,6 → 115,7 |
int rc; |
thread_t *t; |
task_t *task; |
uspace_arg_t *uarg; |
as = as_create(0); |
124,9 → 125,12 |
return NULL; |
} |
uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
uarg->uspace_entry = (__address) ((elf_header_t *) program_addr)->e_entry; |
uarg->uspace_stack = USTACK_ADDRESS; |
task = task_create(as, name); |
t = thread_create(uinit, (void *)((elf_header_t *)program_addr)->e_entry, |
task, 0, "uinit"); |
t = thread_create(uinit, uarg, task, 0, "uinit"); |
/* |
* Create the data as_area. |
/kernel/trunk/generic/src/proc/thread.c |
---|
53,6 → 53,7 |
#include <print.h> |
#include <mm/slab.h> |
#include <debug.h> |
#include <main/uinit.h> |
char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */ |
280,7 → 281,8 |
t->saved_context.ipl = interrupts_read(); |
interrupts_restore(ipl); |
t->name = name; |
memcpy(t->name, name, THREAD_NAME_BUFLEN); |
t->thread_code = func; |
t->thread_arg = arg; |
t->ticks = -1; |
423,3 → 425,40 |
spinlock_unlock(&threads_lock); |
interrupts_restore(ipl); |
} |
/** Process syscall to create new thread. |
* |
*/ |
__native sys_thread_create(__address function, void *arg, void *stack, char *name) |
{ |
thread_t *t; |
char namebuf[THREAD_NAME_BUFLEN]; |
uspace_arg_t *uarg; |
__u32 tid; |
copy_from_uspace(namebuf, name, THREAD_NAME_BUFLEN); |
uarg = (uspace_arg_t *) malloc(sizeof(uarg), 0); |
uarg->uspace_entry = function; |
uarg->uspace_stack = (__address) stack; |
if ((t = thread_create(uinit, uarg, TASK, 0, namebuf))) { |
tid = t->tid; |
thread_ready(t); |
return (__native) tid; |
} else { |
free(namebuf); |
} |
return (__native) -1; |
} |
/** Process syscall to terminate thread. |
* |
*/ |
__native sys_thread_exit(int status) |
{ |
thread_exit(); |
/* Unreachable */ |
return 0; |
} |
/kernel/trunk/generic/src/main/uinit.c |
---|
30,10 → 30,21 |
#include <arch/types.h> |
#include <proc/thread.h> |
#include <userspace.h> |
#include <mm/slab.h> |
#include <print.h> |
/** Thread used to bring up userspace thread. |
* |
* @param arg Pointer to structure containing userspace entry and stack addresses. |
*/ |
void uinit(void *arg) |
{ |
printf("USER task, uinit thread: kernel mode\n"); |
userspace((__address)(arg)); |
uspace_arg_t uarg; |
uarg.uspace_entry = ((uspace_arg_t *) arg)->uspace_entry; |
uarg.uspace_stack = ((uspace_arg_t *) arg)->uspace_stack; |
free((uspace_arg_t *) arg); |
userspace(&uarg); |
} |
/kernel/trunk/generic/src/syscall/syscall.c |
---|
37,13 → 37,6 |
#include <debug.h> |
#include <ipc/sysipc.h> |
static __native sys_ctl(void) { |
printf("Thread finished\n"); |
thread_exit(); |
/* Unreachable */ |
return 0; |
} |
static __native sys_io(int fd, const void * buf, size_t count) { |
// TODO: buf sanity checks and a lot of other stuff ... |
56,7 → 49,6 |
return count; |
} |
static __native sys_mmap(void *address, size_t size, int flags) |
{ |
if (as_area_create(AS, flags, size, (__address) address)) |
71,8 → 63,9 |
} |
syshandler_t syscall_table[SYSCALL_END] = { |
sys_ctl, |
sys_io, |
sys_thread_create, |
sys_thread_exit, |
sys_mmap, |
sys_mremap, |
sys_ipc_call_sync_fast, |