Changeset 294017 in webkit for trunk/Source/JavaScriptCore/tools/Integrity.h
- Timestamp:
- May 10, 2022, 2:55:45 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/tools/Integrity.h
r288815 r294017 1 1 /* 2 * Copyright (C) 2019-202 1Apple Inc. All rights reserved.2 * Copyright (C) 2019-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #include "JSCJSValue.h" 29 #include "StructureID.h" 30 #include <wtf/Gigacage.h> 28 #include <wtf/Assertions.h> 31 29 #include <wtf/Lock.h> 32 30 31 #if OS(DARWIN) 32 #include <mach/vm_param.h> 33 #endif 34 35 #if USE(JSVALUE32) 36 #define ENABLE_EXTRA_INTEGRITY_CHECKS 0 // Not supported. 37 #else 38 // Force ENABLE_EXTRA_INTEGRITY_CHECKS to 1 for your local build if you want 39 // more prolific audits to be enabled. 40 #define ENABLE_EXTRA_INTEGRITY_CHECKS 0 41 #endif 42 43 // From API/JSBase.h 44 typedef const struct OpaqueJSContextGroup* JSContextGroupRef; 45 typedef const struct OpaqueJSContext* JSContextRef; 46 typedef struct OpaqueJSContext* JSGlobalContextRef; 47 typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; 48 typedef const struct OpaqueJSValue* JSValueRef; 49 typedef struct OpaqueJSValue* JSObjectRef; 50 33 51 namespace JSC { 34 52 35 53 class JSCell; 54 class JSGlobalObject; 55 class JSObject; 56 class JSValue; 57 class Structure; 58 class StructureID; 36 59 class VM; 37 60 … … 68 91 }; 69 92 93 ALWAYS_INLINE static bool isSanePointer(const void* pointer) 94 { 95 #if CPU(ADDRESS64) 96 uintptr_t pointerAsInt = bitwise_cast<uintptr_t>(pointer); 97 uintptr_t canonicalPointerBits = pointerAsInt << (64 - OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH)); 98 uintptr_t nonCanonicalPointerBits = pointerAsInt >> OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH); 99 return !nonCanonicalPointerBits && canonicalPointerBits; 100 #else 101 UNUSED_PARAM(pointer); 102 return true; 103 #endif 104 } 105 106 #if USE(JSVALUE64) 107 108 class Analyzer { 109 public: 110 enum Action { LogOnly, LogAndCrash }; 111 112 static bool analyzeVM(VM&, Action); 113 static bool analyzeCell(VM&, JSCell*, Action); 114 static bool analyzeCell(JSCell*, Action); 115 }; 116 117 JS_EXPORT_PRIVATE JSContextRef doAudit(JSContextRef); 118 JS_EXPORT_PRIVATE JSGlobalContextRef doAudit(JSGlobalContextRef); 119 JS_EXPORT_PRIVATE JSObjectRef doAudit(JSObjectRef); 120 JS_EXPORT_PRIVATE JSValueRef doAudit(JSValueRef); 121 122 JS_EXPORT_PRIVATE JSValue doAudit(JSValue); 123 JS_EXPORT_PRIVATE JSCell* doAudit(JSCell*); 124 JS_EXPORT_PRIVATE JSCell* doAudit(VM&, JSCell*); 125 JS_EXPORT_PRIVATE JSObject* doAudit(JSObject*); 126 JS_EXPORT_PRIVATE JSGlobalObject* doAudit(JSGlobalObject*); 127 128 VM* doAudit(VM*); // see IntegrityInlines.h 129 130 // These are used for debugging queries, and will not crash. 131 JS_EXPORT_PRIVATE bool verifyCell(JSCell*); 132 JS_EXPORT_PRIVATE bool verifyCell(VM&, JSCell*); 133 134 #endif // USE(JSVALUE64) 135 70 136 ALWAYS_INLINE void auditCellRandomly(VM&, JSCell*); 71 137 ALWAYS_INLINE void auditCellMinimally(VM&, JSCell*); 72 138 JS_EXPORT_PRIVATE void auditCellMinimallySlow(VM&, JSCell*); 73 JS_EXPORT_PRIVATE void auditCellFully(VM&, JSCell*);139 ALWAYS_INLINE void auditCellFully(VM&, JSCell*); 74 140 75 141 template<AuditLevel = AuditLevel::Random, typename T> … … 79 145 ALWAYS_INLINE void auditCell(VM& vm, JSCell* cell) 80 146 { 81 switch (auditLevel) { 82 case AuditLevel::None: 147 static_assert(auditLevel == AuditLevel::None || auditLevel == AuditLevel::Minimal || auditLevel == AuditLevel::Full || auditLevel == AuditLevel::Random); 148 149 UNUSED_PARAM(vm); 150 UNUSED_PARAM(cell); 151 if constexpr (auditLevel == AuditLevel::None) 83 152 return; 84 case AuditLevel::Minimal:153 if constexpr (auditLevel == AuditLevel::Minimal) 85 154 return auditCellMinimally(vm, cell); 86 case AuditLevel::Full:155 if constexpr (auditLevel == AuditLevel::Full) 87 156 return auditCellFully(vm, cell); 88 case AuditLevel::Random:157 if constexpr (auditLevel == AuditLevel::Random) 89 158 return auditCellRandomly(vm, cell); 90 }91 159 } 92 160 93 161 template<AuditLevel auditLevel = DefaultAuditLevel> 94 ALWAYS_INLINE void auditCell(VM& vm, JSValue value) 95 { 96 if (auditLevel == AuditLevel::None) 97 return; 98 99 if (value.isCell()) 100 auditCell<auditLevel>(vm, value.asCell()); 101 } 162 ALWAYS_INLINE void auditCell(VM&, JSValue); 102 163 103 164 ALWAYS_INLINE void auditStructureID(StructureID); 104 165 166 #if ENABLE(EXTRA_INTEGRITY_CHECKS) && USE(JSVALUE64) 167 template<typename T> ALWAYS_INLINE T audit(T value) { return doAudit(value); } 168 #else 169 template<typename T> ALWAYS_INLINE T audit(T value) { return value; } 170 #endif 171 172 #if COMPILER(MSVC) || !VA_OPT_SUPPORTED 173 174 #define IA_LOG(assertion, format, ...) do { \ 175 WTFLogAlways("Integrity ERROR: %s @ %s:%d\n", #assertion, __FILE__, __LINE__); \ 176 WTFLogAlways(" " format, ##__VA_ARGS__); \ 177 } while (false) 178 179 #define IA_ASSERT_WITH_ACTION(assertion, action, ...) do { \ 180 if (UNLIKELY(!(assertion))) { \ 181 IA_LOG(assertion, __VA_ARGS__); \ 182 WTFReportBacktraceWithPrefix(" "); \ 183 action; \ 184 } \ 185 } while (false) 186 187 #define IA_ASSERT(assertion, ...) \ 188 IA_ASSERT_WITH_ACTION(assertion, { \ 189 RELEASE_ASSERT((assertion), ##__VA_ARGS__); \ 190 }, ## __VA_ARGS__) 191 192 #else // not (COMPILER(MSVC) || !VA_OPT_SUPPORTED) 193 194 #define IA_LOG(assertion, format, ...) do { \ 195 WTFLogAlways("Integrity ERROR: %s @ %s:%d\n", #assertion, __FILE__, __LINE__); \ 196 WTFLogAlways(" " format __VA_OPT__(,) __VA_ARGS__); \ 197 } while (false) 198 199 #define IA_ASSERT_WITH_ACTION(assertion, action, ...) do { \ 200 if (UNLIKELY(!(assertion))) { \ 201 IA_LOG(assertion, __VA_ARGS__); \ 202 WTFReportBacktraceWithPrefix(" "); \ 203 action; \ 204 } \ 205 } while (false) 206 207 #define IA_ASSERT(assertion, ...) \ 208 IA_ASSERT_WITH_ACTION(assertion, { \ 209 RELEASE_ASSERT((assertion) __VA_OPT__(,) __VA_ARGS__); \ 210 } __VA_OPT__(,) __VA_ARGS__) 211 212 #endif // COMPILER(MSVC) || !VA_OPT_SUPPORTED 213 105 214 } // namespace Integrity 106 215
Note:
See TracChangeset
for help on using the changeset viewer.