Skip to content

mmap addr#1870

Merged
bors[bot] merged 1 commit intonix-rust:masterfrom
JonathanWoollett-Light:mmap-addr
Nov 20, 2022
Merged

mmap addr#1870
bors[bot] merged 1 commit intonix-rust:masterfrom
JonathanWoollett-Light:mmap-addr

Conversation

@JonathanWoollett-Light
Copy link
Copy Markdown
Contributor

@JonathanWoollett-Light JonathanWoollett-Light commented Nov 19, 2022

Uses Some<size_t> instead of *mut c_void for the addr passed to sys::mman::mmap.

In this instance we are not usefully passing a pointer, it will never be dereferenced. We are passing a location which represents where to attach the shared memory to.

In this case size_t better represents an address and not a pointer, and Option<size_t> better represents an optional argument than NULLPTR.

In C since there is no optional type this is a pointer as this allows it be null which is an alias here for None.

Copy link
Copy Markdown
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This increases the size of the argument. How about using Option<std::ptr::NonNull> instead? Or Option<std::num::NonZeroUsize>?

@JonathanWoollett-Light
Copy link
Copy Markdown
Contributor Author

Good point, updated to use Option<std::num::NonZeroUsize>.

@JonathanWoollett-Light JonathanWoollett-Light force-pushed the mmap-addr branch 2 times, most recently from 699e482 to 7468c81 Compare November 20, 2022 16:49
CHANGELOG.md Outdated

- The MSRV is now 1.56.1
([#1792](https://github.com/nix-rust/nix/pull/1792))
- Passes `addr` to `sys::mmap` as `Option<NonZeroUsize>` from `*mut c_void`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this wording confusing. How about this?

Suggested change
- Passes `addr` to `sys::mmap` as `Option<NonZeroUsize>` from `*mut c_void`.
- The `addr` argument to `sys::mman::mmap` is now of type `Option<NonZeroUsize>`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Copy Markdown
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors bors bot merged commit 6e2b0a0 into nix-rust:master Nov 20, 2022
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.

2 participants