Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/thread/thread.c

    r3fcea34 rbd41ac52  
    3737#include <stdlib.h>
    3838#include <libarch/faddr.h>
     39#include <abi/proc/uarg.h>
    3940#include <fibril.h>
    4041#include <stack.h>
     
    5354 * and exit when thread returns back.
    5455 *
    55  * @param arg Fibril pointer.
    56  *
    57  */
    58 static void __thread_main(void *arg)
    59 {
    60         fibril_t *fibril = arg;
    61 
     56 * @param uarg Pointer to userspace argument structure.
     57 *
     58 */
     59void __thread_main(uspace_arg_t *uarg)
     60{
    6261        assert(!__tcb_is_set());
     62
     63        fibril_t *fibril = uarg->uspace_thread_arg;
    6364        assert(fibril);
    6465
    6566        __tcb_set(fibril->tcb);
    6667
    67         fibril->func(fibril->arg);
     68        uarg->uspace_thread_function(fibril->arg);
    6869        /*
    6970         * XXX: we cannot free the userspace stack while running on it
     
    8990 * @return Zero on success or a code from @ref errno.h on failure.
    9091 */
    91 errno_t thread_create(errno_t (*func)(void *), void *arg, const char *name)
    92 {
     92errno_t thread_create(void (*function)(void *), void *arg, const char *name,
     93    thread_id_t *tid)
     94{
     95        uspace_arg_t *uarg = calloc(1, sizeof(uspace_arg_t));
     96        if (!uarg)
     97                return ENOMEM;
     98
    9399        fibril_t *fibril = fibril_alloc();
    94         if (!fibril)
     100        if (!fibril) {
     101                free(uarg);
    95102                return ENOMEM;
    96 
    97         fibril->func = func;
    98         fibril->arg = arg;
     103        }
    99104
    100105        size_t stack_size = stack_size_get();
     
    104109        if (stack == AS_MAP_FAILED) {
    105110                fibril_teardown(fibril);
     111                free(uarg);
    106112                return ENOMEM;
    107113        }
    108114
    109         uintptr_t sp = arch_thread_prepare(stack, stack_size, __thread_main,
    110             fibril);
    111 
    112         errno_t rc = (errno_t) __SYSCALL4(SYS_THREAD_CREATE,
    113             (sysarg_t) FADDR(__thread_entry), sp,
    114             (sysarg_t) name, (sysarg_t) str_size(name));
     115        fibril->arg = arg;
     116        uarg->uspace_entry = (void *) FADDR(__thread_entry);
     117        uarg->uspace_stack = stack;
     118        uarg->uspace_stack_size = stack_size;
     119        uarg->uspace_thread_function = function;
     120        uarg->uspace_thread_arg = fibril;
     121        uarg->uspace_uarg = uarg;
     122
     123        errno_t rc = (errno_t) __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg,
     124            (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid);
    115125
    116126        if (rc != EOK) {
     
    120130                 */
    121131                as_area_destroy(stack);
     132                free(uarg);
    122133        }
    123134
     
    137148        while (true)
    138149                ;
     150}
     151
     152/** Detach thread.
     153 *
     154 * Currently not implemented.
     155 *
     156 * @param thread TID.
     157 */
     158void thread_detach(thread_id_t thread)
     159{
    139160}
    140161
Note: See TracChangeset for help on using the changeset viewer.