OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <dlfcn.h> | 6 #include <dlfcn.h> |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <pthread.h> | 8 #include <pthread.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include "libcgo.h" | 11 #include "libcgo.h" |
12 | 12 |
13 static void* threadentry(void*); | 13 static void* threadentry(void*); |
14 static void (*setmg_gcc)(void*, void*); | 14 static void (*setg_gcc)(void*); |
15 | 15 |
16 // TCB_SIZE is sizeof(struct thread_control_block), | 16 // TCB_SIZE is sizeof(struct thread_control_block), |
17 // as defined in /usr/src/lib/librthread/tcb.h | 17 // as defined in /usr/src/lib/librthread/tcb.h |
18 #define TCB_SIZE (4 * sizeof(void *)) | 18 #define TCB_SIZE (4 * sizeof(void *)) |
19 #define TLS_SIZE (2 * sizeof(void *)) | 19 #define TLS_SIZE (2 * sizeof(void *)) |
20 | 20 |
21 void *__get_tcb(void); | 21 void *__get_tcb(void); |
22 void __set_tcb(void *); | 22 void __set_tcb(void *); |
23 | 23 |
24 static int (*sys_pthread_create)(pthread_t *thread, const pthread_attr_t *attr, | 24 static int (*sys_pthread_create)(pthread_t *thread, const pthread_attr_t *attr, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 errno = ENOMEM; | 76 errno = ENOMEM; |
77 return -1; | 77 return -1; |
78 } | 78 } |
79 p->func = start_routine; | 79 p->func = start_routine; |
80 p->arg = arg; | 80 p->arg = arg; |
81 | 81 |
82 return sys_pthread_create(thread, attr, thread_start_wrapper, p); | 82 return sys_pthread_create(thread, attr, thread_start_wrapper, p); |
83 } | 83 } |
84 | 84 |
85 void | 85 void |
86 x_cgo_init(G *g, void (*setmg)(void*, void*)) | 86 x_cgo_init(G *g, void (*setg)(void*)) |
87 { | 87 { |
88 pthread_attr_t attr; | 88 pthread_attr_t attr; |
89 size_t size; | 89 size_t size; |
90 void *handle; | 90 void *handle; |
91 | 91 |
92 » setmg_gcc = setmg; | 92 » setg_gcc = setg; |
93 pthread_attr_init(&attr); | 93 pthread_attr_init(&attr); |
94 pthread_attr_getstacksize(&attr, &size); | 94 pthread_attr_getstacksize(&attr, &size); |
95 g->stackguard = (uintptr)&attr - size + 4096; | 95 g->stackguard = (uintptr)&attr - size + 4096; |
96 pthread_attr_destroy(&attr); | 96 pthread_attr_destroy(&attr); |
97 | 97 |
98 // Locate symbol for the system pthread_create function. | 98 // Locate symbol for the system pthread_create function. |
99 handle = dlopen("libpthread.so", RTLD_LAZY); | 99 handle = dlopen("libpthread.so", RTLD_LAZY); |
100 if(handle == NULL) { | 100 if(handle == NULL) { |
101 fprintf(stderr, "dlopen: failed to load libpthread: %s\n", dlerr
or()); | 101 fprintf(stderr, "dlopen: failed to load libpthread: %s\n", dlerr
or()); |
102 abort(); | 102 abort(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 /* | 153 /* |
154 * _cgo_sys_thread_start set stackguard to stack size; | 154 * _cgo_sys_thread_start set stackguard to stack size; |
155 * change to actual guard pointer. | 155 * change to actual guard pointer. |
156 */ | 156 */ |
157 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096; | 157 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096; |
158 | 158 |
159 /* | 159 /* |
160 * Set specific keys. | 160 * Set specific keys. |
161 */ | 161 */ |
162 » setmg_gcc((void*)ts.m, (void*)ts.g); | 162 » setg_gcc((void*)ts.g); |
163 | 163 |
164 crosscall_amd64(ts.fn); | 164 crosscall_amd64(ts.fn); |
165 return nil; | 165 return nil; |
166 } | 166 } |
OLD | NEW |