vita_system_alloc_wrapper/
lib.rs

1use std::alloc::{GlobalAlloc, System};
2
3pub struct SystemAllocWrapper;
4
5unsafe impl GlobalAlloc for SystemAllocWrapper {
6    #[inline]
7    unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {
8        System::alloc(&System, layout)
9    }
10
11    #[inline]
12    unsafe fn alloc_zeroed(&self, layout: std::alloc::Layout) -> *mut u8 {
13        System::alloc_zeroed(&System, layout)
14    }
15
16    #[inline]
17    unsafe fn realloc(&self, ptr: *mut u8, layout: std::alloc::Layout, new_size: usize) -> *mut u8 {
18        System::realloc(&System, ptr, layout, new_size)
19    }
20
21    #[inline]
22    unsafe fn dealloc(&self, ptr: *mut u8, _layout: std::alloc::Layout) {
23        #[allow(clippy::unit_arg)]
24        std::hint::black_box(libc::free(ptr as *mut libc::c_void));
25    }
26}