LEFT | RIGHT |
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 "runtime.h" | 5 #include "runtime.h" |
6 #include "cgocall.h" | 6 #include "cgocall.h" |
7 | 7 |
8 void *initcgo; /* filled in by dynamic linker when Cgo is available */ | 8 void *initcgo; /* filled in by dynamic linker when Cgo is available */ |
9 int64 ncgocall; | 9 int64 ncgocall; |
10 void runtime·entersyscall(void); | 10 void runtime·entersyscall(void); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 g->lockedm = nil; | 46 g->lockedm = nil; |
47 | 47 |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 // When a C function calls back into Go, the wrapper function will | 51 // When a C function calls back into Go, the wrapper function will |
52 // call this. This switches to a Go stack, copies the arguments | 52 // call this. This switches to a Go stack, copies the arguments |
53 // (arg/argsize) on to the stack, calls the function, copies the | 53 // (arg/argsize) on to the stack, calls the function, copies the |
54 // arguments back where they came from, and finally returns to the old | 54 // arguments back where they came from, and finally returns to the old |
55 // stack. | 55 // stack. |
56 | |
57 #pragma textflag 7 | |
58 uintptr | 56 uintptr |
59 runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize) | 57 runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize) |
60 { | 58 { |
61 Gobuf oldsched, oldg1sched; | 59 Gobuf oldsched, oldg1sched; |
62 G *g1; | 60 G *g1; |
63 void *sp; | 61 void *sp; |
64 uintptr ret; | 62 uintptr ret; |
65 | 63 |
66 if(g != m->g0) | 64 if(g != m->g0) |
67 runtime·throw("bad g in cgocallback"); | 65 runtime·throw("bad g in cgocallback"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 runtime·cgocall(_cgo_malloc, &a); | 110 runtime·cgocall(_cgo_malloc, &a); |
113 return a.ret; | 111 return a.ret; |
114 } | 112 } |
115 | 113 |
116 void | 114 void |
117 runtime·cfree(void *p) | 115 runtime·cfree(void *p) |
118 { | 116 { |
119 runtime·cgocall(_cgo_free, p); | 117 runtime·cgocall(_cgo_free, p); |
120 } | 118 } |
121 | 119 |
LEFT | RIGHT |