From ac25e3323a91f36fe1942dc26d76b8ba84d2363e Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 29 Sep 2026 06:10:20 -0400 Subject: [PATCH] [Tool] (extmem_probe): build inside the API-26 trace APK - memfd_create through syscall() below API 30, the two Vulkan 1.1 calls through vkGetInstanceProcAddr below API 28 --- tools/spikes/extmem_probe/extmem_probe.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/spikes/extmem_probe/extmem_probe.cpp b/tools/spikes/extmem_probe/extmem_probe.cpp index 374f55fe..722ae9a5 100644 --- a/tools/spikes/extmem_probe/extmem_probe.cpp +++ b/tools/spikes/extmem_probe/extmem_probe.cpp @@ -91,6 +91,35 @@ #include #include +// bionic declares memfd_create only from API 30; the trace APK (MOBILEGL_BUILD_EXTMEM_PROBE) +// builds at the project's API 26, where the syscall itself exists. +#if defined(__ANDROID__) && __ANDROID_API__ < 30 +# include +static int memfd_create(const char* name, unsigned int flags) { + return (int)syscall(__NR_memfd_create, name, flags); +} +#endif + +// The NDK's libvulkan stub exports Vulkan 1.1 entry points only from API 28; below that +// (the API-26 trace APK) the two 1.1 calls the probe makes go through the instance. +static VkInstance gVk11ShimInstance = VK_NULL_HANDLE; +#if defined(__ANDROID__) && __ANDROID_API__ < 28 +static void probeGetPhysicalDeviceProperties2(VkPhysicalDevice pd, VkPhysicalDeviceProperties2* out) { + auto fn = (PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(gVk11ShimInstance, + "vkGetPhysicalDeviceProperties2"); + if (fn) fn(pd, out); +} +static void probeGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice pd, + const VkPhysicalDeviceExternalBufferInfo* info, + VkExternalBufferProperties* out) { + auto fn = (PFN_vkGetPhysicalDeviceExternalBufferProperties)vkGetInstanceProcAddr( + gVk11ShimInstance, "vkGetPhysicalDeviceExternalBufferProperties"); + if (fn) fn(pd, info, out); +} +# define vkGetPhysicalDeviceProperties2 probeGetPhysicalDeviceProperties2 +# define vkGetPhysicalDeviceExternalBufferProperties probeGetPhysicalDeviceExternalBufferProperties +#endif + // --------------------------------------------------------------------------- // tiny logging / result table // --------------------------------------------------------------------------- @@ -557,6 +586,7 @@ static bool vkCtxInit(VkCtx& c, bool verbose) { pr("vkCreateInstance failed: %s", vkStr(r).c_str()); return false; } + gVk11ShimInstance = c.instance; uint32_t n = 0; vkEnumeratePhysicalDevices(c.instance, &n, nullptr);