Skip to content
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

mmap addr #1870

Merged
merged 1 commit into from
Nov 20, 2022
Merged

mmap addr #1870

merged 1 commit into from
Nov 20, 2022

Conversation

JonathanWoollett-Light
Copy link
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
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
Contributor Author

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

CHANGELOG.md Outdated
@@ -35,6 +35,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- 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
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
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
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.

None yet

2 participants