v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
foreign.h
Go to the documentation of this file.
1// Copyright 2018 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_OBJECTS_FOREIGN_H_
6#define V8_OBJECTS_FOREIGN_H_
7
10
11// Has to be the last include (doesn't have include guards):
13
14namespace v8::internal {
15
16#include "torque-generated/src/objects/foreign-tq.inc"
17
18// Foreign describes objects pointing from JavaScript to C structures.
19class Foreign : public TorqueGeneratedForeign<Foreign, HeapObject> {
20 public:
21 // [foreign_address]: field containing the address.
22 template <ExternalPointerTag tag>
23 inline Address foreign_address(IsolateForSandbox isolate) const;
24 // Deprecated. Prefer to use the variant above with an isolate parameter.
25 template <ExternalPointerTag tag>
26 inline Address foreign_address() const;
27 template <ExternalPointerTag tag>
28 inline void set_foreign_address(IsolateForSandbox isolate,
29 const Address value);
30 template <ExternalPointerTag tag>
31 inline void init_foreign_address(IsolateForSandbox isolate,
32 const Address initial_value);
33
34 // Load the address without performing a type check. Only use this when the
35 // returned pointer will not be dereferenced.
37
38 // Get the tag of this foreign from the external pointer table. Non-sandbox
39 // builds will always return {kAnyExternalPointerTag}.
40 inline ExternalPointerTag GetTag() const;
41
42 // Dispatched behavior.
44
45#ifdef V8_COMPRESS_POINTERS
46 // TODO(ishell, v8:8875): When pointer compression is enabled the
47 // kForeignAddressOffset is only kTaggedSize aligned but we can keep using
48 // unaligned access since both x64 and arm64 architectures (where pointer
49 // compression is supported) allow unaligned access to full words.
50 static_assert(IsAligned(kForeignAddressOffset, kTaggedSize));
51#else
52 static_assert(IsAligned(kForeignAddressOffset, kExternalPointerSlotSize));
53#endif
54
57 WithExternalPointer<kForeignAddressOffset,
59
60 private:
62};
63
64// TrustedForeign is similar to Foreign but lives in trusted space.
66 : public TorqueGeneratedTrustedForeign<TrustedForeign, TrustedObject> {
67 public:
68 // Dispatched behavior.
70
72
73 private:
75};
76
77} // namespace v8::internal
78
79#include "src/objects/object-macros-undef.h"
80
81#endif // V8_OBJECTS_FOREIGN_H_
Address foreign_address_unchecked() const
Definition foreign-inl.h:51
void init_foreign_address(IsolateForSandbox isolate, const Address initial_value)
Definition foreign-inl.h:46
ExternalPointerTag GetTag() const
Definition foreign-inl.h:57
Address foreign_address() const
Definition foreign-inl.h:34
void set_foreign_address(IsolateForSandbox isolate, const Address value)
Definition foreign-inl.h:40
constexpr int kTaggedSize
Definition globals.h:542
constexpr int kExternalPointerSlotSize
Definition globals.h:613
constexpr ExternalPointerTagRange kAnyForeignExternalPointerTagRange(kFirstForeignExternalPointerTag, kLastForeignExternalPointerTag)
#define DECL_PRINTER(Name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403