diff --git a/vlib/runtime/free_memory_impl_openbsd.c.v b/vlib/runtime/free_memory_impl_openbsd.c.v index 30b9b7c201..337caaf589 100644 --- a/vlib/runtime/free_memory_impl_openbsd.c.v +++ b/vlib/runtime/free_memory_impl_openbsd.c.v @@ -1,14 +1,24 @@ module runtime +#include +#include + +struct C.uvmexp { + pagesize int + free int +} + fn free_memory_impl() usize { $if cross ? { return 1 } $if !cross ? { $if openbsd { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) - av_phys_pages := usize(C.sysconf(C._SC_AVPHYS_PAGES)) - return page_size * av_phys_pages + mib := [C.CTL_VM, C.VM_UVMEXP]! + mut uvm := C.uvmexp{0, 0} + mut len := sizeof(C.uvmexp) + unsafe { C.sysctl(&mib[0], mib.len, &uvm, &len, C.NULL, 0) } + return usize(uvm.pagesize * uvm.free) } } return 1