From 16d1a8e6e3701a8ed2e9b16f7c9b8e70a7b1fc8d Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 30 Apr 2018 19:55:41 -0700 Subject: [PATCH] runtime: move open/close/read/write from syscall to libc on Darwin Update #17490 Change-Id: Ia0bb0ba10dc0bbb299290a60b8228275d55125d7 Reviewed-on: https://go-review.googlesource.com/110438 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/sys_darwin.go | 5 +++ src/runtime/sys_darwin_386.s | 72 ++++++++++++++++++++++++---------- src/runtime/sys_darwin_amd64.s | 48 +++++++++++++---------- 3 files changed, 85 insertions(+), 40 deletions(-) diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go index e2789207677..6af52cbab32 100644 --- a/src/runtime/sys_darwin.go +++ b/src/runtime/sys_darwin.go @@ -86,6 +86,11 @@ func pthread_self_trampoline() pthread //go:cgo_import_dynamic libc_pthread_kill pthread_kill "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_pthread_self pthread_self "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_open open "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib" +//go:cgo_import_dynamic libc_write write "/usr/lib/libSystem.B.dylib" + //go:cgo_import_dynamic libc_mmap mmap "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_munmap munmap "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_madvise madvise "/usr/lib/libSystem.B.dylib" diff --git a/src/runtime/sys_darwin_386.s b/src/runtime/sys_darwin_386.s index 8dc4efc631b..ea6116eb0aa 100644 --- a/src/runtime/sys_darwin_386.s +++ b/src/runtime/sys_darwin_386.s @@ -29,35 +29,67 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-4 MOVL $0xf1, 0xf1 // crash RET -TEXT runtime·open(SB),NOSPLIT,$0 - MOVL $5, AX - INT $0x80 - JAE 2(PC) - MOVL $-1, AX +TEXT runtime·open(SB),NOSPLIT,$0-16 + MOVL name+0(FP), AX // arg 1 name + MOVL mode+4(FP), CX // arg 2 mode + MOVL perm+8(FP), DX // arg 3 perm + PUSHL BP + MOVL SP, BP + SUBL $12, SP + ANDL $~15, SP + MOVL AX, 0(SP) + MOVL CX, 4(SP) + MOVL DX, 8(SP) + CALL libc_open(SB) + MOVL BP, SP + POPL BP MOVL AX, ret+12(FP) RET -TEXT runtime·closefd(SB),NOSPLIT,$0 - MOVL $6, AX - INT $0x80 - JAE 2(PC) - MOVL $-1, AX +TEXT runtime·closefd(SB),NOSPLIT,$0-8 + MOVL fd+0(FP), AX // arg 1 fd + PUSHL BP + MOVL SP, BP + SUBL $4, SP + ANDL $~15, SP + MOVL AX, 0(SP) + CALL libc_close(SB) + MOVL BP, SP + POPL BP MOVL AX, ret+4(FP) RET -TEXT runtime·read(SB),NOSPLIT,$0 - MOVL $3, AX - INT $0x80 - JAE 2(PC) - MOVL $-1, AX +TEXT runtime·read(SB),NOSPLIT,$0-16 + MOVL fd+0(FP), AX // arg 1 fd + MOVL p+4(FP), CX // arg 2 buf + MOVL n+8(FP), DX // arg 3 count + PUSHL BP + MOVL SP, BP + SUBL $12, SP + ANDL $~15, SP + MOVL AX, 0(SP) + MOVL CX, 4(SP) + MOVL DX, 8(SP) + CALL libc_read(SB) + MOVL BP, SP + POPL BP MOVL AX, ret+12(FP) RET -TEXT runtime·write(SB),NOSPLIT,$0 - MOVL $4, AX - INT $0x80 - JAE 2(PC) - MOVL $-1, AX +TEXT runtime·write(SB),NOSPLIT,$0-16 + MOVL fd+0(FP), AX // arg 1 fd + MOVL p+4(FP), CX // arg 2 buf + MOVL n+8(FP), DX // arg 3 count + PUSHL BP + MOVL SP, BP + SUBL $12, SP + ANDL $~15, SP + MOVL AX, 0(SP) + MOVL CX, 4(SP) + MOVL DX, 8(SP) + CALL libc_write(SB) + MOVL BP, SP + POPL BP MOVL AX, ret+12(FP) RET diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s index 1fbc5c52d60..bf5a34a15e3 100644 --- a/src/runtime/sys_darwin_amd64.s +++ b/src/runtime/sys_darwin_amd64.s @@ -32,45 +32,53 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-8 MOVL $0xf1, 0xf1 // crash RET -TEXT runtime·open(SB),NOSPLIT,$0 +TEXT runtime·open(SB),NOSPLIT,$0-20 MOVQ name+0(FP), DI // arg 1 pathname MOVL mode+8(FP), SI // arg 2 flags MOVL perm+12(FP), DX // arg 3 mode - MOVL $(0x2000000+5), AX // syscall entry - SYSCALL - JCC 2(PC) - MOVL $-1, AX + PUSHQ BP + MOVQ SP, BP + ANDQ $~15, SP // align stack + CALL libc_open(SB) + MOVQ BP, SP + POPQ BP MOVL AX, ret+16(FP) RET -TEXT runtime·closefd(SB),NOSPLIT,$0 +TEXT runtime·closefd(SB),NOSPLIT,$0-12 MOVL fd+0(FP), DI // arg 1 fd - MOVL $(0x2000000+6), AX // syscall entry - SYSCALL - JCC 2(PC) - MOVL $-1, AX + PUSHQ BP + MOVQ SP, BP + ANDQ $~15, SP // align stack + CALL libc_close(SB) + MOVQ BP, SP + POPQ BP MOVL AX, ret+8(FP) RET -TEXT runtime·read(SB),NOSPLIT,$0 +TEXT runtime·read(SB),NOSPLIT,$0-28 MOVL fd+0(FP), DI // arg 1 fd MOVQ p+8(FP), SI // arg 2 buf MOVL n+16(FP), DX // arg 3 count - MOVL $(0x2000000+3), AX // syscall entry - SYSCALL - JCC 2(PC) - MOVL $-1, AX + PUSHQ BP + MOVQ SP, BP + ANDQ $~15, SP // align stack + CALL libc_read(SB) + MOVQ BP, SP + POPQ BP MOVL AX, ret+24(FP) RET -TEXT runtime·write(SB),NOSPLIT,$0 +TEXT runtime·write(SB),NOSPLIT,$0-28 MOVQ fd+0(FP), DI // arg 1 fd MOVQ p+8(FP), SI // arg 2 buf MOVL n+16(FP), DX // arg 3 count - MOVL $(0x2000000+4), AX // syscall entry - SYSCALL - JCC 2(PC) - MOVL $-1, AX + PUSHQ BP + MOVQ SP, BP + ANDQ $~15, SP // align stack + CALL libc_write(SB) + MOVQ BP, SP + POPQ BP MOVL AX, ret+24(FP) RET