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

Using mmap64 instead of plain mmap. #87

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,26 @@ jobs:
matrix:
target:
- i686-unknown-linux-gnu
- i686-unknown-linux-musl
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install toolchain
uses: dtolnay/rust-toolchain@master
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable-${{ matrix.target }}
target: ${{ matrix.target }}

- name: Install multilib
if: ${{ matrix.target == 'i686-unknown-linux-gnu' }}
if: ${{ contains(matrix.target, 'i686-unknown-linux-') }}
run: |
sudo apt update -yqq
sudo apt install gcc-multilib

- name: Run tests
run: cargo test --all-features
run: cargo test --all-features --target ${{ matrix.target }}

check-stub:
runs-on: ubuntu-latest
Expand Down
16 changes: 14 additions & 2 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ const MAP_POPULATE: libc::c_int = libc::MAP_POPULATE;
#[cfg(not(any(target_os = "linux", target_os = "android")))]
const MAP_POPULATE: libc::c_int = 0;

#[cfg(any(
target_os = "android",
all(target_os = "linux", not(target_env = "musl"))
))]
use libc::{mmap64 as mmap, off64_t as off_t};

#[cfg(not(any(
target_os = "android",
all(target_os = "linux", not(target_env = "musl"))
)))]
use libc::{mmap, off_t};

pub struct MmapInner {
ptr: *mut libc::c_void,
len: usize,
Expand All @@ -50,13 +62,13 @@ impl MmapInner {
let (map_len, map_offset) = Self::adjust_mmap_params(len as usize, alignment as usize)?;

unsafe {
let ptr = libc::mmap(
let ptr = mmap(
ptr::null_mut(),
map_len as libc::size_t,
prot,
flags,
file,
aligned_offset as libc::off_t,
aligned_offset as off_t,
);

if ptr == libc::MAP_FAILED {
Expand Down