diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e8777fa..de68a52d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1240,3 +1240,10 @@ if (ANDROID AND MOBILEGL_BUILD_EXTMEM_PROBE) endif() endif() endif() + +# The GBM library carries the tree's logger, which reaches Android's own log. The main target gets +# these libraries in its own Android block; a library built from the same sources needs them for the +# same reason, and without them it is the LINK that fails rather than anything in the code. +if (ANDROID) + target_link_libraries(MobileGLGbm PRIVATE log android) +endif() diff --git a/MobileGL/MG_Gbm/GbmDevice.cpp b/MobileGL/MG_Gbm/GbmDevice.cpp index abfb4eba..e4126fc3 100644 --- a/MobileGL/MG_Gbm/GbmDevice.cpp +++ b/MobileGL/MG_Gbm/GbmDevice.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -139,7 +140,15 @@ namespace MobileGL::MG_Gbm device.HeapPath.c_str(), alignedSize, heapErrno, strerror(heapErrno)); } +#if defined(__ANDROID__) && __ANDROID_API__ < 30 + // BIONIC ONLY DECLARES memfd_create FROM API 30, and this library builds against 26. + // The kernel call is far older than the declaration - it has been there since 3.17 - so + // asking for it by number is not a workaround for a missing feature, it is the same call + // with the name the headers of this API level do not carry yet. + const Int fd = static_cast(::syscall(__NR_memfd_create, "mobilegl-gbm", MFD_CLOEXEC)); +#else const Int fd = memfd_create("mobilegl-gbm", MFD_CLOEXEC); +#endif if (fd < 0) { MGLOG_E_ONCE("gbm: memfd_create failed (%d: %s) and no dma-heap node is usable, so no "