Skip to content

Commit

Permalink
os: add os.page_size() (#19770)
Browse files Browse the repository at this point in the history
  • Loading branch information
l1mey112 authored Nov 5, 2023
1 parent 9effbec commit f82529e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
7 changes: 7 additions & 0 deletions vlib/os/os_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,10 @@ pub fn posix_set_permission_bit(path_s string, mode u32, enable bool) {
fn get_long_path(path string) !string {
return path
}

fn C.sysconf(name int) i64

// page_size returns the page size in bytes.
pub fn page_size() int {
return int(C.sysconf(C._SC_PAGESIZE))
}
4 changes: 4 additions & 0 deletions vlib/os/os_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,7 @@ fn test_mv_by_cp_across_partitions() {
fn test_mv_across_partitions() {
move_across_partitions_using_function(os.mv)!
}

fn test_page_size() {
assert os.page_size() >= 4096 // this is normal and assumed.
}
16 changes: 16 additions & 0 deletions vlib/os/os_windows.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,19 @@ fn get_long_path(path string) !string {
long_path := unsafe { string_from_wide(&long_path_buf[0]) }
return long_path
}

// C.SYSTEM_INFO contains information about the current computer system. This includes the architecture and type of the processor, the number of processors in the system, the page size, and other such information.
[typedef]
pub struct C.SYSTEM_INFO {
dwNumberOfProcessors u32
dwPageSize u32
}

fn C.GetSystemInfo(&C.SYSTEM_INFO)

// page_size returns the page size in bytes.
pub fn page_size() int {
sinfo := C.SYSTEM_INFO{}
C.GetSystemInfo(&sinfo)
return int(sinfo.dwPageSize)
}
5 changes: 0 additions & 5 deletions vlib/runtime/runtime_windows.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ module runtime

import os

[typedef]
pub struct C.SYSTEM_INFO {
dwNumberOfProcessors u32
}

[typedef]
pub struct C.MEMORYSTATUS {
dwTotalPhys usize
Expand Down

0 comments on commit f82529e

Please sign in to comment.