From af582674b0b1d4a06ca9c8bda8f66ce9e9846696 Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Mon, 1 Oct 2012 10:09:08 +1000 Subject: [PATCH] pkg/syscall: Plan 9, 64-bit: Update error checks from sys calls. This change updates CL 6576057 for exceptional cases where return values from Syscall/RawSyscall functions are used. The system calls return 32-bit integers. With the recent change in size of `int' in Go for amd64, the type conversion was not catching `-1' return values. This change makes the conversion explicitly `int32'. R=rsc, r CC=golang-dev https://golang.org/cl/6590047 --- src/pkg/syscall/exec_plan9.go | 20 ++++++++++---------- src/pkg/syscall/syscall_plan9.go | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pkg/syscall/exec_plan9.go b/src/pkg/syscall/exec_plan9.go index 75eaad612a..45da9909e6 100644 --- a/src/pkg/syscall/exec_plan9.go +++ b/src/pkg/syscall/exec_plan9.go @@ -207,7 +207,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at r1, _, _ = RawSyscall(SYS_RFORK, uintptr(RFPROC|RFFDG|RFREND|clearenv|rflag), 0, 0) if r1 != 0 { - if int(r1) == -1 { + if int32(r1) == -1 { return 0, NewError(errstr()) } // parent; return PID @@ -219,7 +219,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at // Close fds we don't need. for i = 0; i < len(fdsToClose); i++ { r1, _, _ = RawSyscall(SYS_CLOSE, uintptr(fdsToClose[i]), 0, 0) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } } @@ -229,7 +229,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at for i = 0; i < len(envv); i++ { r1, _, _ = RawSyscall(SYS_CREATE, uintptr(unsafe.Pointer(envv[i].name)), uintptr(O_WRONLY), uintptr(0666)) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } @@ -238,13 +238,13 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at r1, _, _ = RawSyscall6(SYS_PWRITE, uintptr(envfd), uintptr(unsafe.Pointer(envv[i].value)), uintptr(envv[i].nvalue), ^uintptr(0), ^uintptr(0), 0) - if int(r1) == -1 || int(r1) != envv[i].nvalue { + if int32(r1) == -1 || int(r1) != envv[i].nvalue { goto childerror } r1, _, _ = RawSyscall(SYS_CLOSE, uintptr(envfd), 0, 0) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } } @@ -253,7 +253,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at // Chdir if dir != nil { r1, _, _ = RawSyscall(SYS_CHDIR, uintptr(unsafe.Pointer(dir)), 0, 0) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } } @@ -263,7 +263,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at nextfd = int(len(fd)) if pipe < nextfd { r1, _, _ = RawSyscall(SYS_DUP, uintptr(pipe), uintptr(nextfd), 0) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } pipe = nextfd @@ -272,7 +272,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at for i = 0; i < len(fd); i++ { if fd[i] >= 0 && fd[i] < int(i) { r1, _, _ = RawSyscall(SYS_DUP, uintptr(fd[i]), uintptr(nextfd), 0) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } @@ -294,7 +294,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at continue } r1, _, _ = RawSyscall(SYS_DUP, uintptr(fd[i]), uintptr(i), 0) - if int(r1) == -1 { + if int32(r1) == -1 { goto childerror } } @@ -519,7 +519,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle func Exec(argv0 string, argv []string, envv []string) (err error) { if envv != nil { r1, _, _ := RawSyscall(SYS_RFORK, RFCENVG, 0, 0) - if int(r1) == -1 { + if int32(r1) == -1 { return NewError(errstr()) } diff --git a/src/pkg/syscall/syscall_plan9.go b/src/pkg/syscall/syscall_plan9.go index 3657f7c15f..e2da9fe864 100644 --- a/src/pkg/syscall/syscall_plan9.go +++ b/src/pkg/syscall/syscall_plan9.go @@ -255,7 +255,7 @@ func Unmount(name, old string) (err error) { r0, _, e = Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(namep)), oldptr, 0) } - if int(r0) == -1 { + if int32(r0) == -1 { err = e } return -- 2.48.1