-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
std.os: add sysconf(), getDefaultPageSize() with smoke tests #16638
Conversation
REVIEW QUESTION: Should Kernel abi things reference the official repo + tagged commit? Personally, I'd prefer linking to a git reference, if an official one exists. List of TODOs:
Common alias for _SC_PAGE_SIZE is _SC_PAGESIZE
Left out: Apple Libc. Hermit has no reliable page size and neither an api for it. See hermit-os/kernel#815. |
8c57e1c
to
99fbe13
Compare
99fbe13
to
9e3f451
Compare
cbe9203
to
8b4888b
Compare
451182c
to
8e01635
Compare
8e01635
to
1d9095a
Compare
9881625
to
7eabb78
Compare
This comment was marked as resolved.
This comment was marked as resolved.
sysconf() abstracts posix sysconf for comptime- and runtime probing. getDefaultPageSize() reads the Kernel provided default page size, which remains constant from program start to end. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris git clone --depth=1 https://github.com/apple-open-source-mirror/Libc rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
8d9c341
to
5f11466
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this. A few requests-
@@ -233,6 +233,9 @@ pub const mach_header_64 = macho.mach_header_64; | |||
pub const mach_header = macho.mach_header; | |||
|
|||
pub const _errno = __error; | |||
pub const _SC = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No underscore, please.
/// Returns page size assigned by the Kernel to the process. This size is | ||
/// constant during process lifetime, but other page sizes might be usable. | ||
pub fn getDefaultPageSize() error{UnknownPageSize}!usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does not belong in std.os (reminder: #5019)
I think it should go into std.heap.pageSize
.
} | ||
return sbi.PageSize; | ||
}, | ||
// zig fmt: off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to turn off formatting
@@ -1,4 +1,4 @@ | |||
const std = @import("../std.zig"); | |||
const std = @import("std"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be left alone
test "getDefaultPageSize smoke test" { | ||
const page_size = try os.getDefaultPageSize(); | ||
switch (page_size) { | ||
// zig fmt: off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not turn off code formatting
sysconf() abstracts posix sysconf for comptime- and runtime probing.
getDefaultPageSize() reads the Kernel provided default page size,
which remains constant from program start to end.
Reproduce added abi bits with:
git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD
git clone --depth=1 https://git.FreeBSD.org/src.git freebsd
git clone --depth=1 https://fuchsia.googlesource.com/fuchsia
git clone --depth=1 https://github.com/haiku/haiku
git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/
git clone --depth=1 https://github.com/NetBSD/src netbsd
git clone --depth=1 https://github.com/openbsd/src openbsd
git clone --depth=1 https://github.com/kofemann/opensolaris
git clone --depth=1 https://github.com/apple-open-source-mirror/Libc
rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep
Closes #11308.