mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 23:27:31 -04:00
unix: add Mremap for netbsd
Fixes golang/go#60409 Change-Id: I2d872a1a6fb63c27ab3753deff370e1c2f752bdd Reviewed-on: https://go-review.googlesource.com/c/sys/+/508397 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
a1a9c4b846
commit
3fead03e7d
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
//go:build linux || netbsd
|
||||||
|
// +build linux netbsd
|
||||||
|
|
||||||
|
package unix
|
||||||
|
|
||||||
|
const (
|
||||||
|
MremapFixed = mremapFixed
|
||||||
|
MremapMaymove = mremapMaymove
|
||||||
|
)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
//go:build aix || darwin || dragonfly || freebsd || openbsd || solaris
|
||||||
|
// +build aix darwin dragonfly freebsd openbsd solaris
|
||||||
|
|
||||||
|
package unix
|
||||||
|
|
||||||
|
var mapper = &mmapper{
|
||||||
|
active: make(map[*byte][]byte),
|
||||||
|
mmap: mmap,
|
||||||
|
munmap: munmap,
|
||||||
|
}
|
||||||
+17
-4
@@ -2,8 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build linux
|
//go:build linux || netbsd
|
||||||
// +build linux
|
// +build linux netbsd
|
||||||
|
|
||||||
package unix
|
package unix
|
||||||
|
|
||||||
@@ -14,8 +14,17 @@ type mremapMmapper struct {
|
|||||||
mremap func(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error)
|
mremap func(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mapper = &mremapMmapper{
|
||||||
|
mmapper: mmapper{
|
||||||
|
active: make(map[*byte][]byte),
|
||||||
|
mmap: mmap,
|
||||||
|
munmap: munmap,
|
||||||
|
},
|
||||||
|
mremap: mremap,
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) {
|
func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) {
|
||||||
if newLength <= 0 || len(oldData) == 0 || len(oldData) != cap(oldData) || flags&MREMAP_FIXED != 0 {
|
if newLength <= 0 || len(oldData) == 0 || len(oldData) != cap(oldData) || flags&mremapFixed != 0 {
|
||||||
return nil, EINVAL
|
return nil, EINVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,9 +41,13 @@ func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data [
|
|||||||
}
|
}
|
||||||
bNew := unsafe.Slice((*byte)(unsafe.Pointer(newAddr)), newLength)
|
bNew := unsafe.Slice((*byte)(unsafe.Pointer(newAddr)), newLength)
|
||||||
pNew := &bNew[cap(bNew)-1]
|
pNew := &bNew[cap(bNew)-1]
|
||||||
if flags&MREMAP_DONTUNMAP == 0 {
|
if flags&mremapDontunmap == 0 {
|
||||||
delete(m.active, pOld)
|
delete(m.active, pOld)
|
||||||
}
|
}
|
||||||
m.active[pNew] = bNew
|
m.active[pNew] = bNew
|
||||||
return bNew, nil
|
return bNew, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) {
|
||||||
|
return mapper.Mremap(oldData, newLength, flags)
|
||||||
|
}
|
||||||
|
|||||||
+5
-5
@@ -2,8 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build linux
|
//go:build linux || netbsd
|
||||||
// +build linux
|
// +build linux netbsd
|
||||||
|
|
||||||
package unix_test
|
package unix_test
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func TestMremap(t *testing.T) {
|
|||||||
|
|
||||||
b[0] = 42
|
b[0] = 42
|
||||||
|
|
||||||
bNew, err := unix.Mremap(b, unix.Getpagesize()*2, unix.MREMAP_MAYMOVE)
|
bNew, err := unix.Mremap(b, unix.Getpagesize()*2, unix.MremapMaymove)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Mremap2: %v", err)
|
t.Fatalf("Mremap2: %v", err)
|
||||||
}
|
}
|
||||||
@@ -40,8 +40,8 @@ func TestMremap(t *testing.T) {
|
|||||||
t.Fatal("new memory cap not equal to specified len")
|
t.Fatal("new memory cap not equal to specified len")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = unix.Mremap(b, unix.Getpagesize(), unix.MREMAP_FIXED)
|
_, err = unix.Mremap(b, unix.Getpagesize(), unix.MremapFixed)
|
||||||
if err != unix.EINVAL {
|
if err != unix.EINVAL {
|
||||||
t.Fatalf("unix.MREMAP_FIXED should be forbidden")
|
t.Fatalf("remapping to a fixed address; got %v, want %v", err, unix.EINVAL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -535,21 +535,6 @@ func Fsync(fd int) error {
|
|||||||
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = nsendmsg
|
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = nsendmsg
|
||||||
|
|
||||||
//sys munmap(addr uintptr, length uintptr) (err error)
|
//sys munmap(addr uintptr, length uintptr) (err error)
|
||||||
|
|
||||||
var mapper = &mmapper{
|
|
||||||
active: make(map[*byte][]byte),
|
|
||||||
mmap: mmap,
|
|
||||||
munmap: munmap,
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
|
|
||||||
return mapper.Mmap(fd, offset, length, prot, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Munmap(b []byte) (err error) {
|
|
||||||
return mapper.Munmap(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys Madvise(b []byte, advice int) (err error)
|
//sys Madvise(b []byte, advice int) (err error)
|
||||||
//sys Mprotect(b []byte, prot int) (err error)
|
//sys Mprotect(b []byte, prot int) (err error)
|
||||||
//sys Mlock(b []byte) (err error)
|
//sys Mlock(b []byte) (err error)
|
||||||
|
|||||||
@@ -601,20 +601,6 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
|
|||||||
// Gethostuuid(uuid *byte, timeout *Timespec) (err error)
|
// Gethostuuid(uuid *byte, timeout *Timespec) (err error)
|
||||||
// Ptrace(req int, pid int, addr uintptr, data int) (ret uintptr, err error)
|
// Ptrace(req int, pid int, addr uintptr, data int) (ret uintptr, err error)
|
||||||
|
|
||||||
var mapper = &mmapper{
|
|
||||||
active: make(map[*byte][]byte),
|
|
||||||
mmap: mmap,
|
|
||||||
munmap: munmap,
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
|
|
||||||
return mapper.Mmap(fd, offset, length, prot, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Munmap(b []byte) (err error) {
|
|
||||||
return mapper.Munmap(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys Madvise(b []byte, behav int) (err error)
|
//sys Madvise(b []byte, behav int) (err error)
|
||||||
//sys Mlock(b []byte) (err error)
|
//sys Mlock(b []byte) (err error)
|
||||||
//sys Mlockall(flags int) (err error)
|
//sys Mlockall(flags int) (err error)
|
||||||
|
|||||||
+6
-22
@@ -2125,28 +2125,6 @@ func writevRacedetect(iovecs []Iovec, n int) {
|
|||||||
// mmap varies by architecture; see syscall_linux_*.go.
|
// mmap varies by architecture; see syscall_linux_*.go.
|
||||||
//sys munmap(addr uintptr, length uintptr) (err error)
|
//sys munmap(addr uintptr, length uintptr) (err error)
|
||||||
//sys mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error)
|
//sys mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error)
|
||||||
|
|
||||||
var mapper = &mremapMmapper{
|
|
||||||
mmapper: mmapper{
|
|
||||||
active: make(map[*byte][]byte),
|
|
||||||
mmap: mmap,
|
|
||||||
munmap: munmap,
|
|
||||||
},
|
|
||||||
mremap: mremap,
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
|
|
||||||
return mapper.Mmap(fd, offset, length, prot, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Munmap(b []byte) (err error) {
|
|
||||||
return mapper.Munmap(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) {
|
|
||||||
return mapper.Mremap(oldData, newLength, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys Madvise(b []byte, advice int) (err error)
|
//sys Madvise(b []byte, advice int) (err error)
|
||||||
//sys Mprotect(b []byte, prot int) (err error)
|
//sys Mprotect(b []byte, prot int) (err error)
|
||||||
//sys Mlock(b []byte) (err error)
|
//sys Mlock(b []byte) (err error)
|
||||||
@@ -2155,6 +2133,12 @@ func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) {
|
|||||||
//sys Munlock(b []byte) (err error)
|
//sys Munlock(b []byte) (err error)
|
||||||
//sys Munlockall() (err error)
|
//sys Munlockall() (err error)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mremapFixed = MREMAP_FIXED
|
||||||
|
mremapDontunmap = MREMAP_DONTUNMAP
|
||||||
|
mremapMaymove = MREMAP_MAYMOVE
|
||||||
|
)
|
||||||
|
|
||||||
// Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
|
// Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
|
||||||
// using the specified flags.
|
// using the specified flags.
|
||||||
func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
|
func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
|
||||||
|
|||||||
+12
-1
@@ -360,6 +360,18 @@ func Statvfs(path string, buf *Statvfs_t) (err error) {
|
|||||||
//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
|
//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
|
||||||
//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
|
//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mremapFixed = MAP_FIXED
|
||||||
|
mremapDontunmap = 0
|
||||||
|
mremapMaymove = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
//sys mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) = SYS_MREMAP
|
||||||
|
|
||||||
|
func mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (uintptr, error) {
|
||||||
|
return mremapNetBSD(oldaddr, oldlength, newaddr, newlength, flags)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unimplemented
|
* Unimplemented
|
||||||
*/
|
*/
|
||||||
@@ -564,7 +576,6 @@ func Statvfs(path string, buf *Statvfs_t) (err error) {
|
|||||||
// mq_timedreceive
|
// mq_timedreceive
|
||||||
// mq_timedsend
|
// mq_timedsend
|
||||||
// mq_unlink
|
// mq_unlink
|
||||||
// mremap
|
|
||||||
// msgget
|
// msgget
|
||||||
// msgrcv
|
// msgrcv
|
||||||
// msgsnd
|
// msgsnd
|
||||||
|
|||||||
@@ -716,20 +716,6 @@ func writelen(fd int, buf *byte, nbuf int) (n int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapper = &mmapper{
|
|
||||||
active: make(map[*byte][]byte),
|
|
||||||
mmap: mmap,
|
|
||||||
munmap: munmap,
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
|
|
||||||
return mapper.Mmap(fd, offset, length, prot, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Munmap(b []byte) (err error) {
|
|
||||||
return mapper.Munmap(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event Ports
|
// Event Ports
|
||||||
|
|
||||||
type fileObjCookie struct {
|
type fileObjCookie struct {
|
||||||
|
|||||||
@@ -147,6 +147,14 @@ func (m *mmapper) Munmap(data []byte) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
|
||||||
|
return mapper.Mmap(fd, offset, length, prot, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Munmap(b []byte) (err error) {
|
||||||
|
return mapper.Munmap(b)
|
||||||
|
}
|
||||||
|
|
||||||
func Read(fd int, p []byte) (n int, err error) {
|
func Read(fd int, p []byte) (n int, err error) {
|
||||||
n, err = read(fd, p)
|
n, err = read(fd, p)
|
||||||
if raceenabled {
|
if raceenabled {
|
||||||
|
|||||||
@@ -285,25 +285,11 @@ func Close(fd int) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapper = &mmapper{
|
|
||||||
active: make(map[*byte][]byte),
|
|
||||||
mmap: mmap,
|
|
||||||
munmap: munmap,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dummy function: there are no semantics for Madvise on z/OS
|
// Dummy function: there are no semantics for Madvise on z/OS
|
||||||
func Madvise(b []byte, advice int) (err error) {
|
func Madvise(b []byte, advice int) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
|
|
||||||
return mapper.Mmap(fd, offset, length, prot, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Munmap(b []byte) (err error) {
|
|
||||||
return mapper.Munmap(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys Gethostname(buf []byte) (err error) = SYS___GETHOSTNAME_A
|
//sys Gethostname(buf []byte) (err error) = SYS___GETHOSTNAME_A
|
||||||
//sysnb Getegid() (egid int)
|
//sysnb Getegid() (egid int)
|
||||||
//sysnb Geteuid() (uid int)
|
//sysnb Geteuid() (uid int)
|
||||||
|
|||||||
@@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) {
|
||||||
|
r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0)
|
||||||
|
xaddr = uintptr(r0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) {
|
||||||
|
r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0)
|
||||||
|
xaddr = uintptr(r0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) {
|
||||||
|
r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0)
|
||||||
|
xaddr = uintptr(r0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||||
|
|
||||||
|
func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) {
|
||||||
|
r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0)
|
||||||
|
xaddr = uintptr(r0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user