Commit f584c05f authored by Keith Randall's avatar Keith Randall

runtime: Update open/close/read/write to return -1 on error.

Error detection code copied from syscall, where presumably
we actually do it right.

Note that we throw the errno away.  The runtime doesn't use it.

Fixes #10052

Change-Id: I8de77dda6bf287276b137646c26b84fa61554ec8
Reviewed-on: https://go-review.googlesource.com/6571
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 74e88dfd
...@@ -117,3 +117,8 @@ var Gostringnocopy = gostringnocopy ...@@ -117,3 +117,8 @@ var Gostringnocopy = gostringnocopy
var Maxstring = &maxstring var Maxstring = &maxstring
type Uintreg uintreg type Uintreg uintreg
var Open = open
var Close = close
var Read = read
var Write = write
...@@ -52,3 +52,8 @@ func sigpanic() { ...@@ -52,3 +52,8 @@ func sigpanic() {
func raiseproc(sig int32) { func raiseproc(sig int32) {
} }
// Stubs so tests can link correctly. These should never be called.
func open(name *byte, mode, perm int32) int32
func close(fd int32) int32
func read(fd int32, p unsafe.Pointer, n int32) int32
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package runtime package runtime
import _ "unsafe" // for go:linkname import "unsafe"
type stdFunction *byte type stdFunction *byte
...@@ -39,3 +39,17 @@ func sigpanic() { ...@@ -39,3 +39,17 @@ func sigpanic() {
} }
throw("fault") throw("fault")
} }
// Stubs so tests can link correctly. These should never be called.
func open(name *byte, mode, perm int32) int32 {
throw("unimplemented")
return -1
}
func close(fd int32) int32 {
throw("unimplemented")
return -1
}
func read(fd int32, p unsafe.Pointer, n int32) int32 {
throw("unimplemented")
return -1
}
...@@ -292,3 +292,29 @@ func TestTrailingZero(t *testing.T) { ...@@ -292,3 +292,29 @@ func TestTrailingZero(t *testing.T) {
t.Errorf("sizeof(%#v)==%d, want 0", T5{}, unsafe.Sizeof(T5{})) t.Errorf("sizeof(%#v)==%d, want 0", T5{}, unsafe.Sizeof(T5{}))
} }
} }
func TestBadOpen(t *testing.T) {
if GOOS == "windows" || GOOS == "nacl" {
t.Skip("skipping OS that doesn't have open/read/write/close")
}
// make sure we get the correct error code if open fails. Same for
// read/write/close on the resulting -1 fd. See issue 10052.
nonfile := []byte("/notreallyafile")
fd := Open(&nonfile[0], 0, 0)
if fd != -1 {
t.Errorf("open(\"%s\")=%d, want -1", string(nonfile), fd)
}
var buf [32]byte
r := Read(-1, unsafe.Pointer(&buf[0]), int32(len(buf)))
if r != -1 {
t.Errorf("read()=%d, want -1", r)
}
w := Write(^uintptr(0), unsafe.Pointer(&buf[0]), int32(len(buf)))
if w != -1 {
t.Errorf("write()=%d, want -1", w)
}
c := Close(-1)
if c != -1 {
t.Errorf("close()=%d, want -1", c)
}
}
...@@ -29,24 +29,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$0 ...@@ -29,24 +29,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$0
TEXT runtime·open(SB),NOSPLIT,$0 TEXT runtime·open(SB),NOSPLIT,$0
MOVL $5, AX MOVL $5, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·close(SB),NOSPLIT,$0 TEXT runtime·close(SB),NOSPLIT,$0
MOVL $6, AX MOVL $6, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$0 TEXT runtime·read(SB),NOSPLIT,$0
MOVL $3, AX MOVL $3, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$0 TEXT runtime·write(SB),NOSPLIT,$0
MOVL $4, AX MOVL $4, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
......
...@@ -38,6 +38,8 @@ TEXT runtime·open(SB),NOSPLIT,$0 ...@@ -38,6 +38,8 @@ TEXT runtime·open(SB),NOSPLIT,$0
MOVL perm+12(FP), DX // arg 3 mode MOVL perm+12(FP), DX // arg 3 mode
MOVL $(0x2000000+5), AX // syscall entry MOVL $(0x2000000+5), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
...@@ -45,6 +47,8 @@ TEXT runtime·close(SB),NOSPLIT,$0 ...@@ -45,6 +47,8 @@ TEXT runtime·close(SB),NOSPLIT,$0
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVL $(0x2000000+6), AX // syscall entry MOVL $(0x2000000+6), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
...@@ -54,6 +58,8 @@ TEXT runtime·read(SB),NOSPLIT,$0 ...@@ -54,6 +58,8 @@ TEXT runtime·read(SB),NOSPLIT,$0
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $(0x2000000+3), AX // syscall entry MOVL $(0x2000000+3), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
...@@ -63,6 +69,8 @@ TEXT runtime·write(SB),NOSPLIT,$0 ...@@ -63,6 +69,8 @@ TEXT runtime·write(SB),NOSPLIT,$0
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $(0x2000000+4), AX // syscall entry MOVL $(0x2000000+4), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
......
...@@ -48,6 +48,7 @@ TEXT runtime·open(SB),NOSPLIT,$0 ...@@ -48,6 +48,7 @@ TEXT runtime·open(SB),NOSPLIT,$0
MOVW perm+8(FP), R2 MOVW perm+8(FP), R2
MOVW $SYS_open, R12 MOVW $SYS_open, R12
SWI $0x80 SWI $0x80
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -55,6 +56,7 @@ TEXT runtime·close(SB),NOSPLIT,$0 ...@@ -55,6 +56,7 @@ TEXT runtime·close(SB),NOSPLIT,$0
MOVW fd+0(FP), R0 MOVW fd+0(FP), R0
MOVW $SYS_close, R12 MOVW $SYS_close, R12
SWI $0x80 SWI $0x80
MOVW.CS $-1, R0
MOVW R0, ret+4(FP) MOVW R0, ret+4(FP)
RET RET
...@@ -64,6 +66,7 @@ TEXT runtime·write(SB),NOSPLIT,$0 ...@@ -64,6 +66,7 @@ TEXT runtime·write(SB),NOSPLIT,$0
MOVW n+8(FP), R2 MOVW n+8(FP), R2
MOVW $SYS_write, R12 MOVW $SYS_write, R12
SWI $0x80 SWI $0x80
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -73,6 +76,7 @@ TEXT runtime·read(SB),NOSPLIT,$0 ...@@ -73,6 +76,7 @@ TEXT runtime·read(SB),NOSPLIT,$0
MOVW n+8(FP), R2 MOVW n+8(FP), R2
MOVW $SYS_read, R12 MOVW $SYS_read, R12
SWI $0x80 SWI $0x80
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
......
...@@ -85,24 +85,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$16 ...@@ -85,24 +85,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$16
TEXT runtime·open(SB),NOSPLIT,$-4 TEXT runtime·open(SB),NOSPLIT,$-4
MOVL $5, AX MOVL $5, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·close(SB),NOSPLIT,$-4 TEXT runtime·close(SB),NOSPLIT,$-4
MOVL $6, AX MOVL $6, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$-4 TEXT runtime·read(SB),NOSPLIT,$-4
MOVL $3, AX MOVL $3, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$-4 TEXT runtime·write(SB),NOSPLIT,$-4
MOVL $4, AX MOVL $4, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
......
...@@ -77,6 +77,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8 ...@@ -77,6 +77,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8
MOVL perm+12(FP), DX // arg 3 mode MOVL perm+12(FP), DX // arg 3 mode
MOVL $5, AX MOVL $5, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
...@@ -84,6 +86,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8 ...@@ -84,6 +86,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVL $6, AX MOVL $6, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
...@@ -93,6 +97,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8 ...@@ -93,6 +97,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $3, AX MOVL $3, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
...@@ -102,6 +108,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8 ...@@ -102,6 +108,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $4, AX MOVL $4, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
......
...@@ -62,24 +62,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$-4 ...@@ -62,24 +62,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$-4
TEXT runtime·open(SB),NOSPLIT,$-4 TEXT runtime·open(SB),NOSPLIT,$-4
MOVL $5, AX MOVL $5, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·close(SB),NOSPLIT,$-4 TEXT runtime·close(SB),NOSPLIT,$-4
MOVL $6, AX MOVL $6, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$-4 TEXT runtime·read(SB),NOSPLIT,$-4
MOVL $3, AX MOVL $3, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$-4 TEXT runtime·write(SB),NOSPLIT,$-4
MOVL $4, AX MOVL $4, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
......
...@@ -67,6 +67,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8 ...@@ -67,6 +67,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8
MOVL perm+12(FP), DX // arg 3 mode MOVL perm+12(FP), DX // arg 3 mode
MOVL $5, AX MOVL $5, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
...@@ -74,6 +76,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8 ...@@ -74,6 +76,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVL $6, AX MOVL $6, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
...@@ -83,6 +87,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8 ...@@ -83,6 +87,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $3, AX MOVL $3, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
...@@ -92,6 +98,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8 ...@@ -92,6 +98,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $4, AX MOVL $4, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
......
...@@ -93,6 +93,7 @@ TEXT runtime·open(SB),NOSPLIT,$-8 ...@@ -93,6 +93,7 @@ TEXT runtime·open(SB),NOSPLIT,$-8
MOVW perm+8(FP), R2 // arg 3 perm MOVW perm+8(FP), R2 // arg 3 perm
MOVW $SYS_open, R7 MOVW $SYS_open, R7
SWI $0 SWI $0
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -102,6 +103,7 @@ TEXT runtime·read(SB),NOSPLIT,$-8 ...@@ -102,6 +103,7 @@ TEXT runtime·read(SB),NOSPLIT,$-8
MOVW n+8(FP), R2 // arg 3 count MOVW n+8(FP), R2 // arg 3 count
MOVW $SYS_read, R7 MOVW $SYS_read, R7
SWI $0 SWI $0
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -111,6 +113,7 @@ TEXT runtime·write(SB),NOSPLIT,$-8 ...@@ -111,6 +113,7 @@ TEXT runtime·write(SB),NOSPLIT,$-8
MOVW n+8(FP), R2 // arg 3 count MOVW n+8(FP), R2 // arg 3 count
MOVW $SYS_write, R7 MOVW $SYS_write, R7
SWI $0 SWI $0
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -118,6 +121,7 @@ TEXT runtime·close(SB),NOSPLIT,$-8 ...@@ -118,6 +121,7 @@ TEXT runtime·close(SB),NOSPLIT,$-8
MOVW fd+0(FP), R0 // arg 1 fd MOVW fd+0(FP), R0 // arg 1 fd
MOVW $SYS_close, R7 MOVW $SYS_close, R7
SWI $0 SWI $0
MOVW.CS $-1, R0
MOVW R0, ret+4(FP) MOVW R0, ret+4(FP)
RET RET
......
...@@ -30,6 +30,9 @@ TEXT runtime·open(SB),NOSPLIT,$0 ...@@ -30,6 +30,9 @@ TEXT runtime·open(SB),NOSPLIT,$0
MOVL mode+4(FP), CX MOVL mode+4(FP), CX
MOVL perm+8(FP), DX MOVL perm+8(FP), DX
CALL *runtime·_vdso(SB) CALL *runtime·_vdso(SB)
CMPL AX, $0xfffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
...@@ -37,6 +40,9 @@ TEXT runtime·close(SB),NOSPLIT,$0 ...@@ -37,6 +40,9 @@ TEXT runtime·close(SB),NOSPLIT,$0
MOVL $6, AX // syscall - close MOVL $6, AX // syscall - close
MOVL fd+0(FP), BX MOVL fd+0(FP), BX
CALL *runtime·_vdso(SB) CALL *runtime·_vdso(SB)
CMPL AX, $0xfffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
...@@ -46,6 +52,9 @@ TEXT runtime·write(SB),NOSPLIT,$0 ...@@ -46,6 +52,9 @@ TEXT runtime·write(SB),NOSPLIT,$0
MOVL p+4(FP), CX MOVL p+4(FP), CX
MOVL n+8(FP), DX MOVL n+8(FP), DX
CALL *runtime·_vdso(SB) CALL *runtime·_vdso(SB)
CMPL AX, $0xfffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
...@@ -55,6 +64,9 @@ TEXT runtime·read(SB),NOSPLIT,$0 ...@@ -55,6 +64,9 @@ TEXT runtime·read(SB),NOSPLIT,$0
MOVL p+4(FP), CX MOVL p+4(FP), CX
MOVL n+8(FP), DX MOVL n+8(FP), DX
CALL *runtime·_vdso(SB) CALL *runtime·_vdso(SB)
CMPL AX, $0xfffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
......
...@@ -28,6 +28,9 @@ TEXT runtime·open(SB),NOSPLIT,$0-20 ...@@ -28,6 +28,9 @@ TEXT runtime·open(SB),NOSPLIT,$0-20
MOVL perm+12(FP), DX MOVL perm+12(FP), DX
MOVL $2, AX // syscall entry MOVL $2, AX // syscall entry
SYSCALL SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
...@@ -35,6 +38,9 @@ TEXT runtime·close(SB),NOSPLIT,$0-12 ...@@ -35,6 +38,9 @@ TEXT runtime·close(SB),NOSPLIT,$0-12
MOVL fd+0(FP), DI MOVL fd+0(FP), DI
MOVL $3, AX // syscall entry MOVL $3, AX // syscall entry
SYSCALL SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
...@@ -44,6 +50,9 @@ TEXT runtime·write(SB),NOSPLIT,$0-28 ...@@ -44,6 +50,9 @@ TEXT runtime·write(SB),NOSPLIT,$0-28
MOVL n+16(FP), DX MOVL n+16(FP), DX
MOVL $1, AX // syscall entry MOVL $1, AX // syscall entry
SYSCALL SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
...@@ -53,6 +62,9 @@ TEXT runtime·read(SB),NOSPLIT,$0-28 ...@@ -53,6 +62,9 @@ TEXT runtime·read(SB),NOSPLIT,$0-28
MOVL n+16(FP), DX MOVL n+16(FP), DX
MOVL $0, AX // syscall entry MOVL $0, AX // syscall entry
SYSCALL SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
......
...@@ -57,6 +57,9 @@ TEXT runtime·open(SB),NOSPLIT,$0 ...@@ -57,6 +57,9 @@ TEXT runtime·open(SB),NOSPLIT,$0
MOVW perm+8(FP), R2 MOVW perm+8(FP), R2
MOVW $SYS_open, R7 MOVW $SYS_open, R7
SWI $0 SWI $0
MOVW $0xfffff001, R1
CMP R1, R0
MOVW.HI $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -64,6 +67,9 @@ TEXT runtime·close(SB),NOSPLIT,$0 ...@@ -64,6 +67,9 @@ TEXT runtime·close(SB),NOSPLIT,$0
MOVW fd+0(FP), R0 MOVW fd+0(FP), R0
MOVW $SYS_close, R7 MOVW $SYS_close, R7
SWI $0 SWI $0
MOVW $0xfffff001, R1
CMP R1, R0
MOVW.HI $-1, R0
MOVW R0, ret+4(FP) MOVW R0, ret+4(FP)
RET RET
...@@ -73,6 +79,9 @@ TEXT runtime·write(SB),NOSPLIT,$0 ...@@ -73,6 +79,9 @@ TEXT runtime·write(SB),NOSPLIT,$0
MOVW n+8(FP), R2 MOVW n+8(FP), R2
MOVW $SYS_write, R7 MOVW $SYS_write, R7
SWI $0 SWI $0
MOVW $0xfffff001, R1
CMP R1, R0
MOVW.HI $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -82,6 +91,9 @@ TEXT runtime·read(SB),NOSPLIT,$0 ...@@ -82,6 +91,9 @@ TEXT runtime·read(SB),NOSPLIT,$0
MOVW n+8(FP), R2 MOVW n+8(FP), R2
MOVW $SYS_read, R7 MOVW $SYS_read, R7
SWI $0 SWI $0
MOVW $0xfffff001, R1
CMP R1, R0
MOVW.HI $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
......
...@@ -62,12 +62,16 @@ TEXT runtime·open(SB),NOSPLIT,$-8-20 ...@@ -62,12 +62,16 @@ TEXT runtime·open(SB),NOSPLIT,$-8-20
MOVW mode+8(FP), R4 MOVW mode+8(FP), R4
MOVW perm+12(FP), R5 MOVW perm+12(FP), R5
SYSCALL $SYS_open SYSCALL $SYS_open
BVC 2(PC)
MOVW $-1, R3
MOVW R3, ret+16(FP) MOVW R3, ret+16(FP)
RETURN RETURN
TEXT runtime·close(SB),NOSPLIT,$-8-12 TEXT runtime·close(SB),NOSPLIT,$-8-12
MOVW fd+0(FP), R3 MOVW fd+0(FP), R3
SYSCALL $SYS_close SYSCALL $SYS_close
BVC 2(PC)
MOVW $-1, R3
MOVW R3, ret+8(FP) MOVW R3, ret+8(FP)
RETURN RETURN
...@@ -76,6 +80,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8-28 ...@@ -76,6 +80,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8-28
MOVD p+8(FP), R4 MOVD p+8(FP), R4
MOVW n+16(FP), R5 MOVW n+16(FP), R5
SYSCALL $SYS_write SYSCALL $SYS_write
BVC 2(PC)
MOVW $-1, R3
MOVW R3, ret+24(FP) MOVW R3, ret+24(FP)
RETURN RETURN
...@@ -84,6 +90,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8-28 ...@@ -84,6 +90,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8-28
MOVD p+8(FP), R4 MOVD p+8(FP), R4
MOVW n+16(FP), R5 MOVW n+16(FP), R5
SYSCALL $SYS_read SYSCALL $SYS_read
BVC 2(PC)
MOVW $-1, R3
MOVW R3, ret+24(FP) MOVW R3, ret+24(FP)
RETURN RETURN
......
...@@ -27,24 +27,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$-4 ...@@ -27,24 +27,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$-4
TEXT runtime·open(SB),NOSPLIT,$-4 TEXT runtime·open(SB),NOSPLIT,$-4
MOVL $5, AX MOVL $5, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·close(SB),NOSPLIT,$-4 TEXT runtime·close(SB),NOSPLIT,$-4
MOVL $6, AX MOVL $6, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$-4 TEXT runtime·read(SB),NOSPLIT,$-4
MOVL $3, AX MOVL $3, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$-4 TEXT runtime·write(SB),NOSPLIT,$-4
MOVL $4, AX // sys_write MOVL $4, AX // sys_write
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
......
...@@ -91,6 +91,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8 ...@@ -91,6 +91,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8
MOVL perm+12(FP), DX // arg 3 mode MOVL perm+12(FP), DX // arg 3 mode
MOVL $5, AX MOVL $5, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
...@@ -98,6 +100,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8 ...@@ -98,6 +100,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVL $6, AX MOVL $6, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
...@@ -107,6 +111,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8 ...@@ -107,6 +111,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $3, AX MOVL $3, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
...@@ -116,6 +122,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8 ...@@ -116,6 +122,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 - nbyte MOVL n+16(FP), DX // arg 3 - nbyte
MOVL $4, AX // sys_write MOVL $4, AX // sys_write
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
......
...@@ -29,12 +29,14 @@ TEXT runtime·open(SB),NOSPLIT,$-8 ...@@ -29,12 +29,14 @@ TEXT runtime·open(SB),NOSPLIT,$-8
MOVW mode+4(FP), R1 MOVW mode+4(FP), R1
MOVW perm+8(FP), R2 MOVW perm+8(FP), R2
SWI $0xa00005 SWI $0xa00005
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
TEXT runtime·close(SB),NOSPLIT,$-8 TEXT runtime·close(SB),NOSPLIT,$-8
MOVW fd+0(FP), R0 MOVW fd+0(FP), R0
SWI $0xa00006 SWI $0xa00006
MOVW.CS $-1, R0
MOVW R0, ret+4(FP) MOVW R0, ret+4(FP)
RET RET
...@@ -43,6 +45,7 @@ TEXT runtime·read(SB),NOSPLIT,$-8 ...@@ -43,6 +45,7 @@ TEXT runtime·read(SB),NOSPLIT,$-8
MOVW p+4(FP), R1 MOVW p+4(FP), R1
MOVW n+8(FP), R2 MOVW n+8(FP), R2
SWI $0xa00003 SWI $0xa00003
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
...@@ -51,6 +54,7 @@ TEXT runtime·write(SB),NOSPLIT,$-4 ...@@ -51,6 +54,7 @@ TEXT runtime·write(SB),NOSPLIT,$-4
MOVW p+4(FP), R1 // arg 2 - buf MOVW p+4(FP), R1 // arg 2 - buf
MOVW n+8(FP), R2 // arg 3 - nbyte MOVW n+8(FP), R2 // arg 3 - nbyte
SWI $0xa00004 // sys_write SWI $0xa00004 // sys_write
MOVW.CS $-1, R0
MOVW R0, ret+12(FP) MOVW R0, ret+12(FP)
RET RET
......
...@@ -31,24 +31,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$8 ...@@ -31,24 +31,32 @@ TEXT runtime·exit1(SB),NOSPLIT,$8
TEXT runtime·open(SB),NOSPLIT,$-4 TEXT runtime·open(SB),NOSPLIT,$-4
MOVL $5, AX MOVL $5, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·close(SB),NOSPLIT,$-4 TEXT runtime·close(SB),NOSPLIT,$-4
MOVL $6, AX MOVL $6, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+4(FP) MOVL AX, ret+4(FP)
RET RET
TEXT runtime·read(SB),NOSPLIT,$-4 TEXT runtime·read(SB),NOSPLIT,$-4
MOVL $3, AX MOVL $3, AX
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
TEXT runtime·write(SB),NOSPLIT,$-4 TEXT runtime·write(SB),NOSPLIT,$-4
MOVL $4, AX // sys_write MOVL $4, AX // sys_write
INT $0x80 INT $0x80
JAE 2(PC)
MOVL $-1, AX
MOVL AX, ret+12(FP) MOVL AX, ret+12(FP)
RET RET
......
...@@ -101,6 +101,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8 ...@@ -101,6 +101,8 @@ TEXT runtime·open(SB),NOSPLIT,$-8
MOVL perm+12(FP), DX // arg 3 mode MOVL perm+12(FP), DX // arg 3 mode
MOVL $5, AX MOVL $5, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+16(FP) MOVL AX, ret+16(FP)
RET RET
...@@ -108,6 +110,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8 ...@@ -108,6 +110,8 @@ TEXT runtime·close(SB),NOSPLIT,$-8
MOVL fd+0(FP), DI // arg 1 fd MOVL fd+0(FP), DI // arg 1 fd
MOVL $6, AX MOVL $6, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+8(FP) MOVL AX, ret+8(FP)
RET RET
...@@ -117,6 +121,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8 ...@@ -117,6 +121,8 @@ TEXT runtime·read(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 count MOVL n+16(FP), DX // arg 3 count
MOVL $3, AX MOVL $3, AX
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
MOVL AX, ret+24(FP) MOVL AX, ret+24(FP)
RET RET
...@@ -126,6 +132,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8 ...@@ -126,6 +132,8 @@ TEXT runtime·write(SB),NOSPLIT,$-8
MOVL n+16(FP), DX // arg 3 - nbyte MOVL n+16(FP), DX // arg 3 - nbyte
MOVL $4, AX // sys_write MOVL $4, AX // sys_write
SYSCALL SYSCALL
JCC 2(PC)
MOVL $-1, AX
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