From: Ian Lance Taylor Date: Thu, 7 Feb 2019 04:45:01 +0000 (+0000) Subject: os, net, crypto/x509: add hurd support X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4a3e25712f25271876e83dfafe8ff2df4f643df7;p=gcc.git os, net, crypto/x509: add hurd support Patch by Svante Signell. Reviewed-on: https://go-review.googlesource.com/c/161519 From-SVN: r268604 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 53780e1bc21..b7efb211ca5 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -db618eeabdcf1ba56861d21d5639ca4514cd6934 +28b65174d9c9163f4ab2cfaf70dca646f1a7611f 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/crypto/x509/root_hurd.go b/libgo/go/crypto/x509/root_hurd.go new file mode 100644 index 00000000000..59e9ff0c81b --- /dev/null +++ b/libgo/go/crypto/x509/root_hurd.go @@ -0,0 +1,11 @@ +// 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. +// This file is derived from root_linux.go + +package x509 + +// Possible certificate files; stop after finding one. +var certFiles = []string{ + "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc. +} diff --git a/libgo/go/internal/poll/sendfile_glibc.go b/libgo/go/internal/poll/sendfile_glibc.go new file mode 100644 index 00000000000..6652e3fedc1 --- /dev/null +++ b/libgo/go/internal/poll/sendfile_glibc.go @@ -0,0 +1,51 @@ +// Copyright 2011 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 poll + +import "syscall" + +// maxSendfileSize is the largest chunk size we ask the kernel to copy +// at a time. +const maxSendfileSize int = 4 << 20 + +// SendFile wraps the sendfile system call. +func SendFile(dstFD *FD, src int, remain int64) (int64, error) { + if err := dstFD.writeLock(); err != nil { + return 0, err + } + defer dstFD.writeUnlock() + + dst := int(dstFD.Sysfd) + var written int64 + var err error + for remain > 0 { + n := maxSendfileSize + if int64(n) > remain { + n = int(remain) + } + n, err1 := syscall.Sendfile(dst, src, nil, n) + if n > 0 { + written += int64(n) + remain -= int64(n) + } else if n == 0 && err1 == nil { + break + } + if err1 == syscall.EAGAIN { + if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil { + continue + } + } + if err1 != nil { + // This includes syscall.ENOSYS (no kernel + // support) and syscall.EINVAL (fd types which + // don't implement sendfile) + err = err1 + break + } + } + return written, err +} diff --git a/libgo/go/internal/poll/sendfile_linux.go b/libgo/go/internal/poll/sendfile_linux.go deleted file mode 100644 index 8e938065f17..00000000000 --- a/libgo/go/internal/poll/sendfile_linux.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2011 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 poll - -import "syscall" - -// maxSendfileSize is the largest chunk size we ask the kernel to copy -// at a time. -const maxSendfileSize int = 4 << 20 - -// SendFile wraps the sendfile system call. -func SendFile(dstFD *FD, src int, remain int64) (int64, error) { - if err := dstFD.writeLock(); err != nil { - return 0, err - } - defer dstFD.writeUnlock() - - dst := int(dstFD.Sysfd) - var written int64 - var err error - for remain > 0 { - n := maxSendfileSize - if int64(n) > remain { - n = int(remain) - } - n, err1 := syscall.Sendfile(dst, src, nil, n) - if n > 0 { - written += int64(n) - remain -= int64(n) - } else if n == 0 && err1 == nil { - break - } - if err1 == syscall.EAGAIN { - if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil { - continue - } - } - if err1 != nil { - // This includes syscall.ENOSYS (no kernel - // support) and syscall.EINVAL (fd types which - // don't implement sendfile) - err = err1 - break - } - } - return written, err -} diff --git a/libgo/go/net/cgo_hurd.go b/libgo/go/net/cgo_hurd.go new file mode 100644 index 00000000000..98e4cfa6352 --- /dev/null +++ b/libgo/go/net/cgo_hurd.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. +// This file is derived from cgo_bsd.go + +// +build cgo,!netgo +// +build hurd + +package net + +/* +#include +*/ + +import "syscall" + +const cgoAddrInfoFlags = syscall.AI_CANONNAME | syscall.AI_V4MAPPED | syscall.AI_ALL diff --git a/libgo/go/net/sendfile_glibc.go b/libgo/go/net/sendfile_glibc.go new file mode 100644 index 00000000000..a71cfc961c2 --- /dev/null +++ b/libgo/go/net/sendfile_glibc.go @@ -0,0 +1,55 @@ +// Copyright 2011 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 net + +import ( + "internal/poll" + "io" + "os" +) + +// sendFile copies the contents of r to c using the sendfile +// system call to minimize copies. +// +// if handled == true, sendFile returns the number of bytes copied and any +// non-EOF error. +// +// if handled == false, sendFile performed no work. +func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { + var remain int64 = 1 << 62 // by default, copy until EOF + + lr, ok := r.(*io.LimitedReader) + if ok { + remain, r = lr.N, lr.R + if remain <= 0 { + return 0, nil, true + } + } + f, ok := r.(*os.File) + if !ok { + return 0, nil, false + } + + sc, err := f.SyscallConn() + if err != nil { + return 0, nil, false + } + + var werr error + err = sc.Read(func(fd uintptr) bool { + written, werr = poll.SendFile(&c.pfd, int(fd), remain) + return true + }) + if werr == nil { + werr = err + } + + if lr != nil { + lr.N = remain - written + } + return written, wrapSyscallError("sendfile", err), written > 0 +} diff --git a/libgo/go/net/sendfile_linux.go b/libgo/go/net/sendfile_linux.go deleted file mode 100644 index 297e625d24b..00000000000 --- a/libgo/go/net/sendfile_linux.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2011 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 net - -import ( - "internal/poll" - "io" - "os" -) - -// sendFile copies the contents of r to c using the sendfile -// system call to minimize copies. -// -// if handled == true, sendFile returns the number of bytes copied and any -// non-EOF error. -// -// if handled == false, sendFile performed no work. -func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { - var remain int64 = 1 << 62 // by default, copy until EOF - - lr, ok := r.(*io.LimitedReader) - if ok { - remain, r = lr.N, lr.R - if remain <= 0 { - return 0, nil, true - } - } - f, ok := r.(*os.File) - if !ok { - return 0, nil, false - } - - sc, err := f.SyscallConn() - if err != nil { - return 0, nil, false - } - - var werr error - err = sc.Read(func(fd uintptr) bool { - written, werr = poll.SendFile(&c.pfd, int(fd), remain) - return true - }) - if werr == nil { - werr = err - } - - if lr != nil { - lr.N = remain - written - } - return written, wrapSyscallError("sendfile", err), written > 0 -} diff --git a/libgo/go/net/sockopt_hurd.go b/libgo/go/net/sockopt_hurd.go new file mode 100644 index 00000000000..c6de7a9a1f0 --- /dev/null +++ b/libgo/go/net/sockopt_hurd.go @@ -0,0 +1,41 @@ +// 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. + +package net + +import ( + "os" + "syscall" +) + +func setDefaultSockopts(s, family, sotype int, ipv6only bool) error { + if family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW { + // Allow both IP versions even if the OS default + // is otherwise. Note that some operating systems + // never admit this option. + syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only)) + } + // Allow broadcast. + if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil { + return os.NewSyscallError("setsockopt", err) + } + return nil +} + +func setDefaultListenerSockopts(s int) error { + // Allow reuse of recently-used addresses. + if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { + return os.NewSyscallError("setsockopt", err) + } + return nil +} + +func setDefaultMulticastSockopts(s int) error { + // Allow multicast UDP and raw IP datagram sockets to listen + // concurrently across multiple listeners. + if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { + return os.NewSyscallError("setsockopt", err) + } + return nil +} diff --git a/libgo/go/os/executable_procfs.go b/libgo/go/os/executable_procfs.go index d6ac270ace4..e690103b0ad 100644 --- a/libgo/go/os/executable_procfs.go +++ b/libgo/go/os/executable_procfs.go @@ -19,7 +19,7 @@ var executablePath, executablePathErr = func() (string, error) { switch runtime.GOOS { default: return "", errors.New("Executable not implemented for " + runtime.GOOS) - case "linux", "android": + case "hurd", "linux", "android": procfn = "/proc/self/exe" case "netbsd": procfn = "/proc/curproc/exe" diff --git a/libgo/go/os/pipe_glibc.go b/libgo/go/os/pipe_glibc.go new file mode 100644 index 00000000000..31b144e92c7 --- /dev/null +++ b/libgo/go/os/pipe_glibc.go @@ -0,0 +1,35 @@ +// Copyright 2013 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 os + +import "syscall" + +// Pipe returns a connected pair of Files; reads from r return bytes written to w. +// It returns the files and an error, if any. +func Pipe() (r *File, w *File, err error) { + var p [2]int + + e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC) + // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it + // might not be implemented. + if e == syscall.ENOSYS { + // See ../syscall/exec.go for description of lock. + syscall.ForkLock.RLock() + e = syscall.Pipe(p[0:]) + if e != nil { + syscall.ForkLock.RUnlock() + return nil, nil, NewSyscallError("pipe", e) + } + syscall.CloseOnExec(p[0]) + syscall.CloseOnExec(p[1]) + syscall.ForkLock.RUnlock() + } else if e != nil { + return nil, nil, NewSyscallError("pipe2", e) + } + + return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil +} diff --git a/libgo/go/os/pipe_linux.go b/libgo/go/os/pipe_linux.go deleted file mode 100644 index acd7b88e1d4..00000000000 --- a/libgo/go/os/pipe_linux.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2013 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 os - -import "syscall" - -// Pipe returns a connected pair of Files; reads from r return bytes written to w. -// It returns the files and an error, if any. -func Pipe() (r *File, w *File, err error) { - var p [2]int - - e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC) - // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it - // might not be implemented. - if e == syscall.ENOSYS { - // See ../syscall/exec.go for description of lock. - syscall.ForkLock.RLock() - e = syscall.Pipe(p[0:]) - if e != nil { - syscall.ForkLock.RUnlock() - return nil, nil, NewSyscallError("pipe", e) - } - syscall.CloseOnExec(p[0]) - syscall.CloseOnExec(p[1]) - syscall.ForkLock.RUnlock() - } else if e != nil { - return nil, nil, NewSyscallError("pipe2", e) - } - - return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil -}