termux / libandroid-shmem

System V shared memory emulation on Android using ashmem.
BSD 3-Clause "New" or "Revised" License
121 stars 39 forks source link

Do not declare symbols defined in `libc.so` #12

Closed xtkoba closed 2 years ago

xtkoba commented 2 years ago

On Android API 26 or later, shmctl, shmdt and shmget are defined in libc.so but are disallowed by SELinux. When a main executable links against a shared library linking against libandroid-shmem.so which the main executable itself does not link against, then the definitions in libandroid-shmem.so are bypassed but instead the ones in libc.so are used. As a result, when the program calls one of these three functions, then it fails with "Bad system call".

To avoid this situation, the public header should not directly declare these symbols. Instead it should declare symbols that are prefixed by libandroid_ and #define the original symbols as aliases.

Related issue: https://github.com/termux/termux-packages/issues/9560.