From 0dc6b011fe585d2fb97087103543022e1fd750b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 13 Jun 2015 14:25:35 +0200 Subject: [PATCH] malloc: implement malloc_usable_size(). * Fix #12132 --- headers/posix/malloc.h | 4 ++++ src/system/libroot/posix/malloc/wrapper.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/headers/posix/malloc.h b/headers/posix/malloc.h index b36b17d9e9..7754038311 100644 --- a/headers/posix/malloc.h +++ b/headers/posix/malloc.h @@ -20,6 +20,10 @@ extern void free(void *pointer); extern void *memalign(size_t alignment, size_t numBytes); extern void *valloc(size_t numBytes); +#ifdef _GNU_SOURCE +size_t malloc_usable_size(void *ptr); +#endif + #ifdef __cplusplus } #endif diff --git a/src/system/libroot/posix/malloc/wrapper.cpp b/src/system/libroot/posix/malloc/wrapper.cpp index 5b5e06680e..c83336a55e 100644 --- a/src/system/libroot/posix/malloc/wrapper.cpp +++ b/src/system/libroot/posix/malloc/wrapper.cpp @@ -490,6 +490,15 @@ realloc(void *ptr, size_t size) } +extern "C" size_t +malloc_usable_size(void *ptr) +{ + if (ptr == NULL) + return 0; + return threadHeap::objectSize(ptr); +} + + // #pragma mark - BeOS specific extensions