1 // Copyright 2021 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/memory/nonscannable_memory.h" 6 7 #include "partition_alloc/partition_alloc_buildflags.h" 8 9 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) 10 #include "partition_alloc/shim/nonscannable_allocator.h" 11 #else 12 #include <stdlib.h> 13 #endif 14 15 namespace base { 16 AllocNonScannable(size_t size)17void* AllocNonScannable(size_t size) { 18 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) 19 return allocator_shim::NonScannableAllocator::Instance().Alloc(size); 20 #else 21 return ::malloc(size); 22 #endif 23 } 24 FreeNonScannable(void * ptr)25void FreeNonScannable(void* ptr) { 26 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) 27 allocator_shim::NonScannableAllocator::Instance().Free(ptr); 28 #else 29 return ::free(ptr); 30 #endif 31 } 32 AllocNonQuarantinable(size_t size)33void* AllocNonQuarantinable(size_t size) { 34 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) 35 return allocator_shim::NonQuarantinableAllocator::Instance().Alloc(size); 36 #else 37 return ::malloc(size); 38 #endif 39 } 40 FreeNonQuarantinable(void * ptr)41void FreeNonQuarantinable(void* ptr) { 42 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) 43 allocator_shim::NonQuarantinableAllocator::Instance().Free(ptr); 44 #else 45 return ::free(ptr); 46 #endif 47 } 48 49 } // namespace base 50