-
-
Notifications
You must be signed in to change notification settings - Fork 756
Update linux.Map_Flags_Bits
#5152
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
Conversation
Fixes odin-lang#5151 - Removes `SHARED_VALIDATE` from the enum and turns it into `Map_Shared_Validate :: Map_Flags{.SHARED, .PRIVATE}` so it has the proper value of 0x03. - Adds `DROPPABLE`. - Adds constants `MAP_HUGE_SHIFT` and `MAP_HUGE_MASK`. - Adds the huge page precomputed constants from `mman.h`, defined as the log2 of the size shifted left by `MAP_HUGE_SHIFT`: Map_Huge_16KB Map_Huge_64KB Map_Huge_512KB Map_Huge_1MB Map_Huge_2MB Map_Huge_8MB Map_Huge_16MB Map_Huge_32MB Map_Huge_256MB Map_Huge_512MB Map_Huge_1GB Map_Huge_2GB Map_Huge_16GB
core/sys/linux/bits.odin
Outdated
@@ -619,6 +619,10 @@ Map_Flags_Bits :: enum { | |||
UNINITIALIZED = 26, | |||
} | |||
|
|||
// Not actually flags, but a shift and mask for when HUGETLB is defined |
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.
These should go into constants.odin and prob good to stay consistent with the comment style used in the package.
core/sys/linux/types.odin
Outdated
@@ -371,6 +371,21 @@ Mem_Protection :: bit_set[Mem_Protection_Bits; i32] | |||
*/ | |||
Map_Flags :: bit_set[Map_Flags_Bits; i32] | |||
|
|||
Map_Shared_Validate :: Map_Flags{.SHARED, .PRIVATE} |
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.
These are constants right? Should go into constants.odin and be in upper snake case.
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.
That's not very usable, though. Who's going to look for Map_Shared_Validate
in constants.odin
instead of next to either the enum or the bit_set
?
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.
And when it comes to os.open
flag combinations, we don't put them in another file either.
File_Flags :: distinct bit_set[File_Flag; uint]
File_Flag :: enum {
Read,
Write,
Append,
Create,
Excl,
Sync,
Trunc,
Sparse,
Inheritable,
Unbuffered_IO,
}
O_RDONLY :: File_Flags{.Read}
O_WRONLY :: File_Flags{.Write}
O_RDWR :: File_Flags{.Read, .Write}
O_APPEND :: File_Flags{.Append}
O_CREATE :: File_Flags{.Create}
O_EXCL :: File_Flags{.Excl}
O_SYNC :: File_Flags{.Sync}
O_TRUNC :: File_Flags{.Trunc}
O_SPARSE :: File_Flags{.Sparse}
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.
I mean that's how the entirety of this package is structured
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.
True. The core:os/os2
way is much more convenient, but it's also much newer.
I'll make it UPPER_SNAKE_CASE
and move it to constants.odin
for consistency, but leave a comment under the bit_set
in types.odin
that some precomputed huge page sizes are available over there.
We may at some point want to give core:sys
the core:os/os2
convenience treatment and keep related info together.
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.
Right, I am not saying I fully agree with the structure here but to be at least consistent on the package level is a good thing.
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.
I made the changes and left a comment where to find it for people who expect it next to the enum or bit_set.
Fixes #5151
SHARED_VALIDATE
from the enum and turns it intoMap_Shared_Validate :: Map_Flags{.SHARED, .PRIVATE}
so it has the proper value of 0x03.DROPPABLE
.MAP_HUGE_SHIFT
andMAP_HUGE_MASK
.mman.h
, defined as the log2 of the size shifted left byMAP_HUGE_SHIFT
:Map_Huge_16KB
Map_Huge_64KB
Map_Huge_512KB
Map_Huge_1MB
Map_Huge_2MB
Map_Huge_8MB
Map_Huge_16MB
Map_Huge_32MB
Map_Huge_256MB
Map_Huge_512MB
Map_Huge_1GB
Map_Huge_2GB
Map_Huge_16GB