OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 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 <pthread.h> | 5 #include <pthread.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include "libcgo.h" | 7 #include "libcgo.h" |
8 | 8 |
9 static void *threadentry(void*); | 9 static void *threadentry(void*); |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 pthread_attr_getstacksize(&attr, &size); | 21 pthread_attr_getstacksize(&attr, &size); |
22 g->stackguard = (uintptr)&attr - size + 4096; | 22 g->stackguard = (uintptr)&attr - size + 4096; |
23 pthread_attr_destroy(&attr); | 23 pthread_attr_destroy(&attr); |
24 } | 24 } |
25 | 25 |
26 | 26 |
27 void | 27 void |
28 _cgo_sys_thread_start(ThreadStart *ts) | 28 _cgo_sys_thread_start(ThreadStart *ts) |
29 { | 29 { |
30 pthread_attr_t attr; | 30 pthread_attr_t attr; |
| 31 sigset_t ign, oset; |
31 pthread_t p; | 32 pthread_t p; |
32 size_t size; | 33 size_t size; |
33 int err; | 34 int err; |
34 | 35 |
| 36 sigfillset(&ign); |
| 37 pthread_sigmask(SIG_SETMASK, &ign, &oset); |
| 38 |
35 // Not sure why the memset is necessary here, | 39 // Not sure why the memset is necessary here, |
36 // but without it, we get a bogus stack size | 40 // but without it, we get a bogus stack size |
37 // out of pthread_attr_getstacksize. C'est la Linux. | 41 // out of pthread_attr_getstacksize. C'est la Linux. |
38 memset(&attr, 0, sizeof attr); | 42 memset(&attr, 0, sizeof attr); |
39 pthread_attr_init(&attr); | 43 pthread_attr_init(&attr); |
40 size = 0; | 44 size = 0; |
41 pthread_attr_getstacksize(&attr, &size); | 45 pthread_attr_getstacksize(&attr, &size); |
42 ts->g->stackguard = size; | 46 ts->g->stackguard = size; |
43 err = pthread_create(&p, &attr, threadentry, ts); | 47 err = pthread_create(&p, &attr, threadentry, ts); |
| 48 |
| 49 pthread_sigmask(SIG_SETMASK, &oset, nil); |
| 50 |
44 if (err != 0) { | 51 if (err != 0) { |
45 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); | 52 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); |
46 abort(); | 53 abort(); |
47 } | 54 } |
48 } | 55 } |
49 | 56 |
50 extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), vo
id*, void*); | 57 extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), vo
id*, void*); |
51 static void* | 58 static void* |
52 threadentry(void *v) | 59 threadentry(void *v) |
53 { | 60 { |
54 ThreadStart ts; | 61 ThreadStart ts; |
55 | 62 |
56 ts = *(ThreadStart*)v; | 63 ts = *(ThreadStart*)v; |
57 free(v); | 64 free(v); |
58 | 65 |
59 ts.g->stackbase = (uintptr)&ts; | 66 ts.g->stackbase = (uintptr)&ts; |
60 | 67 |
61 /* | 68 /* |
62 * _cgo_sys_thread_start set stackguard to stack size; | 69 * _cgo_sys_thread_start set stackguard to stack size; |
63 * change to actual guard pointer. | 70 * change to actual guard pointer. |
64 */ | 71 */ |
65 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; | 72 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; |
66 | 73 |
67 crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); | 74 crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); |
68 return nil; | 75 return nil; |
69 } | 76 } |
OLD | NEW |