@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +7 -0
  2. package/include/node/cppgc/allocation.h +308 -0
  3. package/include/node/cppgc/common.h +28 -0
  4. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  5. package/include/node/cppgc/custom-space.h +97 -0
  6. package/include/node/cppgc/default-platform.h +68 -0
  7. package/include/node/cppgc/explicit-management.h +100 -0
  8. package/include/node/cppgc/garbage-collected.h +114 -0
  9. package/include/node/cppgc/heap-consistency.h +309 -0
  10. package/include/node/cppgc/heap-handle.h +48 -0
  11. package/include/node/cppgc/heap-state.h +82 -0
  12. package/include/node/cppgc/heap-statistics.h +126 -0
  13. package/include/node/cppgc/heap.h +202 -0
  14. package/include/node/cppgc/internal/api-constants.h +75 -0
  15. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  16. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  17. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  18. package/include/node/cppgc/internal/caged-heap.h +64 -0
  19. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  20. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  21. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  22. package/include/node/cppgc/internal/gc-info.h +150 -0
  23. package/include/node/cppgc/internal/logging.h +50 -0
  24. package/include/node/cppgc/internal/member-storage.h +305 -0
  25. package/include/node/cppgc/internal/name-trait.h +141 -0
  26. package/include/node/cppgc/internal/persistent-node.h +219 -0
  27. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  28. package/include/node/cppgc/internal/write-barrier.h +487 -0
  29. package/include/node/cppgc/liveness-broker.h +78 -0
  30. package/include/node/cppgc/macros.h +56 -0
  31. package/include/node/cppgc/member.h +669 -0
  32. package/include/node/cppgc/name-provider.h +75 -0
  33. package/include/node/cppgc/object-size-trait.h +58 -0
  34. package/include/node/cppgc/persistent.h +376 -0
  35. package/include/node/cppgc/platform.h +174 -0
  36. package/include/node/cppgc/prefinalizer.h +75 -0
  37. package/include/node/cppgc/process-heap-statistics.h +36 -0
  38. package/include/node/cppgc/sentinel-pointer.h +39 -0
  39. package/include/node/cppgc/source-location.h +16 -0
  40. package/include/node/cppgc/tagged-member.h +114 -0
  41. package/include/node/cppgc/testing.h +106 -0
  42. package/include/node/cppgc/trace-trait.h +127 -0
  43. package/include/node/cppgc/type-traits.h +272 -0
  44. package/include/node/cppgc/visitor.h +534 -0
  45. package/include/node/js_native_api.h +634 -0
  46. package/include/node/js_native_api_types.h +244 -0
  47. package/include/node/libplatform/libplatform-export.h +29 -0
  48. package/include/node/libplatform/libplatform.h +112 -0
  49. package/include/node/libplatform/v8-tracing.h +343 -0
  50. package/include/node/node.h +1744 -0
  51. package/include/node/node_api.h +265 -0
  52. package/include/node/node_api_types.h +58 -0
  53. package/include/node/node_buffer.h +94 -0
  54. package/include/node/node_object_wrap.h +145 -0
  55. package/include/node/node_version.h +116 -0
  56. package/include/node/uv/aix.h +32 -0
  57. package/include/node/uv/bsd.h +34 -0
  58. package/include/node/uv/darwin.h +61 -0
  59. package/include/node/uv/errno.h +483 -0
  60. package/include/node/uv/linux.h +34 -0
  61. package/include/node/uv/os390.h +33 -0
  62. package/include/node/uv/posix.h +31 -0
  63. package/include/node/uv/sunos.h +44 -0
  64. package/include/node/uv/threadpool.h +37 -0
  65. package/include/node/uv/tree.h +521 -0
  66. package/include/node/uv/unix.h +509 -0
  67. package/include/node/uv/version.h +43 -0
  68. package/include/node/uv/win.h +698 -0
  69. package/include/node/uv.h +1994 -0
  70. package/include/node/v8-array-buffer.h +646 -0
  71. package/include/node/v8-callbacks.h +533 -0
  72. package/include/node/v8-container.h +183 -0
  73. package/include/node/v8-context.h +580 -0
  74. package/include/node/v8-cpp-heap-external.h +56 -0
  75. package/include/node/v8-cppgc.h +194 -0
  76. package/include/node/v8-data.h +96 -0
  77. package/include/node/v8-date.h +57 -0
  78. package/include/node/v8-debug.h +210 -0
  79. package/include/node/v8-embedder-heap.h +54 -0
  80. package/include/node/v8-embedder-state-scope.h +52 -0
  81. package/include/node/v8-exception.h +298 -0
  82. package/include/node/v8-extension.h +60 -0
  83. package/include/node/v8-external-memory-accounter.h +60 -0
  84. package/include/node/v8-external.h +73 -0
  85. package/include/node/v8-fast-api-calls.h +784 -0
  86. package/include/node/v8-forward.h +82 -0
  87. package/include/node/v8-function-callback.h +708 -0
  88. package/include/node/v8-function.h +148 -0
  89. package/include/node/v8-handle-base.h +155 -0
  90. package/include/node/v8-initialization.h +343 -0
  91. package/include/node/v8-inspector-protocol.h +13 -0
  92. package/include/node/v8-inspector.h +458 -0
  93. package/include/node/v8-internal.h +1827 -0
  94. package/include/node/v8-isolate.h +1925 -0
  95. package/include/node/v8-json.h +54 -0
  96. package/include/node/v8-local-handle.h +884 -0
  97. package/include/node/v8-locker.h +138 -0
  98. package/include/node/v8-maybe.h +185 -0
  99. package/include/node/v8-memory-span.h +273 -0
  100. package/include/node/v8-message.h +215 -0
  101. package/include/node/v8-metrics.h +273 -0
  102. package/include/node/v8-microtask-queue.h +152 -0
  103. package/include/node/v8-microtask.h +28 -0
  104. package/include/node/v8-object.h +1134 -0
  105. package/include/node/v8-persistent-handle.h +556 -0
  106. package/include/node/v8-platform.h +1552 -0
  107. package/include/node/v8-primitive-object.h +118 -0
  108. package/include/node/v8-primitive.h +1056 -0
  109. package/include/node/v8-profiler.h +1401 -0
  110. package/include/node/v8-promise.h +185 -0
  111. package/include/node/v8-proxy.h +49 -0
  112. package/include/node/v8-regexp.h +105 -0
  113. package/include/node/v8-sandbox.h +170 -0
  114. package/include/node/v8-script.h +996 -0
  115. package/include/node/v8-snapshot.h +302 -0
  116. package/include/node/v8-source-location.h +91 -0
  117. package/include/node/v8-statistics.h +246 -0
  118. package/include/node/v8-template.h +1096 -0
  119. package/include/node/v8-trace-categories.h +28 -0
  120. package/include/node/v8-traced-handle.h +420 -0
  121. package/include/node/v8-typed-array.h +386 -0
  122. package/include/node/v8-unwinder-state.h +30 -0
  123. package/include/node/v8-unwinder.h +146 -0
  124. package/include/node/v8-util.h +549 -0
  125. package/include/node/v8-value-serializer-version.h +24 -0
  126. package/include/node/v8-value-serializer.h +316 -0
  127. package/include/node/v8-value.h +674 -0
  128. package/include/node/v8-version-string.h +38 -0
  129. package/include/node/v8-version.h +20 -0
  130. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  131. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  132. package/include/node/v8-wasm.h +325 -0
  133. package/include/node/v8-weak-callback-info.h +88 -0
  134. package/include/node/v8.h +88 -0
  135. package/include/node/v8config.h +1077 -0
  136. package/lib/libc++_shared.so +0 -0
  137. package/lib/libnode.so +4 -0
  138. package/package.json +23 -3
@@ -0,0 +1,185 @@
1
+ // Copyright 2021 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 INCLUDE_V8_PROMISE_H_
6
+ #define INCLUDE_V8_PROMISE_H_
7
+
8
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
+ #include "v8-object.h" // NOLINT(build/include_directory)
10
+ #include "v8config.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+
14
+ class Context;
15
+
16
+ #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
17
+ // Defined using gn arg `v8_promise_internal_field_count`.
18
+ #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
19
+ #endif
20
+
21
+ /**
22
+ * An instance of the built-in Promise constructor.
23
+ */
24
+ class V8_EXPORT Promise : public Object {
25
+ public:
26
+ /**
27
+ * State of the promise. Each value corresponds to one of the possible values
28
+ * of the [[PromiseState]] field.
29
+ */
30
+ enum PromiseState { kPending, kFulfilled, kRejected };
31
+
32
+ class V8_EXPORT Resolver : public Object {
33
+ public:
34
+ /**
35
+ * Create a new resolver, along with an associated promise in pending state.
36
+ */
37
+ static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
38
+ Local<Context> context);
39
+
40
+ /**
41
+ * Extract the associated promise.
42
+ */
43
+ Local<Promise> GetPromise();
44
+
45
+ /**
46
+ * Resolve/reject the associated promise with a given value.
47
+ * Ignored if the promise is no longer pending.
48
+ */
49
+ V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
50
+ Local<Value> value);
51
+
52
+ V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context,
53
+ Local<Value> value);
54
+
55
+ V8_INLINE static Resolver* Cast(Value* value) {
56
+ #ifdef V8_ENABLE_CHECKS
57
+ CheckCast(value);
58
+ #endif
59
+ return static_cast<Promise::Resolver*>(value);
60
+ }
61
+
62
+ private:
63
+ Resolver();
64
+ static void CheckCast(Value* obj);
65
+ };
66
+
67
+ /**
68
+ * Register a resolution/rejection handler with a promise. The handler is
69
+ * given the respective resolution/rejection value as an argument. If the
70
+ * promise is already resolved/rejected, the handler is invoked at the end of
71
+ * turn.
72
+ *
73
+ * This performs the PerformPromiseThen abstract operation with a fresh native
74
+ * promise as result, rather than the similar Promise.prototype.then
75
+ * operation. In particular, it does not do species lookup on the Promise
76
+ * constructor, and is therefore guaranteed to return a Promise.
77
+ *
78
+ * https://tc39.es/ecma262/#sec-performpromisethen
79
+ *
80
+ * This is consistent with Promise reactions in WebIDL:
81
+ *
82
+ * https://webidl.spec.whatwg.org/#dfn-perform-steps-once-promise-is-settled
83
+ */
84
+ V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
85
+ Local<Function> handler);
86
+
87
+ V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
88
+ Local<Function> handler);
89
+
90
+ V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
91
+ Local<Function> on_fulfilled,
92
+ Local<Function> on_rejected);
93
+
94
+ /**
95
+ * Returns true if the promise has at least one derived promise, and
96
+ * therefore resolve/reject handlers (including default handler).
97
+ */
98
+ bool HasHandler() const;
99
+
100
+ /**
101
+ * Returns the content of the [[PromiseResult]] field. The Promise must not
102
+ * be pending.
103
+ */
104
+ Local<Value> Result();
105
+
106
+ /**
107
+ * Returns the value of the [[PromiseState]] field.
108
+ */
109
+ PromiseState State();
110
+
111
+ /**
112
+ * Marks this promise as handled to avoid reporting unhandled rejections.
113
+ */
114
+ void MarkAsHandled();
115
+
116
+ /**
117
+ * Marks this promise as silent to prevent pausing the debugger when the
118
+ * promise is rejected.
119
+ */
120
+ void MarkAsSilent();
121
+
122
+ V8_INLINE static Promise* Cast(Value* value) {
123
+ #ifdef V8_ENABLE_CHECKS
124
+ CheckCast(value);
125
+ #endif
126
+ return static_cast<Promise*>(value);
127
+ }
128
+
129
+ static constexpr int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
130
+
131
+ private:
132
+ Promise();
133
+ static void CheckCast(Value* obj);
134
+ };
135
+
136
+ /**
137
+ * PromiseHook with type kInit is called when a new promise is
138
+ * created. When a new promise is created as part of the chain in the
139
+ * case of Promise.then or in the intermediate promises created by
140
+ * Promise.{race, all}/AsyncFunctionAwait, we pass the parent promise
141
+ * otherwise we pass undefined.
142
+ *
143
+ * PromiseHook with type kResolve is called at the beginning of
144
+ * resolve or reject function defined by CreateResolvingFunctions.
145
+ *
146
+ * PromiseHook with type kBefore is called at the beginning of the
147
+ * PromiseReactionJob.
148
+ *
149
+ * PromiseHook with type kAfter is called right at the end of the
150
+ * PromiseReactionJob.
151
+ */
152
+ enum class PromiseHookType { kInit, kResolve, kBefore, kAfter };
153
+
154
+ using PromiseHook = void (*)(PromiseHookType type, Local<Promise> promise,
155
+ Local<Value> parent);
156
+
157
+ // --- Promise Reject Callback ---
158
+ enum PromiseRejectEvent {
159
+ kPromiseRejectWithNoHandler = 0,
160
+ kPromiseHandlerAddedAfterReject = 1,
161
+ kDeprecatedPromiseRejectAfterResolved V8_DEPRECATED("Removed event") = 2,
162
+ kDeprecatedPromiseResolveAfterResolved V8_DEPRECATED("Removed event") = 3,
163
+ };
164
+
165
+ class PromiseRejectMessage {
166
+ public:
167
+ PromiseRejectMessage(Local<Promise> promise, PromiseRejectEvent event,
168
+ Local<Value> value)
169
+ : promise_(promise), event_(event), value_(value) {}
170
+
171
+ V8_INLINE Local<Promise> GetPromise() const { return promise_; }
172
+ V8_INLINE PromiseRejectEvent GetEvent() const { return event_; }
173
+ V8_INLINE Local<Value> GetValue() const { return value_; }
174
+
175
+ private:
176
+ Local<Promise> promise_;
177
+ PromiseRejectEvent event_;
178
+ Local<Value> value_;
179
+ };
180
+
181
+ using PromiseRejectCallback = void (*)(PromiseRejectMessage message);
182
+
183
+ } // namespace v8
184
+
185
+ #endif // INCLUDE_V8_PROMISE_H_
@@ -0,0 +1,49 @@
1
+ // Copyright 2021 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 INCLUDE_V8_PROXY_H_
6
+ #define INCLUDE_V8_PROXY_H_
7
+
8
+ #include "v8-context.h" // NOLINT(build/include_directory)
9
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
10
+ #include "v8-object.h" // NOLINT(build/include_directory)
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace v8 {
14
+
15
+ class Context;
16
+
17
+ /**
18
+ * An instance of the built-in Proxy constructor (ECMA-262, 6th Edition,
19
+ * 26.2.1).
20
+ */
21
+ class V8_EXPORT Proxy : public Object {
22
+ public:
23
+ Local<Value> GetTarget();
24
+ Local<Value> GetHandler();
25
+ bool IsRevoked() const;
26
+ void Revoke();
27
+
28
+ /**
29
+ * Creates a new Proxy for the target object.
30
+ */
31
+ static MaybeLocal<Proxy> New(Local<Context> context,
32
+ Local<Object> local_target,
33
+ Local<Object> local_handler);
34
+
35
+ V8_INLINE static Proxy* Cast(Value* value) {
36
+ #ifdef V8_ENABLE_CHECKS
37
+ CheckCast(value);
38
+ #endif
39
+ return static_cast<Proxy*>(value);
40
+ }
41
+
42
+ private:
43
+ Proxy();
44
+ static void CheckCast(Value* obj);
45
+ };
46
+
47
+ } // namespace v8
48
+
49
+ #endif // INCLUDE_V8_PROXY_H_
@@ -0,0 +1,105 @@
1
+ // Copyright 2021 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 INCLUDE_V8_REGEXP_H_
6
+ #define INCLUDE_V8_REGEXP_H_
7
+
8
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
+ #include "v8-object.h" // NOLINT(build/include_directory)
10
+ #include "v8config.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+
14
+ class Context;
15
+
16
+ /**
17
+ * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
18
+ */
19
+ class V8_EXPORT RegExp : public Object {
20
+ public:
21
+ /**
22
+ * Regular expression flag bits. They can be or'ed to enable a set
23
+ * of flags.
24
+ * The kLinear value ('l') is experimental and can only be used with
25
+ * --enable-experimental-regexp-engine. RegExps with kLinear flag are
26
+ * guaranteed to be executed in asymptotic linear time wrt. the length of
27
+ * the subject string.
28
+ */
29
+ enum Flags {
30
+ kNone = 0,
31
+ kGlobal = 1 << 0,
32
+ kIgnoreCase = 1 << 1,
33
+ kMultiline = 1 << 2,
34
+ kSticky = 1 << 3,
35
+ kUnicode = 1 << 4,
36
+ kDotAll = 1 << 5,
37
+ kLinear = 1 << 6,
38
+ kHasIndices = 1 << 7,
39
+ kUnicodeSets = 1 << 8,
40
+ };
41
+
42
+ static constexpr int kFlagCount = 9;
43
+
44
+ /**
45
+ * Creates a regular expression from the given pattern string and
46
+ * the flags bit field. May throw a JavaScript exception as
47
+ * described in ECMA-262, 15.10.4.1.
48
+ *
49
+ * For example,
50
+ * RegExp::New(v8::String::New("foo"),
51
+ * static_cast<RegExp::Flags>(kGlobal | kMultiline))
52
+ * is equivalent to evaluating "/foo/gm".
53
+ */
54
+ static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
55
+ Local<String> pattern,
56
+ Flags flags);
57
+
58
+ /**
59
+ * Like New, but additionally specifies a backtrack limit. If the number of
60
+ * backtracks done in one Exec call hits the limit, a match failure is
61
+ * immediately returned.
62
+ */
63
+ static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> NewWithBacktrackLimit(
64
+ Local<Context> context, Local<String> pattern, Flags flags,
65
+ uint32_t backtrack_limit);
66
+
67
+ /**
68
+ * Executes the current RegExp instance on the given subject string.
69
+ * Equivalent to RegExp.prototype.exec as described in
70
+ *
71
+ * https://tc39.es/ecma262/#sec-regexp.prototype.exec
72
+ *
73
+ * On success, an Array containing the matched strings is returned. On
74
+ * failure, returns Null.
75
+ *
76
+ * Note: modifies global context state, accessible e.g. through RegExp.input.
77
+ */
78
+ V8_WARN_UNUSED_RESULT MaybeLocal<Object> Exec(Local<Context> context,
79
+ Local<String> subject);
80
+
81
+ /**
82
+ * Returns the value of the source property: a string representing
83
+ * the regular expression.
84
+ */
85
+ Local<String> GetSource() const;
86
+
87
+ /**
88
+ * Returns the flags bit field.
89
+ */
90
+ Flags GetFlags() const;
91
+
92
+ V8_INLINE static RegExp* Cast(Value* value) {
93
+ #ifdef V8_ENABLE_CHECKS
94
+ CheckCast(value);
95
+ #endif
96
+ return static_cast<RegExp*>(value);
97
+ }
98
+
99
+ private:
100
+ static void CheckCast(Value* obj);
101
+ };
102
+
103
+ } // namespace v8
104
+
105
+ #endif // INCLUDE_V8_REGEXP_H_
@@ -0,0 +1,170 @@
1
+ // Copyright 2024 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 INCLUDE_V8_SANDBOX_H_
6
+ #define INCLUDE_V8_SANDBOX_H_
7
+
8
+ #include <cstdint>
9
+
10
+ #include "v8-internal.h" // NOLINT(build/include_directory)
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace v8 {
14
+
15
+ /**
16
+ * A pointer tag used for wrapping and unwrapping `CppHeap` pointers as used
17
+ * with JS API wrapper objects that rely on `v8::Object::Wrap()` and
18
+ * `v8::Object::Unwrap()`.
19
+ *
20
+ * The CppHeapPointers use a range-based type checking scheme, where on access
21
+ * to a pointer, the actual type of the pointer is checked to be within a
22
+ * specified range of types. This allows supporting type hierarchies, where a
23
+ * type check for a supertype must succeed for any subtype.
24
+ *
25
+ * The tag is currently in practice limited to 15 bits since it needs to fit
26
+ * together with a marking bit into the unused parts of a pointer.
27
+ */
28
+ enum class CppHeapPointerTag : uint16_t {
29
+ kFirstTag = 0,
30
+ kNullTag = 0,
31
+
32
+ /**
33
+ * The lower type ids are reserved for the embedder to assign. For that, the
34
+ * main requirement is that all (transitive) child classes of a given parent
35
+ * class have type ids in the same range, and that there are no unrelated
36
+ * types in that range. For example, given the following type hierarchy:
37
+ *
38
+ * A F
39
+ * / \
40
+ * B E
41
+ * / \
42
+ * C D
43
+ *
44
+ * a potential type id assignment that satistifes these requirements is
45
+ * {C: 0, D: 1, B: 2, A: 3, E: 4, F: 5}. With that, the type check for type A
46
+ * would check for the range [0, 4], while the check for B would check range
47
+ * [0, 2], and for F it would simply check [5, 5].
48
+ *
49
+ * In addition, there is an option for performance tweaks: if the size of the
50
+ * type range corresponding to a supertype is a power of two and starts at a
51
+ * power of two (e.g. [0x100, 0x13f]), then the compiler can often optimize
52
+ * the type check to use even fewer instructions (essentially replace a AND +
53
+ * SUB with a single AND).
54
+ */
55
+
56
+ kDefaultTag = 0x7000,
57
+
58
+ kZappedEntryTag = 0x7ffd,
59
+ kEvacuationEntryTag = 0x7ffe,
60
+ kFreeEntryTag = 0x7fff,
61
+ // The tags are limited to 15 bits, so the last tag is 0x7fff.
62
+ kLastTag = 0x7fff,
63
+ };
64
+
65
+ using CppHeapPointerTagRange = internal::TagRange<CppHeapPointerTag>;
66
+
67
+ constexpr CppHeapPointerTagRange kAnyCppHeapPointer(
68
+ CppHeapPointerTag::kFirstTag, CppHeapPointerTag::kLastTag);
69
+
70
+ /**
71
+ * Hardware support for the V8 Sandbox.
72
+ *
73
+ * This is an experimental feature that may change or be removed without
74
+ * further notice. Use at your own risk.
75
+ */
76
+ class SandboxHardwareSupport {
77
+ public:
78
+ /**
79
+ * Initialize sandbox hardware support. This needs to be called before
80
+ * creating any thread that might access sandbox memory since it sets up
81
+ * hardware permissions to the memory that will be inherited on clone.
82
+ */
83
+ V8_EXPORT static void InitializeBeforeThreadCreation();
84
+ };
85
+
86
+ namespace internal {
87
+
88
+ #ifdef V8_COMPRESS_POINTERS
89
+ V8_INLINE static Address* GetCppHeapPointerTableBase(v8::Isolate* isolate) {
90
+ Address addr = reinterpret_cast<Address>(isolate) +
91
+ Internals::kIsolateCppHeapPointerTableOffset +
92
+ Internals::kExternalEntityTableBasePointerOffset;
93
+ return *reinterpret_cast<Address**>(addr);
94
+ }
95
+ #endif // V8_COMPRESS_POINTERS
96
+
97
+ template <typename T>
98
+ V8_INLINE static T* ReadCppHeapPointerField(v8::Isolate* isolate,
99
+ Address heap_object_ptr, int offset,
100
+ CppHeapPointerTagRange tag_range) {
101
+ // This is a specialized version of the the CppHeapPointerTable accessors
102
+ // which (1) allows the code to be inlined into the callers for performance
103
+ // and (2) is optimized for code size as there are a huge number of callers
104
+ // from auto-generated bindings code.
105
+
106
+ #ifdef V8_COMPRESS_POINTERS
107
+ const CppHeapPointerHandle handle =
108
+ Internals::ReadRawField<CppHeapPointerHandle>(heap_object_ptr, offset);
109
+ const uint32_t index = handle >> kExternalPointerIndexShift;
110
+ const Address* table = GetCppHeapPointerTableBase(isolate);
111
+ const std::atomic<Address>* ptr =
112
+ reinterpret_cast<const std::atomic<Address>*>(&table[index]);
113
+ Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed);
114
+
115
+ // Note: the cast to uint32_t is important here. Otherwise, the uint16_t's
116
+ // would be promoted to int in the range check below, which would result in
117
+ // undefined behavior (signed integer underflow) if the actual value is less
118
+ // than the lower bound. Then, the compiler would take advantage of the
119
+ // undefined behavior and turn the range check into a simple
120
+ // `actual_tag <= last_tag` comparison, which is incorrect.
121
+ uint32_t actual_tag = static_cast<uint16_t>(entry);
122
+ // The actual_tag is shifted to the left by one and contains the marking
123
+ // bit in the LSB. To ignore that during the type check, simply add one to
124
+ // the (shifted) range.
125
+ constexpr int kTagShift = internal::kCppHeapPointerTagShift;
126
+ uint32_t first_tag = static_cast<uint32_t>(tag_range.first) << kTagShift;
127
+ uint32_t last_tag = (static_cast<uint32_t>(tag_range.last) << kTagShift) + 1;
128
+ if (V8_LIKELY(actual_tag >= first_tag && actual_tag <= last_tag)) {
129
+ entry = entry >> kCppHeapPointerPayloadShift;
130
+ } else {
131
+ // If the type check failed, we simply return nullptr here. That way:
132
+ // 1. The null handle always results in nullptr being returned here, which
133
+ // is a desired property. Otherwise, we would need an explicit check for
134
+ // the null handle above, and therefore an additional branch. This
135
+ // works because the 0th entry of the table always contains nullptr
136
+ // tagged with the null tag (i.e. an all-zeros entry). As such,
137
+ // regardless of whether the type check succeeds, the result will
138
+ // always be nullptr.
139
+ // 2. The returned pointer is guaranteed to crash even on platforms with
140
+ // top byte ignore (TBI), such as Arm64. The alternative would be to
141
+ // simply return the original entry with the left-shifted payload.
142
+ // However, due to TBI, an access to that may not always result in a
143
+ // crash (specifically, if the second most significant byte happens to
144
+ // be zero). In addition, there shouldn't be a difference on Arm64
145
+ // between returning nullptr or the original entry, since it will
146
+ // simply compile to a `csel x0, x8, xzr, lo` instead of a
147
+ // `csel x0, x10, x8, lo` instruction.
148
+ // 3. The machine code sequence ends up being pretty short, which is
149
+ // important here as this code will be inlined into a lot of functions.
150
+ entry = 0;
151
+ }
152
+ return reinterpret_cast<T*>(entry);
153
+ #else // !V8_COMPRESS_POINTERS
154
+ return reinterpret_cast<T*>(
155
+ Internals::ReadRawField<Address>(heap_object_ptr, offset));
156
+ #endif // !V8_COMPRESS_POINTERS
157
+ }
158
+
159
+ // TODO(saelo): temporary workaround needed to introduce range-based type
160
+ // checks for the external pointer table. See comment above
161
+ // ExternalPointerCanBeEmpty(ExternalPointerTagRange) function for details.
162
+ V8_INLINE static constexpr bool ExternalPointerCanBeEmpty(
163
+ CppHeapPointerTagRange tag_range) {
164
+ return true;
165
+ }
166
+
167
+ } // namespace internal
168
+ } // namespace v8
169
+
170
+ #endif // INCLUDE_V8_SANDBOX_H_