diff options
Diffstat (limited to 'src/jit/hostallocator.cpp')
-rw-r--r-- | src/jit/hostallocator.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/jit/hostallocator.cpp b/src/jit/hostallocator.cpp new file mode 100644 index 0000000000..b737424ee8 --- /dev/null +++ b/src/jit/hostallocator.cpp @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include "jitpch.h" +#include "hostallocator.h" + +HostAllocator HostAllocator::s_hostAllocator; + +void* HostAllocator::Alloc(size_t size) +{ + assert(g_jitHost != nullptr); + return g_jitHost->allocateMemory(size, false); +} + +void* HostAllocator::ArrayAlloc(size_t elemSize, size_t numElems) +{ + assert(g_jitHost != nullptr); + + ClrSafeInt<size_t> safeElemSize(elemSize); + ClrSafeInt<size_t> safeNumElems(numElems); + ClrSafeInt<size_t> size = safeElemSize * safeNumElems; + if (size.IsOverflow()) + { + return nullptr; + } + + return g_jitHost->allocateMemory(size.Value(), false); +} + +void HostAllocator::Free(void* p) +{ + assert(g_jitHost != nullptr); + g_jitHost->freeMemory(p, false); +} + +HostAllocator* HostAllocator::getHostAllocator() +{ + return &s_hostAllocator; +} |