/kernel/trunk/generic/include/proc/uarg.h |
---|
0,0 → 1,43 |
/* |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __UARG_H__ |
#define __UARG_H__ |
/** Structure passed to uinit kernel thread as argument. */ |
typedef struct uspace_arg { |
void *uspace_entry; |
void *uspace_stack; |
void (* uspace_thread_function)(); |
void *uspace_thread_arg; |
struct uspace_arg *uspace_uarg; |
} uspace_arg_t; |
#endif |
/kernel/trunk/generic/include/proc/thread.h |
---|
40,6 → 40,7 |
#include <config.h> |
#include <adt/list.h> |
#include <mm/slab.h> |
#include <proc/uarg.h> |
#define THREAD_STACK_SIZE STACK_SIZE |
117,12 → 118,6 |
__u8 *kstack; /**< Thread's kernel stack. */ |
}; |
/** Structure passed to uinit kernel thread as argument. */ |
typedef struct uspace_arg { |
__address uspace_entry; |
__address uspace_stack; |
} uspace_arg_t; |
/** Thread list lock. |
* |
* This lock protects all link_t structures chained in threads_head. |
149,7 → 144,7 |
extern slab_cache_t *fpu_context_slab; |
/** Thread syscall prototypes. */ |
__native sys_thread_create(__address function, void *arg, void *stack, char *name); |
__native sys_thread_exit(int status); |
__native sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name); |
__native sys_thread_exit(int uspace_status); |
#endif |
/kernel/trunk/generic/src/proc/task.c |
---|
29,9 → 29,9 |
#include <main/uinit.h> |
#include <proc/thread.h> |
#include <proc/task.h> |
#include <proc/uarg.h> |
#include <mm/as.h> |
#include <mm/slab.h> |
#include <synch/spinlock.h> |
#include <arch.h> |
#include <panic.h> |
39,7 → 39,6 |
#include <ipc/ipc.h> |
#include <memstr.h> |
#include <print.h> |
#include <elf.h> |
SPINLOCK_INITIALIZE(tasks_lock); |
115,7 → 114,7 |
int rc; |
thread_t *t; |
task_t *task; |
uspace_arg_t *uarg; |
uspace_arg_t *kernel_uarg; |
as = as_create(0); |
125,12 → 124,15 |
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; |
kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
kernel_uarg->uspace_entry = (void *) ((elf_header_t *) program_addr)->e_entry; |
kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS; |
kernel_uarg->uspace_thread_function = NULL; |
kernel_uarg->uspace_thread_arg = NULL; |
kernel_uarg->uspace_uarg = NULL; |
task = task_create(as, name); |
t = thread_create(uinit, uarg, task, 0, "uinit"); |
t = thread_create(uinit, kernel_uarg, task, 0, "uinit"); |
/* |
* Create the data as_area. |
/kernel/trunk/generic/src/proc/thread.c |
---|
29,6 → 29,7 |
#include <proc/scheduler.h> |
#include <proc/thread.h> |
#include <proc/task.h> |
#include <proc/uarg.h> |
#include <mm/frame.h> |
#include <mm/page.h> |
#include <arch/asm.h> |
429,25 → 430,24 |
/** Process syscall to create new thread. |
* |
*/ |
__native sys_thread_create(__address function, void *arg, void *stack, char *name) |
__native sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name) |
{ |
thread_t *t; |
char namebuf[THREAD_NAME_BUFLEN]; |
uspace_arg_t *uarg; |
uspace_arg_t *kernel_uarg; /* TODO: store kernel_uarg in thread_t */ |
__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; |
copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN); |
if ((t = thread_create(uinit, uarg, TASK, 0, namebuf))) { |
kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
copy_from_uspace(kernel_uarg, uspace_uarg, sizeof(uspace_arg_t)); |
if ((t = thread_create(uinit, kernel_uarg, TASK, 0, namebuf))) { |
tid = t->tid; |
thread_ready(t); |
return (__native) tid; |
} else { |
free(namebuf); |
free(kernel_uarg); |
} |
return (__native) -1; |
456,7 → 456,7 |
/** Process syscall to terminate thread. |
* |
*/ |
__native sys_thread_exit(int status) |
__native sys_thread_exit(int uspace_status) |
{ |
thread_exit(); |
/* Unreachable */ |
/kernel/trunk/generic/src/main/uinit.c |
---|
43,6 → 43,9 |
uarg.uspace_entry = ((uspace_arg_t *) arg)->uspace_entry; |
uarg.uspace_stack = ((uspace_arg_t *) arg)->uspace_stack; |
uarg.uspace_uarg = ((uspace_arg_t *) arg)->uspace_uarg; |
uarg.uspace_thread_function = NULL; |
uarg.uspace_thread_arg = NULL; |
free((uspace_arg_t *) arg); |