Skip to content

Commit

Permalink
unix: add Uvmexp and SysctlUvmexp for NetBSD
Browse files Browse the repository at this point in the history
NetBSD has both struct uvmexp (used internally) and struct uvmexp_sysctl
(preferred for interfacing from user code). Expose the latter as type
Uvmexp with the same interface as on OpenBSD.

I am not sure if it makes sense to even have a name parameter for
SysctlUvmexp, since the only valid value can be "vm.uvmext2".

Change-Id: I40a743536c28e3fb7a54253768db35b1629fabfe
Reviewed-on: https://go-review.googlesource.com/c/sys/+/460156
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
bsiegert committed Jan 4, 2023
1 parent b751db5 commit b60007c
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 0 deletions.
14 changes: 14 additions & 0 deletions unix/syscall_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func direntNamlen(buf []byte) (uint64, bool) {
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
}

func SysctlUvmexp(name string) (*Uvmexp, error) {
mib, err := sysctlmib(name)
if err != nil {
return nil, err
}

n := uintptr(SizeofUvmexp)
var u Uvmexp
if err := sysctl(mib, (*byte)(unsafe.Pointer(&u)), &n, nil, 0); err != nil {
return nil, err
}
return &u, nil
}

func Pipe(p []int) (err error) {
return Pipe2(p, 0)
}
Expand Down
15 changes: 15 additions & 0 deletions unix/sysctl_netbsd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

package unix

import "testing"

func TestSysctlUvmexp(t *testing.T) {
uvm, err := SysctlUvmexp("vm.uvmexp2")
if err != nil {
t.Fatal(err)
}
t.Logf("%#v", uvm)
}
7 changes: 7 additions & 0 deletions unix/types_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ package unix
#include <sys/un.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <uvm/uvm_extern.h>
#include <net/bpf.h>
#include <net/if.h>
#include <net/if_dl.h>
Expand Down Expand Up @@ -297,6 +298,12 @@ type Sysctlnode C.struct_sysctlnode

type Utsname C.struct_utsname

// Uvmexp

const SizeofUvmexp = C.sizeof_struct_uvmexp_sysctl

type Uvmexp C.struct_uvmexp_sysctl

// Clockinfo

const SizeofClockinfo = C.sizeof_struct_clockinfo
Expand Down
84 changes: 84 additions & 0 deletions unix/ztypes_netbsd_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions unix/ztypes_netbsd_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions unix/ztypes_netbsd_arm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b60007c

Please sign in to comment.