From: Ian Lance Taylor Date: Thu, 7 Feb 2019 03:11:47 +0000 (+0000) Subject: syscall: add Hurd support X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4321f202f985f659e0150ee72ed3e14e554f9735;p=gcc.git syscall: add Hurd support Loosely based on a patch by Svante Signell. Reviewed-on: https://go-review.googlesource.com/c/161518 From-SVN: r268603 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 8c57e163409..53780e1bc21 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/libgo/go/syscall/errstr_glibc.go b/libgo/go/syscall/errstr_glibc.go new file mode 100644 index 00000000000..5b19e6f202d --- /dev/null +++ b/libgo/go/syscall/errstr_glibc.go @@ -0,0 +1,33 @@ +// 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]) +} diff --git a/libgo/go/syscall/errstr_linux.go b/libgo/go/syscall/errstr_linux.go deleted file mode 100644 index 7156b790da5..00000000000 --- a/libgo/go/syscall/errstr_linux.go +++ /dev/null @@ -1,31 +0,0 @@ -// 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]) -} diff --git a/libgo/go/syscall/exec_unix.go b/libgo/go/syscall/exec_unix.go index 54e322c748c..bad2ce44302 100644 --- a/libgo/go/syscall/exec_unix.go +++ b/libgo/go/syscall/exec_unix.go @@ -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)), diff --git a/libgo/go/syscall/libcall_glibc.go b/libgo/go/syscall/libcall_glibc.go new file mode 100644 index 00000000000..a90fc9b3f8b --- /dev/null +++ b/libgo/go/syscall/libcall_glibc.go @@ -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 diff --git a/libgo/go/syscall/libcall_hurd.go b/libgo/go/syscall/libcall_hurd.go new file mode 100644 index 00000000000..f0e038ca616 --- /dev/null +++ b/libgo/go/syscall/libcall_hurd.go @@ -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 diff --git a/libgo/go/syscall/libcall_hurd_386.go b/libgo/go/syscall/libcall_hurd_386.go new file mode 100644 index 00000000000..783429ca60a --- /dev/null +++ b/libgo/go/syscall/libcall_hurd_386.go @@ -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 diff --git a/libgo/go/syscall/libcall_linux.go b/libgo/go/syscall/libcall_linux.go index 79033287720..88286c07b6e 100644 --- a/libgo/go/syscall/libcall_linux.go +++ b/libgo/go/syscall/libcall_linux.go @@ -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 diff --git a/libgo/go/syscall/libcall_posix.go b/libgo/go/syscall/libcall_posix.go index f57276356e6..d2fa0d9d433 100644 --- a/libgo/go/syscall/libcall_posix.go +++ b/libgo/go/syscall/libcall_posix.go @@ -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 diff --git a/libgo/go/syscall/libcall_posix_nonhurd.go b/libgo/go/syscall/libcall_posix_nonhurd.go new file mode 100644 index 00000000000..afdca3f2f49 --- /dev/null +++ b/libgo/go/syscall/libcall_posix_nonhurd.go @@ -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 . +// 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 diff --git a/libgo/go/syscall/syscall_glibc.go b/libgo/go/syscall/syscall_glibc.go new file mode 100644 index 00000000000..b40f297facb --- /dev/null +++ b/libgo/go/syscall/syscall_glibc.go @@ -0,0 +1,30 @@ +// 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 +} diff --git a/libgo/go/syscall/syscall_linux.go b/libgo/go/syscall/syscall_linux.go deleted file mode 100644 index d2d49c3af4b..00000000000 --- a/libgo/go/syscall/syscall_linux.go +++ /dev/null @@ -1,28 +0,0 @@ -// 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 -}