v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
handler-shared.cc
Go to the documentation of this file.
1
// Copyright 2017 the V8 project authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// PLEASE READ BEFORE CHANGING THIS FILE!
6
//
7
// This file contains code that is used both inside and outside the out of
8
// bounds trap handler. Because this code runs in a trap handler context,
9
// use extra care when modifying this file. Here are some rules to follow.
10
//
11
// 1. Do not introduce any new external dependencies. This file needs
12
// to be self contained so it is easy to audit everything that a
13
// trap handler might do.
14
//
15
// 2. Any changes must be reviewed by someone from the crash reporting
16
// or security team. See OWNERS for suggested reviewers.
17
//
18
// For more information, see https://goo.gl/yMeyUY.
19
20
#include "
src/trap-handler/trap-handler-internal.h
"
21
22
namespace
v8
{
23
namespace
internal
{
24
namespace
trap_handler {
25
26
// We declare this as int rather than bool as a workaround for a glibc bug, in
27
// which the dynamic loader cannot handle executables whose TLS area is only
28
// 1 byte in size; see https://sourceware.org/bugzilla/show_bug.cgi?id=14898.
29
thread_local
int
g_thread_in_wasm_code
;
30
31
static_assert
(
sizeof
(
g_thread_in_wasm_code
) > 1,
32
"sizeof(thread_local_var) must be > 1, see "
33
"https://sourceware.org/bugzilla/show_bug.cgi?id=14898"
);
34
35
size_t
gNumCodeObjects
= 0;
36
CodeProtectionInfoListEntry
*
gCodeObjects
=
nullptr
;
37
SandboxRecord
*
gSandboxRecordsHead
=
nullptr
;
38
std::atomic_size_t
gRecoveredTrapCount
= {0};
39
std::atomic<uintptr_t>
gLandingPad
= {0};
40
41
#if !defined(__cpp_lib_atomic_value_initialization) || \
42
__cpp_lib_atomic_value_initialization < 201911L
43
std::atomic_flag
MetadataLock::spinlock_
= ATOMIC_FLAG_INIT;
44
std::atomic_flag
SandboxRecordsLock::spinlock_
= ATOMIC_FLAG_INIT;
45
#else
46
std::atomic_flag
MetadataLock::spinlock_
;
47
std::atomic_flag
SandboxRecordsLock::spinlock_
;
48
#endif
49
50
MetadataLock::MetadataLock
() {
51
if
(
g_thread_in_wasm_code
) {
52
abort();
53
}
54
55
while
(
spinlock_
.test_and_set(std::memory_order_acquire)) {
56
}
57
}
58
59
MetadataLock::~MetadataLock
() {
60
if
(
g_thread_in_wasm_code
) {
61
abort();
62
}
63
64
spinlock_
.clear(std::memory_order_release);
65
}
66
67
SandboxRecordsLock::SandboxRecordsLock
() {
68
while
(
spinlock_
.test_and_set(std::memory_order_acquire)) {
69
}
70
}
71
72
SandboxRecordsLock::~SandboxRecordsLock
() {
73
spinlock_
.clear(std::memory_order_release);
74
}
75
76
}
// namespace trap_handler
77
}
// namespace internal
78
}
// namespace v8
v8::internal::trap_handler::MetadataLock::MetadataLock
MetadataLock()
Definition
handler-shared.cc:50
v8::internal::trap_handler::MetadataLock::spinlock_
static std::atomic_flag spinlock_
Definition
trap-handler-internal.h:32
v8::internal::trap_handler::MetadataLock::~MetadataLock
~MetadataLock()
Definition
handler-shared.cc:59
v8::internal::trap_handler::SandboxRecordsLock::~SandboxRecordsLock
~SandboxRecordsLock()
Definition
handler-shared.cc:72
v8::internal::trap_handler::SandboxRecordsLock::spinlock_
static std::atomic_flag spinlock_
Definition
trap-handler-internal.h:65
v8::internal::trap_handler::SandboxRecordsLock::SandboxRecordsLock
SandboxRecordsLock()
Definition
handler-shared.cc:67
v8::internal::trap_handler::gSandboxRecordsHead
SandboxRecord * gSandboxRecordsHead
Definition
handler-shared.cc:37
v8::internal::trap_handler::gCodeObjects
CodeProtectionInfoListEntry * gCodeObjects
Definition
handler-shared.cc:36
v8::internal::trap_handler::g_thread_in_wasm_code
thread_local int g_thread_in_wasm_code
Definition
handler-shared.cc:29
v8::internal::trap_handler::gLandingPad
std::atomic< uintptr_t > gLandingPad
Definition
handler-shared.cc:39
v8::internal::trap_handler::gRecoveredTrapCount
std::atomic_size_t gRecoveredTrapCount
Definition
handler-shared.cc:38
v8::internal::trap_handler::gNumCodeObjects
size_t gNumCodeObjects
Definition
handler-shared.cc:35
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8
Definition
api-arguments-inl.h:19
v8::internal::trap_handler::CodeProtectionInfoListEntry
Definition
trap-handler-internal.h:49
v8::internal::trap_handler::SandboxRecord
Definition
trap-handler-internal.h:58
trap-handler-internal.h
src
trap-handler
handler-shared.cc
Generated on Sun Apr 6 2025 21:08:57 for v8 by
1.12.0