LEFT | RIGHT |
(no file at all) | |
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 <signal.h> | 7 #include <signal.h> |
8 #include "libcgo.h" | 8 #include "libcgo.h" |
9 | 9 |
10 static void *threadentry(void*); | 10 static void *threadentry(void*); |
11 | 11 |
12 static void (*setmg_gcc)(void*, void*); | 12 static void (*setg_gcc)(void*); |
13 | 13 |
14 void | 14 void |
15 x_cgo_init(G *g, void (*setmg)(void*, void*)) | 15 x_cgo_init(G *g, void (*setg)(void*)) |
16 { | 16 { |
17 pthread_attr_t attr; | 17 pthread_attr_t attr; |
18 size_t size; | 18 size_t size; |
19 | 19 |
20 » setmg_gcc = setmg; | 20 » setg_gcc = setg; |
21 pthread_attr_init(&attr); | 21 pthread_attr_init(&attr); |
22 pthread_attr_getstacksize(&attr, &size); | 22 pthread_attr_getstacksize(&attr, &size); |
23 g->stackguard = (uintptr)&attr - size + 4096; | 23 g->stackguard = (uintptr)&attr - size + 4096; |
24 pthread_attr_destroy(&attr); | 24 pthread_attr_destroy(&attr); |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 void | 28 void |
29 _cgo_sys_thread_start(ThreadStart *ts) | 29 _cgo_sys_thread_start(ThreadStart *ts) |
30 { | 30 { |
(...skipping 17 matching lines...) Expand all Loading... |
48 err = pthread_create(&p, &attr, threadentry, ts); | 48 err = pthread_create(&p, &attr, threadentry, ts); |
49 | 49 |
50 pthread_sigmask(SIG_SETMASK, &oset, nil); | 50 pthread_sigmask(SIG_SETMASK, &oset, nil); |
51 | 51 |
52 if (err != 0) { | 52 if (err != 0) { |
53 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); | 53 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); |
54 abort(); | 54 abort(); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), vo
id*, void*); | 58 extern void crosscall_arm1(void (*fn)(void), void (*setg_gcc)(void*), void *g); |
59 static void* | 59 static void* |
60 threadentry(void *v) | 60 threadentry(void *v) |
61 { | 61 { |
62 ThreadStart ts; | 62 ThreadStart ts; |
63 | 63 |
64 ts = *(ThreadStart*)v; | 64 ts = *(ThreadStart*)v; |
65 free(v); | 65 free(v); |
66 | 66 |
67 ts.g->stackbase = (uintptr)&ts; | 67 ts.g->stackbase = (uintptr)&ts; |
68 | 68 |
69 /* | 69 /* |
70 * _cgo_sys_thread_start set stackguard to stack size; | 70 * _cgo_sys_thread_start set stackguard to stack size; |
71 * change to actual guard pointer. | 71 * change to actual guard pointer. |
72 */ | 72 */ |
73 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; | 73 ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; |
74 | 74 |
75 » crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); | 75 » crosscall_arm1(ts.fn, setg_gcc, (void*)ts.g); |
76 return nil; | 76 return nil; |
77 } | 77 } |
LEFT | RIGHT |