Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
cb309173
Commit
cb309173
authored
Oct 09, 2013
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runtime/cgo: mark callback functions as NOSPLIT
R=golang-dev, minux.ma CC=golang-dev
https://golang.org/cl/14448044
parent
0965459b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
0 deletions
+32
-0
misc/cgo/test/callback.go
misc/cgo/test/callback.go
+14
-0
misc/cgo/test/callback_c.c
misc/cgo/test/callback_c.c
+14
-0
misc/cgo/test/cgo_test.go
misc/cgo/test/cgo_test.go
+1
-0
src/pkg/runtime/cgo/callbacks.c
src/pkg/runtime/cgo/callbacks.c
+3
-0
No files found.
misc/cgo/test/callback.go
View file @
cb309173
...
...
@@ -8,6 +8,7 @@ package cgotest
void callback(void *f);
void callGoFoo(void);
void callGoStackCheck(void);
void callPanic(void);
*/
import
"C"
...
...
@@ -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
)
{
// 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.
...
...
misc/cgo/test/callback_c.c
View file @
cb309173
...
...
@@ -64,3 +64,17 @@ callGoStackCheck(void)
extern
void
goStackCheck
(
void
);
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
;
}
misc/cgo/test/cgo_test.go
View file @
cb309173
...
...
@@ -22,6 +22,7 @@ func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
func
TestCallbackPanic
(
t
*
testing
.
T
)
{
testCallbackPanic
(
t
)
}
func
TestCallbackPanicLoop
(
t
*
testing
.
T
)
{
testCallbackPanicLoop
(
t
)
}
func
TestCallbackPanicLocked
(
t
*
testing
.
T
)
{
testCallbackPanicLocked
(
t
)
}
func
TestPanicFromC
(
t
*
testing
.
T
)
{
testPanicFromC
(
t
)
}
func
TestZeroArgCallback
(
t
*
testing
.
T
)
{
testZeroArgCallback
(
t
)
}
func
TestBlocking
(
t
*
testing
.
T
)
{
testBlocking
(
t
)
}
func
Test1328
(
t
*
testing
.
T
)
{
test1328
(
t
)
}
...
...
src/pkg/runtime/cgo/callbacks.c
View file @
cb309173
...
...
@@ -4,6 +4,7 @@
#include "../runtime.h"
#include "../cgocall.h"
#include "../../../cmd/ld/textflag.h"
// These utility functions are available to be called from code
// compiled with gcc via crosscall2.
...
...
@@ -47,6 +48,7 @@ _cgo_allocate_internal(uintptr len, byte *ret)
#pragma cgo_export_static _cgo_allocate
#pragma cgo_export_dynamic _cgo_allocate
#pragma textflag NOSPLIT
void
_cgo_allocate
(
void
*
a
,
int32
n
)
{
...
...
@@ -76,6 +78,7 @@ _cgo_panic_internal(byte *p)
#pragma cgo_export_static _cgo_panic
#pragma cgo_export_dynamic _cgo_panic
#pragma textflag NOSPLIT
void
_cgo_panic
(
void
*
a
,
int32
n
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment