Commit ce5c3871 authored by Keith Randall's avatar Keith Randall

runtime: move more syscalls to libc on Darwin

Moving mmap, munmap, madvise, usleep.

Also introduce __error function to get at libc's errno variable.

Change-Id: Ic47ac1d9eb71c64ba2668ce304644dd7e5bdfb5a
Reviewed-on: https://go-review.googlesource.com/110437
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 6658219b
...@@ -86,6 +86,12 @@ func pthread_self_trampoline() pthread ...@@ -86,6 +86,12 @@ 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_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"
//go:cgo_import_dynamic libc_error __error "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_usleep usleep "/usr/lib/libSystem.B.dylib"
// Magic incantation to get libSystem actually dynamically linked. // Magic incantation to get libSystem actually dynamically linked.
// TODO: Why does the code require this? See cmd/compile/internal/ld/go.go:210 // TODO: Why does the code require this? See cmd/compile/internal/ld/go.go:210
//go:cgo_import_dynamic _ _ "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic _ _ "/usr/lib/libSystem.B.dylib"
...@@ -72,29 +72,69 @@ TEXT runtime·raiseproc(SB),NOSPLIT,$16 ...@@ -72,29 +72,69 @@ TEXT runtime·raiseproc(SB),NOSPLIT,$16
INT $0x80 INT $0x80
RET RET
TEXT runtime·mmap(SB),NOSPLIT,$0 TEXT runtime·mmap(SB),NOSPLIT,$0-32
MOVL $197, AX MOVL addr+0(FP), AX // arg 1 addr
INT $0x80 MOVL n+4(FP), CX // arg 2 len
JAE ok MOVL prot+8(FP), DX // arg 3 prot
MOVL $0, p+24(FP) MOVL flags+12(FP), BX // arg 4 flags
MOVL AX, err+28(FP) MOVL fd+16(FP), DI // arg 5 fid
RET MOVL off+20(FP), SI // arg 6 offset
PUSHL BP
MOVL SP, BP
SUBL $24, SP
ANDL $~15, SP
MOVL AX, 0(SP)
MOVL CX, 4(SP)
MOVL DX, 8(SP)
MOVL BX, 12(SP)
MOVL DI, 16(SP)
MOVL SI, 20(SP)
CALL libc_mmap(SB)
XORL DX, DX
CMPL AX, $-1
JNE ok
CALL libc_error(SB)
MOVL (AX), DX // errno
XORL AX, AX
ok: ok:
MOVL BP, SP
POPL BP
MOVL AX, p+24(FP) MOVL AX, p+24(FP)
MOVL $0, err+28(FP) MOVL DX, err+28(FP)
RET RET
TEXT runtime·madvise(SB),NOSPLIT,$0 TEXT runtime·madvise(SB),NOSPLIT,$0-12
MOVL $75, AX MOVL addr+0(FP), AX // arg 1 addr
INT $0x80 MOVL n+4(FP), CX // arg 2 len
MOVL flags+8(FP), DX // arg 3 advice
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_madvise(SB)
// ignore failure - maybe pages are locked // ignore failure - maybe pages are locked
MOVL BP, SP
POPL BP
RET RET
TEXT runtime·munmap(SB),NOSPLIT,$0 TEXT runtime·munmap(SB),NOSPLIT,$0-8
MOVL $73, AX MOVL addr+0(FP), AX // arg 1 addr
INT $0x80 MOVL n+4(FP), CX // arg 2 len
JAE 2(PC) PUSHL BP
MOVL SP, BP
SUBL $8, SP
ANDL $~15, SP
MOVL AX, 0(SP)
MOVL CX, 4(SP)
CALL libc_munmap(SB)
TESTL AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
MOVL BP, SP
POPL BP
RET RET
TEXT runtime·setitimer(SB),NOSPLIT,$0 TEXT runtime·setitimer(SB),NOSPLIT,$0
...@@ -322,24 +362,16 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$0 ...@@ -322,24 +362,16 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$0
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
RET RET
TEXT runtime·usleep(SB),NOSPLIT,$32 TEXT runtime·usleep(SB),NOSPLIT,$0-4
MOVL $0, DX
MOVL usec+0(FP), AX MOVL usec+0(FP), AX
MOVL $1000000, CX PUSHL BP
DIVL CX MOVL SP, BP
MOVL AX, 24(SP) // sec SUBL $4, SP
MOVL DX, 28(SP) // usec ANDL $~15, SP
MOVL AX, 0(SP)
// select(0, 0, 0, 0, &tv) CALL libc_usleep(SB)
MOVL $0, 0(SP) // "return PC" - ignored MOVL BP, SP
MOVL $0, 4(SP) POPL BP
MOVL $0, 8(SP)
MOVL $0, 12(SP)
MOVL $0, 16(SP)
LEAL 24(SP), AX
MOVL AX, 20(SP)
MOVL $93, AX
INT $0x80
RET RET
// Invoke Mach system call. // Invoke Mach system call.
......
...@@ -92,13 +92,17 @@ TEXT runtime·setitimer(SB), NOSPLIT, $0 ...@@ -92,13 +92,17 @@ TEXT runtime·setitimer(SB), NOSPLIT, $0
SYSCALL SYSCALL
RET RET
TEXT runtime·madvise(SB), NOSPLIT, $0 TEXT runtime·madvise(SB), NOSPLIT, $0-20
MOVQ addr+0(FP), DI // arg 1 addr MOVQ addr+0(FP), DI // arg 1 addr
MOVQ n+8(FP), SI // arg 2 len MOVQ n+8(FP), SI // arg 2 len
MOVL flags+16(FP), DX // arg 3 advice MOVL flags+16(FP), DX // arg 3 advice
MOVL $(0x2000000+75), AX // syscall entry madvise PUSHQ BP
SYSCALL MOVQ SP, BP
ANDQ $~15, SP
CALL libc_madvise(SB)
// ignore failure - maybe pages are locked // ignore failure - maybe pages are locked
MOVQ BP, SP
POPQ BP
RET RET
// OS X comm page time offsets // OS X comm page time offsets
...@@ -345,31 +349,42 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$40 ...@@ -345,31 +349,42 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$40
SYSCALL SYSCALL
INT $3 // not reached INT $3 // not reached
TEXT runtime·mmap(SB),NOSPLIT,$0 TEXT runtime·mmap(SB),NOSPLIT,$0-48
MOVQ addr+0(FP), DI // arg 1 addr MOVQ addr+0(FP), DI // arg 1 addr
MOVQ n+8(FP), SI // arg 2 len MOVQ n+8(FP), SI // arg 2 len
MOVL prot+16(FP), DX // arg 3 prot MOVL prot+16(FP), DX // arg 3 prot
MOVL flags+20(FP), R10 // arg 4 flags MOVL flags+20(FP), CX // arg 4 flags
MOVL fd+24(FP), R8 // arg 5 fid MOVL fd+24(FP), R8 // arg 5 fid
MOVL off+28(FP), R9 // arg 6 offset MOVL off+28(FP), R9 // arg 6 offset
MOVL $(0x2000000+197), AX // syscall entry PUSHQ BP
SYSCALL MOVQ SP, BP
JCC ok ANDQ $~15, SP
MOVQ $0, p+32(FP) CALL libc_mmap(SB)
MOVQ AX, err+40(FP) XORL DX, DX
RET CMPQ AX, $-1
JNE ok
CALL libc_error(SB)
MOVQ (AX), DX // errno
XORL AX, AX
ok: ok:
MOVQ BP, SP
POPQ BP
MOVQ AX, p+32(FP) MOVQ AX, p+32(FP)
MOVQ $0, err+40(FP) MOVQ DX, err+40(FP)
RET RET
TEXT runtime·munmap(SB),NOSPLIT,$0 TEXT runtime·munmap(SB),NOSPLIT,$0-16
MOVQ addr+0(FP), DI // arg 1 addr MOVQ addr+0(FP), DI // arg 1 addr
MOVQ n+8(FP), SI // arg 2 len MOVQ n+8(FP), SI // arg 2 len
MOVL $(0x2000000+73), AX // syscall entry PUSHQ BP
SYSCALL MOVQ SP, BP
JCC 2(PC) ANDQ $~15, SP
CALL libc_munmap(SB)
TESTQ AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
MOVQ BP, SP
POPQ BP
RET RET
TEXT runtime·sigaltstack(SB),NOSPLIT,$0 TEXT runtime·sigaltstack(SB),NOSPLIT,$0
...@@ -381,22 +396,14 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$0 ...@@ -381,22 +396,14 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$0
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
RET RET
TEXT runtime·usleep(SB),NOSPLIT,$16 TEXT runtime·usleep(SB),NOSPLIT,$0-4
MOVL $0, DX MOVL usec+0(FP), DI
MOVL usec+0(FP), AX PUSHQ BP
MOVL $1000000, CX MOVQ SP, BP
DIVL CX ANDQ $~15, SP
MOVQ AX, 0(SP) // sec CALL libc_usleep(SB)
MOVL DX, 8(SP) // usec MOVQ BP, SP
POPQ BP
// select(0, 0, 0, 0, &tv)
MOVL $0, DI
MOVL $0, SI
MOVL $0, DX
MOVL $0, R10
MOVQ SP, R8
MOVL $(0x2000000+93), AX
SYSCALL
RET RET
// Mach system calls use 0x1000000 instead of the BSD's 0x2000000. // Mach system calls use 0x1000000 instead of the BSD's 0x2000000.
......
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