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