Skip to content

WebGPU on Android 16 (API 36 emulator) crashes in wgpuQueueWriteBuffer (SIGSEGV); API 35 works #25655

Closed

Description

@agneszitte

Current behavior 🐛

An Android app that draws with WebGPU crashes a few seconds after start on the Android 16 (API 36) emulator: a segmentation fault in wgpu's wgpuQueueWriteBuffer, on Uno's WebGPU render thread.

[webgpu] init device — adapter='SwiftShader Device (LLVM 10.0.0)' backend=Vulkan type=CPU colorFormat=BGRA8Unorm
F libc    : Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7b371787e160 in tid 3645 (UnoWebGpuRender), pid 3238 (ive.uno.ui.demo)
F DEBUG   : backtrace:
F DEBUG   :       #00 pc 000000000008fa47  /apex/com.android.runtime/lib64/bionic/libc.so (memmove+87)
F DEBUG   :       #01 pc 000000000031be73  .../lib/x86_64/libwgpu_native.so (wgpu_core::device::queue::Queue::write_buffer+723)
F DEBUG   :       #02 pc 0000000000432d44  .../lib/x86_64/libwgpu_native.so (wgpu_core::...::Global::queue_write_buffer+180)
F DEBUG   :       #03 pc 00000000002824e0  .../lib/x86_64/libwgpu_native.so (wgpuQueueWriteBuffer+80)
F DEBUG   :       #04 pc 00000000007e3386  <anonymous:52002000>

SEGV_ACCERR inside memmove: the write into the buffer's mapped memory is refused.

The same APK on an Android 15 (API 35) emulator, with the same SwiftShader adapter, starts, renders and passes the app's runtime tests. Uno's own Android WebGPU lane runs on API 34, so it doesn't cover API 35 or 36.

Expected behavior 🎯

The app renders with WebGPU on Android 16 as it does on Android 15.

How to reproduce it (as minimally and precisely as possible) 🔬

  1. Build an Android app with <UnoFeatures>Skia;WebGpu</UnoFeatures> that registers the WebGPU backend in CreateHost():

    UnoPlatformHostBuilder.Create()
        .App(() => new App())
        .UseAndroid()
        .GraphicsBackend(WebGpuBackend.CreateGraphicsProvider())
        .GeometryFactory(ManagedBackend.CreateGeometryFactory())
        .Build();
  2. Start an API 36 emulator with software Vulkan: system-images;android-36;google_apis;x86_64, emulator -avd <avd> -gpu swiftshader_indirect -no-window.

  3. Install and start the app: it crashes within a few seconds, with the backtrace above.

Seen with the Uno Gallery's WebGPU canary build (Release), twice out of two runs on API 36; zero crashes on API 35 (system-images;android-35;google_apis;x86_64, same emulator, same flags). The emulator reports a 4 KB page size on both, so 16 KB pages aren't involved.

Workaround 🛠️

None found in the app. The Uno Gallery's CI emulator is API 34, so its WebGPU canary isn't blocked.

Affected platforms 📱💻🖥️

Android (seen on the API 36 emulator; real Android 16 devices not checked)

Uno.Sdk version (and other relevant versions) 📦

  • Uno.Sdk 7.0.0-dev.87 (Uno.WinUI and Uno.WinUI.Composition.WebGpu 7.0.0-dev.2420)
  • Android emulator 36.2.12.0 on Windows 11 (WHPX), -gpu swiftshader_indirect; guest kernel 6.6.66-android15

IDE version 🧑‍💻

None: dotnet CLI.

Anything else we need to know? 💬

Found while setting up the Uno Gallery's WebGPU canary. Adding an API 36 run to the Android WebGPU lane would cover it.

Activity

  1. added
    7.0
    on Oct 23, 2026
  2. ramezgerges commented on Oct 23, 2026

    @ramezgerges
    Contributor

    Root cause: the API 36 emulator image's Vulkan driver, not Uno or wgpu

    I reproduced this with a small standalone NDK program (source below) that uses no Uno and no wgpu. It allocates host-visible Vulkan memory, maps it and writes every page, which is what wgpuQueueWriteBuffer does with its staging buffer.

    API 36 (system-images;android-36;google_apis;x86_64, emulator 37.2.12, -gpu swiftshader_indirect):

    • Once about 16 MB of host-visible memory is allocated, the next mapped allocation can't be written: SIGSEGV SEGV_ACCERR, usually at offset 4096 of the block.
      • 4 MB blocks: the 5th one faults.
      • 16, 32 or 64 MB blocks: the 2nd one faults.
      • 1 MB blocks ×10: all fine.
    • A single first allocation of any size (up to 512 MB) is fully writable. What matters is how much is allocated at the same time.
    • Memory that is allocated but never mapped still counts. With 256 MB held unmapped, the first mapped block faults at offset 0.
    • Freeing a block and allocating again reuses the same address and works indefinitely.
    • Allocating a large block up front and freeing it doesn't help, whether or not it was mapped and written first. The fault comes at the same point.

    API 35 (android-35, same emulator, same host SwiftShader): 12 blocks totalling 1.4 GB, all writable.

    The host side is identical, so the defect is in the guest Vulkan driver shipped in the API 36 system image. wgpu keeps its memory blocks mapped and goes past 16 MB within seconds (render targets alone are about 10 MB each), hence the crash in Queue::write_buffer.

    Correction: Skia is affected too. SamplesApp with the default Skia backend (Vulkan) crashes on the same API 36 image with the same signature: SIGSEGV SEGV_ACCERR in memmove, called from libSkiaSharp.so, 7 s after launch. In my earlier runs the emulator process itself crashed before the app got that far, which hid this. So this isn't specific to WebGPU: any app that keeps more than ~16 MB of Vulkan memory allocated on this image can hit it.

    What we're doing:

    Real Android 16 devices use their vendor's Vulkan driver, not this one, so they shouldn't be affected. I haven't checked one.

    Repro program (vkmaptest.c)

    Build with the NDK (x86_64-linux-android30-clang -O1 -o vkmaptest vkmaptest.c -lvulkan), then adb push it and run /data/local/tmp/vkmaptest 16384 16384 16384 16384. The arguments are block sizes in KB. An optional first argument holds flags: u unmaps each block after writing, f also frees it, p<MB> first allocates that much without mapping it, r<MB> allocates that much and frees it first (rw<MB> also maps and writes it).

    // does the guest Vulkan driver hand out writable mappings? For every HOST_VISIBLE memory type, binds
    // a buffer, maps it and writes into it - what wgpu's Queue::write_buffer does with its staging buffer. A SIGSEGV
    // handler reports the memory type that refused the write instead of killing the run.
    #include <setjmp.h>
    #include <signal.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <vulkan/vulkan.h>
    
    static sigjmp_buf jump;
    static volatile void *faultAddr;
    
    static void onSegv(int sig, siginfo_t *info, void *ctx)
    {
    	(void)sig; (void)ctx;
    	faultAddr = info->si_addr;
    	siglongjmp(jump, info->si_code);
    }
    
    int main(int argc, char **argv)
    {
    	struct sigaction sa = { 0 };
    	sa.sa_sigaction = onSegv;
    	sa.sa_flags = SA_SIGINFO;
    	sigaction(SIGSEGV, &sa, NULL);
    
    	VkApplicationInfo app = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_1 };
    	VkInstanceCreateInfo ici = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app };
    	VkInstance inst;
    	if (vkCreateInstance(&ici, NULL, &inst) != VK_SUCCESS) { printf("vkCreateInstance failed\n"); return 1; }
    
    	uint32_t n = 1;
    	VkPhysicalDevice pd;
    	vkEnumeratePhysicalDevices(inst, &n, &pd);
    	VkPhysicalDeviceProperties props;
    	vkGetPhysicalDeviceProperties(pd, &props);
    	printf("device: %s (api %u.%u.%u, driver 0x%x)\n", props.deviceName, VK_VERSION_MAJOR(props.apiVersion),
    		VK_VERSION_MINOR(props.apiVersion), VK_VERSION_PATCH(props.apiVersion), props.driverVersion);
    
    	float prio = 1.0f;
    	VkDeviceQueueCreateInfo qci = { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, .queueFamilyIndex = 0, .queueCount = 1, .pQueuePriorities = &prio };
    	VkDeviceCreateInfo dci = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .queueCreateInfoCount = 1, .pQueueCreateInfos = &qci };
    	VkDevice dev;
    	if (vkCreateDevice(pd, &dci, NULL, &dev) != VK_SUCCESS) { printf("vkCreateDevice failed\n"); return 1; }
    
    	VkPhysicalDeviceMemoryProperties mp;
    	vkGetPhysicalDeviceMemoryProperties(pd, &mp);
    
    	const VkDeviceSize sizes[] = { 256, 64 * 1024, 4 * 1024 * 1024 };
    	int failures = 0;
    	for (uint32_t t = 0; t < mp.memoryTypeCount; t++)
    	{
    		VkMemoryPropertyFlags f = mp.memoryTypes[t].propertyFlags;
    		if (!(f & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) { continue; }
    		for (unsigned s = 0; s < sizeof(sizes) / sizeof(sizes[0]); s++)
    		{
    			VkBufferCreateInfo bci = { .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = sizes[s],
    				.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
    				.sharingMode = VK_SHARING_MODE_EXCLUSIVE };
    			VkBuffer buf;
    			vkCreateBuffer(dev, &bci, NULL, &buf);
    			VkMemoryRequirements req;
    			vkGetBufferMemoryRequirements(dev, buf, &req);
    			if (!(req.memoryTypeBits & (1u << t))) { vkDestroyBuffer(dev, buf, NULL); continue; }
    			VkMemoryAllocateInfo mai = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, .memoryTypeIndex = t };
    			VkDeviceMemory mem;
    			VkResult ar = vkAllocateMemory(dev, &mai, NULL, &mem);
    			if (ar != VK_SUCCESS) { printf("type %u flags 0x%x size %llu: allocate failed %d\n", t, f, (unsigned long long)sizes[s], ar); vkDestroyBuffer(dev, buf, NULL); continue; }
    			vkBindBufferMemory(dev, buf, mem, 0);
    			void *ptr = NULL;
    			VkResult mr = vkMapMemory(dev, mem, 0, VK_WHOLE_SIZE, 0, &ptr);
    			const char *result;
    			int code = sigsetjmp(jump, 1);
    			if (mr != VK_SUCCESS) { result = "map failed"; }
    			else if (code == 0)
    			{
    				memset(ptr, 0x5a, (size_t)sizes[s]);
    				result = ((unsigned char *)ptr)[sizes[s] - 1] == 0x5a ? "write ok" : "write LOST";
    			}
    			else
    			{
    				static char msg[96];
    				snprintf(msg, sizeof msg, "SIGSEGV %s at %p (mapped %p)", code == SEGV_ACCERR ? "SEGV_ACCERR" : "SEGV_MAPERR", faultAddr, ptr);
    				result = msg;
    				failures++;
    			}
    			printf("type %u flags 0x%x heap %u size %llu: %s\n", t, f, mp.memoryTypes[t].heapIndex, (unsigned long long)sizes[s], result);
    			if (mr == VK_SUCCESS) { vkUnmapMemory(dev, mem); }
    			vkFreeMemory(dev, mem, NULL);
    			vkDestroyBuffer(dev, buf, NULL);
    		}
    	}
    	// Phase 2: what an allocator does over time - large blocks that stay mapped, accumulating, every page written.
    	{
    		uint32_t t = 0;
    		while (t < mp.memoryTypeCount && !(mp.memoryTypes[t].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) { t++; }
    		printf("heap %u size %llu MB\n", mp.memoryTypes[t].heapIndex, (unsigned long long)(mp.memoryHeaps[mp.memoryTypes[t].heapIndex].size >> 20));
    		// Block sizes in KB from the command line (default 32 MB, 64 MB, 128 MB, 256 MB, repeated).
    		VkDeviceSize blocks[64] = { 32u << 20, 64u << 20, 128u << 20, 256u << 20 };
    		int nblocks = 4, rounds = 12;
    		// An optional first argument of flags: u = unmap each block once written, f = also free it, p<MB> = first
    		// allocate that much without ever mapping it (memory a renderer uses for textures).
    		int flagged = argc > 1 && argv[1][0] >= 'a' && argv[1][0] <= 'z';
    		int unmapEach = flagged && strchr(argv[1], 'u') != NULL;
    		int freeEach = flagged && strchr(argv[1], 'f') != NULL;
    		long preMb = flagged && strchr(argv[1], 'p') != NULL ? atol(strchr(argv[1], 'p') + 1) : 0;
    		for (long m = 0; m < preMb; m += 16)
    		{
    			VkMemoryAllocateInfo pai = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = 16u << 20, .memoryTypeIndex = t };
    			VkDeviceMemory pm;
    			if (vkAllocateMemory(dev, &pai, NULL, &pm) != VK_SUCCESS) { printf("preallocation failed at %ld MB\n", m); break; }
    		}
    		if (preMb) { printf("preallocated %ld MB, never mapped\n", preMb); }
    		// r<MB> = prime: allocate one block of that size and free it before anything else; w = also map and write it first.
    		long primeMb = flagged && strchr(argv[1], 'r') != NULL ? atol(strpbrk(argv[1], "0123456789")) : 0;
    		if (primeMb)
    		{
    			int primeWrite = strchr(argv[1], 'w') != NULL;
    			VkMemoryAllocateInfo rai = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = (VkDeviceSize)primeMb << 20, .memoryTypeIndex = t };
    			VkDeviceMemory rm;
    			if (vkAllocateMemory(dev, &rai, NULL, &rm) == VK_SUCCESS)
    			{
    				void *rp = NULL;
    				if (primeWrite && vkMapMemory(dev, rm, 0, VK_WHOLE_SIZE, 0, &rp) == VK_SUCCESS)
    				{
    					for (VkDeviceSize o = 0; o < rai.allocationSize; o += 4096) { ((volatile unsigned char *)rp)[o] = 1; }
    					vkUnmapMemory(dev, rm);
    				}
    				vkFreeMemory(dev, rm, NULL);
    				printf("primed with %ld MB (%s), freed\n", primeMb, primeWrite ? "mapped and written" : "never mapped");
    			}
    		}
    		if (argc > 1 + flagged)
    		{
    			nblocks = 0;
    			for (int a = 1 + flagged; a < argc && nblocks < 64; a++) { blocks[nblocks++] = (VkDeviceSize)atoll(argv[a]) << 10; }
    			rounds = nblocks;
    		}
    		VkDeviceSize total = 0;
    		for (int round = 0; round < rounds; round++)
    		{
    			VkDeviceSize size = blocks[round % nblocks];
    			VkMemoryAllocateInfo mai = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = size, .memoryTypeIndex = t };
    			VkDeviceMemory mem;
    			VkResult ar = vkAllocateMemory(dev, &mai, NULL, &mem);
    			if (ar != VK_SUCCESS) { printf("block %d (%llu MB, total %llu MB): allocate failed %d\n", round, (unsigned long long)(size >> 20), (unsigned long long)(total >> 20), ar); break; }
    			void *ptr = NULL;
    			VkResult mr = vkMapMemory(dev, mem, 0, VK_WHOLE_SIZE, 0, &ptr);
    			if (mr != VK_SUCCESS) { printf("block %d: map failed %d\n", round, mr); break; }
    			int code = sigsetjmp(jump, 1);
    			if (code == 0)
    			{
    				for (VkDeviceSize o = 0; o < size; o += 4096) { ((volatile unsigned char *)ptr)[o] = 0x5a; }
    				total += size;
    				printf("block %d (%llu MB at %p): all pages writable, total mapped %llu MB\n", round, (unsigned long long)(size >> 20), ptr, (unsigned long long)(total >> 20));
    				if (unmapEach || freeEach) { vkUnmapMemory(dev, mem); }
    				if (freeEach) { vkFreeMemory(dev, mem, NULL); }
    			}
    			else
    			{
    				printf("block %d (%llu MB at %p): SIGSEGV %s at %p (offset %lld), total before %llu MB\n", round, (unsigned long long)(size >> 20), ptr,
    					code == SEGV_ACCERR ? "SEGV_ACCERR" : "SEGV_MAPERR", faultAddr, (long long)((char *)faultAddr - (char *)ptr), (unsigned long long)(total >> 20));
    				failures++;
    				break;
    			}
    		}
    	}
    	printf("DONE failures=%d\n", failures);
    	return 0;
    }
  3. ramezgerges commented on Oct 26, 2026

    @ramezgerges
    Contributor

    Update: fixed in revision 7 of the API 36 image

    The emulator side is fixed. Revision 7 of the API 36 system image ships a guest Vulkan driver without the 16 MB mapping fault. Google now publishes revision 7 for both google_apis and google_apis_playstore.

    Checked locally with the same vkmaptest program as above, on system-images;android-36;google_apis_playstore;x86_64 revision 7:

    • 16 MB blocks ×4: all writable (64 MB), 0 failures.
    • 4 MB blocks ×8: all writable (32 MB), 0 failures. Revision 5 faulted on the 5th of these.
    • SamplesApp Given_Border also runs on revision 7 with both WebGPU and Skia (Vulkan), without crashing.

    What this means:

    • Uno's CI: ci(android): Run the Android lanes on API 36 #25669 now runs the Android WebGPU lane on API 36 rather than pinning API 35. sdkmanager --install upgrades an already-installed older revision, and the lane now logs the Pkg.Revision it installed.
    • Local emulators still on revision 5 keep crashing (Skia too). Update the image with sdkmanager --install "system-images;android-36;google_apis_playstore;x86_64" (or the google_apis variant), then check Pkg.Revision=7 in the image's source.properties.
    • One local caveat: with emulator 37.2.12 on Windows, revision 7 only booted with -feature -Wifi,-VirtioWifi. I haven't checked whether other hosts need it.

    So no workaround is needed in Uno or wgpu, and no upstream emulator report is needed either.

  4. removed
    7.0
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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