1 | /* |
2 | * Copyright (C) 2017-2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include <wtf/FastMalloc.h> |
29 | #include <wtf/StdLibExtras.h> |
30 | |
31 | #if defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC |
32 | #define GIGACAGE_ENABLED 0 |
33 | |
34 | namespace Gigacage { |
35 | |
36 | const size_t primitiveGigacageMask = 0; |
37 | const size_t jsValueGigacageMask = 0; |
38 | |
39 | enum Kind { |
40 | Primitive, |
41 | JSValue, |
42 | NumberOfKinds |
43 | }; |
44 | |
45 | inline void ensureGigacage() { } |
46 | inline void disablePrimitiveGigacage() { } |
47 | inline bool shouldBeEnabled() { return false; } |
48 | |
49 | inline void addPrimitiveDisableCallback(void (*)(void*), void*) { } |
50 | inline void removePrimitiveDisableCallback(void (*)(void*), void*) { } |
51 | |
52 | inline void forbidDisablingPrimitiveGigacage() { } |
53 | |
54 | inline bool isDisablingPrimitiveGigacageForbidden() { return false; } |
55 | inline bool isPrimitiveGigacagePermanentlyEnabled() { return false; } |
56 | inline bool canPrimitiveGigacageBeDisabled() { return true; } |
57 | |
58 | ALWAYS_INLINE const char* name(Kind kind) |
59 | { |
60 | switch (kind) { |
61 | case Primitive: |
62 | return "Primitive" ; |
63 | case JSValue: |
64 | return "JSValue" ; |
65 | case NumberOfKinds: |
66 | break; |
67 | } |
68 | RELEASE_ASSERT_NOT_REACHED(); |
69 | return nullptr; |
70 | } |
71 | |
72 | ALWAYS_INLINE bool contains(const void*) { return false; } |
73 | ALWAYS_INLINE bool isEnabled(Kind) { return false; } |
74 | ALWAYS_INLINE size_t mask(Kind) { return 0; } |
75 | |
76 | template<typename T> |
77 | inline T* caged(Kind, T* ptr) { return ptr; } |
78 | template<typename T> |
79 | inline T* cagedMayBeNull(Kind, T* ptr) { return ptr; } |
80 | |
81 | inline bool isCaged(Kind, const void*) { return false; } |
82 | |
83 | inline void* tryAlignedMalloc(Kind, size_t alignment, size_t size) { return tryFastAlignedMalloc(alignment, size); } |
84 | inline void alignedFree(Kind, void* p) { fastAlignedFree(p); } |
85 | WTF_EXPORT_PRIVATE void* tryMalloc(Kind, size_t size); |
86 | WTF_EXPORT_PRIVATE void* tryRealloc(Kind, void*, size_t); |
87 | inline void free(Kind, void* p) { fastFree(p); } |
88 | |
89 | WTF_EXPORT_PRIVATE void* tryAllocateZeroedVirtualPages(Kind, size_t size); |
90 | WTF_EXPORT_PRIVATE void freeVirtualPages(Kind, void* basePtr, size_t size); |
91 | |
92 | } // namespace Gigacage |
93 | #else |
94 | #include <bmalloc/Gigacage.h> |
95 | |
96 | namespace Gigacage { |
97 | |
98 | WTF_EXPORT_PRIVATE void* tryAlignedMalloc(Kind, size_t alignment, size_t size); |
99 | WTF_EXPORT_PRIVATE void alignedFree(Kind, void*); |
100 | WTF_EXPORT_PRIVATE void* tryMalloc(Kind, size_t); |
101 | WTF_EXPORT_PRIVATE void* tryRealloc(Kind, void*, size_t); |
102 | WTF_EXPORT_PRIVATE void free(Kind, void*); |
103 | |
104 | WTF_EXPORT_PRIVATE void* tryAllocateZeroedVirtualPages(Kind, size_t size); |
105 | WTF_EXPORT_PRIVATE void freeVirtualPages(Kind, void* basePtr, size_t size); |
106 | |
107 | } // namespace Gigacage |
108 | #endif |
109 | |
110 | namespace Gigacage { |
111 | |
112 | WTF_EXPORT_PRIVATE void* tryMallocArray(Kind, size_t numElements, size_t elementSize); |
113 | |
114 | WTF_EXPORT_PRIVATE void* malloc(Kind, size_t); |
115 | WTF_EXPORT_PRIVATE void* mallocArray(Kind, size_t numElements, size_t elementSize); |
116 | |
117 | } // namespace Gigacage |
118 | |
119 | |
120 | |