Skip to content

Commit

Permalink
syscall: make Exit call runtime.exit
Browse files Browse the repository at this point in the history
syscall.Exit and runtime.exit do the same thing.
Why duplicate code?

CL 45115 fixed bug where windows runtime.exit was correct,
but syscall.Exit was broken. So CL 45115 fixed windows
syscall.Exit by calling runtime.exit.

Austin suggested that all OSes should do the same, and
this CL implements his idea.

While making changes, I discovered that nacl syscall.Exit
returned error

func Exit(code int) (err error)

and I changed it into

func Exit(code int)

like all other OSes. I assumed it was a mistake and it
is OK to do because cmd/api does not complain about it.

Also I changed plan9 runtime.exit to accept int32 just
like all other OSes do.

Change-Id: I12f6022ad81406566cf9befcc6edc382eebd413b
Reviewed-on: https://go-review.googlesource.com/66170
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: David du Colombier <0intro@gmail.com>
  • Loading branch information
alexbrainman committed Sep 27, 2017
1 parent 5e42658 commit 438c8f6
Show file tree
Hide file tree
Showing 46 changed files with 9 additions and 264 deletions.
2 changes: 1 addition & 1 deletion src/runtime/os_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func postnote(pid uint64, msg []byte) int {
}

//go:nosplit
func exit(e int) {
func exit(e int32) {
var status []byte
if e == 0 {
status = emptystatus
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ func syscall_Getpagesize() int { return int(physPageSize) }

//go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string { return append([]string{}, argslice...) }

//go:linkname syscall_Exit syscall.Exit
//go:nosplit
func syscall_Exit(code int) {
exit(int32(code))
}
6 changes: 0 additions & 6 deletions src/runtime/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,3 @@ func syscall_Syscall15(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
cgocall(asmstdcallAddr, unsafe.Pointer(c))
return c.r1, c.r2, c.err
}

//go:linkname syscall_exit syscall.Exit
//go:nosplit
func syscall_exit(code int) {
exit(int32(code))
}
9 changes: 0 additions & 9 deletions src/syscall/asm_plan9_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,3 @@ copyresult6:
MOVSL
MOVSL
RET

//func exit(code int)
// Import runtime·exit for cleanly exiting.
TEXT ·exit(SB),NOSPLIT,$4-4
NO_LOCAL_POINTERS
MOVL code+0(FP), AX
MOVL AX, 0(SP)
CALL runtime·exit(SB)
RET
9 changes: 0 additions & 9 deletions src/syscall/asm_plan9_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,3 @@ copyresult6:
MOVSQ
MOVSQ
RET

//func exit(code int)
// Import runtime·exit for cleanly exiting.
TEXT ·exit(SB),NOSPLIT,$8-8
NO_LOCAL_POINTERS
MOVQ code+0(FP), AX
MOVQ AX, 0(SP)
CALL runtime·exit(SB)
RET
9 changes: 0 additions & 9 deletions src/syscall/asm_plan9_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,3 @@ TEXT ·seek(SB),NOSPLIT,$0-36
MOVW $err+28(FP), R1
BL sysresult<>(SB)
RET

//func exit(code int)
// Import runtime·exit for cleanly exiting.
TEXT ·exit(SB),NOSPLIT,$4-4
NO_LOCAL_POINTERS
MOVW code+0(FP), R0
MOVW R0, e-4(SP)
BL runtime·exit(SB)
RET
3 changes: 2 additions & 1 deletion src/syscall/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (tv *Timeval) Nano() int64 {
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
}

// Getpagesize is provided by the runtime.
// Getpagesize and Exit are provided by the runtime.

func Getpagesize() int
func Exit(code int)
1 change: 0 additions & 1 deletion src/syscall/syscall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
//sys Dup(fd int) (nfd int, err error)
//sys Dup2(from int, to int) (err error)
//sys Exchangedata(path1 string, path2 string, options int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (err error)
//sys Fchflags(fd int, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
//sys Close(fd int) (err error)
//sys Dup(fd int) (nfd int, err error)
//sys Dup2(from int, to int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (err error)
//sys Fchflags(fd int, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
//sys Close(fd int) (err error)
//sys Dup(fd int) (nfd int, err error)
//sys Dup2(from int, to int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (err error)
//sys Fchflags(fd int, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
//sysnb EpollCreate1(flag int) (fd int, err error)
//sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error)
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
//sys Exit(code int) = SYS_EXIT_GROUP
//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)
//sys Fchdir(fd int) (err error)
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_nacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

//sys naclClose(fd int) (err error) = sys_close
//sys Exit(code int) (err error)
//sys naclFstat(fd int, stat *Stat_t) (err error) = sys_fstat
//sys naclRead(fd int, b []byte) (n int, err error) = sys_read
//sys naclSeek(fd int, off *int64, whence int) (err error) = sys_lseek
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
//sys Close(fd int) (err error)
//sys Dup(fd int) (nfd int, err error)
//sys Dup2(from int, to int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (err error)
//sys Fchflags(fd int, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
//sys Close(fd int) (err error)
//sys Dup(fd int) (nfd int, err error)
//sys Dup2(from int, to int) (err error)
//sys Exit(code int)
//sys Fchdir(fd int) (err error)
//sys Fchflags(fd int, flags int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
Expand Down
5 changes: 0 additions & 5 deletions src/syscall/syscall_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ func errstr() string {
return cstring(buf[:])
}

// Implemented in assembly to import from runtime.
func exit(code int)

func Exit(code int) { exit(code) }

func readnum(path string) (uint, error) {
var b [12]byte

Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)
//sys Chroot(path string) (err error)
//sys Close(fd int) (err error)
//sys Dup(fd int) (nfd int, err error)
//sys Exit(code int)
//sys Fchdir(fd int) (err error)
//sys Fchmod(fd int, mode uint32) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
Expand Down
3 changes: 0 additions & 3 deletions src/syscall/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ func NewCallbackCDecl(fn interface{}) uintptr {

// syscall interface implementation for other packages

// Implemented in ../runtime/syscall_windows.go.
func Exit(code int)

func makeInheritSa() *SecurityAttributes {
var sa SecurityAttributes
sa.Length = uint32(unsafe.Sizeof(sa))
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_darwin_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,6 @@ func Exchangedata(path1 string, path2 string, options int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,6 @@ func Exchangedata(path1 string, path2 string, options int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_darwin_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,6 @@ func Exchangedata(path1 string, path2 string, options int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,6 @@ func Exchangedata(path1 string, path2 string, options int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_dragonfly_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ func Dup2(from int, to int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_freebsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,6 @@ func Dup2(from int, to int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_freebsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,6 @@ func Dup2(from int, to int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_freebsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,6 @@ func Dup2(from int, to int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fchdir(fd int) (err error) {
_, _, e1 := Syscall(SYS_FCHDIR, uintptr(fd), 0, 0)
if e1 != 0 {
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_mips.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_mips64.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_mips64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
7 changes: 0 additions & 7 deletions src/syscall/zsyscall_linux_mipsle.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Exit(code int) {
Syscall(SYS_EXIT_GROUP, uintptr(code), 0, 0)
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
Expand Down
Loading

0 comments on commit 438c8f6

Please sign in to comment.