]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix exit1 arguments on Darwin
authorAustin Clements <austin@google.com>
Fri, 16 Jun 2017 13:23:45 +0000 (09:23 -0400)
committerAustin Clements <austin@google.com>
Thu, 5 Oct 2017 20:34:45 +0000 (20:34 +0000)
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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/sys_darwin_386.s
src/runtime/sys_darwin_amd64.s
src/runtime/sys_darwin_arm.s
src/runtime/sys_darwin_arm64.s

index 5c62bfd20e4adcc1d68a198c166a075f5f0f7e8e..dc4516dbdd043074322598a1c5ea7f8a2a2459ca 100644 (file)
@@ -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)
index e8ae6fac4f4242909c1310354ced3df53c825215..16125b0d4f6c503b5b75b27fb9873586132a71ec 100644 (file)
@@ -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
index 5def7766b02d263752e16b2cea37ba27e2b442d8..d59a3aaa4dc191a68e7fb586eb804e7b3422a216 100644 (file)
@@ -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
index 34fb1f30861509cf0858889951b63e362553c865..513f1284ef7fb6141cc01c6b94b1207227533fed 100644 (file)
@@ -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