v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
external-pointer-inl.h
Go to the documentation of this file.
1// Copyright 2020 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_EXTERNAL_POINTER_INL_H_
6#define V8_SANDBOX_EXTERNAL_POINTER_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "include/v8-internal.h"
16#include "src/sandbox/isolate.h"
17
18namespace v8 {
19namespace internal {
20
21template <ExternalPointerTag tag>
23 IsolateForSandbox isolate,
24 Address value) {
26 host_address, reinterpret_cast<Address>(storage_), isolate, value);
27}
28
29template <ExternalPointerTag tag>
31 const IsolateForSandbox isolate) const {
32 return ReadExternalPointerField<tag>(reinterpret_cast<Address>(storage_),
33 isolate);
34}
35
36template <ExternalPointerTag tag>
38 Address value) {
39 WriteExternalPointerField<tag>(reinterpret_cast<Address>(storage_), isolate,
40 value);
41}
42
43template <ExternalPointerTag tag>
47
48template <ExternalPointerTag tag>
50 memcpy(storage_, &value, sizeof(ExternalPointer_t));
51}
52
53template <ExternalPointerTag tag>
55 Address field_address,
56 IsolateForSandbox isolate,
57 Address value) {
58#ifdef V8_ENABLE_SANDBOX
59 static_assert(tag != kExternalPointerNullTag);
60 ExternalPointerTable& table = isolate.GetExternalPointerTableFor(tag);
61 ExternalPointerHandle handle = table.AllocateAndInitializeEntry(
62 isolate.GetExternalPointerTableSpaceFor(tag, host_address), value, tag);
63 // Use a Release_Store to ensure that the store of the pointer into the
64 // table is not reordered after the store of the handle. Otherwise, other
65 // threads may access an uninitialized table entry and crash.
66 auto location = reinterpret_cast<ExternalPointerHandle*>(field_address);
68#else
69 WriteExternalPointerField<tag>(field_address, isolate, value);
70#endif // V8_ENABLE_SANDBOX
71}
72
73template <ExternalPointerTagRange tag_range>
75 IsolateForSandbox isolate) {
76#ifdef V8_ENABLE_SANDBOX
77 // static_assert(tag != kExternalPointerNullTag); // TODO
78 // Handles may be written to objects from other threads so the handle needs
79 // to be loaded atomically. We assume that the load from the table cannot
80 // be reordered before the load of the handle due to the data dependency
81 // between the two loads and therefore use relaxed memory ordering, but
82 // technically we should use memory_order_consume here.
83 auto location = reinterpret_cast<ExternalPointerHandle*>(field_address);
85 return isolate.GetExternalPointerTableFor(tag_range).Get(handle, tag_range);
86#else
87 return ReadMaybeUnalignedValue<Address>(field_address);
88#endif // V8_ENABLE_SANDBOX
89}
90
91template <ExternalPointerTag tag>
93 IsolateForSandbox isolate,
94 Address value) {
95#ifdef V8_ENABLE_SANDBOX
96 static_assert(tag != kExternalPointerNullTag);
97 // See comment above for why this is a Relaxed_Load.
98 auto location = reinterpret_cast<ExternalPointerHandle*>(field_address);
100 isolate.GetExternalPointerTableFor(tag).Set(handle, value, tag);
101#else
102 WriteMaybeUnalignedValue<Address>(field_address, value);
103#endif // V8_ENABLE_SANDBOX
104}
105
109
110} // namespace internal
111} // namespace v8
112
113#endif // V8_SANDBOX_EXTERNAL_POINTER_INL_H_
static void Release_Store(T *addr, typename std::remove_reference< T >::type new_value)
static T Relaxed_Load(T *addr)
void store_encoded(ExternalPointer_t value)
void store(IsolateForSandbox isolate, Address value)
void Init(Address host_address, IsolateForSandbox isolate, Address value)
Address load(const IsolateForSandbox isolate) const
digit_t * storage_
Definition mul-fft.cc:475
V8_INLINE Dest bit_cast(Source const &source)
Definition macros.h:95
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
V8_INLINE void WriteExternalPointerField(Address field_address, IsolateForSandbox isolate, Address value)
static void WriteMaybeUnalignedValue(Address p, V value)
Definition ptr-compr.h:225
V8_INLINE Address ReadExternalPointerField(Address field_address, IsolateForSandbox isolate)
Address ExternalPointer_t
@ kExternalPointerNullTag
V8_INLINE void InitExternalPointerField(Address host_address, Address field_address, IsolateForSandbox isolate, Address value)
uint32_t ExternalPointerHandle
V8_INLINE void SetupLazilyInitializedExternalPointerField(Address field_address)
static V ReadMaybeUnalignedValue(Address p)
Definition ptr-compr.h:207
#define V8_INLINE
Definition v8config.h:500