forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-pointer-inl.h
More file actions
53 lines (45 loc) · 2.12 KB
/
code-pointer-inl.h
File metadata and controls
53 lines (45 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_SANDBOX_CODE_POINTER_INL_H_
#define V8_SANDBOX_CODE_POINTER_INL_H_
#include "src/sandbox/code-pointer.h"
// Include the non-inl header before the rest of the headers.
#include "include/v8-internal.h"
#include "src/base/atomic-utils.h"
#include "src/execution/isolate.h"
#include "src/sandbox/code-pointer-table-inl.h"
namespace v8 {
namespace internal {
V8_INLINE Address ReadCodeEntrypointViaCodePointerField(Address field_address,
CodeEntrypointTag tag) {
#ifdef V8_ENABLE_SANDBOX
// Handles may be written to objects from other threads so the handle needs
// to be loaded atomically. We assume that the load from the table cannot
// be reordered before the load of the handle due to the data dependency
// between the two loads and therefore use relaxed memory ordering, but
// technically we should use memory_order_consume here.
auto location = reinterpret_cast<CodePointerHandle*>(field_address);
CodePointerHandle handle = base::AsAtomic32::Relaxed_Load(location);
return IsolateGroup::current()->code_pointer_table()->GetEntrypoint(handle,
tag);
#else
UNREACHABLE();
#endif // V8_ENABLE_SANDBOX
}
V8_INLINE void WriteCodeEntrypointViaCodePointerField(Address field_address,
Address value,
CodeEntrypointTag tag) {
#ifdef V8_ENABLE_SANDBOX
// See comment above for why this is a Relaxed_Load.
auto location = reinterpret_cast<CodePointerHandle*>(field_address);
CodePointerHandle handle = base::AsAtomic32::Relaxed_Load(location);
IsolateGroup::current()->code_pointer_table()->SetEntrypoint(handle, value,
tag);
#else
UNREACHABLE();
#endif // V8_ENABLE_SANDBOX
}
} // namespace internal
} // namespace v8
#endif // V8_SANDBOX_CODE_POINTER_INL_H_