Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement darwin pagesize without cgo #136

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions providers/darwin/syscall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"sync"
"syscall"
"unsafe"

"golang.org/x/sys/unix"
)

// Single-word zero for use when we need a valid pointer to 0 bytes.
Expand Down Expand Up @@ -209,15 +211,12 @@ func getHostVMInfo64() (*vmStatistics64Data, error) {
}

func getPageSize() (uint64, error) {
var pageSize vmSize
status := C.host_page_size(
C.host_t(C.mach_host_self()),
(*C.vm_size_t)(unsafe.Pointer(&pageSize)))
if status != C.KERN_SUCCESS {
return 0, fmt.Errorf("host_page_size returned status %d", status)
i, err := unix.SysctlUint32("vm.pagesize")
if err != nil {
return 0, fmt.Errorf("vm.pagesize returned %w", err)
}

return uint64(pageSize), nil
return uint64(i), nil
}

// From sysctl.h - xsw_usage.
Expand Down