From: Austin Clements Date: Fri, 16 Jun 2017 13:23:45 +0000 (-0400) Subject: runtime: fix exit1 arguments on Darwin X-Git-Tag: go1.10beta1~854 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=91121ff704b937da9268ef0a7fc71c34233bbd1d;p=gostls13.git runtime: fix exit1 arguments on Darwin exit1 calls the bsdthread_terminate system call on Darwin. Currently it passes no arguments on 386, arm, and arm64, and an exit status on amd64. None of these are right. The signature of bsdthread_terminate is: int bsdthread_terminate(user_addr_t stackaddr, size_t freesize, uint32_t port, uint32_t sem); Fix all of the Darwin exit1 implementations to call bsdthread_terminate with 0 for all of these arguments so it doesn't try to unmap some random memory, free some random port, or signal a random semaphore. This isn't a problem in practice because exit1 is never called. However, we're about to start using exit1. Change-Id: Idc534d196e3104e5253fc399553f21eb608693d7 Reviewed-on: https://go-review.googlesource.com/46036 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/runtime/sys_darwin_386.s b/src/runtime/sys_darwin_386.s index 5c62bfd20e..dc4516dbdd 100644 --- a/src/runtime/sys_darwin_386.s +++ b/src/runtime/sys_darwin_386.s @@ -19,7 +19,13 @@ TEXT runtime·exit(SB),NOSPLIT,$0 // Exit this OS thread (like pthread_exit, which eventually // calls __bsdthread_terminate). -TEXT runtime·exit1(SB),NOSPLIT,$0 +TEXT runtime·exit1(SB),NOSPLIT,$16-0 + // __bsdthread_terminate takes 4 word-size arguments. + // Set them all to 0. (None are an exit status.) + MOVL $0, 0(SP) + MOVL $0, 4(SP) + MOVL $0, 8(SP) + MOVL $0, 12(SP) MOVL $361, AX INT $0x80 JAE 2(PC) diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s index e8ae6fac4f..16125b0d4f 100644 --- a/src/runtime/sys_darwin_amd64.s +++ b/src/runtime/sys_darwin_amd64.s @@ -26,12 +26,19 @@ TEXT runtime·exit(SB),NOSPLIT,$0 // Exit this OS thread (like pthread_exit, which eventually // calls __bsdthread_terminate). TEXT runtime·exit1(SB),NOSPLIT,$0 - MOVL code+0(FP), DI // arg 1 exit status + // __bsdthread_terminate takes 4 word-size arguments. + // Set them all to 0. (None are an exit status.) + MOVL $0, DI + MOVL $0, SI + MOVL $0, DX + MOVL $0, R10 MOVL $(0x2000000+361), AX // syscall entry SYSCALL MOVL $0xf1, 0xf1 // crash RET + + TEXT runtime·open(SB),NOSPLIT,$0 MOVQ name+0(FP), DI // arg 1 pathname MOVL mode+8(FP), SI // arg 2 flags diff --git a/src/runtime/sys_darwin_arm.s b/src/runtime/sys_darwin_arm.s index 5def7766b0..d59a3aaa4d 100644 --- a/src/runtime/sys_darwin_arm.s +++ b/src/runtime/sys_darwin_arm.s @@ -90,6 +90,12 @@ TEXT runtime·exit(SB),NOSPLIT,$-4 // Exit this OS thread (like pthread_exit, which eventually // calls __bsdthread_terminate). TEXT runtime·exit1(SB),NOSPLIT,$0 + // __bsdthread_terminate takes 4 word-size arguments. + // Set them all to 0. (None are an exit status.) + MOVW $0, R0 + MOVW $0, R1 + MOVW $0, R2 + MOVW $0, R3 MOVW $SYS_bsdthread_terminate, R12 SWI $0x80 MOVW $1234, R0 diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s index 34fb1f3086..513f1284ef 100644 --- a/src/runtime/sys_darwin_arm64.s +++ b/src/runtime/sys_darwin_arm64.s @@ -90,6 +90,12 @@ TEXT runtime·exit(SB),NOSPLIT,$-8 // Exit this OS thread (like pthread_exit, which eventually // calls __bsdthread_terminate). TEXT runtime·exit1(SB),NOSPLIT,$0 + // __bsdthread_terminate takes 4 word-size arguments. + // Set them all to 0. (None are an exit status.) + MOVW $0, R0 + MOVW $0, R1 + MOVW $0, R2 + MOVW $0, R3 MOVW $SYS_bsdthread_terminate, R16 SVC $0x80 MOVD $1234, R0