v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
indirect-pointer-inl.h
Go to the documentation of this file.
1// Copyright 2023 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#ifndef V8_SANDBOX_INDIRECT_POINTER_INL_H_
6#define V8_SANDBOX_INDIRECT_POINTER_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "include/v8-internal.h"
16
17namespace v8 {
18namespace internal {
19
21 Address field_address, IsolateForSandbox isolate, Tagged<HeapObject> host,
23 TrustedPointerPublishingScope* opt_publishing_scope) {
24#ifdef V8_ENABLE_SANDBOX
26 // TODO(saelo): in the future, we might want to CHECK here or in
27 // AllocateAndInitializeEntry that the host lives in trusted space.
28
30 if (tag == kCodeIndirectPointerTag) {
31 CodePointerTable::Space* space =
32 isolate.GetCodePointerTableSpaceFor(field_address);
33 handle =
35 ->code_pointer_table()
36 ->AllocateAndInitializeEntry(space, host.address(), kNullAddress,
38 } else {
39 TrustedPointerTable::Space* space =
40 isolate.GetTrustedPointerTableSpaceFor(tag);
41 handle = isolate.GetTrustedPointerTableFor(tag).AllocateAndInitializeEntry(
42 space, host.ptr(), tag, opt_publishing_scope);
43 }
44
45 // Use a Release_Store to ensure that the store of the pointer into the table
46 // is not reordered after the store of the handle. Otherwise, other threads
47 // may access an uninitialized table entry and crash.
48 auto location = reinterpret_cast<IndirectPointerHandle*>(field_address);
50#else
52#endif
53}
54
55namespace {
56#ifdef V8_ENABLE_SANDBOX
57template <IndirectPointerTag tag>
58V8_INLINE Tagged<Object> ResolveTrustedPointerHandle(
59 IndirectPointerHandle handle, IsolateForSandbox isolate) {
60 const TrustedPointerTable& table = isolate.GetTrustedPointerTableFor(tag);
61 return Tagged<Object>(table.Get(handle, tag));
62}
63
64V8_INLINE Tagged<Object> ResolveCodePointerHandle(
66 CodePointerTable* table = IsolateGroup::current()->code_pointer_table();
67 return Tagged<Object>(table->GetCodeObject(handle));
68}
69#endif // V8_ENABLE_SANDBOX
70} // namespace
71
72template <IndirectPointerTag tag>
74 IsolateForSandbox isolate,
76#ifdef V8_ENABLE_SANDBOX
77 // Load the indirect pointer handle from the object.
78 // Technically, we could use memory_order_consume here as the loads are
79 // dependent, but that appears to be deprecated in favor of acquire ordering.
80 auto location = reinterpret_cast<IndirectPointerHandle*>(field_address);
82
83 // Resolve the handle. The tag implies the pointer table to use.
84 if constexpr (tag == kUnknownIndirectPointerTag) {
85 // In this case we need to check if the handle is a code pointer handle and
86 // select the appropriate table based on that.
88 return ResolveCodePointerHandle(handle);
89 } else {
90 // TODO(saelo): once we have type tagging for entries in the trusted
91 // pointer table, we could ASSUME that the top bits of the tag match the
92 // instance type, which might allow the compiler to optimize subsequent
93 // instance type checks.
94 return ResolveTrustedPointerHandle<tag>(handle, isolate);
95 }
96 } else if constexpr (tag == kCodeIndirectPointerTag) {
97 return ResolveCodePointerHandle(handle);
98 } else {
99 return ResolveTrustedPointerHandle<tag>(handle, isolate);
100 }
101#else
102 UNREACHABLE();
103#endif
104}
105
106template <IndirectPointerTag tag>
110#ifdef V8_ENABLE_SANDBOX
111 static_assert(tag != kIndirectPointerNullTag);
112 IndirectPointerHandle handle = value->self_indirect_pointer_handle();
114 auto location = reinterpret_cast<IndirectPointerHandle*>(field_address);
116#else
117 UNREACHABLE();
118#endif
119}
120
121} // namespace internal
122} // namespace v8
123
124#endif // V8_SANDBOX_INDIRECT_POINTER_INL_H_
static void Release_Store(T *addr, typename std::remove_reference< T >::type new_value)
static T Acquire_Load(T *addr)
static IsolateGroup * current()
V8_INLINE constexpr StorageType ptr() const
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
V8_INLINE void WriteIndirectPointerField(Address field_address, Tagged< ExposedTrustedObject > value, ReleaseStoreTag)
V8_INLINE Tagged< Object > ReadIndirectPointerField(Address field_address, IsolateForSandbox isolate, AcquireLoadTag)
uint32_t IndirectPointerHandle
V8_INLINE void InitSelfIndirectPointerField(Address field_address, IsolateForSandbox isolate, Tagged< HeapObject > host, IndirectPointerTag tag, TrustedPointerPublishingScope *opt_publishing_scope)
constexpr IndirectPointerHandle kNullIndirectPointerHandle
static constexpr Address kNullAddress
Definition v8-internal.h:53
constexpr uint32_t kCodePointerHandleMarker
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define V8_INLINE
Definition v8config.h:500