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> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void | 85 void |
86 x_cgo_init(G *g, void (*setg)(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 setg_gcc = setg; | 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->stacklo = (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(); |
103 } | 103 } |
104 sys_pthread_create = dlsym(handle, "pthread_create"); | 104 sys_pthread_create = dlsym(handle, "pthread_create"); |
105 if(sys_pthread_create == NULL) { | 105 if(sys_pthread_create == NULL) { |
(...skipping 14 matching lines...) Expand all Loading... |
120 pthread_t p; | 120 pthread_t p; |
121 size_t size; | 121 size_t size; |
122 int err; | 122 int err; |
123 | 123 |
124 sigfillset(&ign); | 124 sigfillset(&ign); |
125 pthread_sigmask(SIG_SETMASK, &ign, &oset); | 125 pthread_sigmask(SIG_SETMASK, &ign, &oset); |
126 | 126 |
127 pthread_attr_init(&attr); | 127 pthread_attr_init(&attr); |
128 pthread_attr_getstacksize(&attr, &size); | 128 pthread_attr_getstacksize(&attr, &size); |
129 | 129 |
130 » ts->g->stackguard = size; | 130 » // Leave stacklo=0 and set stackhi=size; mstack will do the rest. |
| 131 » ts->g->stackhi = size; |
131 err = sys_pthread_create(&p, &attr, threadentry, ts); | 132 err = sys_pthread_create(&p, &attr, threadentry, ts); |
132 | 133 |
133 pthread_sigmask(SIG_SETMASK, &oset, nil); | 134 pthread_sigmask(SIG_SETMASK, &oset, nil); |
134 | 135 |
135 if (err != 0) { | 136 if (err != 0) { |
136 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); | 137 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); |
137 abort(); | 138 abort(); |
138 } | 139 } |
139 } | 140 } |
140 | 141 |
141 static void* | 142 static void* |
142 threadentry(void *v) | 143 threadentry(void *v) |
143 { | 144 { |
144 ThreadStart ts; | 145 ThreadStart ts; |
145 | 146 |
146 tcb_fixup(0); | 147 tcb_fixup(0); |
147 | 148 |
148 ts = *(ThreadStart*)v; | 149 ts = *(ThreadStart*)v; |
149 free(v); | 150 free(v); |
150 | 151 |
151 ts.g->stackbase = (uintptr)&ts; | |
152 | |
153 /* | |
154 * _cgo_sys_thread_start set stackguard to stack size; | |
155 * change to actual guard pointer. | |
156 */ | |
157 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096; | |
158 | |
159 /* | 152 /* |
160 * Set specific keys. | 153 * Set specific keys. |
161 */ | 154 */ |
162 setg_gcc((void*)ts.g); | 155 setg_gcc((void*)ts.g); |
163 | 156 |
164 crosscall_amd64(ts.fn); | 157 crosscall_amd64(ts.fn); |
165 return nil; | 158 return nil; |
166 } | 159 } |
OLD | NEW |