From 0cb234dfd9c38b5c27c987ec4b984df2852695da Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 25 Sep 2025 18:12:53 +0000 Subject: [PATCH] [android] fix memfd_create() issue Signed-off-by: lizzie --- src/common/host_memory.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 2e36d59569..b91d472f22 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -439,10 +439,11 @@ static void* ChooseVirtualBase(size_t virtual_size) { #endif -#if defined(__sun__) || defined(__HAIKU__) || defined(__NetBSD__) || defined(__DragonFly__) +#if defined(__sun__) || defined(__HAIKU__) || defined(__NetBSD__) || defined(__DragonFly__) || (defined(__ANDROID__) && __ANDROID_API__ <= 29) /// Most Unices don't have a portable shm_open (AIX, OpenBSD, NetBSD, Solaris 11, OpenIndiana) /// Portable implementation of shm_open(SHM_ANON, ...) - roughly equivalent but without /// OS support - may fail sporadically, beware! +/// For example legacy android (ndk <= 29, aka. Android 10) doesn't have memfd_create() static int shm_open_anon(int flags, mode_t mode) { char name[16] = "/shm-"; char *const limit = name + sizeof(name) - 1; @@ -494,7 +495,7 @@ public: ASSERT_MSG(page_size == 0x1000, "page size {:#x} is incompatible with 4K paging", page_size); // Backing memory initialization -#if defined(__sun__) || defined(__HAIKU__) || defined(__NetBSD__) || defined(__DragonFly__) +#if defined(__sun__) || defined(__HAIKU__) || defined(__NetBSD__) || defined(__DragonFly__) || (defined(__ANDROID__) && __ANDROID_API__ <= 29) fd = shm_open_anon(O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); #elif defined(__OpenBSD__) fd = shm_open_anon(O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);