https://android.googlesource.com/platform/external/qemu/+/em...
These 3 files should be a fairly self contained, minimal way to allocate into existing buffers. No attempt is made at thread safety though (we assume the user synchronizes that themselves)