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

runtime: add freebsd free_memory() support #23594

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions vlib/builtin/cfns.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ fn C.isatty(fd int) int
fn C.syscall(number int, va ...voidptr) int

fn C.sysctl(name &int, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen usize) int
fn C.sysctlnametomib(name charptr, mib &int, len &usize) int
spytheman marked this conversation as resolved.
Show resolved Hide resolved

@[trusted]
fn C._fileno(int) int
Expand Down
9 changes: 4 additions & 5 deletions vlib/runtime/free_memory_impl_freebsd.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ fn free_memory_impl() usize {
$if !cross ? {
$if freebsd {
page_size := usize(C.sysconf(C._SC_PAGESIZE))
// sysctlnametomib("vm.stats.vm.v_free_count") => mib :
mib := [C.CTL_VM, 2147481600, 2147481598, 2147481557]!
mut mib := [4]int{}
mut len := usize(4)
unsafe { C.sysctlnametomib(c'vm.stats.vm.v_free_count', &mib[0], &len) }
mut free_pages := int(0)
bufsize := usize(4)
unsafe {
C.sysctl(&mib[0], mib.len, &free_pages, &bufsize, 0, 0)
}
unsafe { C.sysctl(&mib[0], mib.len, &free_pages, &bufsize, 0, 0) }
return page_size * usize(free_pages)
}
}
Expand Down
Loading