Fix alignedMalloc NULL check and 32-bit Android BatchData pool size

On 32-bit ARM kernels (CONFIG_VMSPLIT_3G=y), each process is limited to
a 3 GB virtual address space (0x00000000-0xbfffffff). When system_server
on 32-bit Android Cuttlefish initializes a software Vulkan renderer via
SwiftShader (vulkan.pastel.so) for PowerManagerService ColorFade,
sw::Renderer allocates a contiguous DrawCall::BatchData::Pool of 16
batches (0x047ce040 bytes, ~75.3 MB). Due to VMA fragmentation across
~3,760 mappings in system_server, malloc(0x047ce054) can return NULL.

1. In third_party/marl/src/memory.cpp (alignedMalloc), check for
   allocation == nullptr before computing aligned + size and calling
   memcpy, preventing a SIGSEGV (SEGV_ACCERR) write fault at
   0x0 + 0x047ce040. (Note: upstream github.com/google/marl was archived
   read-only on 2026-04-27, so this fix is applied directly here.)
2. In src/Device/Renderer.hpp, reduce MaxBatchCount from 16 to 4 on
   32-bit Android builds (defined(__ANDROID__) && !defined(__LP64__)),
   shrinking the contiguous BatchData::Pool allocation from 75.3 MB to
   18.8 MB so it succeeds within the 3 GB 32-bit address space.

Bug: b/581958296
Test: Trigger screen-off ColorFade in system_server on 32-bit ARM Cuttlefish
Change-Id: I14b0ab6d5e3f4961fdb823b013566f4e9880359d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/77988
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Device/Renderer.hpp b/src/Device/Renderer.hpp
index 284a6e9..d115a03 100644
--- a/src/Device/Renderer.hpp
+++ b/src/Device/Renderer.hpp
@@ -48,7 +48,15 @@
 struct Constants;
 
 static constexpr int MaxBatchSize = 128;
+#if defined(__ANDROID__) && !defined(__LP64__)
+// On 32-bit Android (CONFIG_VMSPLIT_3G=y, 3 GB process VA space), reduce the
+// contiguous DrawCall::BatchData::Pool allocation from 16 batches (~75.3 MB)
+// to 4 batches (~18.8 MB) so system_server ColorFade Vulkan initialization
+// does not fail due to 32-bit VMA fragmentation on Cuttlefish.
+static constexpr int MaxBatchCount = 4;
+#else
 static constexpr int MaxBatchCount = 16;
+#endif
 static constexpr int MaxClusterCount = 16;
 static constexpr int MaxDrawCount = 16;
 
diff --git a/third_party/marl/src/memory.cpp b/third_party/marl/src/memory.cpp
index f52be55..803b80d 100644
--- a/third_party/marl/src/memory.cpp
+++ b/third_party/marl/src/memory.cpp
@@ -183,6 +183,9 @@
 inline void* alignedMalloc(size_t alignment, size_t size) {
   size_t allocSize = size + alignment + sizeof(void*);
   auto allocation = malloc(allocSize);
+  if (allocation == nullptr) {
+    return nullptr;
+  }
   auto aligned = reinterpret_cast<uint8_t*>(marl::alignUp(
       reinterpret_cast<uintptr_t>(allocation), alignment));  // align
   memcpy(aligned + size, &allocation, sizeof(void*));  // pointer-to-allocation