Skip to content

Commit f82529e

Browse files
authored
os: add os.page_size() (#19770)
1 parent 9effbec commit f82529e

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

vlib/os/os_nix.c.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,10 @@ pub fn posix_set_permission_bit(path_s string, mode u32, enable bool) {
506506
fn get_long_path(path string) !string {
507507
return path
508508
}
509+
510+
fn C.sysconf(name int) i64
511+
512+
// page_size returns the page size in bytes.
513+
pub fn page_size() int {
514+
return int(C.sysconf(C._SC_PAGESIZE))
515+
}

vlib/os/os_test.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,7 @@ fn test_mv_by_cp_across_partitions() {
10121012
fn test_mv_across_partitions() {
10131013
move_across_partitions_using_function(os.mv)!
10141014
}
1015+
1016+
fn test_page_size() {
1017+
assert os.page_size() >= 4096 // this is normal and assumed.
1018+
}

vlib/os/os_windows.c.v

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,19 @@ fn get_long_path(path string) !string {
592592
long_path := unsafe { string_from_wide(&long_path_buf[0]) }
593593
return long_path
594594
}
595+
596+
// 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.
597+
[typedef]
598+
pub struct C.SYSTEM_INFO {
599+
dwNumberOfProcessors u32
600+
dwPageSize u32
601+
}
602+
603+
fn C.GetSystemInfo(&C.SYSTEM_INFO)
604+
605+
// page_size returns the page size in bytes.
606+
pub fn page_size() int {
607+
sinfo := C.SYSTEM_INFO{}
608+
C.GetSystemInfo(&sinfo)
609+
return int(sinfo.dwPageSize)
610+
}

vlib/runtime/runtime_windows.c.v

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ module runtime
22

33
import os
44

5-
[typedef]
6-
pub struct C.SYSTEM_INFO {
7-
dwNumberOfProcessors u32
8-
}
9-
105
[typedef]
116
pub struct C.MEMORYSTATUS {
127
dwTotalPhys usize

0 commit comments

Comments
 (0)