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