From 74e833b57266f0ecd4deb7157be785aa134257bc Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 24 Sep 2020 11:49:36 +0200 Subject: [PATCH] Use madvise syscall wrapper from golang.org/x/sys/unix Direct syscalls using syscall.Syscall(SYS_*, ...) should no longer be used on darwin, see [1]. Instead, use the madvise syscall wrapper provided by the golang.org/x/sys/unix package for all unix platforms. This implement the same functionality. [1] https://golang.org/doc/go1.12#darwin As suggested by @ptabor in https://github.com/etcd-io/etcd/pull/12316#issuecomment-698193671 --- .travis.yml | 1 + bolt_unix.go | 13 +++---------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 257dfdf..4dbe73a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ go: - 1.12 before_install: +- go get -v golang.org/x/sys/unix - go get -v honnef.co/go/tools/... - go get -v github.com/kisielk/errcheck diff --git a/bolt_unix.go b/bolt_unix.go index 2938fed..34753e8 100644 --- a/bolt_unix.go +++ b/bolt_unix.go @@ -7,6 +7,8 @@ import ( "syscall" "time" "unsafe" + + "golang.org/x/sys/unix" ) // flock acquires an advisory lock on a file descriptor. @@ -55,7 +57,7 @@ func mmap(db *DB, sz int) error { } // Advise the kernel that the mmap is accessed randomly. - err = madvise(b, syscall.MADV_RANDOM) + err = unix.Madvise(b, syscall.MADV_RANDOM) if err != nil && err != syscall.ENOSYS { // Ignore not implemented error in kernel because it still works. return fmt.Errorf("madvise: %s", err) @@ -82,12 +84,3 @@ func munmap(db *DB) error { db.datasz = 0 return err } - -// NOTE: This function is copied from stdlib because it is not available on darwin. -func madvise(b []byte, advice int) (err error) { - _, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/go.mod b/go.mod index c2366da..96355a6 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module go.etcd.io/bbolt go 1.12 -require golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 +require golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d diff --git a/go.sum b/go.sum index 4ad15a4..c13f8f4 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es= +golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=