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