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