Skip to content

Commit 224f05b

Browse files
committed
runtime: darwin signal masking
Fixes #3101 (darwin). R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5693044
1 parent 240b1d5 commit 224f05b

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/pkg/runtime/os_darwin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ uint32 runtime·mach_thread_self(void);
2020
uint32 runtime·mach_thread_self(void);
2121
int32 runtime·sysctl(uint32*, uint32, byte*, uintptr*, byte*, uintptr);
2222

23+
typedef uint32 Sigset;
24+
void runtime·sigprocmask(int32, Sigset*, Sigset*);
25+
2326
struct Sigaction;
2427
void runtime·sigaction(uintptr, struct Sigaction*, struct Sigaction*);
2528
void runtime·setsig(int32, void(*)(int32, Siginfo*, void*, G*), bool);
@@ -35,3 +38,4 @@ void runtime·raisesigpipe(void);
3538

3639
#define NSIG 32
3740
#define SI_USER 0 /* empirically true, but not what headers say */
41+
#define SIG_SETMASK 3

src/pkg/runtime/sys_darwin_386.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ TEXT runtime·nanotime(SB), 7, $32
106106
MOVL DX, 4(DI)
107107
RET
108108

109+
TEXT runtime·sigprocmask(SB),7,$0
110+
MOVL $48, AX
111+
INT $0x80
112+
JAE 2(PC)
113+
CALL runtime·notok(SB)
114+
RET
115+
109116
TEXT runtime·sigaction(SB),7,$0
110117
MOVL $46, AX
111118
INT $0x80

src/pkg/runtime/sys_darwin_amd64.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ TEXT runtime·nanotime(SB), 7, $32
9292
ADDQ DX, AX
9393
RET
9494

95+
TEXT runtime·sigprocmask(SB),7,$0
96+
MOVL 8(SP), DI
97+
MOVQ 16(SP), SI
98+
MOVQ 24(SP), DX
99+
MOVL $(0x2000000+48), AX // syscall entry
100+
SYSCALL
101+
JCC 2(PC)
102+
CALL runtime·notok(SB)
103+
RET
104+
95105
TEXT runtime·sigaction(SB),7,$0
96106
MOVL 8(SP), DI // arg 1 sig
97107
MOVQ 16(SP), SI // arg 2 act

src/pkg/runtime/thread_darwin.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
extern SigTab runtime·sigtab[];
1111

12+
static Sigset sigset_all = ~(Sigset)0;
13+
static Sigset sigset_none;
14+
1215
static void
1316
unimplemented(int8 *name)
1417
{
@@ -70,13 +73,19 @@ void
7073
runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
7174
{
7275
int32 errno;
76+
Sigset oset;
7377

7478
m->tls[0] = m->id; // so 386 asm can find it
7579
if(0){
7680
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
7781
stk, m, g, fn, m->id, m->tls[0], &m);
7882
}
79-
if((errno = runtime·bsdthread_create(stk, m, g, fn)) < 0) {
83+
84+
runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
85+
errno = runtime·bsdthread_create(stk, m, g, fn);
86+
runtime·sigprocmask(SIG_SETMASK, &oset, nil);
87+
88+
if(errno < 0) {
8089
runtime·printf("runtime: failed to create new OS thread (have %d already; errno=%d)\n", runtime·mcount(), -errno);
8190
runtime·throw("runtime.newosproc");
8291
}
@@ -89,6 +98,7 @@ runtime·minit(void)
8998
// Initialize signal handling.
9099
m->gsignal = runtime·malg(32*1024); // OS X wants >=8K, Linux >=2K
91100
runtime·signalstack(m->gsignal->stackguard - StackGuard, 32*1024);
101+
runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
92102
}
93103

94104
// Mach IPC, to get at semaphores

0 commit comments

Comments
 (0)