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

MAP_FIXED_NOREPLACE support #1393

Closed
jgarvin opened this issue Feb 24, 2021 · 2 comments · Fixed by #1636
Closed

MAP_FIXED_NOREPLACE support #1393

jgarvin opened this issue Feb 24, 2021 · 2 comments · Fixed by #1636
Assignees

Comments

@jgarvin
Copy link

jgarvin commented Feb 24, 2021

A new flag introduced in kernel 4.17.

I was taking a look at trying to add this myself, but I don't know if it should use #[cfg(target_os = "linux")] or #[cfg(any(target_os = "android", target_os = "linux"))]. I also don't know if there is any cfg hackery that should be done for supporting people on older kernels?

#define MAP_FIXED_NOREPLACE 0x100000

   MAP_FIXED_NOREPLACE (since Linux 4.17)
          This  flag  provides  behavior  that  is  similar   to
          MAP_FIXED  with  respect  to the addr enforcement, but
          differs in that MAP_FIXED_NOREPLACE never  clobbers  a
          preexisting  mapped  range.   If  the  requested range
          would collide with an existing mapping, then this call
          fails  with the error EEXIST.  This flag can therefore
          be used as a way to atomically (with respect to  other
          threads)  attempt  to map an address range: one thread
          will succeed; all others will report failure.

          Note that older kernels which  do  not  recognize  the
          MAP_FIXED_NOREPLACE  flag will typically (upon detect‐
          ing a collision with a preexisting mapping) fall  back
          to  a  "non-MAP_FIXED" type of behavior: they will re‐
          turn an address that is different from  the  requested
          address.    Therefore,   backward-compatible  software
          should check the  returned  address  against  the  re‐
          quested address.
@asomers
Copy link
Member

asomers commented Mar 21, 2021

You don't need to do anything at build-time to support older Linux kernels. If an application tries to use an unsupported feature, it will simply fail at runtime. As for Android support, the best thing to do is to check the latest version of the Android headers. If it's in there, then you should include it here (and you may have to add it to https://github.com/rust-lang/libc first).

@rtzoeller rtzoeller changed the title MAP_FIXED_REPLACE support MAP_FIXED_NOREPLACE support Jan 16, 2022
@rtzoeller rtzoeller self-assigned this Jan 16, 2022
@rtzoeller
Copy link
Collaborator

#1636 addresses this for Linux. If it should be defined on Android as well, it'll need to be added to rust-lang/libc before it can be added to nix.

@jgarvin jgarvin closed this as completed Jan 19, 2022
bors bot added a commit that referenced this issue Jan 19, 2022
1636: Add MAP_FIXED_NOREPLACE on Linux r=rtzoeller a=rtzoeller

Resolves #1393.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
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 a pull request may close this issue.

3 participants