From 3e23660e89dd726ba4155c6f774fdb0c4cfbd95e Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Thu, 21 Apr 2022 16:34:21 -0700 Subject: [PATCH] go.mod: update /x/sys to latest version It has some new bug fixes we can use. Also replace a use of the "syscall" package with the x/sys/unix package, which has a compatible API. --- go.mod | 4 ++-- go.sum | 4 ++-- internal/buffer/buffer_mmap.go | 15 +++++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 912ec016..e63db00c 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/segmentio/asm -go 1.17 +go 1.18 -require golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 +require golang.org/x/sys v0.0.0-20220412211240-33da011f77ad diff --git a/go.sum b/go.sum index f000ecc3..7f2d82d5 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ= -golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/internal/buffer/buffer_mmap.go b/internal/buffer/buffer_mmap.go index d23a2d9f..57a6489f 100644 --- a/internal/buffer/buffer_mmap.go +++ b/internal/buffer/buffer_mmap.go @@ -2,10 +2,13 @@ // +build !purego // +build aix android darwin dragonfly freebsd illumos ios linux netbsd openbsd plan9 solaris +// TODO: replace the above with go:build unix once Go 1.19 is the lowest +// supported version + package buffer import ( - "syscall" + "golang.org/x/sys/unix" ) type Buffer struct { @@ -15,18 +18,18 @@ type Buffer struct { } func New(n int) (Buffer, error) { - pg := syscall.Getpagesize() + pg := unix.Getpagesize() full := ((n+(pg-1))/pg + 2) * pg - b, err := syscall.Mmap(-1, 0, full, syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE) + b, err := unix.Mmap(-1, 0, full, unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE) if err != nil { return Buffer{}, err } if n > 0 { - err = syscall.Mprotect(b[pg:full-pg], syscall.PROT_READ|syscall.PROT_WRITE) + err = unix.Mprotect(b[pg:full-pg], unix.PROT_READ|unix.PROT_WRITE) if err != nil { - syscall.Munmap(b) + unix.Munmap(b) return Buffer{}, err } } @@ -49,5 +52,5 @@ func (a *Buffer) ProtectTail() []byte { } func (a *Buffer) Release() { - syscall.Munmap(a.mmap) + unix.Munmap(a.mmap) }