Patchwork libgo patch committed: Fix errno handling in syscall.Syscall

login
register
mail settings
Submitter Ian Taylor
Date March 23, 2012, 6:41 p.m.
Message ID <mcrsjgzrwgx.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/148479/
State New
Headers show

Comments

Ian Taylor - March 23, 2012, 6:41 p.m.
This patch to libgo fixes the handling of errno in syscall.Syscall and
friends.  Previously it would return a non-zero errno value even when
the system call succeeded.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.7 branch.

Ian

Patch

diff -r b626c77ab40e libgo/go/syscall/syscall_unix.go
--- a/libgo/go/syscall/syscall_unix.go	Tue Mar 13 15:57:41 2012 -0700
+++ b/libgo/go/syscall/syscall_unix.go	Fri Mar 23 11:35:53 2012 -0700
@@ -31,6 +31,7 @@ 
 // expects a 32-bit one.
 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
 	Entersyscall()
+	SetErrno(0)
 	var r uintptr
 	if unsafe.Sizeof(r) == 4 {
 		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
@@ -46,6 +47,7 @@ 
 
 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
 	Entersyscall()
+	SetErrno(0)
 	var r uintptr
 	if unsafe.Sizeof(r) == 4 {
 		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
@@ -63,6 +65,7 @@ 
 
 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
 	var r uintptr
+	SetErrno(0)
 	if unsafe.Sizeof(r) == 4 {
 		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3), 0, 0, 0)
 		r = uintptr(r1)
@@ -76,6 +79,7 @@ 
 
 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
 	var r uintptr
+	SetErrno(0)
 	if unsafe.Sizeof(r) == 4 {
 		r1 := c_syscall32(int32(trap), int32(a1), int32(a2), int32(a3),
 			int32(a4), int32(a5), int32(a6))