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

android: use proper types for dirent.d_ino, dirent.d_off, stat.st_mode and stat64.st_mode #4216

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thunder-coding
Copy link

@thunder-coding thunder-coding commented Dec 21, 2024

This bug was noticed in termux/termux-packages#22609

Description

Fixes types for dirent.d_ino, dirent.d_off, stat.st_mode and stat64.st_mode on Android.

The hardcoded types are incorrect and this PR changes them to how they are declared for Linux. Also fixes the incorrect type errors in termux/termux-packages#22609, where I found the bug (The builds are still failing due to missing posix_spawn* support here, but that's a different issue.)

This patch should likely also be backported to 0.2.x release, I have the patchset already applied on my other branch. Will link another PR soon.
It seems that this patch applies cleanly to libc-0.2 branch, I was backporting to an older release earlier. @rustbot label stable-nominated should be it according to CONTRIBUTING.md

Sources

mode_t:
mode_t is defined as unsigned int on 64-bit android platforms:
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/sys/types.h#64
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/asm-generic/posix_types.h#18
and is defined as unsigned short on 32-bit platforms:
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/i686-linux-android/asm/posix_types_32.h#9
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/arm-linux-androideabi/asm/posix_types.h#9

off_t:
https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md mentions that off_t is i32 on 32-bit and i64 on 64-bit

ino_t:
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/dirent.h#64
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/sys/types.h#70
https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/asm-generic/posix_types.h#14
Due to "historic accident", although ino_t is unsigned long on all platforms, the actual type used is unsigned long on 64-bit and uint64_t on 32-bit. I think we should just declare ino_t to be of type unsigned long on 64-bit and uint64_t on 32-bit as that's how code using these types is supposed to be used.

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI
    I tried building the tests locally, it seems like the tests are already broken for Android. But I was able to fix some of the issues in [DO NOT MERGE] bump(main/fish): 4.0b1 termux/termux-packages#22609

@rustbot
Copy link
Collaborator

rustbot commented Dec 21, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants