add POSIX, obsolete glibc, and h_malloc extensions to bindings

Signed-off-by: strawberry <strawberry@pupbrain.dev>
This commit is contained in:
strawberry 2024-04-10 13:20:10 -04:00
parent 7f4b5c097d
commit fcf6e16a5d

View file

@ -1,4 +1,6 @@
use core::ffi::c_void; use core::ffi::{c_int, c_void};
// ideally we would use c_size_t but it's unstable
#[allow(dead_code)] #[allow(dead_code)]
extern "C" { extern "C" {
@ -6,5 +8,56 @@ extern "C" {
pub fn malloc(size: usize) -> *mut c_void; pub fn malloc(size: usize) -> *mut c_void;
pub fn calloc(nmemb: usize, size: usize) -> *mut c_void; pub fn calloc(nmemb: usize, size: usize) -> *mut c_void;
pub fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void; pub fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void;
pub fn aligned_alloc(alignment: usize, size: usize) -> *mut c_void;
pub fn free(ptr: *mut c_void); pub fn free(ptr: *mut c_void);
/* POSIX */
pub fn posix_memalign(memptr: *mut *mut c_void, alignment: usize, size: usize) -> c_int;
/* glibc extensions */
#[cfg(target_os = "android")]
pub fn malloc_usable_size(ptr: *const c_void) -> usize;
#[cfg(not(target_os = "android"))]
pub fn malloc_usable_size(ptr: *mut c_void) -> usize;
pub fn mallopt(param: c_int, value: c_int) -> c_int;
pub fn malloc_trim(pad: usize) -> c_int;
pub fn malloc_stats() -> c_void;
/* TODO: add support for these
#if defined(__GLIBC__) || defined(__ANDROID__)
struct mallinfo h_mallinfo(void);
#endif
#ifndef __ANDROID__
int h_malloc_info(int options, FILE *fp);
#endif
*/
/* obsolete glbc extensions */
pub fn memalign(alignment: usize, size: usize) -> *mut c_void;
#[cfg(not(target_os = "android"))]
pub fn valloc(size: usize) -> *mut c_void;
#[cfg(not(target_os = "android"))]
pub fn pvalloc(size: usize) -> *mut c_void;
pub fn cfree(ptr: *mut c_void) -> c_void;
pub fn malloc_get_state() -> *mut c_void;
pub fn malloc_set_state(state: *mut c_void) -> c_int;
/* TODO: add support for these android extensions
// Android extensions
#ifdef __ANDROID__
size_t h_mallinfo_narenas(void);
size_t h_mallinfo_nbins(void);
struct mallinfo h_mallinfo_arena_info(size_t arena);
struct mallinfo h_mallinfo_bin_info(size_t arena, size_t bin);
int h_malloc_iterate(uintptr_t base, size_t size, void (*callback)(uintptr_t ptr, size_t size, void *arg),
void *arg);
void h_malloc_disable(void);
void h_malloc_enable(void);
void h_malloc_disable_memory_tagging(void);
#endif */
/* hardened_malloc extensions */
pub fn malloc_object_size(ptr: *const c_void) -> usize;
pub fn malloc_object_size_fast(ptr: *const c_void) -> usize;
pub fn free_sized(ptr: *mut c_void, expected_size: usize) -> c_void;
} }