Reactos
at master 42 lines 1.5 kB view raw
1// 2// msize.cpp 3// 4// Copyright (c) Microsoft Corporation. All rights reserved. 5// 6// Implementation of msize(). 7// 8#include <corecrt_internal.h> 9#include <malloc.h> 10 11 12 13// This function implements the logic of _msize(). It is called only in the 14// Release CRT. The Debug CRT has its own implementation of this function. 15// 16// This function must be marked noinline, otherwise _msize and 17// _msize_base will have identical COMDATs, and the linker will fold 18// them when calling one from the CRT. This is necessary because _msize 19// needs to support users patching in custom implementations. 20extern "C" __declspec(noinline) size_t __cdecl _msize_base(void* const block) noexcept 21{ 22 // Validation section 23 _VALIDATE_RETURN(block != nullptr, EINVAL, static_cast<size_t>(-1)); 24 25 return static_cast<size_t>(HeapSize(__acrt_heap, 0, block)); 26} 27 28// Calculates the size of the specified block in the heap. 'block' must be a 29// pointer to a valid block of heap-allocated memory (it must not be nullptr). 30// 31// This function supports patching and therefore must be marked noinline. 32// Both _msize_dbg and _msize_base must also be marked noinline 33// to prevent identical COMDAT folding from substituting calls to _msize 34// with either other function or vice versa. 35extern "C" _CRT_HYBRIDPATCHABLE __declspec(noinline) size_t __cdecl _msize(void* const block) 36{ 37 #ifdef _DEBUG 38 return _msize_dbg(block, _NORMAL_BLOCK); 39 #else 40 return _msize_base(block); 41 #endif 42}