Loosely based on a patch by Svante Signell.
Reviewed-on: https://go-review.googlesource.com/c/161518
From-SVN: r268603
-77f0f28af556f50c561ff5c2cca17ad6f985068e
+db618eeabdcf1ba56861d21d5639ca4514cd6934
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
--- /dev/null
+// errstr_glibc.go -- GNU/Linux and GNU/Hurd specific error strings.
+
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// We use this rather than errstr.go because on GNU/Linux sterror_r
+// returns a pointer to the error message, and may not use buf at all.
+
+// +build hurd linux
+
+package syscall
+
+import "unsafe"
+
+//sysnb strerror_r(errnum int, b []byte) (errstr *byte)
+//strerror_r(errnum _C_int, b *byte, len Size_t) *byte
+
+func Errstr(errnum int) string {
+ a := make([]byte, 128)
+ p := strerror_r(errnum, a)
+ b := (*[1000]byte)(unsafe.Pointer(p))
+ i := 0
+ for b[i] != 0 {
+ i++
+ }
+ // Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
+ if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
+ c := b[0] + 'a' - 'A'
+ return string(c) + string(b[1:i])
+ }
+ return string(b[:i])
+}
+++ /dev/null
-// errstr_linux.go -- GNU/Linux specific error strings.
-
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// We use this rather than errstr.go because on GNU/Linux sterror_r
-// returns a pointer to the error message, and may not use buf at all.
-
-package syscall
-
-import "unsafe"
-
-//sysnb strerror_r(errnum int, b []byte) (errstr *byte)
-//strerror_r(errnum _C_int, b *byte, len Size_t) *byte
-
-func Errstr(errnum int) string {
- a := make([]byte, 128)
- p := strerror_r(errnum, a)
- b := (*[1000]byte)(unsafe.Pointer(p))
- i := 0
- for b[i] != 0 {
- i++
- }
- // Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
- if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
- c := b[0] + 'a' - 'A'
- return string(c) + string(b[1:i])
- }
- return string(b[:i])
-}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd hurd linux netbsd openbsd solaris
// Fork, exec, wait, etc.
runtime_BeforeExec()
var err1 error
- if runtime.GOOS == "solaris" || runtime.GOOS == "aix" {
+ if runtime.GOOS == "solaris" || runtime.GOOS == "aix" || runtime.GOOS == "hurd" {
// RawSyscall should never be used on Solaris or AIX.
err1 = execveLibc(
uintptr(unsafe.Pointer(argv0p)),
--- /dev/null
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build hurd linux
+
+// glibc library calls.
+
+package syscall
+
+import (
+ "internal/race"
+ "unsafe"
+)
+
+//sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
+//__go_openat(dirfd _C_int, path *byte, flags _C_int, mode Mode_t) _C_int
+
+//sys futimesat(dirfd int, path *byte, times *[2]Timeval) (err error)
+//futimesat(dirfd _C_int, path *byte, times *[2]Timeval) _C_int
+func Futimesat(dirfd int, path string, tv []Timeval) (err error) {
+ if len(tv) != 2 {
+ return EINVAL
+ }
+ return futimesat(dirfd, StringBytePtr(path), (*[2]Timeval)(unsafe.Pointer(&tv[0])))
+}
+
+func Futimes(fd int, tv []Timeval) (err error) {
+ // Believe it or not, this is the best we can do on GNU/Linux
+ // (and is what glibc does).
+ return Utimes("/proc/self/fd/"+itoa(fd), tv)
+}
+
+//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
+//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
+
+//sys accept4(fd int, sa *RawSockaddrAny, len *Socklen_t, flags int) (nfd int, err error)
+//accept4(fd _C_int, sa *RawSockaddrAny, len *Socklen_t, flags _C_int) _C_int
+
+func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
+ var rsa RawSockaddrAny
+ var len Socklen_t = SizeofSockaddrAny
+ nfd, err = accept4(fd, &rsa, &len, flags)
+ if err != nil {
+ return -1, nil, err
+ }
+ sa, err = anyToSockaddr(&rsa)
+ if err != nil {
+ Close(nfd)
+ return -1, nil, err
+ }
+ return nfd, sa, nil
+}
+
+//sysnb Dup3(oldfd int, newfd int, flags int) (err error)
+//dup3(oldfd _C_int, newfd _C_int, flags _C_int) _C_int
+
+//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
+//faccessat(dirfd _C_int, pathname *byte, mode _C_int, flags _C_int) _C_int
+
+//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)
+//fallocate(fd _C_int, mode _C_int, offset Offset_t, len Offset_t) _C_int
+
+//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
+//fchmodat(dirfd _C_int, pathname *byte, mode Mode_t, flags _C_int) _C_int
+
+//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
+//fchownat(dirfd _C_int, path *byte, owner Uid_t, group Gid_t, flags _C_int) _C_int
+
+//sys Flock(fd int, how int) (err error)
+//flock(fd _C_int, how _C_int) _C_int
+
+func Getdents(fd int, buf []byte) (n int, err error) {
+ var p *byte
+ if len(buf) > 0 {
+ p = &buf[0]
+ } else {
+ p = (*byte)(unsafe.Pointer(&_zero))
+ }
+ s := SYS_GETDENTS64
+ if s == 0 {
+ s = SYS_GETDENTS
+ }
+ r1, _, errno := Syscall(uintptr(s), uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(len(buf)))
+ n = int(r1)
+ if n < 0 {
+ err = errno
+ }
+ return
+}
+
+func ReadDirent(fd int, buf []byte) (n int, err error) {
+ return Getdents(fd, buf)
+}
+
+//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
+//mkdirat(dirfd _C_int, path *byte, mode Mode_t) _C_int
+
+//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
+//mknodat(dirfd _C_int, path *byte, mode Mode_t, dev _dev_t) _C_int
+
+//sysnb pipe2(p *[2]_C_int, flags int) (err error)
+//pipe2(p *[2]_C_int, flags _C_int) _C_int
+func Pipe2(p []int, flags int) (err error) {
+ if len(p) != 2 {
+ return EINVAL
+ }
+ var pp [2]_C_int
+ err = pipe2(&pp, flags)
+ p[0] = int(pp[0])
+ p[1] = int(pp[1])
+ return
+}
+
+//sys sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error)
+//sendfile64(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t
+func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
+ if race.Enabled {
+ race.ReleaseMerge(unsafe.Pointer(&ioSync))
+ }
+ var soff Offset_t
+ var psoff *Offset_t
+ if offset != nil {
+ soff = Offset_t(*offset)
+ psoff = &soff
+ }
+ written, err = sendfile(outfd, infd, psoff, count)
+ if offset != nil {
+ *offset = int64(soff)
+ }
+ return
+}
+
+//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
+//sync_file_range(fd _C_int, off Offset_t, n Offset_t, flags _C_uint) _C_int
--- /dev/null
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// GNU/Hurd library calls.
+
+package syscall
+
+// Dummy function
+func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
+ return ENOSYS
+}
+
+//sys Fstatfs(fd int, buf *Statfs_t) (err error)
+//fstatfs(fd _C_int, buf *Statfs_t) _C_int
+
+// For exec_unix.go.
+const SYS_EXECVE = 0
--- /dev/null
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// GNU/Hurd library calls 386 specific derived from libcall_linux_386.go.
+// Remove Iopl, iopl.
+
+package syscall
+
+//sys Ioperm(from int, num int, on int) (err error)
+//ioperm(from _C_long, num _C_long, on _C_int) _C_int
package syscall
import (
- "internal/race"
"unsafe"
)
-//sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
-//__go_openat(dirfd _C_int, path *byte, flags _C_int, mode Mode_t) _C_int
-
-//sys futimesat(dirfd int, path *byte, times *[2]Timeval) (err error)
-//futimesat(dirfd _C_int, path *byte, times *[2]Timeval) _C_int
-func Futimesat(dirfd int, path string, tv []Timeval) (err error) {
- if len(tv) != 2 {
- return EINVAL
- }
- return futimesat(dirfd, StringBytePtr(path), (*[2]Timeval)(unsafe.Pointer(&tv[0])))
-}
-
-func Futimes(fd int, tv []Timeval) (err error) {
- // Believe it or not, this is the best we can do on GNU/Linux
- // (and is what glibc does).
- return Utimes("/proc/self/fd/"+itoa(fd), tv)
-}
-
-//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
-//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
-
//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno)
//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "")
}
-//sys accept4(fd int, sa *RawSockaddrAny, len *Socklen_t, flags int) (nfd int, err error)
-//accept4(fd _C_int, sa *RawSockaddrAny, len *Socklen_t, flags _C_int) _C_int
-
-func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
- var rsa RawSockaddrAny
- var len Socklen_t = SizeofSockaddrAny
- nfd, err = accept4(fd, &rsa, &len, flags)
- if err != nil {
- return -1, nil, err
- }
- sa, err = anyToSockaddr(&rsa)
- if err != nil {
- Close(nfd)
- return -1, nil, err
- }
- return nfd, sa, nil
-}
-
//sys Acct(path string) (err error)
//acct(path *byte) _C_int
//sys Adjtimex(buf *Timex) (state int, err error)
//adjtimex(buf *Timex) _C_int
-//sysnb Dup3(oldfd int, newfd int, flags int) (err error)
-//dup3(oldfd _C_int, newfd _C_int, flags _C_int) _C_int
-
-//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
-//faccessat(dirfd _C_int, pathname *byte, mode _C_int, flags _C_int) _C_int
-
-//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)
-//fallocate(fd _C_int, mode _C_int, offset Offset_t, len Offset_t) _C_int
-
-//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
-//fchmodat(dirfd _C_int, pathname *byte, mode Mode_t, flags _C_int) _C_int
-
-//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
-//fchownat(dirfd _C_int, path *byte, owner Uid_t, group Gid_t, flags _C_int) _C_int
-
-//sys Flock(fd int, how int) (err error)
-//flock(fd _C_int, how _C_int) _C_int
-
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
//fstatfs64(fd _C_int, buf *Statfs_t) _C_int
return int(r1)
}
-func Getdents(fd int, buf []byte) (n int, err error) {
- var p *byte
- if len(buf) > 0 {
- p = &buf[0]
- } else {
- p = (*byte)(unsafe.Pointer(&_zero))
- }
- s := SYS_GETDENTS64
- if s == 0 {
- s = SYS_GETDENTS
- }
- r1, _, errno := Syscall(uintptr(s), uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(len(buf)))
- n = int(r1)
- if n < 0 {
- err = errno
- }
- return
-}
-
-func ReadDirent(fd int, buf []byte) (n int, err error) {
- return Getdents(fd, buf)
-}
-
//sys Getxattr(path string, attr string, dest []byte) (sz int, err error)
//getxattr(path *byte, attr *byte, buf *byte, count Size_t) Ssize_t
//sys Listxattr(path string, dest []byte) (sz int, err error)
//listxattr(path *byte, list *byte, size Size_t) Ssize_t
-//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
-//mkdirat(dirfd _C_int, path *byte, mode Mode_t) _C_int
-
-//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
-//mknodat(dirfd _C_int, path *byte, mode Mode_t, dev _dev_t) _C_int
-
-//sysnb pipe2(p *[2]_C_int, flags int) (err error)
-//pipe2(p *[2]_C_int, flags _C_int) _C_int
-func Pipe2(p []int, flags int) (err error) {
- if len(p) != 2 {
- return EINVAL
- }
- var pp [2]_C_int
- err = pipe2(&pp, flags)
- p[0] = int(pp[0])
- p[1] = int(pp[1])
- return
-}
-
//sys PivotRoot(newroot string, putold string) (err error)
//pivot_root(newroot *byte, putold *byte) _C_int
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
//renameat(olddirfd _C_int, oldpath *byte, newdirfd _C_int, newpath *byte) _C_int
-//sys sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error)
-//sendfile64(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t
-func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
- if race.Enabled {
- race.ReleaseMerge(unsafe.Pointer(&ioSync))
- }
- var soff Offset_t
- var psoff *Offset_t
- if offset != nil {
- soff = Offset_t(*offset)
- psoff = &soff
- }
- written, err = sendfile(outfd, infd, psoff, count)
- if offset != nil {
- *offset = int64(soff)
- }
- return
-}
-
//sys Setfsgid(gid int) (err error)
//setfsgid(gid Gid_t) _C_int
//sys Statfs(path string, buf *Statfs_t) (err error)
//statfs64(path *byte, buf *Statfs_t) _C_int
-//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
-//sync_file_range(fd _C_int, off Offset_t, n Offset_t, flags _C_uint) _C_int
-
//sysnb Sysinfo(info *Sysinfo_t) (err error)
//sysinfo(info *Sysinfo_t) _C_int
// Note that sometimes we use a lowercase //sys name and
// wrap it in our own nicer implementation.
-// +build !hurd
-
package syscall
import "unsafe"
//sys Mknod(path string, mode uint32, dev int) (err error)
//mknod(path *byte, mode Mode_t, dev _dev_t) _C_int
-//sys Mount(source string, target string, fstype string, flags uintptr, data string) (err error)
-//mount(source *byte, target *byte, fstype *byte, flags _C_long, data *byte) _C_int
-
//sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
//nanosleep(time *Timespec, leftover *Timespec) _C_int
//sys munmap(addr uintptr, length uintptr) (err error)
//munmap(addr *byte, length Size_t) _C_int
-//sys Madvise(b []byte, advice int) (err error)
-//madvise(addr *byte, len Size_t, advice _C_int) _C_int
-
//sys Mprotect(b []byte, prot int) (err error)
//mprotect(addr *byte, len Size_t, prot _C_int) _C_int
--- /dev/null
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !hurd
+
+package syscall
+
+// Removed the mount call for GNU/Hurd, it exists but use translators.
+// Functionality is not the same as descibed in Linux <sys/mount.h>.
+// Removed the madvise call for GNU/Hurd, not yet implemented.
+
+//sys Mount(source string, target string, fstype string, flags uintptr, data string) (err error)
+//mount(source *byte, target *byte, fstype *byte, flags _C_long, data *byte) _C_int
+
+//sys Madvise(b []byte, advice int) (err error)
+//madvise(addr *byte, len Size_t, advice _C_int) _C_int
--- /dev/null
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build hurd linux
+
+package syscall
+
+import "unsafe"
+
+func rawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr) {
+ r1, r2, _ = RawSyscall(trap, a1, a2, a3)
+ return
+}
+
+func direntIno(buf []byte) (uint64, bool) {
+ return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
+}
+
+func direntReclen(buf []byte) (uint64, bool) {
+ return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
+}
+
+func direntNamlen(buf []byte) (uint64, bool) {
+ reclen, ok := direntReclen(buf)
+ if !ok {
+ return 0, false
+ }
+ return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
+}
+++ /dev/null
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package syscall
-
-import "unsafe"
-
-func rawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr) {
- r1, r2, _ = RawSyscall(trap, a1, a2, a3)
- return
-}
-
-func direntIno(buf []byte) (uint64, bool) {
- return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
-}
-
-func direntReclen(buf []byte) (uint64, bool) {
- return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
-}
-
-func direntNamlen(buf []byte) (uint64, bool) {
- reclen, ok := direntReclen(buf)
- if !ok {
- return 0, false
- }
- return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
-}