Skip to content

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

Merged
merged 2 commits into from
May 12, 2025
Merged

Update linux.Map_Flags_Bits #5152

merged 2 commits into from
May 12, 2025

Conversation

Kelimion
Copy link
Member

Fixes #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

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
@@ -619,6 +619,10 @@ Map_Flags_Bits :: enum {
UNINITIALIZED = 26,
}

// Not actually flags, but a shift and mask for when HUGETLB is defined
Copy link
Collaborator

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.

@@ -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}
Copy link
Collaborator

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.

Copy link
Member Author

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?

Copy link
Member Author

@Kelimion Kelimion May 12, 2025

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}

Copy link
Collaborator

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

Copy link
Member Author

@Kelimion Kelimion May 12, 2025

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.

@Kelimion Kelimion merged commit 8809ce2 into odin-lang:master May 12, 2025
7 checks passed
@Kelimion Kelimion deleted the mmap-flags branch May 12, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

linux.Map_Flags_Bits.SHARED_VALIDATE is wrong
2 participants