34size_t gNextCodeObject = 0;
36#ifdef ENABLE_SLOW_DCHECKS
37constexpr bool kEnableSlowChecks =
true;
39constexpr bool kEnableSlowChecks =
false;
55bool IsDisjoint(
const CodeProtectionInfo* a,
const CodeProtectionInfo* b) {
56 if (a ==
nullptr || b ==
nullptr) {
59 return a->base >= b->base + b->size || b->base >= a->base + a->size;
65void VerifyCodeRangeIsDisjoint(
const CodeProtectionInfo* code_info) {
71void ValidateCodeObjects() {
76 if (data ==
nullptr)
continue;
79 for (
unsigned j = 0; j < data->num_protected_instructions; ++j) {
80 TH_DCHECK(data->instructions[j].instr_offset >= 0);
81 TH_DCHECK(data->instructions[j].instr_offset < data->size);
87 size_t free_count = 0;
97 size_t free_count2 = 0;
109 uintptr_t base,
size_t size,
size_t num_protected_instructions,
115 if (data ==
nullptr) {
121 data->num_protected_instructions = num_protected_instructions;
123 if (num_protected_instructions > 0) {
124 memcpy(data->instructions, protected_instructions,
132 uintptr_t base,
size_t size,
size_t num_protected_instructions,
135 base, size, num_protected_instructions, protected_instructions);
137 if (data ==
nullptr) {
143 if (kEnableSlowChecks) {
144 VerifyCodeRangeIsDisjoint(data);
147 size_t i = gNextCodeObject;
153 const size_t int_max = std::numeric_limits<int>::max();
163 if (new_size > int_max) {
196 if (kEnableSlowChecks) {
197 ValidateCodeObjects();
200 return static_cast<int>(
i);
222 gNextCodeObject =
index;
224 if (kEnableSlowChecks) {
225 ValidateCodeObjects();
239 current = current->
next) {
246 if (new_record ==
nullptr) {
262 while (current !=
nullptr) {
263 if (current->base ==
base) {
267 current = current->next;
286#if !V8_TRAP_HANDLER_SUPPORTED
310 if (use_v8_handler) {
320#if defined(BUILDING_V8_SHARED_PRIVATE) || defined(USING_V8_SHARED_PRIVATE)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
constexpr size_t HandlerDataSize(size_t num_protected_instructions)
constexpr size_t kInitialCodeObjectSize
std::atomic< bool > g_can_enable_trap_handler
SandboxRecord * gSandboxRecordsHead
int * GetThreadInWasmThreadLocalAddress()
bool RegisterDefaultTrapHandler()
CodeProtectionInfoListEntry * gCodeObjects
void AssertThreadNotInWasm()
bool g_is_trap_handler_enabled
void ReleaseHandlerData(int index)
thread_local int g_thread_in_wasm_code
void SetLandingPad(uintptr_t landing_pad)
size_t GetRecoveredTrapCount()
int RegisterHandlerData(uintptr_t base, size_t size, size_t num_protected_instructions, const ProtectedInstructionData *protected_instructions)
CodeProtectionInfo * CreateHandlerData(uintptr_t base, size_t size, size_t num_protected_instructions, const ProtectedInstructionData *protected_instructions)
constexpr size_t kCodeObjectGrowthFactor
std::atomic< uintptr_t > gLandingPad
bool EnableTrapHandler(bool use_v8_handler)
void UnregisterV8Sandbox(uintptr_t base, size_t size)
std::atomic_size_t gRecoveredTrapCount
bool RegisterV8Sandbox(uintptr_t base, size_t size)
CodeProtectionInfo * code_info
#define V8_TRAP_HANDLER_SUPPORTED
#define TH_DCHECK(condition)
#define TH_CHECK(condition)