From c1ae47dfb27ac125395470df5b709c74259cb6d2 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Fri, 23 May 2025 10:16:27 -0700 Subject: [PATCH] Add `mallopt` and related constants for Android The `HeapTaggingLevel` enum does not have a typedef alias and thus generated tests will not compile due to the missing `enum` keyword. As a result the constants are defined using `i32` to match the signature for `mallopt`. See: https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/malloc.h;l=215 --- libc-test/semver/android.txt | 17 +++++++++++++++++ src/unix/linux_like/android/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index d2a6ac3750d4e..ffe95ab9e2a2f 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -1326,6 +1326,22 @@ MS_STRICTATIME MS_SYNC MS_SYNCHRONOUS MS_UNBINDABLE +M_BIONIC_SET_HEAP_TAGGING_LEVEL +M_BIONIC_ZERO_INIT +M_CACHE_COUNT_MAX +M_CACHE_SIZE_MAX +M_DECAY_TIME +M_HEAP_TAGGING_LEVEL_ASYNC +M_HEAP_TAGGING_LEVEL_NONE +M_HEAP_TAGGING_LEVEL_SYNC +M_HEAP_TAGGING_LEVEL_TBI +M_MEMTAG_TUNING +M_MEMTAG_TUNING_BUFFER_OVERFLOW +M_MEMTAG_TUNING_UAF +M_PURGE +M_PURGE_ALL +M_THREAD_DISABLE_MEM_INIT +M_TSDS_COUNT_MAX NCCS NCP_SUPER_MAGIC NDA_CACHEINFO @@ -3520,6 +3536,7 @@ makedev mallinfo malloc malloc_usable_size +mallopt mcontext_t memalign memchr diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 2ad28f34b270c..9995703c53410 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -3153,6 +3153,26 @@ pub const IFLA_INFO_XSTATS: c_ushort = 3; pub const IFLA_INFO_SLAVE_KIND: c_ushort = 4; pub const IFLA_INFO_SLAVE_DATA: c_ushort = 5; +// malloc.h +pub const M_DECAY_TIME: c_int = -100; +pub const M_PURGE: c_int = -101; +pub const M_MEMTAG_TUNING: c_int = -102; +pub const M_THREAD_DISABLE_MEM_INIT: c_int = -103; +pub const M_PURGE_ALL: c_int = -104; +pub const M_CACHE_COUNT_MAX: c_int = -200; +pub const M_CACHE_SIZE_MAX: c_int = -201; +pub const M_TSDS_COUNT_MAX: c_int = -202; +pub const M_BIONIC_ZERO_INIT: c_int = -203; +pub const M_BIONIC_SET_HEAP_TAGGING_LEVEL: c_int = -204; + +pub const M_MEMTAG_TUNING_BUFFER_OVERFLOW: c_int = 0; +pub const M_MEMTAG_TUNING_UAF: c_int = 1; + +pub const M_HEAP_TAGGING_LEVEL_NONE: i32 = 0; +pub const M_HEAP_TAGGING_LEVEL_TBI: i32 = 1; +pub const M_HEAP_TAGGING_LEVEL_ASYNC: i32 = 2; +pub const M_HEAP_TAGGING_LEVEL_SYNC: i32 = 3; + // linux/rtnetlink.h pub const TCA_UNSPEC: c_ushort = 0; pub const TCA_KIND: c_ushort = 1; @@ -3650,6 +3670,9 @@ extern "C" { pub fn malloc_usable_size(ptr: *const c_void) -> size_t; + // available from API level 26 + pub fn mallopt(opt: c_int, arg: c_int) -> c_int; + pub fn utmpname(name: *const c_char) -> c_int; pub fn setutent(); pub fn getutent() -> *mut utmp;