Changes in uspace/lib/c/generic/thread.c [c0699467:e7267a2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/thread.c
rc0699467 re7267a2 39 39 #include <abi/proc/uarg.h> 40 40 #include <fibril.h> 41 #include <stack.h> 41 42 #include <str.h> 42 43 #include <async.h> 44 #include <errno.h> 45 #include <as.h> 43 46 #include "private/thread.h" 44 45 #ifndef THREAD_INITIAL_STACK_PAGES_NO46 #define THREAD_INITIAL_STACK_PAGES_NO 247 #endif48 47 49 48 /** Main thread function. … … 65 64 66 65 uarg->uspace_thread_function(uarg->uspace_thread_arg); 67 /* XXX: we cannot free the userspace stack while running on it 68 free(uarg->uspace_stack); 69 free(uarg); 70 */ 66 /* 67 * XXX: we cannot free the userspace stack while running on it 68 * 69 * free(uarg->uspace_stack); 70 * free(uarg); 71 */ 71 72 72 73 /* If there is a manager, destroy it */ … … 92 93 thread_id_t *tid) 93 94 { 94 char *stack;95 uspace_arg_t *uarg;96 i nt rc;97 98 stack = (char *) malloc(getpagesize() * THREAD_INITIAL_STACK_PAGES_NO);99 if (!stack)100 return -1;101 102 uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t));103 if ( !uarg) {104 free( stack);105 return -1;95 uspace_arg_t *uarg = 96 (uspace_arg_t *) malloc(sizeof(uspace_arg_t)); 97 if (!uarg) 98 return ENOMEM; 99 100 size_t stack_size = stack_size_get(); 101 void *stack = as_area_create(AS_AREA_ANY, stack_size, 102 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE | AS_AREA_GUARD | 103 AS_AREA_LATE_RESERVE); 104 if (stack == AS_MAP_FAILED) { 105 free(uarg); 106 return ENOMEM; 106 107 } 107 108 108 109 uarg->uspace_entry = (void *) FADDR(__thread_entry); 109 uarg->uspace_stack = (void *) stack; 110 uarg->uspace_stack = stack; 111 uarg->uspace_stack_size = stack_size; 110 112 uarg->uspace_thread_function = function; 111 113 uarg->uspace_thread_arg = arg; 112 114 uarg->uspace_uarg = uarg; 113 115 114 rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name,115 (sysarg_t) str_size(name), (sysarg_t) tid);116 int rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, 117 (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid); 116 118 117 if (rc ) {119 if (rc != EOK) { 118 120 /* 119 121 * Failed to create a new thread. 120 * Free up the allocated structures.122 * Free up the allocated data. 121 123 */ 124 as_area_destroy(stack); 122 125 free(uarg); 123 free(stack);124 126 } 125 127 126 128 return rc; 127 129 }
Note:
See TracChangeset
for help on using the changeset viewer.