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

Mapping beyond 4GB offset if broken on 32 bit glibc (Linux) #85

Closed
lvella opened this issue Jun 20, 2023 · 3 comments
Closed

Mapping beyond 4GB offset if broken on 32 bit glibc (Linux) #85

lvella opened this issue Jun 20, 2023 · 3 comments

Comments

@lvella
Copy link

lvella commented Jun 20, 2023

This is a direct consequence of this rust's libc issue. In rust targeting 32 bits glibc, libc::off_t is 32 bits, which breaks this code if you are trying to map beyond 4 GB in a file:

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

I had a similar issue with nix crate, where posix_fallocate() also relied on libc::off_t for file sizes. The fix was to use rustix crate, that calls the system-call directly. Maybe a similar workaround could be applied here?

@RazrFalcon
Copy link
Owner

Switching to rustix seems like a pretty extreme solution. Will wait for libc fix.

@lvella
Copy link
Author

lvella commented Jun 21, 2023

Then I suggest at least doing aligned_offset.try_into().unwrap() instead of aligned_offset as libc::off_t, or an assert like assert!(aligned_offset <= libc::off_t::MAX);. That would have saved me a lot of debugging time.

@RazrFalcon
Copy link
Owner

Feel free to send a pull request.

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

No branches or pull requests

2 participants