Ticket #3883: pthread_attr_getstack_2.patch
File pthread_attr_getstack_2.patch, 5.6 KB (added by , 16 years ago) |
---|
-
src/system/kernel/thread.cpp
567 567 status = thread->user_stack_area; 568 568 kill_thread(thread->id); 569 569 } 570 attributes.stack_address = (void *)thread->user_stack_base; 570 571 } else { 571 572 thread->user_stack_base = (addr_t)attributes.stack_address; 572 573 thread->user_stack_size = attributes.stack_size; … … 2804 2805 threadID = create_thread(attributes, false); 2805 2806 2806 2807 if (threadID >= 0) 2808 { 2807 2809 user_debug_thread_created(threadID); 2810 + // Copy the attributes back to tell the user which stack_address we are 2811 + // using. 2812 + if (user_memcpy(userAttributes, &attributes, sizeof(*userAttributes)) < B_OK) 2813 + dprintf("_user_spawn_thread: error copying attributes baack to user space\n"); 2814 } 2808 2815 2809 2816 return threadID; 2810 2817 } -
src/system/libroot/posix/pthread/pthread.c
22 22 static const pthread_attr pthread_attr_default = { 23 23 PTHREAD_CREATE_JOINABLE, 24 24 B_NORMAL_PRIORITY, 25 NULL, 25 26 USER_STACK_SIZE 26 27 }; 27 28 … … 75 76 pthread_create(pthread_t *_thread, const pthread_attr_t *_attr, 76 77 void *(*startRoutine)(void*), void *arg) 77 78 { 78 const pthread_attr *attr = NULL;79 79 pthread_thread *thread; 80 80 struct thread_creation_attributes attributes; 81 81 82 82 if (_thread == NULL) 83 83 return B_BAD_VALUE; 84 84 85 if (_attr == NULL)86 attr = &pthread_attr_default;87 else88 attr = *_attr;89 90 85 thread = (pthread_thread *)malloc(sizeof(pthread_thread)); 91 86 if (thread == NULL) 92 87 return B_WOULD_BLOCK; 93 88 89 if (_attr == NULL) 90 memcpy(&thread->attr, &pthread_attr_default, sizeof(thread->attr)); 91 else 92 memcpy(&thread->attr, *_attr, sizeof(thread->attr)); 93 94 94 thread->entry = startRoutine; 95 95 thread->entry_argument = arg; 96 96 thread->exit_value = NULL; … … 100 100 thread->cleanup_handlers = NULL; 101 101 thread->flags = 0; 102 102 103 if ( attr->detach_state == PTHREAD_CREATE_DETACHED)103 if (thread->attr.detach_state == PTHREAD_CREATE_DETACHED) 104 104 thread->flags |= THREAD_DETACHED; 105 105 106 106 if (sPthreadSlot == -1) { … … 110 110 111 111 attributes.entry = pthread_thread_entry; 112 112 attributes.name = "pthread func"; 113 attributes.priority = attr->sched_priority;113 attributes.priority = thread->attr.sched_priority; 114 114 attributes.args1 = NULL; 115 115 attributes.args2 = thread; 116 116 attributes.stack_address = NULL; 117 attributes.stack_size = attr->stack_size;117 attributes.stack_size = thread->attr.stack_size; 118 118 119 119 thread->id = _kern_spawn_thread(&attributes); 120 120 if (thread->id < 0) { … … 123 123 return B_WOULD_BLOCK; 124 124 } 125 125 126 thread->attr.stack_address = attributes.stack_address; 127 126 128 resume_thread(thread->id); 127 129 *_thread = thread; 128 130 -
src/system/libroot/posix/pthread/pthread_attr.c
15 15 16 16 17 17 int 18 pthread_getattr_np(pthread_t _thread, pthread_attr_t *_attr) 19 { 20 pthread_thread *thread = (pthread_thread *)_thread; 21 pthread_attr *attr; 22 23 if (thread == NULL || _attr == NULL) 24 return B_BAD_VALUE; 25 26 attr = (pthread_attr *)malloc(sizeof(pthread_attr)); 27 if (attr == NULL) 28 return B_NO_MEMORY; 29 30 memcpy(_attr, &thread->attr, sizeof(pthread_attr_t)); 31 32 *_attr = attr; 33 34 return B_OK; 35 } 36 37 int 18 38 pthread_attr_init(pthread_attr_t *_attr) 19 39 { 20 40 pthread_attr *attr; … … 28 48 29 49 attr->detach_state = PTHREAD_CREATE_JOINABLE; 30 50 attr->sched_priority = B_NORMAL_PRIORITY; 51 attr->stack_address = NULL; 31 52 attr->stack_size = USER_STACK_SIZE; 32 53 33 54 *_attr = attr; … … 134 155 135 156 return 0; 136 157 } 158 159 int 160 pthread_attr_getstack(const pthread_attr_t *_attr, void **stackaddr, size_t *stacksize) 161 { 162 pthread_attr *attr = (pthread_attr *)_attr; 163 164 if (attr == NULL) 165 return EINVAL; 166 167 *stackaddr = attr->stack_address; 168 *stacksize = attr->stack_size; 169 170 return 0; 171 } 172 -
src/system/libroot/posix/pthread/pthread_private.h
28 28 typedef struct _pthread_attr { 29 29 int32 detach_state; 30 30 int32 sched_priority; 31 void *stack_address; 31 32 size_t stack_size; 32 33 } pthread_attr; 33 34 … … 60 61 bool cancelled; 61 62 struct pthread_key_data specific[PTHREAD_KEYS_MAX]; 62 63 struct __pthread_cleanup_handler *cleanup_handlers; 64 pthread_attr attr; 63 65 // TODO: move pthread keys in here, too 64 66 } pthread_thread; 65 67 -
headers/posix/pthread.h
229 229 int *contentionScope); 230 230 extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionScope); 231 231 232 extern int pthread_getattr_np(pthread_t _thread, pthread_attr_t *_attr); 233 234 /* [TSA TSS] */ 235 extern int pthread_attr_getstack(const pthread_attr_t *attr, 236 void **stackaddr, size_t *stacksize); 237 232 238 #if 0 /* Unimplemented attribute functions: */ 233 239 234 240 /* mandatory! */ … … 257 263 extern int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr); 258 264 259 265 /* [TSA TSS] */ 260 extern int pthread_attr_getstack(const pthread_attr_t *attr,261 void **stackaddr, size_t *stacksize);262 266 extern int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize); 263 267 264 268 #endif /* 0 */