syscall: add Hurd support
Loosely based on a patch by Svante Signell. Reviewed-on: https://go-review.googlesource.com/c/161518 From-SVN: r268603
This commit is contained in:
parent
9fa4b2aa45
commit
4321f202f9
|
@ -1,4 +1,4 @@
|
|||
77f0f28af556f50c561ff5c2cca17ad6f985068e
|
||||
db618eeabdcf1ba56861d21d5639ca4514cd6934
|
||||
|
||||
The first line of this file holds the git revision number of the last
|
||||
merge done from the gofrontend repository.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// errstr_linux.go -- GNU/Linux specific error strings.
|
||||
// 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
|
||||
|
@ -7,6 +7,8 @@
|
|||
// 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"
|
|
@ -2,7 +2,7 @@
|
|||
// 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.
|
||||
|
||||
|
@ -319,7 +319,7 @@ func Exec(argv0 string, argv []string, envv []string) (err error) {
|
|||
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)),
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
// 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
|
|
@ -0,0 +1,18 @@
|
|||
// 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
|
|
@ -0,0 +1,11 @@
|
|||
// 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
|
|
@ -7,31 +7,9 @@
|
|||
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
|
||||
|
||||
|
@ -169,48 +147,12 @@ func Reboot(cmd int) (err error) {
|
|||
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
|
||||
|
||||
|
@ -219,29 +161,6 @@ func Gettid() (tid 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
|
||||
|
||||
|
@ -263,25 +182,6 @@ func ReadDirent(fd int, buf []byte) (n int, err error) {
|
|||
//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
|
||||
|
||||
|
@ -291,25 +191,6 @@ func Pipe2(p []int, flags int) (err error) {
|
|||
//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
|
||||
|
||||
|
@ -353,9 +234,6 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i
|
|||
//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
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
// Note that sometimes we use a lowercase //sys name and
|
||||
// wrap it in our own nicer implementation.
|
||||
|
||||
// +build !hurd
|
||||
|
||||
package syscall
|
||||
|
||||
import "unsafe"
|
||||
|
@ -267,9 +265,6 @@ func Gettimeofday(tv *Timeval) (err error) {
|
|||
//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
|
||||
|
||||
|
@ -355,9 +350,6 @@ func Settimeofday(tv *Timeval) (err error) {
|
|||
//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
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// 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
|
|
@ -2,6 +2,8 @@
|
|||
// 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"
|
Loading…
Reference in New Issue