From e76934261449e82857fa060dbd3212492b08e2ea Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 19 Sep 2010 22:52:30 -0400 Subject: [PATCH] nacl: fix zero-length writes NaCl rejects zero-length write using nil pointer. R=r CC=golang-dev https://golang.org/cl/2237042 --- src/pkg/syscall/syscall_nacl.go | 2 ++ src/pkg/syscall/zsyscall_nacl_386.go | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/pkg/syscall/syscall_nacl.go b/src/pkg/syscall/syscall_nacl.go index b7a6508fb98..1eca1a328d2 100644 --- a/src/pkg/syscall/syscall_nacl.go +++ b/src/pkg/syscall/syscall_nacl.go @@ -8,6 +8,8 @@ package syscall const OS = "nacl" +var _zero [1]byte // pointer used for zero-length writes + // Auto-generated //sys Chmod(path string, mode uint32) (errno int) diff --git a/src/pkg/syscall/zsyscall_nacl_386.go b/src/pkg/syscall/zsyscall_nacl_386.go index 17b4919fe53..4fa04599a85 100644 --- a/src/pkg/syscall/zsyscall_nacl_386.go +++ b/src/pkg/syscall/zsyscall_nacl_386.go @@ -1,4 +1,4 @@ -// mksyscall.sh -l32 syscall_nacl.go syscall_nacl_386.go +// mksyscall.sh -l32 -nacl syscall_nacl.go syscall_nacl_386.go // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT package syscall @@ -35,11 +35,13 @@ func Fstat(fd int, stat *Stat_t) (errno int) { } func Getdents(fd int, buf []byte) (n int, errno int) { - var _p0 *byte + var _p0 unsafe.Pointer if len(buf) > 0 { - _p0 = &buf[0] + _p0 = unsafe.Pointer(&buf[0]) + } else { + _p0 = unsafe.Pointer(&_zero[0]) } - r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf))) + r0, _, e1 := Syscall(SYS_GETDENTS, uintptr(fd), uintptr(_p0), uintptr(len(buf))) n = int(r0) errno = int(e1) return @@ -65,11 +67,13 @@ func Open(path string, mode int, perm uint32) (fd int, errno int) { } func Read(fd int, p []byte) (n int, errno int) { - var _p0 *byte + var _p0 unsafe.Pointer if len(p) > 0 { - _p0 = &p[0] + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero[0]) } - r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p))) + r0, _, e1 := Syscall(SYS_READ, uintptr(fd), uintptr(_p0), uintptr(len(p))) n = int(r0) errno = int(e1) return @@ -89,11 +93,13 @@ func Stat(path string, stat *Stat_t) (errno int) { } func Write(fd int, p []byte) (n int, errno int) { - var _p0 *byte + var _p0 unsafe.Pointer if len(p) > 0 { - _p0 = &p[0] + _p0 = unsafe.Pointer(&p[0]) + } else { + _p0 = unsafe.Pointer(&_zero[0]) } - r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p))) + r0, _, e1 := Syscall(SYS_WRITE, uintptr(fd), uintptr(_p0), uintptr(len(p))) n = int(r0) errno = int(e1) return