Commit cb309173 authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime/cgo: mark callback functions as NOSPLIT

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/14448044
parent 0965459b
...@@ -8,6 +8,7 @@ package cgotest ...@@ -8,6 +8,7 @@ package cgotest
void callback(void *f); void callback(void *f);
void callGoFoo(void); void callGoFoo(void);
void callGoStackCheck(void); void callGoStackCheck(void);
void callPanic(void);
*/ */
import "C" import "C"
...@@ -186,6 +187,19 @@ func testCallbackCallers(t *testing.T) { ...@@ -186,6 +187,19 @@ func testCallbackCallers(t *testing.T) {
} }
} }
func testPanicFromC(t *testing.T) {
defer func() {
r := recover()
if r == nil {
t.Fatal("did not panic")
}
if r.(string) != "panic from C" {
t.Fatal("wrong panic:", r)
}
}()
C.callPanic()
}
func testCallbackStack(t *testing.T) { func testCallbackStack(t *testing.T) {
// Make cgo call and callback with different amount of stack stack available. // Make cgo call and callback with different amount of stack stack available.
// We do not do any explicit checks, just ensure that it does not crash. // We do not do any explicit checks, just ensure that it does not crash.
......
...@@ -64,3 +64,17 @@ callGoStackCheck(void) ...@@ -64,3 +64,17 @@ callGoStackCheck(void)
extern void goStackCheck(void); extern void goStackCheck(void);
goStackCheck(); goStackCheck();
} }
/* Test calling panic from C. This is what SWIG does. */
extern void crosscall2(void (*fn)(void *, int), void *, int);
extern void _cgo_panic(void *, int);
void
callPanic(void)
{
struct { const char *p; } a;
a.p = "panic from C";
crosscall2(_cgo_panic, &a, sizeof a);
*(int*)1 = 1;
}
...@@ -22,6 +22,7 @@ func TestCallbackGC(t *testing.T) { testCallbackGC(t) } ...@@ -22,6 +22,7 @@ func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) } func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) } func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) } func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
func TestPanicFromC(t *testing.T) { testPanicFromC(t) }
func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) } func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
func TestBlocking(t *testing.T) { testBlocking(t) } func TestBlocking(t *testing.T) { testBlocking(t) }
func Test1328(t *testing.T) { test1328(t) } func Test1328(t *testing.T) { test1328(t) }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../runtime.h" #include "../runtime.h"
#include "../cgocall.h" #include "../cgocall.h"
#include "../../../cmd/ld/textflag.h"
// These utility functions are available to be called from code // These utility functions are available to be called from code
// compiled with gcc via crosscall2. // compiled with gcc via crosscall2.
...@@ -47,6 +48,7 @@ _cgo_allocate_internal(uintptr len, byte *ret) ...@@ -47,6 +48,7 @@ _cgo_allocate_internal(uintptr len, byte *ret)
#pragma cgo_export_static _cgo_allocate #pragma cgo_export_static _cgo_allocate
#pragma cgo_export_dynamic _cgo_allocate #pragma cgo_export_dynamic _cgo_allocate
#pragma textflag NOSPLIT
void void
_cgo_allocate(void *a, int32 n) _cgo_allocate(void *a, int32 n)
{ {
...@@ -76,6 +78,7 @@ _cgo_panic_internal(byte *p) ...@@ -76,6 +78,7 @@ _cgo_panic_internal(byte *p)
#pragma cgo_export_static _cgo_panic #pragma cgo_export_static _cgo_panic
#pragma cgo_export_dynamic _cgo_panic #pragma cgo_export_dynamic _cgo_panic
#pragma textflag NOSPLIT
void void
_cgo_panic(void *a, int32 n) _cgo_panic(void *a, int32 n)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment