Skip to content

Commit

Permalink
go.mod: update /x/sys to latest version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevinburkesegment committed Apr 21, 2022
1 parent 56bf31b commit 3e23660
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions 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
4 changes: 2 additions & 2 deletions 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=
15 changes: 9 additions & 6 deletions internal/buffer/buffer_mmap.go
Expand Up @@ -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 {
Expand All @@ -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
}
}
Expand All @@ -49,5 +52,5 @@ func (a *Buffer) ProtectTail() []byte {
}

func (a *Buffer) Release() {
syscall.Munmap(a.mmap)
unix.Munmap(a.mmap)
}

0 comments on commit 3e23660

Please sign in to comment.