From ca9128f18fe75878ba2d5e0df09ae755c085f72a Mon Sep 17 00:00:00 2001 From: Srdjan Petrovic Date: Fri, 17 Apr 2015 17:27:07 -0700 Subject: runtime: merge clone0 and clone We initially added clone0 to handle the case when G or M don't exist, but it turns out that we could have just modified clone. (It also helps that the function we're invoking in clone0 no longer needs arguments.) As a side-effect, newosproc0 is now supported on all linux archs. Change-Id: Ie603af75d8f164310fc16446052d83743961f3ca Reviewed-on: https://go-review.googlesource.com/9164 Reviewed-by: David Crawshaw --- src/runtime/sys_linux_amd64.s | 47 +++++++++++++------------------------------ 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'src/runtime/sys_linux_amd64.s') diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index 43a65b7ccd..3a0c47fb63 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -302,14 +302,16 @@ TEXT runtime·futex(SB),NOSPLIT,$0 // int32 clone(int32 flags, void *stack, M *mp, G *gp, void (*fn)(void)); TEXT runtime·clone(SB),NOSPLIT,$0 - MOVL flags+8(SP), DI - MOVQ stack+16(SP), SI + MOVL flags+0(FP), DI + MOVQ stack+8(FP), SI + MOVQ $0, DX + MOVQ $0, R10 // Copy mp, gp, fn off parent stack for use by child. // Careful: Linux system call clobbers CX and R11. - MOVQ mm+24(SP), R8 - MOVQ gg+32(SP), R9 - MOVQ fn+40(SP), R12 + MOVQ mp+16(FP), R8 + MOVQ gp+24(FP), R9 + MOVQ fn+32(FP), R12 MOVL $56, AX SYSCALL @@ -323,6 +325,12 @@ TEXT runtime·clone(SB),NOSPLIT,$0 // In child, on new stack. MOVQ SI, SP + // If g or m are nil, skip Go-related setup. + CMPQ R8, $0 // m + JEQ nog + CMPQ R9, $0 // g + JEQ nog + // Initialize m->procid to Linux tid MOVL $186, AX // gettid SYSCALL @@ -338,6 +346,7 @@ TEXT runtime·clone(SB),NOSPLIT,$0 MOVQ R9, g(CX) CALL runtime·stackcheck(SB) +nog: // Call fn CALL R12 @@ -347,34 +356,6 @@ TEXT runtime·clone(SB),NOSPLIT,$0 SYSCALL JMP -3(PC) // keep exiting -// int32 clone0(int32 flags, void *stack, void* fn, void* fnarg); -TEXT runtime·clone0(SB),NOSPLIT,$16-36 - MOVL flags+0(FP), DI - MOVQ stack+8(FP), SI - MOVQ fn+16(FP), R12 // used by the child - MOVQ fnarg+24(FP), R13 // used by the child - MOVL $0, DX - MOVL $0, R10 - MOVL $56, AX - SYSCALL - - CMPQ AX, $0 - JEQ child - // In parent, return. - MOVL AX, ret+32(FP) - RET -child: - MOVQ SI, SP - MOVQ R12, AX // fn - MOVQ R13, DI // fnarg - CALL AX - - // fn shouldn't return; if it does, exit. - MOVL $111, DI - MOVL $60, AX - SYSCALL - JMP -3(PC) // keep exiting - TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 MOVQ new+8(SP), DI MOVQ old+16(SP), SI -- cgit v1.3-5-g9baa