mirror of
https://github.com/reactos/reactos.git
synced 2025-06-26 19:19:43 +00:00
[UCRT] Import Microsoft.Windows.SDK.CRTSource version 10.0.22621.3
Imported from https://www.nuget.org/packages/Microsoft.Windows.SDK.CRTSource/10.0.22621.3 License: MIT
This commit is contained in:
parent
f1b60c66f0
commit
04e0dc4a7a
568 changed files with 115483 additions and 0 deletions
47
sdk/lib/ucrt/heap/malloc_base.cpp
Normal file
47
sdk/lib/ucrt/heap/malloc_base.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// malloc_base.cpp
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Implementation of _malloc_base(). This is defined in a different source file
|
||||
// from the malloc() function to allow malloc() to be replaced by the user.
|
||||
//
|
||||
#include <corecrt_internal.h>
|
||||
#include <malloc.h>
|
||||
#include <new.h>
|
||||
|
||||
|
||||
|
||||
// This function implements the logic of malloc(). It is called directly by the
|
||||
// malloc() function in the Release CRT and is called by the debug heap in the
|
||||
// Debug CRT.
|
||||
//
|
||||
// This function must be marked noinline, otherwise malloc and
|
||||
// _malloc_base will have identical COMDATs, and the linker will fold
|
||||
// them when calling one from the CRT. This is necessary because malloc
|
||||
// needs to support users patching in custom implementations.
|
||||
extern "C" __declspec(noinline) _CRTRESTRICT void* __cdecl _malloc_base(size_t const size)
|
||||
{
|
||||
// Ensure that the requested size is not too large:
|
||||
_VALIDATE_RETURN_NOEXC(_HEAP_MAXREQ >= size, ENOMEM, nullptr);
|
||||
|
||||
// Ensure we request an allocation of at least one byte:
|
||||
size_t const actual_size = size == 0 ? 1 : size;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
void* const block = HeapAlloc(__acrt_heap, 0, actual_size);
|
||||
if (block)
|
||||
return block;
|
||||
|
||||
// Otherwise, see if we need to call the new handler, and if so call it.
|
||||
// If the new handler fails, just return nullptr:
|
||||
if (_query_new_mode() == 0 || !_callnewh(actual_size))
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The new handler was successful; try to allocate again...
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue