1 // Copyright 2023 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 "build/build_config.h" 6 #include "partition_alloc/partition_alloc_buildflags.h" 7 #include "partition_alloc/shim/allocator_dispatch.h" 8 #include "partition_alloc/shim/winheap_stubs_win.h" 9 10 // This file must not include any headers that include <malloc.h> or <new>. 11 // e.g. if <new> is included, we will see the following error: 12 // "redeclaration of 'operator new' should not add 'dllexport' attribute" 13 14 namespace std { 15 struct nothrow_t; 16 } // namespace std 17 18 namespace allocator_shim { 19 namespace internal { 20 21 const allocator_shim::AllocatorDispatch* GetChainHead(); 22 bool CallNewHandler(size_t size); 23 extern bool g_call_new_handler_on_malloc_failure; 24 size_t CheckedMultiply(size_t multiplicand, size_t multiplier); 25 26 } // namespace internal 27 28 void SetCallNewHandlerOnMallocFailure(bool value); 29 30 } // namespace allocator_shim 31 32 // No calls to malloc / new in this file. They would cause re-entrancy of 33 // the shim, which is hard to deal with. Keep this code as simple as possible 34 // and don't use any external C++ object here, not even //base ones. Even if 35 // they are safe to use today, in future they might be refactored. 36 37 #include "partition_alloc/shim/allocator_shim_override_ucrt_symbols_win.h" 38 39 // Cross-checks. 40 #if !defined(COMPONENT_BUILD) || !BUILDFLAG(IS_WIN) 41 #error This code is only for Windows component build. 42 #endif 43 44 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 45 #error The allocator shim should not be compiled when building for memory tools. 46 #endif 47 48 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ 49 (defined(_MSC_VER) && defined(_CPPUNWIND)) 50 #error This code cannot be used when exceptions are turned on. 51 #endif 52