OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../include/fxcrt/fx_basic.h" | 7 #include <stdlib.h> // For abort(). |
8 #ifdef __cplusplus | 8 #include "../../include/fxcrt/fx_memory.h" |
9 extern "C" { | 9 |
10 #endif | |
11 void* FXMEM_DefaultAlloc(size_t byte_size, int flags) | 10 void* FXMEM_DefaultAlloc(size_t byte_size, int flags) |
12 { | 11 { |
13 return (void*)malloc(byte_size); | 12 return (void*)malloc(byte_size); |
14 } | 13 } |
15 void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags) | 14 void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags) |
16 { | 15 { |
17 return realloc(pointer, new_size); | 16 return realloc(pointer, new_size); |
18 } | 17 } |
19 void FXMEM_DefaultFree(void* pointer, int flags) | 18 void FXMEM_DefaultFree(void* pointer, int flags) |
20 { | 19 { |
21 free(pointer); | 20 free(pointer); |
22 } | 21 } |
23 #ifdef __cplusplus | 22 |
| 23 NEVER_INLINE void FX_OutOfMemoryTerminate() { |
| 24 // Termimate cleanly if we can, else crash at a specific address (0xbd). |
| 25 abort(); |
| 26 reinterpret_cast<void(*)()>(0xbd)(); |
24 } | 27 } |
25 #endif | 28 |
26 CFX_GrowOnlyPool::CFX_GrowOnlyPool(size_t trunk_size) | 29 CFX_GrowOnlyPool::CFX_GrowOnlyPool(size_t trunk_size) |
27 { | 30 { |
28 m_TrunkSize = trunk_size; | 31 m_TrunkSize = trunk_size; |
29 m_pFirstTrunk = NULL; | 32 m_pFirstTrunk = NULL; |
30 } | 33 } |
31 CFX_GrowOnlyPool::~CFX_GrowOnlyPool() | 34 CFX_GrowOnlyPool::~CFX_GrowOnlyPool() |
32 { | 35 { |
33 FreeAll(); | 36 FreeAll(); |
34 } | 37 } |
35 struct _FX_GrowOnlyTrunk { | 38 struct _FX_GrowOnlyTrunk { |
(...skipping 24 matching lines...) Expand all Loading... |
60 pTrunk = pTrunk->m_pNext; | 63 pTrunk = pTrunk->m_pNext; |
61 } | 64 } |
62 size_t alloc_size = size > m_TrunkSize ? size : m_TrunkSize; | 65 size_t alloc_size = size > m_TrunkSize ? size : m_TrunkSize; |
63 pTrunk = (_FX_GrowOnlyTrunk*)FX_Alloc(FX_BYTE, sizeof(_FX_GrowOnlyTrunk) + a
lloc_size); | 66 pTrunk = (_FX_GrowOnlyTrunk*)FX_Alloc(FX_BYTE, sizeof(_FX_GrowOnlyTrunk) + a
lloc_size); |
64 pTrunk->m_Size = alloc_size; | 67 pTrunk->m_Size = alloc_size; |
65 pTrunk->m_Allocated = size; | 68 pTrunk->m_Allocated = size; |
66 pTrunk->m_pNext = (_FX_GrowOnlyTrunk*)m_pFirstTrunk; | 69 pTrunk->m_pNext = (_FX_GrowOnlyTrunk*)m_pFirstTrunk; |
67 m_pFirstTrunk = pTrunk; | 70 m_pFirstTrunk = pTrunk; |
68 return pTrunk + 1; | 71 return pTrunk + 1; |
69 } | 72 } |
OLD | NEW |