libgo patch committed: Add hurd support to os, net, crypto/x509

Ian Lance Taylor iant@golang.org
Thu Feb 7 04:46:00 GMT 2019


This libgo patch by Svante Signell adds Hurd support to the os, net,
and crypto/x509 packages.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
-------------- next part --------------
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268603)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -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.
Index: libgo/go/crypto/x509/root_hurd.go
===================================================================
--- libgo/go/crypto/x509/root_hurd.go	(nonexistent)
+++ libgo/go/crypto/x509/root_hurd.go	(working copy)
@@ -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.
+}
Index: libgo/go/internal/poll/sendfile_glibc.go
===================================================================
--- libgo/go/internal/poll/sendfile_glibc.go	(revision 268369)
+++ libgo/go/internal/poll/sendfile_glibc.go	(working copy)
@@ -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 poll
 
 import "syscall"
Index: libgo/go/internal/poll/sendfile_linux.go
===================================================================
--- libgo/go/internal/poll/sendfile_linux.go	(revision 268369)
+++ libgo/go/internal/poll/sendfile_linux.go	(nonexistent)
@@ -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
-}
Index: libgo/go/net/cgo_hurd.go
===================================================================
--- libgo/go/net/cgo_hurd.go	(nonexistent)
+++ libgo/go/net/cgo_hurd.go	(working copy)
@@ -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 <netdb.h>
+*/
+
+import "syscall"
+
+const cgoAddrInfoFlags = syscall.AI_CANONNAME | syscall.AI_V4MAPPED | syscall.AI_ALL
Index: libgo/go/net/sendfile_glibc.go
===================================================================
--- libgo/go/net/sendfile_glibc.go	(revision 268369)
+++ libgo/go/net/sendfile_glibc.go	(working copy)
@@ -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 net
 
 import (
Index: libgo/go/net/sendfile_linux.go
===================================================================
--- libgo/go/net/sendfile_linux.go	(revision 268369)
+++ libgo/go/net/sendfile_linux.go	(nonexistent)
@@ -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
-}
Index: libgo/go/net/sockopt_hurd.go
===================================================================
--- libgo/go/net/sockopt_hurd.go	(nonexistent)
+++ libgo/go/net/sockopt_hurd.go	(working copy)
@@ -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
+}
Index: libgo/go/os/executable_procfs.go
===================================================================
--- libgo/go/os/executable_procfs.go	(revision 268459)
+++ libgo/go/os/executable_procfs.go	(working copy)
@@ -19,7 +19,7 @@ var executablePath, executablePathErr =
 	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"
Index: libgo/go/os/pipe_glibc.go
===================================================================
--- libgo/go/os/pipe_glibc.go	(revision 268369)
+++ libgo/go/os/pipe_glibc.go	(working copy)
@@ -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 os
 
 import "syscall"
Index: libgo/go/os/pipe_linux.go
===================================================================
--- libgo/go/os/pipe_linux.go	(revision 268369)
+++ libgo/go/os/pipe_linux.go	(nonexistent)
@@ -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
-}


More information about the Gcc-patches mailing list