ReactOS 0.4.16-dev-979-g79f281e
msize.cpp
Go to the documentation of this file.
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
39 #else
40 return _msize_base(block);
41 #endif
42}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
_Check_return_ _ACRTIMP size_t __cdecl _msize_base(_Pre_notnull_ void *_Block) _CRT_NOEXCEPT
#define _NORMAL_BLOCK
Definition: crtdbg.h:67
#define _msize_dbg(p, t)
Definition: crtdbg.h:210
_Check_return_ _CRTIMP size_t __cdecl _msize(_In_ void *_Memory)
#define noinline
Definition: types.h:64
void __declspec(noinline) __cdecl _free_base(void *const block)
Definition: free_base.cpp:98
HANDLE __acrt_heap
Definition: heap_handle.cpp:15
#define _CRT_HYBRIDPATCHABLE
Definition: corecrt.h:188
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)
static unsigned int block
Definition: xmlmemory.c:101