Skip to content

stat/statx usage on Android 9.0+ #229

Closed
@Phil25

Description

@Phil25

We're supplying a dynamic library which uses Boost for an Android app. Since the seccomp filter introduction in Android 8.0, we've been getting crashes related to stat syscalls:

syscall 0x00000078c59610d0
boost::filesystem::details::status(boost::filesystem::path const&, boost::system::error_code*) 0x00000077d0dbac64
boost::filesystem::is_directory(boost::filesystem::path const&, boost::system::error_code&) 0x00000077d0d0a5e0

This is because stat was not available in the syscall whitelist in Android 8.0. The fix was simply updating from Boost 1.76 to 1.77 where runtime detection for statx was added.

However, from Android 9.0, statx is also not on the syscall whitelist anymore:

syscall 0x0000007dd7848340
boost::filesystem::detail::(anonymous namespace)::statx_syscall(int, char const*, int, unsigned int, statx*) 0x0000007c2d6dc0a0
boost::filesystem::detail::(anonymous namespace)::invoke_statx(int, char const*, int, unsigned int, statx*) 0x0000007c2d6d938c
boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*) 0x0000007c2d6d6638
boost::filesystem::is_directory(boost::filesystem::path const&, boost::system::error_code&) 0x0000007c2d58951c

Interestingly, older versions of Boost (1.72) work for newer Androids (9 and 10), which is a bit similar to what #183 reports. #172 hints at using BOOST_FILESYSTEM_DISABLE_STATX, but wouldn't this just make Boost fall back to stat?

I've been investigating this for a while now but my experience in Android is lacking, what I'm most curious about is this:

  1. I inspected the source code of 1.72, but don't see any other solutions to stat/statx syscalls than in the newer versions. How come 1.72 works on all Androids we tested (8, 9 and 10), while 1.76 works on neither (except pre-8) and 1.77 works only on 8.
  2. Does BOOST_FILESYSTEM_DISABLE_STATX disable the usage of both stat and statx? Is there another way to call status on a file though Boost?
  3. Is it possible to support a wide range of Androids with one build (from before Linux 4.11 update, where statx was added)? The runtime detection of statx solved it for us, but if we can't rely on it anymore we might need a different solution.
  4. Am I thinking about this whole thing correctly?

Android API level: minimal 24, targeting 31
Android SDK: 28
Android NDK: r16b (both library and the app)
Platforms: armv7 and armv8

Thank you in advance, I can try to fish out any other information 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions