Commit 4497d7eb authored by Cherry Zhang's avatar Cherry Zhang

[dev.link] all: merge branch 'master' into dev.link

Clean merge.

Change-Id: I26a4e3d4c09a928c9fd95e394304ee10319ca7c5
parents 32190b0a 35cfe059
......@@ -813,3 +813,52 @@ func TestCachedInstall(t *testing.T) {
t.Errorf("p.h not installed in second run: %v", err)
}
}
// Issue 35294.
func TestManyCalls(t *testing.T) {
t.Parallel()
defer func() {
os.Remove("testp7" + exeSuffix)
os.Remove("libgo7.a")
os.Remove("libgo7.h")
}()
cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo7.a", "./libgo7")
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
checkLineComments(t, "libgo7.h")
ccArgs := append(cc, "-o", "testp7"+exeSuffix, "main7.c", "libgo7.a")
if runtime.Compiler == "gccgo" {
ccArgs = append(ccArgs, "-lgo")
}
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
argv := cmdToRun("./testp7")
cmd = exec.Command(argv[0], argv[1:]...)
var sb strings.Builder
cmd.Stdout = &sb
cmd.Stderr = &sb
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
timer := time.AfterFunc(time.Minute,
func() {
t.Error("test program timed out")
cmd.Process.Kill()
},
)
defer timer.Stop()
if err := cmd.Wait(); err != nil {
t.Log(sb.String())
t.Error(err)
}
}
// 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 main
import "C"
var sink []byte
//export GoFunction7
func GoFunction7() {
sink = make([]byte, 4096)
}
func main() {
}
// 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.
// Test that lots of calls don't deadlock.
#include <stdio.h>
#include "libgo7.h"
int main() {
int i;
for (i = 0; i < 100000; i++) {
GoFunction7();
}
}
......@@ -2809,7 +2809,7 @@ func typecheckcomplit(n *Node) (res *Node) {
n.Right = nil
case TSLICE:
length := typecheckarraylit(t.Elem(), -2, n.List.Slice(), "slice literal")
length := typecheckarraylit(t.Elem(), -1, n.List.Slice(), "slice literal")
n.Op = OSLICELIT
n.Right = nodintconst(length)
......
......@@ -27,6 +27,7 @@ var (
BuildBuildmode string // -buildmode flag
BuildContext = defaultContext()
BuildMod string // -mod flag
BuildModReason string // reason -mod flag is set, if set by default
BuildI bool // -i flag
BuildLinkshared bool // -linkshared flag
BuildMSan bool // -msan flag
......
......@@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
......@@ -25,10 +26,10 @@ import (
"golang.org/x/mod/semver"
)
var QuietLookup bool // do not print about lookups
var PkgMod string // $GOPATH/pkg/mod; set by package modload
const logFindingDelay = 1 * time.Second
func cacheDir(path string) (string, error) {
if PkgMod == "" {
return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
......@@ -140,6 +141,11 @@ func (r *cachingRepo) Versions(prefix string) ([]string, error) {
err error
}
c := r.cache.Do("versions:"+prefix, func() interface{} {
logTimer := time.AfterFunc(logFindingDelay, func() {
fmt.Fprintf(os.Stderr, "go: finding versions for %s\n", r.path)
})
defer logTimer.Stop()
list, err := r.r.Versions(prefix)
return cached{list, err}
}).(cached)
......@@ -162,9 +168,11 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
return cachedInfo{info, nil}
}
if !QuietLookup {
logTimer := time.AfterFunc(logFindingDelay, func() {
fmt.Fprintf(os.Stderr, "go: finding %s %s\n", r.path, rev)
}
})
defer logTimer.Stop()
info, err = r.r.Stat(rev)
if err == nil {
// If we resolved, say, 1234abcde to v0.0.0-20180604122334-1234abcdef78,
......@@ -192,9 +200,11 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
func (r *cachingRepo) Latest() (*RevInfo, error) {
c := r.cache.Do("latest:", func() interface{} {
if !QuietLookup {
logTimer := time.AfterFunc(logFindingDelay, func() {
fmt.Fprintf(os.Stderr, "go: finding %s latest\n", r.path)
}
})
defer logTimer.Stop()
info, err := r.r.Latest()
// Save info for likely future Stat call.
......
......@@ -71,10 +71,6 @@ func download(mod module.Version, dir string) (err error) {
return err
}
if cfg.CmdName != "mod download" {
fmt.Fprintf(os.Stderr, "go: extracting %s %s\n", mod.Path, mod.Version)
}
unlock, err := lockVersion(mod)
if err != nil {
return err
......
......@@ -5,7 +5,6 @@
package modfetch
import (
"errors"
"fmt"
"io"
"os"
......@@ -215,7 +214,7 @@ func Lookup(proxy, path string) (Repo, error) {
// lookup returns the module with the given module path.
func lookup(proxy, path string) (r Repo, err error) {
if cfg.BuildMod == "vendor" {
return nil, errModVendor
return nil, errLookupDisabled
}
if str.GlobsMatchPath(cfg.GONOPROXY, path) {
......@@ -239,11 +238,21 @@ func lookup(proxy, path string) (r Repo, err error) {
}
}
type lookupDisabledError struct{}
func (lookupDisabledError) Error() string {
if cfg.BuildModReason == "" {
return fmt.Sprintf("module lookup disabled by -mod=%s", cfg.BuildMod)
}
return fmt.Sprintf("module lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
}
var errLookupDisabled error = lookupDisabledError{}
var (
errModVendor = errors.New("module lookup disabled by -mod=vendor")
errProxyOff = notExistError("module lookup disabled by GOPROXY=off")
errNoproxy error = notExistError("disabled by GOPRIVATE/GONOPROXY")
errUseProxy error = notExistError("path does not match GOPRIVATE/GONOPROXY")
errProxyOff = notExistError("module lookup disabled by GOPROXY=off")
errNoproxy error = notExistError("disabled by GOPRIVATE/GONOPROXY")
errUseProxy error = notExistError("path does not match GOPRIVATE/GONOPROXY")
)
func lookupDirect(path string) (Repo, error) {
......
......@@ -372,7 +372,7 @@ func runGet(cmd *base.Command, args []string) {
continue
default:
// The argument is a package path.
// The argument is a package or module path.
if pkgs := modload.TargetPackages(path); len(pkgs) != 0 {
// The path is in the main module. Nothing to query.
if vers != "upgrade" && vers != "patch" {
......@@ -763,6 +763,9 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
info, err := modload.Query(path, vers, prevM.Version, modload.Allowed)
if err == nil {
if info.Version != vers && info.Version != prevM.Version {
logOncef("go: %s %s => %s", path, vers, info.Version)
}
return module.Version{Path: path, Version: info.Version}, nil
}
......@@ -791,6 +794,9 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
if !strings.Contains(path, "...") {
var modErr *modload.PackageNotInModuleError
if errors.As(err, &modErr) && modErr.Mod.Path == path {
if modErr.Mod.Version != vers {
logOncef("go: %s %s => %s", path, vers, modErr.Mod.Version)
}
return modErr.Mod, nil
}
}
......@@ -798,7 +804,13 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
return module.Version{}, err
}
return results[0].Mod, nil
m := results[0].Mod
if m.Path != path {
logOncef("go: found %s in %s %s", path, m.Path, m.Version)
} else if m.Version != vers {
logOncef("go: %s %s => %s", path, vers, m.Version)
}
return m, nil
}
// An upgrader adapts an underlying mvs.Reqs to apply an
......@@ -955,6 +967,9 @@ func (u *upgrader) Upgrade(m module.Version) (module.Version, error) {
return m, nil
}
if info.Version != m.Version {
logOncef("go: %s %s => %s", m.Path, getU, info.Version)
}
return module.Version{Path: m.Path, Version: info.Version}, nil
}
......@@ -983,3 +998,12 @@ func (r *lostUpgradeReqs) Required(mod module.Version) ([]module.Version, error)
}
return r.Reqs.Required(mod)
}
var loggedLines sync.Map
func logOncef(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
if _, dup := loggedLines.LoadOrStore(msg, true); !dup {
fmt.Fprintln(os.Stderr, msg)
}
}
......@@ -460,25 +460,36 @@ func setDefaultBuildMod() {
// manipulate the build list.
return
}
if modRoot != "" {
if fi, err := os.Stat(filepath.Join(modRoot, "vendor")); err == nil && fi.IsDir() {
modGo := "unspecified"
if modFile.Go != nil {
if semver.Compare("v"+modFile.Go.Version, "v1.14") >= 0 {
// The Go version is at least 1.14, and a vendor directory exists.
// Set -mod=vendor by default.
cfg.BuildMod = "vendor"
return
} else {
modGo = modFile.Go.Version
}
if modRoot == "" {
return
}
if fi, err := os.Stat(filepath.Join(modRoot, "vendor")); err == nil && fi.IsDir() {
modGo := "unspecified"
if modFile.Go != nil {
if semver.Compare("v"+modFile.Go.Version, "v1.14") >= 0 {
// The Go version is at least 1.14, and a vendor directory exists.
// Set -mod=vendor by default.
cfg.BuildMod = "vendor"
cfg.BuildModReason = "Go version in go.mod is at least 1.14 and vendor directory exists."
return
} else {
modGo = modFile.Go.Version
}
fmt.Fprintf(os.Stderr, "go: not defaulting to -mod=vendor because go.mod 'go' version is %s\n", modGo)
}
// Since a vendor directory exists, we have a non-trivial reason for
// choosing -mod=mod, although it probably won't be used for anything.
// Record the reason anyway for consistency.
// It may be overridden if we switch to mod=readonly below.
cfg.BuildModReason = fmt.Sprintf("Go version in go.mod is %s.", modGo)
}
// TODO(golang.org/issue/33326): set -mod=readonly implicitly if the go.mod
// file is itself read-only?
p := ModFilePath()
if fi, err := os.Stat(p); err == nil && !hasWritePerm(p, fi) {
cfg.BuildMod = "readonly"
cfg.BuildModReason = "go.mod file is read-only."
}
}
// checkVendorConsistency verifies that the vendor/modules.txt file matches (if
......@@ -858,7 +869,11 @@ func WriteGoMod() {
if dirty && cfg.BuildMod == "readonly" {
// If we're about to fail due to -mod=readonly,
// prefer to report a dirty go.mod over a dirty go.sum
base.Fatalf("go: updates to go.mod needed, disabled by -mod=readonly")
if cfg.BuildModReason != "" {
base.Fatalf("go: updates to go.mod needed, disabled by -mod=readonly\n\t(%s)", cfg.BuildModReason)
} else {
base.Fatalf("go: updates to go.mod needed, disabled by -mod=readonly")
}
}
// Always update go.sum, even if we didn't change go.mod: we may have
// downloaded modules that we didn't have before.
......
......@@ -626,6 +626,7 @@ func (ld *loader) load(roots func() []string) {
added[pkg.path] = true
numAdded++
if !haveMod[err.Module] {
fmt.Fprintf(os.Stderr, "go: found %s in %s %s\n", pkg.path, err.Module.Path, err.Module.Version)
haveMod[err.Module] = true
modAddedBy[err.Module] = pkg
buildList = append(buildList, err.Module)
......
......@@ -12,6 +12,7 @@ import (
"strings"
"sync"
"cmd/go/internal/cfg"
"cmd/go/internal/imports"
"cmd/go/internal/modfetch"
"cmd/go/internal/search"
......@@ -62,10 +63,24 @@ func Query(path, query, current string, allowed func(module.Version) bool) (*mod
return info, err
}
var errQueryDisabled error = queryDisabledError{}
type queryDisabledError struct{}
func (queryDisabledError) Error() string {
if cfg.BuildModReason == "" {
return fmt.Sprintf("cannot query module due to -mod=%s", cfg.BuildMod)
}
return fmt.Sprintf("cannot query module due to -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
}
func queryProxy(proxy, path, query, current string, allowed func(module.Version) bool) (*modfetch.RevInfo, error) {
if current != "" && !semver.IsValid(current) {
return nil, fmt.Errorf("invalid previous version %q", current)
}
if cfg.BuildMod != "" && cfg.BuildMod != "mod" {
return nil, errQueryDisabled
}
if allowed == nil {
allowed = func(module.Version) bool { return true }
}
......
// 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 aix js,wasm plan9
// On plan9, per http://9p.io/magic/man2html/2/access: “Since file permissions
// are checked by the server and group information is not known to the client,
// access must open the file to check permissions.”
//
// aix and js,wasm are similar, in that they do not define syscall.Access.
package modload
import (
"os"
)
// hasWritePerm reports whether the current user has permission to write to the
// file with the given info.
func hasWritePerm(path string, _ os.FileInfo) bool {
if f, err := os.OpenFile(path, os.O_WRONLY, 0); err == nil {
f.Close()
return true
}
return false
}
// 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 darwin dragonfly freebsd linux netbsd openbsd solaris
package modload
import (
"os"
"syscall"
)
// hasWritePerm reports whether the current user has permission to write to the
// file with the given info.
//
// Although the root user on most Unix systems can write to files even without
// permission, hasWritePerm reports false if no appropriate permission bit is
// set even if the current user is root.
func hasWritePerm(path string, fi os.FileInfo) bool {
if os.Getuid() == 0 {
// The root user can access any file, but we still want to default to
// read-only mode if the go.mod file is marked as globally non-writable.
// (If the user really intends not to be in readonly mode, they can
// pass -mod=mod explicitly.)
return fi.Mode()&0222 != 0
}
const W_OK = 0x2
return syscall.Access(path, W_OK) == nil
}
// 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 windows
package modload
import (
"os"
)
// hasWritePerm reports whether the current user has permission to write to the
// file with the given info.
func hasWritePerm(_ string, fi os.FileInfo) bool {
// Windows has a read-only attribute independent of ACLs, so use that to
// determine whether the file is intended to be overwritten.
//
// Per https://golang.org/pkg/os/#Chmod:
// “On Windows, only the 0200 bit (owner writable) of mode is used; it
// controls whether the file's read-only attribute is set or cleared.”
return fi.Mode()&0200 != 0
}
......@@ -431,7 +431,11 @@ func (ts *testScript) cmdChmod(neg bool, args []string) {
if err != nil || perm&uint64(os.ModePerm) != perm {
ts.fatalf("invalid mode: %s", args[0])
}
for _, path := range args[1:] {
for _, arg := range args[1:] {
path := arg
if !filepath.IsAbs(path) {
path = filepath.Join(ts.cd, arg)
}
err := os.Chmod(path, os.FileMode(perm))
ts.check(err)
}
......
......@@ -11,6 +11,5 @@ go mod init m
cmp stderr stderr-expected
-- stderr-expected --
go: finding example.com/newcycle v1.0.0
go get: inconsistent versions:
example.com/newcycle/a@v1.0.0 requires example.com/newcycle/a@v1.0.1 (not example.com/newcycle/a@v1.0.0)
......@@ -11,7 +11,7 @@ stdout '^rsc.io/quote v1.5.1 .*vendor[\\/]rsc.io[\\/]quote$'
stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text[\\/]language$'
! go list -mod=vendor -m rsc.io/quote@latest
stderr 'go list -m: rsc.io/quote@latest: module lookup disabled by -mod=vendor'
stderr 'go list -m: rsc.io/quote@latest: cannot query module due to -mod=vendor'
! go get -mod=vendor -u
stderr 'flag provided but not defined: -mod'
......
......@@ -56,11 +56,13 @@ import (
func Test(t *testing.T) {}
-- update-main-expected --
go: example.com/badchain/c upgrade => v1.1.0
go get: example.com/badchain/c@v1.0.0 updating to
example.com/badchain/c@v1.1.0: parsing go.mod:
module declares its path as: badchain.example.com/c
but was required as: example.com/badchain/c
-- update-a-expected --
go: example.com/badchain/a upgrade => v1.1.0
go get: example.com/badchain/a@v1.1.0 requires
example.com/badchain/b@v1.1.0 requires
example.com/badchain/c@v1.1.0: parsing go.mod:
......@@ -73,11 +75,13 @@ go: example.com/badchain/a@v1.1.0 requires
module declares its path as: badchain.example.com/c
but was required as: example.com/badchain/c
-- list-missing-expected --
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
go: m/use imports
example.com/badchain/c: example.com/badchain/c@v1.1.0: parsing go.mod:
module declares its path as: badchain.example.com/c
but was required as: example.com/badchain/c
-- list-missing-test-expected --
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
go: m/testuse tested by
m/testuse.test imports
example.com/badchain/c: example.com/badchain/c@v1.1.0: parsing go.mod:
......
......@@ -12,6 +12,14 @@ cp go.mod go.mod.empty
stderr 'import lookup disabled by -mod=readonly'
cmp go.mod go.mod.empty
# -mod=readonly should be set implicitly if the go.mod file is read-only
chmod 0400 go.mod
env GOFLAGS=
! go list all
chmod 0600 go.mod
env GOFLAGS=-mod=readonly
# update go.mod - go get allowed
go get rsc.io/quote
grep rsc.io/quote go.mod
......@@ -21,11 +29,11 @@ cp go.mod.empty go.mod
go mod tidy
# -mod=readonly must succeed once go.mod is up-to-date...
go list
go list all
# ... even if it needs downloads
go clean -modcache
go list
go list all
# -mod=readonly should reject inconsistent go.mod files
# (ones that would be rewritten).
......
......@@ -48,7 +48,6 @@ go list -f {{.Dir}} -tags tools all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
stderr '^go: not defaulting to -mod=vendor because go.mod .go. version is 1.13$'
go list -m -f '{{.Dir}}' all
stdout '^'$WORK'[/\\]auto$'
......@@ -146,7 +145,6 @@ go list -mod=vendor -f {{.Dir}} -tags tools all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
! stderr 'not defaulting to -mod=vendor'
# ...but a version mismatch for an explicit dependency should be noticed.
cp $WORK/modules-bad-1.13.txt vendor/modules.txt
......
......@@ -202,7 +202,7 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
// FIPS 186-3, section 4.6
n := priv.Q.BitLen()
if priv.Q.Sign() <= 0 || priv.P.Sign() <= 0 || priv.G.Sign() <= 0 || priv.X.Sign() <= 0 || n&7 != 0 {
if priv.Q.Sign() <= 0 || priv.P.Sign() <= 0 || priv.G.Sign() <= 0 || priv.X.Sign() <= 0 || n%8 != 0 {
err = ErrInvalidPublicKey
return
}
......@@ -281,7 +281,7 @@ func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool {
w := new(big.Int).ModInverse(s, pub.Q)
n := pub.Q.BitLen()
if n&7 != 0 {
if n%8 != 0 {
return false
}
z := new(big.Int).SetBytes(hash)
......
......@@ -26,6 +26,7 @@ import (
"io"
"math"
"reflect"
"sync"
)
// A ByteOrder specifies how to convert byte sequences into
......@@ -363,18 +364,32 @@ func Size(v interface{}) int {
return dataSize(reflect.Indirect(reflect.ValueOf(v)))
}
var structSize sync.Map // map[reflect.Type]int
// dataSize returns the number of bytes the actual data represented by v occupies in memory.
// For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice
// it returns the length of the slice times the element size and does not count the memory
// occupied by the header. If the type of v is not acceptable, dataSize returns -1.
func dataSize(v reflect.Value) int {
if v.Kind() == reflect.Slice {
switch v.Kind() {
case reflect.Slice:
if s := sizeof(v.Type().Elem()); s >= 0 {
return s * v.Len()
}
return -1
case reflect.Struct:
t := v.Type()
if size, ok := structSize.Load(t); ok {
return size.(int)
}
size := sizeof(t)
structSize.Store(t, size)
return size
default:
return sizeof(v.Type())
}
return sizeof(v.Type())
}
// sizeof returns the size >= 0 of variables for the given type or -1 if the type is not acceptable.
......
......@@ -7,9 +7,11 @@ package binary
import (
"bytes"
"io"
"io/ioutil"
"math"
"reflect"
"strings"
"sync"
"testing"
)
......@@ -296,6 +298,58 @@ func TestBlankFields(t *testing.T) {
}
}
func TestSizeStructCache(t *testing.T) {
// Reset the cache, otherwise multiple test runs fail.
structSize = sync.Map{}
count := func() int {
var i int
structSize.Range(func(_, _ interface{}) bool {
i++
return true
})
return i
}
var total int
added := func() int {
delta := count() - total
total += delta
return delta
}
type foo struct {
A uint32
}
type bar struct {
A Struct
B foo
C Struct
}
testcases := []struct {
val interface{}
want int
}{
{new(foo), 1},
{new(bar), 1},
{new(bar), 0},
{new(struct{ A Struct }), 1},
{new(struct{ A Struct }), 0},
}
for _, tc := range testcases {
if Size(tc.val) == -1 {
t.Fatalf("Can't get the size of %T", tc.val)
}
if n := added(); n != tc.want {
t.Errorf("Sizing %T added %d entries to the cache, want %d", tc.val, n, tc.want)
}
}
}
// An attempt to read into a struct with an unexported field will
// panic. This is probably not the best choice, but at this point
// anything else would be an API change.
......@@ -436,6 +490,14 @@ func BenchmarkReadStruct(b *testing.B) {
}
}
func BenchmarkWriteStruct(b *testing.B) {
b.SetBytes(int64(Size(&s)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
Write(ioutil.Discard, BigEndian, &s)
}
}
func BenchmarkReadInts(b *testing.B) {
var ls Struct
bsr := &byteSliceReader{}
......
......@@ -84,18 +84,16 @@ var pkgDeps = map[string][]string{
},
// L2 adds Unicode and strings processing.
"bufio": {"L0", "unicode/utf8", "bytes"},
"bytes": {"L0", "unicode", "unicode/utf8"},
"bytes/hash": {"L0"},
"path": {"L0", "unicode/utf8", "strings"},
"strings": {"L0", "unicode", "unicode/utf8"},
"unicode": {},
"bufio": {"L0", "unicode/utf8", "bytes"},
"bytes": {"L0", "unicode", "unicode/utf8"},
"path": {"L0", "unicode/utf8", "strings"},
"strings": {"L0", "unicode", "unicode/utf8"},
"unicode": {},
"L2": {
"L1",
"bufio",
"bytes",
"bytes/hash",
"path",
"strings",
"unicode",
......@@ -116,6 +114,7 @@ var pkgDeps = map[string][]string{
"hash/crc32": {"L2", "hash"},
"hash/crc64": {"L2", "hash"},
"hash/fnv": {"L2", "hash"},
"hash/maphash": {"L2", "hash"},
"image": {"L2", "image/color"}, // interfaces
"image/color": {"L2"}, // interfaces
"image/color/palette": {"L2", "image/color"},
......@@ -244,51 +243,51 @@ var pkgDeps = map[string][]string{
"go/types": {"L4", "GOPARSER", "container/heap", "go/constant"},
// One of a kind.
"archive/tar": {"L4", "OS", "syscall", "os/user"},
"archive/zip": {"L4", "OS", "compress/flate"},
"container/heap": {"sort"},
"compress/bzip2": {"L4"},
"compress/flate": {"L4"},
"compress/gzip": {"L4", "compress/flate"},
"compress/lzw": {"L4"},
"compress/zlib": {"L4", "compress/flate"},
"context": {"errors", "internal/reflectlite", "sync", "sync/atomic", "time"},
"database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"},
"database/sql/driver": {"L4", "context", "time", "database/sql/internal"},
"debug/dwarf": {"L4"},
"debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/gosym": {"L4"},
"debug/macho": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/pe": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/plan9obj": {"L4", "OS"},
"encoding": {"L4"},
"encoding/ascii85": {"L4"},
"encoding/asn1": {"L4", "math/big"},
"encoding/csv": {"L4"},
"encoding/gob": {"L4", "OS", "encoding"},
"encoding/hex": {"L4"},
"encoding/json": {"L4", "encoding"},
"encoding/pem": {"L4"},
"encoding/xml": {"L4", "encoding"},
"flag": {"L4", "OS"},
"go/build": {"L4", "OS", "GOPARSER", "internal/goroot", "internal/goversion"},
"html": {"L4"},
"image/draw": {"L4", "image/internal/imageutil"},
"image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"},
"image/internal/imageutil": {"L4"},
"image/jpeg": {"L4", "image/internal/imageutil"},
"image/png": {"L4", "compress/zlib"},
"index/suffixarray": {"L4", "regexp"},
"internal/goroot": {"L4", "OS"},
"internal/singleflight": {"sync"},
"internal/trace": {"L4", "OS", "container/heap"},
"internal/xcoff": {"L4", "OS", "debug/dwarf"},
"math/big": {"L4"},
"mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"},
"mime/quotedprintable": {"L4"},
"net/internal/socktest": {"L4", "OS", "syscall", "internal/syscall/windows"},
"net/url": {"L4"},
"plugin": {"L0", "OS", "CGO"},
"archive/tar": {"L4", "OS", "syscall", "os/user"},
"archive/zip": {"L4", "OS", "compress/flate"},
"container/heap": {"sort"},
"compress/bzip2": {"L4"},
"compress/flate": {"L4"},
"compress/gzip": {"L4", "compress/flate"},
"compress/lzw": {"L4"},
"compress/zlib": {"L4", "compress/flate"},
"context": {"errors", "internal/reflectlite", "sync", "sync/atomic", "time"},
"database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"},
"database/sql/driver": {"L4", "context", "time", "database/sql/internal"},
"debug/dwarf": {"L4"},
"debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/gosym": {"L4"},
"debug/macho": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/pe": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/plan9obj": {"L4", "OS"},
"encoding": {"L4"},
"encoding/ascii85": {"L4"},
"encoding/asn1": {"L4", "math/big"},
"encoding/csv": {"L4"},
"encoding/gob": {"L4", "OS", "encoding"},
"encoding/hex": {"L4"},
"encoding/json": {"L4", "encoding"},
"encoding/pem": {"L4"},
"encoding/xml": {"L4", "encoding"},
"flag": {"L4", "OS"},
"go/build": {"L4", "OS", "GOPARSER", "internal/goroot", "internal/goversion"},
"html": {"L4"},
"image/draw": {"L4", "image/internal/imageutil"},
"image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"},
"image/internal/imageutil": {"L4"},
"image/jpeg": {"L4", "image/internal/imageutil"},
"image/png": {"L4", "compress/zlib"},
"index/suffixarray": {"L4", "regexp"},
"internal/goroot": {"L4", "OS"},
"internal/singleflight": {"sync"},
"internal/trace": {"L4", "OS", "container/heap"},
"internal/xcoff": {"L4", "OS", "debug/dwarf"},
"math/big": {"L4"},
"mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"},
"mime/quotedprintable": {"L4"},
"net/internal/socktest": {"L4", "OS", "syscall", "internal/syscall/windows"},
"net/url": {"L4"},
"plugin": {"L0", "OS", "CGO"},
"runtime/pprof/internal/profile": {"L4", "OS", "compress/gzip", "regexp"},
"testing/internal/testdeps": {"L4", "internal/testlog", "runtime/pprof", "regexp"},
"text/scanner": {"L4", "OS"},
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package bytes/hash provides hash functions on byte sequences. These
// Package hash/maphash provides hash functions on byte sequences. These
// hash functions are intended to be used to implement hash tables or
// other data structures that need to map arbitrary strings or byte
// sequences to a uniform distribution of integers. The hash functions
......@@ -29,7 +29,7 @@
// All bits of the Hash result are close to uniformly and
// independently distributed, so can be safely restricted to a range
// using bit masking, shifting, or modular arithmetic.
package hash
package maphash
import (
"unsafe"
......@@ -161,7 +161,7 @@ func rthash(b []byte, seed uint64) uint64 {
//go:linkname runtime_memhash runtime.memhash
func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr
// Wrapper functions so that a bytes/hash.Hash implements
// Wrapper functions so that a hash/maphash.Hash implements
// the hash.Hash and hash.Hash64 interfaces.
func (h *Hash) Write(b []byte) (int, error) {
......
......@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hash_test
package maphash_test
import (
"bytes/hash"
basehash "hash"
"hash"
"hash/maphash"
"testing"
)
func TestUnseededHash(t *testing.T) {
m := map[uint64]struct{}{}
for i := 0; i < 1000; i++ {
h := hash.New()
h := maphash.New()
m[h.Hash()] = struct{}{}
}
if len(m) < 900 {
......@@ -22,10 +22,10 @@ func TestUnseededHash(t *testing.T) {
}
func TestSeededHash(t *testing.T) {
s := hash.MakeSeed(1234)
s := maphash.MakeSeed(1234)
m := map[uint64]struct{}{}
for i := 0; i < 1000; i++ {
h := hash.New()
h := maphash.New()
h.SetSeed(s)
m[h.Hash()] = struct{}{}
}
......@@ -36,8 +36,8 @@ func TestSeededHash(t *testing.T) {
func TestHashGrouping(t *testing.T) {
b := []byte("foo")
h1 := hash.New()
h2 := hash.New()
h1 := maphash.New()
h2 := maphash.New()
h2.SetSeed(h1.Seed())
h1.AddBytes(b)
for _, x := range b {
......@@ -51,8 +51,8 @@ func TestHashGrouping(t *testing.T) {
func TestHashBytesVsString(t *testing.T) {
s := "foo"
b := []byte(s)
h1 := hash.New()
h2 := hash.New()
h1 := maphash.New()
h2 := maphash.New()
h2.SetSeed(h1.Seed())
h1.AddString(s)
h2.AddBytes(b)
......@@ -66,7 +66,7 @@ func TestHashHighBytes(t *testing.T) {
const N = 10
m := map[uint64]struct{}{}
for i := 0; i < N; i++ {
h := hash.New()
h := maphash.New()
h.AddString("foo")
m[h.Hash()>>32] = struct{}{}
}
......@@ -76,5 +76,5 @@ func TestHashHighBytes(t *testing.T) {
}
// Make sure a Hash implements the hash.Hash and hash.Hash64 interfaces.
var _ basehash.Hash = &hash.Hash{}
var _ basehash.Hash64 = &hash.Hash{}
var _ hash.Hash = &maphash.Hash{}
var _ hash.Hash64 = &maphash.Hash{}
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hash_test
package maphash_test
import (
"bytes/hash"
"fmt"
"hash/maphash"
"math"
"math/rand"
"runtime"
......@@ -45,14 +45,14 @@ func TestSmhasherSanity(t *testing.T) {
}
func bytesHash(b []byte, seed uint64) uint64 {
h := hash.New()
h.SetSeed(hash.MakeSeed(seed))
h := maphash.New()
h.SetSeed(maphash.MakeSeed(seed))
h.AddBytes(b)
return h.Hash()
}
func stringHash(s string, seed uint64) uint64 {
h := hash.New()
h.SetSeed(hash.MakeSeed(seed))
h := maphash.New()
h.SetSeed(maphash.MakeSeed(seed))
h.AddString(s)
return h.Hash()
}
......
......@@ -162,7 +162,8 @@ IFS=$'\n'; for go_exe in $(type -ap go); do
fi
fi
done; unset IFS
echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP."
GOROOT_BOOTSTRAP_VERSION=$($GOROOT_BOOTSTRAP/bin/go version | sed 's/go version //')
echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP. ($GOROOT_BOOTSTRAP_VERSION)"
if $verbose; then
echo cmd/dist
fi
......
......@@ -178,6 +178,7 @@ func (h Header) sortedKeyValues(exclude map[string]bool) (kvs []keyValues, hs *h
// WriteSubset writes a header in wire format.
// If exclude is not nil, keys where exclude[key] == true are not written.
// Keys are not canonicalized before checking the exclude map.
func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error {
return h.writeSubset(w, exclude, nil)
}
......
......@@ -122,7 +122,7 @@ func afterTest(t testing.TB) {
").noteClientGone(": "a closenotifier sender",
}
var stacks string
for i := 0; i < 4; i++ {
for i := 0; i < 10; i++ {
bad = ""
stacks = strings.Join(interestingGoroutines(), "\n\n")
for substr, what := range badSubstring {
......
......@@ -22,7 +22,6 @@ import (
"fmt"
"go/token"
"internal/nettrace"
"internal/testenv"
"io"
"io/ioutil"
"log"
......@@ -2355,9 +2354,6 @@ func TestCancelRequestWithChannel(t *testing.T) {
}
func TestCancelRequestWithChannelBeforeDo_Cancel(t *testing.T) {
if os.Getenv("GO_BUILDER_NAME") == "windows-amd64-longtest" {
testenv.SkipFlaky(t, 35122)
}
testCancelRequestWithChannelBeforeDo(t, false)
}
func TestCancelRequestWithChannelBeforeDo_Context(t *testing.T) {
......
......@@ -136,9 +136,13 @@ func gcPaceScavenger() {
// physical page.
retainedNow := heapRetained()
// If we're already below our goal, publish the goal in case it changed
// then disable the background scavenger.
if retainedNow <= retainedGoal {
// If we're already below our goal or there's less the one physical page
// worth of work to do, publish the goal in case it changed then disable
// the background scavenger. We disable the background scavenger if there's
// less than one physical page of work to do to avoid a potential divide-by-zero
// in the calculations below (totalTime will be zero), and it's not worth
// turning on the scavenger for less than one page of work.
if retainedNow <= retainedGoal || retainedNow-retainedGoal < uint64(physPageSize) {
mheap_.scavengeRetainedGoal = retainedGoal
mheap_.scavengeBytesPerNS = 0
return
......
......@@ -229,13 +229,21 @@ func netpoll(delay int64) gList {
var events [128]portevent
retry:
var n uint32 = 1
if port_getn(portfd, &events[0], uint32(len(events)), &n, wait) < 0 {
if e := errno(); e != _EINTR && e != _ETIME {
r := port_getn(portfd, &events[0], uint32(len(events)), &n, wait)
e := errno()
if r < 0 && e == _ETIME && n > 0 {
// As per port_getn(3C), an ETIME failure does not preclude the
// delivery of some number of events. Treat a timeout failure
// with delivered events as a success.
r = 0
}
if r < 0 {
if e != _EINTR && e != _ETIME {
print("runtime: port_getn on fd ", portfd, " failed (errno=", e, ")\n")
throw("runtime: netpoll failed")
}
// If a timed sleep was interrupted, just return to
// recalculate how long we should sleep now.
// If a timed sleep was interrupted and there are no events,
// just return to recalculate how long we should sleep now.
if delay > 0 {
return gList{}
}
......
......@@ -1625,6 +1625,7 @@ func dropm() {
// Return mp.curg to dead state.
casgstatus(mp.curg, _Gsyscall, _Gdead)
mp.curg.preemptStop = false
atomic.Xadd(&sched.ngsys, +1)
// Block signals before unminit.
......@@ -4359,6 +4360,7 @@ func checkdead() {
}
unlock(&allglock)
if grunning == 0 { // possible if main goroutine calls runtime·Goexit()
unlock(&sched.lock) // unlock so that GODEBUG=scheddetail=1 doesn't hang
throw("no goroutines (main called runtime.Goexit) - deadlock!")
}
......@@ -4411,6 +4413,7 @@ func checkdead() {
}
getg().m.throwing = -1 // do not dump full stacks
unlock(&sched.lock) // unlock so that GODEBUG=scheddetail=1 doesn't hang
throw("all goroutines are asleep - deadlock!")
}
......
......@@ -585,9 +585,10 @@ loop:
case timerNoStatus, timerRemoved:
// Timer was already run and t is no longer in a heap.
// Act like addtimer.
wasRemoved = true
atomic.Store(&t.status, timerWaiting)
break loop
if atomic.Cas(&t.status, status, timerWaiting) {
wasRemoved = true
break loop
}
case timerRunning, timerRemoving, timerMoving:
// The timer is being run or moved, by a different P.
// Wait for it to complete.
......@@ -687,10 +688,11 @@ func resettimer(t *timer, when int64) {
for {
switch s := atomic.Load(&t.status); s {
case timerNoStatus, timerRemoved:
atomic.Store(&t.status, timerWaiting)
t.when = when
addInitializedTimer(t)
return
if atomic.Cas(&t.status, s, timerWaiting) {
t.when = when
addInitializedTimer(t)
return
}
case timerDeleted:
if atomic.Cas(&t.status, s, timerModifying) {
t.nextwhen = when
......
// 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.
#include "textflag.h"
//
// System calls for riscv64, Linux
//
// func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64)
TEXT ·Syscall(SB),NOSPLIT,$0-56
CALL runtime·entersyscall(SB)
MOV a1+8(FP), A0
MOV a2+16(FP), A1
MOV a3+24(FP), A2
MOV trap+0(FP), A7 // syscall entry
ECALL
MOV $-4096, T0
BLTU T0, A0, err
MOV A0, r1+32(FP) // r1
MOV A1, r2+40(FP) // r2
MOV $0, err+48(FP) // errno
CALL runtime·exitsyscall(SB)
RET
err:
MOV $-1, T0
MOV T0, r1+32(FP) // r1
MOV $0, r2+40(FP) // r2
SUB A0, $0, A0
MOV A0, err+48(FP) // errno
CALL runtime·exitsyscall(SB)
RET
// func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
CALL runtime·entersyscall(SB)
MOV a1+8(FP), A0
MOV a2+16(FP), A1
MOV a3+24(FP), A2
MOV a4+32(FP), A3
MOV a5+40(FP), A4
MOV a6+48(FP), A5
MOV trap+0(FP), A7 // syscall entry
ECALL
MOV $-4096, T0
BLTU T0, A0, err
MOV A0, r1+56(FP) // r1
MOV A1, r2+64(FP) // r2
MOV $0, err+72(FP) // errno
CALL runtime·exitsyscall(SB)
RET
err:
MOV $-1, T0
MOV T0, r1+56(FP) // r1
MOV $0, r2+64(FP) // r2
SUB A0, $0, A0
MOV A0, err+72(FP) // errno
CALL runtime·exitsyscall(SB)
RET
// func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
MOV a1+8(FP), A0
MOV a2+16(FP), A1
MOV a3+24(FP), A2
MOV trap+0(FP), A7 // syscall entry
ECALL
MOV $-4096, T0
BLTU T0, A0, err
MOV A0, r1+32(FP) // r1
MOV A1, r2+40(FP) // r2
MOV $0, err+48(FP) // errno
RET
err:
MOV $-1, T0
MOV T0, r1+32(FP) // r1
MOV $0, r2+40(FP) // r2
SUB A0, $0, A0
MOV A0, err+48(FP) // errno
RET
// func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
MOV a1+8(FP), A0
MOV a2+16(FP), A1
MOV a3+24(FP), A2
MOV a4+32(FP), A3
MOV a5+40(FP), A4
MOV a6+48(FP), A5
MOV trap+0(FP), A7 // syscall entry
ECALL
MOV $-4096, T0
BLTU T0, A0, err
MOV A0, r1+56(FP) // r1
MOV A1, r2+64(FP) // r2
MOV $0, err+72(FP) // errno
RET
err:
MOV $-1, T0
MOV T0, r1+56(FP) // r1
MOV $0, r2+64(FP) // r2
SUB A0, $0, A0
MOV A0, err+72(FP) // errno
RET
TEXT ·rawSyscallNoError(SB),NOSPLIT,$0-48
MOV a1+8(FP), A0
MOV a2+16(FP), A1
MOV a3+24(FP), A2
MOV trap+0(FP), A7 // syscall entry
ECALL
MOV A0, r1+32(FP)
MOV A1, r2+40(FP)
RET
......@@ -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 386 amd64 arm arm64 ppc64le mips64le mipsle wasm
// +build 386 amd64 arm arm64 ppc64le mips64le mipsle riscv64 wasm
package syscall
......
......@@ -258,6 +258,15 @@ linux_ppc64le)
mksysnum="./mksysnum_linux.pl $unistd_h"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
linux_riscv64)
unistd_h=$(ls -1 /usr/include/asm/unistd.h /usr/include/asm-generic/unistd.h 2>/dev/null | head -1)
if [ "$unistd_h" = "" ]; then
echo >&2 cannot find unistd_64.h
exit 1
fi
mksysnum="./mksysnum_linux.pl $unistd_h"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
linux_s390x)
GOOSARCH_in=syscall_linux_s390x.go
unistd_h=/usr/include/asm/unistd.h
......
// 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 syscall
import "unsafe"
const (
_SYS_dup = SYS_DUP3
_SYS_setgroups = SYS_SETGROUPS
)
func EpollCreate(size int) (fd int, err error) {
if size <= 0 {
return -1, EINVAL
}
return EpollCreate1(0)
}
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
//sys fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error)
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sysnb Getegid() (egid int)
//sysnb Geteuid() (euid int)
//sysnb Getgid() (gid int)
//sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
//sysnb Getuid() (uid int)
//sys Listen(s int, n int) (err error)
//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
//sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
//sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
//sys Setfsgid(gid int) (err error)
//sys Setfsuid(uid int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
//sysnb Setresgid(rgid int, egid int, sgid int) (err error)
//sysnb Setresuid(ruid int, euid int, suid int) (err error)
//sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
//sysnb Setreuid(ruid int, euid int) (err error)
//sys Shutdown(fd int, how int) (err error)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
func Stat(path string, stat *Stat_t) (err error) {
return Fstatat(_AT_FDCWD, path, stat, 0)
}
func Lchown(path string, uid int, gid int) (err error) {
return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
}
func Lstat(path string, stat *Stat_t) (err error) {
return Fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
}
//sys Statfs(path string, buf *Statfs_t) (err error)
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error)
//sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
//sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
//sysnb socket(domain int, typ int, proto int) (fd int, err error)
//sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
//sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
type sigset_t struct {
X__val [16]uint64
}
//sys pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_t) (n int, err error) = SYS_PSELECT6
func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
var ts *Timespec
if timeout != nil {
ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
}
return pselect(nfd, r, w, e, ts, nil)
}
//sysnb Gettimeofday(tv *Timeval) (err error)
func setTimespec(sec, nsec int64) Timespec {
return Timespec{Sec: sec, Nsec: nsec}
}
func setTimeval(sec, usec int64) Timeval {
return Timeval{Sec: sec, Usec: usec}
}
func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
if tv == nil {
return utimensat(dirfd, path, nil, 0)
}
ts := []Timespec{
NsecToTimespec(TimevalToNsec(tv[0])),
NsecToTimespec(TimevalToNsec(tv[1])),
}
return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
}
func Time(t *Time_t) (Time_t, error) {
var tv Timeval
err := Gettimeofday(&tv)
if err != nil {
return 0, err
}
if t != nil {
*t = Time_t(tv.Sec)
}
return Time_t(tv.Sec), nil
}
func Utime(path string, buf *Utimbuf) error {
tv := []Timeval{
{Sec: buf.Actime},
{Sec: buf.Modtime},
}
return Utimes(path, tv)
}
func utimes(path string, tv *[2]Timeval) (err error) {
if tv == nil {
return utimensat(_AT_FDCWD, path, nil, 0)
}
ts := []Timespec{
NsecToTimespec(TimevalToNsec(tv[0])),
NsecToTimespec(TimevalToNsec(tv[1])),
}
return utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
}
func Pipe(p []int) (err error) {
if len(p) != 2 {
return EINVAL
}
var pp [2]_C_int
err = pipe2(&pp, 0)
p[0] = int(pp[0])
p[1] = int(pp[1])
return
}
//sysnb pipe2(p *[2]_C_int, flags int) (err error)
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
}
func (r *PtraceRegs) PC() uint64 { return r.Pc }
func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
func (iov *Iovec) SetLen(length int) {
iov.Len = uint64(length)
}
func (msghdr *Msghdr) SetControllen(length int) {
msghdr.Controllen = uint64(length)
}
func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint64(length)
}
func InotifyInit() (fd int, err error) {
return InotifyInit1(0)
}
//sys ppoll(fds *pollFd, nfds int, timeout *Timespec, sigmask *sigset_t) (n int, err error)
func Pause() error {
_, err := ppoll(nil, 0, nil, nil)
return err
}
func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) {
panic("not implemented")
}
......@@ -76,8 +76,8 @@ struct sockaddr_any {
// copied from /usr/include/linux/un.h
struct my_sockaddr_un {
sa_family_t sun_family;
#if defined(__ARM_EABI__) || defined(__powerpc64__) || defined(__s390x__)
// on ARM, PPC and s390x char is by default unsigned
#if defined(__ARM_EABI__) || defined(__powerpc64__) || defined(__riscv__) || defined(__s390x__)
// on ARM, PPC, RISC-V, and s390x char is by default unsigned
signed char sun_path[108];
#else
char sun_path[108];
......@@ -116,7 +116,7 @@ struct my_epoll_event {
// alignment requirements of EABI
int32_t padFd;
#endif
#if defined(__powerpc64__) || defined(__s390x__)
#if defined(__powerpc64__) || defined(__s390x__) || (defined(__riscv_xlen) && __riscv_xlen == 64)
int32_t _padFd;
#endif
int32_t fd;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -65,6 +65,11 @@ var UTC *Location = &utcLoc
var utcLoc = Location{name: "UTC"}
// Local represents the system's local time zone.
// On Unix systems, Local consults the TZ environment
// variable to find the time zone to use. No TZ means
// use the system default /etc/localtime.
// TZ="" means use UTC.
// TZ="foo" means use file foo in the system timezone directory.
var Local *Location = &localLoc
// localLoc is separate so that initLocal can initialize
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment