Created
April 10, 2021 23:20
-
-
Save tiborvass/9887cf0ae3f96cbd39436028f293768c to your computer and use it in GitHub Desktop.
go run csignal.go & sleep 1; kill -USR1 %%
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
#include <stdio.h> | |
#include <signal.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
extern double asin(double); | |
extern double acos(double); | |
static void sighandler(int signum) { | |
fprintf(stderr, "Signal caught, exiting!\n"); | |
fprintf(stderr, "acos = %lf\n", acos(3.14)); | |
fprintf(stderr, "Past Go call!\n"); | |
exit(0); | |
} | |
static void main() { | |
struct sigaction sigact; | |
sigact.sa_handler = sighandler; | |
sigemptyset(&sigact.sa_mask); | |
sigact.sa_flags = 0; | |
sigaction(SIGINT, &sigact, NULL); | |
sigaction(SIGUSR1, &sigact, NULL); | |
sigaction(SIGTERM, &sigact, NULL); | |
sigaction(SIGQUIT, &sigact, NULL); | |
sigaction(SIGPIPE, &sigact, NULL); | |
fprintf(stderr, "Loaded; waiting for SIGINT\n"); | |
acos(3.14); | |
asin(3.14); | |
sleep(0xFFFFFFFF); | |
} | |
*/ | |
import "C" | |
//export asin | |
func asin(x C.double) C.double { | |
for {} | |
return x | |
} | |
//export acos | |
func acos(x C.double) C.double { | |
return x | |
} | |
func main() { | |
C.main() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] 27268 | |
Loaded; waiting for SIGINT | |
Signal caught, exiting! | |
unexpected fault address 0xfffffffffffffff8 | |
fatal: morestack on g0 | |
SIGTRAP: trace trap | |
PC=0x45ce02 m=0 sigcode=128 | |
signal arrived during cgo execution | |
goroutine 1 [running, locked to thread]: | |
runtime.abort() | |
/usr/local/go/src/runtime/asm_amd64.s:854 +0x2 fp=0xc00004a750 sp=0xc00004a748 pc=0x45ce02 | |
runtime.morestack() | |
/usr/local/go/src/runtime/asm_amd64.s:425 +0x25 fp=0xc00004a758 sp=0xc00004a750 pc=0x45b2c5 | |
rax 0x17 | |
rbx 0x6d8840 | |
rcx 0x45e675 | |
rdx 0x17 | |
rdi 0x2 | |
rsi 0x47d19a | |
rbp 0xc00004a720 | |
rsp 0xc00004a748 | |
r8 0x1 | |
r9 0x706280 | |
r10 0x0 | |
r11 0x202 | |
r12 0xf2 | |
r13 0x0 | |
r14 0x48fd98 | |
r15 0x0 | |
rip 0x45ce02 | |
rflags 0x206 | |
cs 0x33 | |
fs 0x0 | |
gs 0x0 | |
exit status 2 | |
[1]+ Exit 1 go run test.go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment