From d46aa3cc7f4044329c6b66835b11c75d5616edc1 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 6 Dec 2024 11:52:41 +0800 Subject: [PATCH] xglobals: Add `__MCF_mresize_0()` --- mcfgthread/thread.c | 2 +- mcfgthread/xglobals.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mcfgthread/thread.c b/mcfgthread/thread.c index b05afecdb7..838dd277bf 100644 --- a/mcfgthread/thread.c +++ b/mcfgthread/thread.c @@ -75,7 +75,7 @@ _MCF_thread_new_aligned(_MCF_thread_procedure* proc, size_t align, const void* d size_request = (uintptr_t) thrd->__data_opt + size - (uintptr_t) thrd; __MCF_ASSERT(size_need <= size_request); - HeapReAlloc(__MCF_crt_heap, HEAP_REALLOC_IN_PLACE_ONLY, thrd, size_request); + __MCF_mresize_0(thrd, size_request); } /* Copy user-defined data. If this doesn't happen, they are implicit zeroes. */ diff --git a/mcfgthread/xglobals.h b/mcfgthread/xglobals.h index 24058bc7ee..6b9a9e3c3d 100644 --- a/mcfgthread/xglobals.h +++ b/mcfgthread/xglobals.h @@ -232,6 +232,13 @@ __MCF_XGLOBALS_INLINE void* __MCF_malloc_0(size_t size) __attribute__((__malloc__, __alloc_size__(1))); +/* Set the size a block of memory in place, like `truncate()` on files. + * If the existent block should be extended, vacuum bytes are filled with + * zeroes. */ +__MCF_XGLOBALS_INLINE +void* +__MCF_mresize_0(void* ptr, size_t size) __attribute__((__alloc_size__(2))); + /* Re-allocate a block of memory, like `realloc()`. If the existent * block should be extended, vacuum bytes are filled with zeroes. */ __MCF_XGLOBALS_INLINE @@ -489,6 +496,13 @@ __MCF_malloc_0(size_t size) return HeapAlloc(__MCF_crt_heap, HEAP_ZERO_MEMORY, size); } +__MCF_XGLOBALS_INLINE +void* +__MCF_mresize_0(void* ptr, size_t size) + { + return HeapReAlloc(__MCF_crt_heap, HEAP_ZERO_MEMORY | HEAP_REALLOC_IN_PLACE_ONLY, ptr, size); + } + __MCF_XGLOBALS_INLINE void* __MCF_mrealloc_0(void** pptr, size_t size)