Commit 16d1a8e6 authored by Keith Randall's avatar Keith Randall

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 <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent ce5c3871
...@@ -86,6 +86,11 @@ func pthread_self_trampoline() pthread ...@@ -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_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_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_mmap mmap "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_munmap munmap "/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" //go:cgo_import_dynamic libc_madvise madvise "/usr/lib/libSystem.B.dylib"
......
...@@ -29,35 +29,67 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-4 ...@@ -29,35 +29,67 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-4
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
RET RET
TEXT runtime·open(SB),NOSPLIT,$0 TEXT runtime·open(SB),NOSPLIT,$0-16
MOVL $5, AX MOVL name+0(FP), AX // arg 1 name
INT $0x80 MOVL mode+4(FP), CX // arg 2 mode
JAE 2(PC) MOVL perm+8(FP), DX // arg 3 perm
MOVL $-1, AX 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) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·closefd(SB),NOSPLIT,$0 TEXT runtime·closefd(SB),NOSPLIT,$0-8
MOVL $6, AX MOVL fd+0(FP), AX // arg 1 fd
INT $0x80 PUSHL BP
JAE 2(PC) MOVL SP, BP
MOVL $-1, AX SUBL $4, SP
ANDL $~15, SP
MOVL AX, 0(SP)
CALL libc_close(SB)
MOVL BP, SP
POPL BP
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$0 TEXT runtime·read(SB),NOSPLIT,$0-16
MOVL $3, AX MOVL fd+0(FP), AX // arg 1 fd
INT $0x80 MOVL p+4(FP), CX // arg 2 buf
JAE 2(PC) MOVL n+8(FP), DX // arg 3 count
MOVL $-1, AX 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) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$0 TEXT runtime·write(SB),NOSPLIT,$0-16
MOVL $4, AX MOVL fd+0(FP), AX // arg 1 fd
INT $0x80 MOVL p+4(FP), CX // arg 2 buf
JAE 2(PC) MOVL n+8(FP), DX // arg 3 count
MOVL $-1, AX 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) MOVL AX, ret+12(FP)
RET RET
......
...@@ -32,45 +32,53 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-8 ...@@ -32,45 +32,53 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-8
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
RET RET
TEXT runtime·open(SB),NOSPLIT,$0 TEXT runtime·open(SB),NOSPLIT,$0-20
MOVQ name+0(FP), DI // arg 1 pathname MOVQ name+0(FP), DI // arg 1 pathname
MOVL mode+8(FP), SI // arg 2 flags MOVL mode+8(FP), SI // arg 2 flags
MOVL perm+12(FP), DX // arg 3 mode MOVL perm+12(FP), DX // arg 3 mode
MOVL $(0x2000000+5), AX // syscall entry PUSHQ BP
SYSCALL MOVQ SP, BP
JCC 2(PC) ANDQ $~15, SP // align stack
MOVL $-1, AX CALL libc_open(SB)
MOVQ BP, SP
POPQ BP
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
TEXT runtime·closefd(SB),NOSPLIT,$0 TEXT runtime·closefd(SB),NOSPLIT,$0-12
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVL $(0x2000000+6), AX // syscall entry PUSHQ BP
SYSCALL MOVQ SP, BP
JCC 2(PC) ANDQ $~15, SP // align stack
MOVL $-1, AX CALL libc_close(SB)
MOVQ BP, SP
POPQ BP
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$0 TEXT runtime·read(SB),NOSPLIT,$0-28
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVQ p+8(FP), SI // arg 2 buf MOVQ p+8(FP), SI // arg 2 buf
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $(0x2000000+3), AX // syscall entry PUSHQ BP
SYSCALL MOVQ SP, BP
JCC 2(PC) ANDQ $~15, SP // align stack
MOVL $-1, AX CALL libc_read(SB)
MOVQ BP, SP
POPQ BP
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$0 TEXT runtime·write(SB),NOSPLIT,$0-28
MOVQ fd+0(FP), DI // arg 1 fd MOVQ fd+0(FP), DI // arg 1 fd
MOVQ p+8(FP), SI // arg 2 buf MOVQ p+8(FP), SI // arg 2 buf
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $(0x2000000+4), AX // syscall entry PUSHQ BP
SYSCALL MOVQ SP, BP
JCC 2(PC) ANDQ $~15, SP // align stack
MOVL $-1, AX CALL libc_write(SB)
MOVQ BP, SP
POPQ BP
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment