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

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 (137) hide show
  1. package/include/node/cppgc/allocation.h +308 -0
  2. package/include/node/cppgc/common.h +28 -0
  3. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  4. package/include/node/cppgc/custom-space.h +97 -0
  5. package/include/node/cppgc/default-platform.h +68 -0
  6. package/include/node/cppgc/explicit-management.h +100 -0
  7. package/include/node/cppgc/garbage-collected.h +114 -0
  8. package/include/node/cppgc/heap-consistency.h +309 -0
  9. package/include/node/cppgc/heap-handle.h +48 -0
  10. package/include/node/cppgc/heap-state.h +82 -0
  11. package/include/node/cppgc/heap-statistics.h +126 -0
  12. package/include/node/cppgc/heap.h +202 -0
  13. package/include/node/cppgc/internal/api-constants.h +75 -0
  14. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  15. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  16. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  17. package/include/node/cppgc/internal/caged-heap.h +64 -0
  18. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  19. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  20. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  21. package/include/node/cppgc/internal/gc-info.h +150 -0
  22. package/include/node/cppgc/internal/logging.h +50 -0
  23. package/include/node/cppgc/internal/member-storage.h +305 -0
  24. package/include/node/cppgc/internal/name-trait.h +141 -0
  25. package/include/node/cppgc/internal/persistent-node.h +219 -0
  26. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  27. package/include/node/cppgc/internal/write-barrier.h +487 -0
  28. package/include/node/cppgc/liveness-broker.h +78 -0
  29. package/include/node/cppgc/macros.h +56 -0
  30. package/include/node/cppgc/member.h +669 -0
  31. package/include/node/cppgc/name-provider.h +75 -0
  32. package/include/node/cppgc/object-size-trait.h +58 -0
  33. package/include/node/cppgc/persistent.h +376 -0
  34. package/include/node/cppgc/platform.h +174 -0
  35. package/include/node/cppgc/prefinalizer.h +75 -0
  36. package/include/node/cppgc/process-heap-statistics.h +36 -0
  37. package/include/node/cppgc/sentinel-pointer.h +39 -0
  38. package/include/node/cppgc/source-location.h +16 -0
  39. package/include/node/cppgc/tagged-member.h +114 -0
  40. package/include/node/cppgc/testing.h +106 -0
  41. package/include/node/cppgc/trace-trait.h +127 -0
  42. package/include/node/cppgc/type-traits.h +272 -0
  43. package/include/node/cppgc/visitor.h +534 -0
  44. package/include/node/js_native_api.h +634 -0
  45. package/include/node/js_native_api_types.h +244 -0
  46. package/include/node/libplatform/libplatform-export.h +29 -0
  47. package/include/node/libplatform/libplatform.h +112 -0
  48. package/include/node/libplatform/v8-tracing.h +343 -0
  49. package/include/node/node.h +1744 -0
  50. package/include/node/node_api.h +265 -0
  51. package/include/node/node_api_types.h +58 -0
  52. package/include/node/node_buffer.h +94 -0
  53. package/include/node/node_object_wrap.h +145 -0
  54. package/include/node/node_version.h +116 -0
  55. package/include/node/uv/aix.h +32 -0
  56. package/include/node/uv/bsd.h +34 -0
  57. package/include/node/uv/darwin.h +61 -0
  58. package/include/node/uv/errno.h +483 -0
  59. package/include/node/uv/linux.h +34 -0
  60. package/include/node/uv/os390.h +33 -0
  61. package/include/node/uv/posix.h +31 -0
  62. package/include/node/uv/sunos.h +44 -0
  63. package/include/node/uv/threadpool.h +37 -0
  64. package/include/node/uv/tree.h +521 -0
  65. package/include/node/uv/unix.h +509 -0
  66. package/include/node/uv/version.h +43 -0
  67. package/include/node/uv/win.h +698 -0
  68. package/include/node/uv.h +1994 -0
  69. package/include/node/v8-array-buffer.h +646 -0
  70. package/include/node/v8-callbacks.h +533 -0
  71. package/include/node/v8-container.h +183 -0
  72. package/include/node/v8-context.h +580 -0
  73. package/include/node/v8-cpp-heap-external.h +56 -0
  74. package/include/node/v8-cppgc.h +194 -0
  75. package/include/node/v8-data.h +96 -0
  76. package/include/node/v8-date.h +57 -0
  77. package/include/node/v8-debug.h +210 -0
  78. package/include/node/v8-embedder-heap.h +54 -0
  79. package/include/node/v8-embedder-state-scope.h +52 -0
  80. package/include/node/v8-exception.h +298 -0
  81. package/include/node/v8-extension.h +60 -0
  82. package/include/node/v8-external-memory-accounter.h +60 -0
  83. package/include/node/v8-external.h +73 -0
  84. package/include/node/v8-fast-api-calls.h +784 -0
  85. package/include/node/v8-forward.h +82 -0
  86. package/include/node/v8-function-callback.h +708 -0
  87. package/include/node/v8-function.h +148 -0
  88. package/include/node/v8-handle-base.h +155 -0
  89. package/include/node/v8-initialization.h +343 -0
  90. package/include/node/v8-inspector-protocol.h +13 -0
  91. package/include/node/v8-inspector.h +458 -0
  92. package/include/node/v8-internal.h +1827 -0
  93. package/include/node/v8-isolate.h +1925 -0
  94. package/include/node/v8-json.h +54 -0
  95. package/include/node/v8-local-handle.h +884 -0
  96. package/include/node/v8-locker.h +138 -0
  97. package/include/node/v8-maybe.h +185 -0
  98. package/include/node/v8-memory-span.h +273 -0
  99. package/include/node/v8-message.h +215 -0
  100. package/include/node/v8-metrics.h +273 -0
  101. package/include/node/v8-microtask-queue.h +152 -0
  102. package/include/node/v8-microtask.h +28 -0
  103. package/include/node/v8-object.h +1134 -0
  104. package/include/node/v8-persistent-handle.h +556 -0
  105. package/include/node/v8-platform.h +1552 -0
  106. package/include/node/v8-primitive-object.h +118 -0
  107. package/include/node/v8-primitive.h +1056 -0
  108. package/include/node/v8-profiler.h +1401 -0
  109. package/include/node/v8-promise.h +185 -0
  110. package/include/node/v8-proxy.h +49 -0
  111. package/include/node/v8-regexp.h +105 -0
  112. package/include/node/v8-sandbox.h +170 -0
  113. package/include/node/v8-script.h +996 -0
  114. package/include/node/v8-snapshot.h +302 -0
  115. package/include/node/v8-source-location.h +91 -0
  116. package/include/node/v8-statistics.h +246 -0
  117. package/include/node/v8-template.h +1096 -0
  118. package/include/node/v8-trace-categories.h +28 -0
  119. package/include/node/v8-traced-handle.h +420 -0
  120. package/include/node/v8-typed-array.h +386 -0
  121. package/include/node/v8-unwinder-state.h +30 -0
  122. package/include/node/v8-unwinder.h +146 -0
  123. package/include/node/v8-util.h +549 -0
  124. package/include/node/v8-value-serializer-version.h +24 -0
  125. package/include/node/v8-value-serializer.h +316 -0
  126. package/include/node/v8-value.h +674 -0
  127. package/include/node/v8-version-string.h +38 -0
  128. package/include/node/v8-version.h +20 -0
  129. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  130. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  131. package/include/node/v8-wasm.h +325 -0
  132. package/include/node/v8-weak-callback-info.h +88 -0
  133. package/include/node/v8.h +88 -0
  134. package/include/node/v8config.h +1077 -0
  135. package/lib/libc++_shared.so +0 -0
  136. package/lib/libnode.so +4 -0
  137. package/package.json +23 -3
@@ -0,0 +1,1552 @@
1
+ // Copyright 2013 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_V8_PLATFORM_H_
6
+ #define V8_V8_PLATFORM_H_
7
+
8
+ #include <math.h>
9
+ #include <stddef.h>
10
+ #include <stdint.h>
11
+ #include <stdlib.h> // For abort.
12
+
13
+ #include <memory>
14
+ #include <optional>
15
+ #include <string>
16
+
17
+ #include "v8-source-location.h" // NOLINT(build/include_directory)
18
+ #include "v8config.h" // NOLINT(build/include_directory)
19
+
20
+ namespace v8 {
21
+
22
+ class Isolate;
23
+
24
+ // Valid priorities supported by the task scheduling infrastructure.
25
+ enum class TaskPriority : uint8_t {
26
+ /**
27
+ * Best effort tasks are not critical for performance of the application. The
28
+ * platform implementation should preempt such tasks if higher priority tasks
29
+ * arrive.
30
+ */
31
+ kBestEffort,
32
+ /**
33
+ * User visible tasks are long running background tasks that will
34
+ * improve performance and memory usage of the application upon completion.
35
+ * Example: background compilation and garbage collection.
36
+ */
37
+ kUserVisible,
38
+ /**
39
+ * User blocking tasks are highest priority tasks that block the execution
40
+ * thread (e.g. major garbage collection). They must be finished as soon as
41
+ * possible.
42
+ */
43
+ kUserBlocking,
44
+ kMaxPriority = kUserBlocking
45
+ };
46
+
47
+ /**
48
+ * A Task represents a unit of work.
49
+ */
50
+ class Task {
51
+ public:
52
+ virtual ~Task() = default;
53
+
54
+ virtual void Run() = 0;
55
+ };
56
+
57
+ /**
58
+ * An IdleTask represents a unit of work to be performed in idle time.
59
+ * The Run method is invoked with an argument that specifies the deadline in
60
+ * seconds returned by MonotonicallyIncreasingTime().
61
+ * The idle task is expected to complete by this deadline.
62
+ */
63
+ class IdleTask {
64
+ public:
65
+ virtual ~IdleTask() = default;
66
+ virtual void Run(double deadline_in_seconds) = 0;
67
+ };
68
+
69
+ /**
70
+ * A TaskRunner allows scheduling of tasks. The TaskRunner may still be used to
71
+ * post tasks after the isolate gets destructed, but these tasks may not get
72
+ * executed anymore. All tasks posted to a given TaskRunner will be invoked in
73
+ * sequence. Tasks can be posted from any thread.
74
+ */
75
+ class TaskRunner {
76
+ public:
77
+ /**
78
+ * Schedules a task to be invoked by this TaskRunner. The TaskRunner
79
+ * implementation takes ownership of |task|.
80
+ *
81
+ * Embedders should override PostTaskImpl instead of this.
82
+ */
83
+ void PostTask(std::unique_ptr<Task> task,
84
+ SourceLocation location = SourceLocation::Current()) {
85
+ PostTaskImpl(std::move(task), location);
86
+ }
87
+
88
+ /**
89
+ * Schedules a task to be invoked by this TaskRunner. The TaskRunner
90
+ * implementation takes ownership of |task|. The |task| cannot be nested
91
+ * within other task executions.
92
+ *
93
+ * Tasks which shouldn't be interleaved with JS execution must be posted with
94
+ * |PostNonNestableTask| or |PostNonNestableDelayedTask|. This is because the
95
+ * embedder may process tasks in a callback which is called during JS
96
+ * execution.
97
+ *
98
+ * In particular, tasks which execute JS must be non-nestable, since JS
99
+ * execution is not allowed to nest.
100
+ *
101
+ * Requires that |TaskRunner::NonNestableTasksEnabled()| is true.
102
+ *
103
+ * Embedders should override PostNonNestableTaskImpl instead of this.
104
+ */
105
+ void PostNonNestableTask(
106
+ std::unique_ptr<Task> task,
107
+ SourceLocation location = SourceLocation::Current()) {
108
+ PostNonNestableTaskImpl(std::move(task), location);
109
+ }
110
+
111
+ /**
112
+ * Schedules a task to be invoked by this TaskRunner. The task is scheduled
113
+ * after the given number of seconds |delay_in_seconds|. The TaskRunner
114
+ * implementation takes ownership of |task|.
115
+ *
116
+ * Embedders should override PostDelayedTaskImpl instead of this.
117
+ */
118
+ void PostDelayedTask(std::unique_ptr<Task> task, double delay_in_seconds,
119
+ SourceLocation location = SourceLocation::Current()) {
120
+ PostDelayedTaskImpl(std::move(task), delay_in_seconds, location);
121
+ }
122
+
123
+ /**
124
+ * Schedules a task to be invoked by this TaskRunner. The task is scheduled
125
+ * after the given number of seconds |delay_in_seconds|. The TaskRunner
126
+ * implementation takes ownership of |task|. The |task| cannot be nested
127
+ * within other task executions.
128
+ *
129
+ * Tasks which shouldn't be interleaved with JS execution must be posted with
130
+ * |PostNonNestableTask| or |PostNonNestableDelayedTask|. This is because the
131
+ * embedder may process tasks in a callback which is called during JS
132
+ * execution.
133
+ *
134
+ * In particular, tasks which execute JS must be non-nestable, since JS
135
+ * execution is not allowed to nest.
136
+ *
137
+ * Requires that |TaskRunner::NonNestableDelayedTasksEnabled()| is true.
138
+ *
139
+ * Embedders should override PostNonNestableDelayedTaskImpl instead of this.
140
+ */
141
+ void PostNonNestableDelayedTask(
142
+ std::unique_ptr<Task> task, double delay_in_seconds,
143
+ SourceLocation location = SourceLocation::Current()) {
144
+ PostNonNestableDelayedTaskImpl(std::move(task), delay_in_seconds, location);
145
+ }
146
+
147
+ /**
148
+ * Schedules an idle task to be invoked by this TaskRunner. The task is
149
+ * scheduled when the embedder is idle. Requires that
150
+ * |TaskRunner::IdleTasksEnabled()| is true. Idle tasks may be reordered
151
+ * relative to other task types and may be starved for an arbitrarily long
152
+ * time if no idle time is available. The TaskRunner implementation takes
153
+ * ownership of |task|.
154
+ *
155
+ * Embedders should override PostIdleTaskImpl instead of this.
156
+ */
157
+ void PostIdleTask(std::unique_ptr<IdleTask> task,
158
+ SourceLocation location = SourceLocation::Current()) {
159
+ PostIdleTaskImpl(std::move(task), location);
160
+ }
161
+
162
+ /**
163
+ * Returns true if idle tasks are enabled for this TaskRunner.
164
+ */
165
+ virtual bool IdleTasksEnabled() = 0;
166
+
167
+ /**
168
+ * Returns true if non-nestable tasks are enabled for this TaskRunner.
169
+ */
170
+ virtual bool NonNestableTasksEnabled() const { return false; }
171
+
172
+ /**
173
+ * Returns true if non-nestable delayed tasks are enabled for this TaskRunner.
174
+ */
175
+ virtual bool NonNestableDelayedTasksEnabled() const { return false; }
176
+
177
+ TaskRunner() = default;
178
+ virtual ~TaskRunner() = default;
179
+
180
+ TaskRunner(const TaskRunner&) = delete;
181
+ TaskRunner& operator=(const TaskRunner&) = delete;
182
+
183
+ protected:
184
+ /**
185
+ * Implementation of above methods with an additional `location` argument.
186
+ */
187
+ virtual void PostTaskImpl(std::unique_ptr<Task> task,
188
+ const SourceLocation& location) {}
189
+ virtual void PostNonNestableTaskImpl(std::unique_ptr<Task> task,
190
+ const SourceLocation& location) {}
191
+ virtual void PostDelayedTaskImpl(std::unique_ptr<Task> task,
192
+ double delay_in_seconds,
193
+ const SourceLocation& location) {}
194
+ virtual void PostNonNestableDelayedTaskImpl(std::unique_ptr<Task> task,
195
+ double delay_in_seconds,
196
+ const SourceLocation& location) {}
197
+ virtual void PostIdleTaskImpl(std::unique_ptr<IdleTask> task,
198
+ const SourceLocation& location) {}
199
+ };
200
+
201
+ /**
202
+ * Delegate that's passed to Job's worker task, providing an entry point to
203
+ * communicate with the scheduler.
204
+ */
205
+ class JobDelegate {
206
+ public:
207
+ /**
208
+ * Returns true if this thread *must* return from the worker task on the
209
+ * current thread ASAP. Workers should periodically invoke ShouldYield (or
210
+ * YieldIfNeeded()) as often as is reasonable.
211
+ * After this method returned true, ShouldYield must not be called again.
212
+ */
213
+ virtual bool ShouldYield() = 0;
214
+
215
+ /**
216
+ * Notifies the scheduler that max concurrency was increased, and the number
217
+ * of worker should be adjusted accordingly. See Platform::PostJob() for more
218
+ * details.
219
+ */
220
+ virtual void NotifyConcurrencyIncrease() = 0;
221
+
222
+ /**
223
+ * Returns a task_id unique among threads currently running this job, such
224
+ * that GetTaskId() < worker count. To achieve this, the same task_id may be
225
+ * reused by a different thread after a worker_task returns.
226
+ */
227
+ virtual uint8_t GetTaskId() = 0;
228
+
229
+ /**
230
+ * Returns true if the current task is called from the thread currently
231
+ * running JobHandle::Join().
232
+ */
233
+ virtual bool IsJoiningThread() const = 0;
234
+ };
235
+
236
+ /**
237
+ * Handle returned when posting a Job. Provides methods to control execution of
238
+ * the posted Job.
239
+ */
240
+ class JobHandle {
241
+ public:
242
+ virtual ~JobHandle() = default;
243
+
244
+ /**
245
+ * Notifies the scheduler that max concurrency was increased, and the number
246
+ * of worker should be adjusted accordingly. See Platform::PostJob() for more
247
+ * details.
248
+ */
249
+ virtual void NotifyConcurrencyIncrease() = 0;
250
+
251
+ /**
252
+ * Contributes to the job on this thread. Doesn't return until all tasks have
253
+ * completed and max concurrency becomes 0. When Join() is called and max
254
+ * concurrency reaches 0, it should not increase again. This also promotes
255
+ * this Job's priority to be at least as high as the calling thread's
256
+ * priority.
257
+ */
258
+ virtual void Join() = 0;
259
+
260
+ /**
261
+ * Forces all existing workers to yield ASAP. Waits until they have all
262
+ * returned from the Job's callback before returning.
263
+ */
264
+ virtual void Cancel() = 0;
265
+
266
+ /*
267
+ * Forces all existing workers to yield ASAP but doesn’t wait for them.
268
+ * Warning, this is dangerous if the Job's callback is bound to or has access
269
+ * to state which may be deleted after this call.
270
+ */
271
+ virtual void CancelAndDetach() = 0;
272
+
273
+ /**
274
+ * Returns true if there's any work pending or any worker running.
275
+ */
276
+ virtual bool IsActive() = 0;
277
+
278
+ /**
279
+ * Returns true if associated with a Job and other methods may be called.
280
+ * Returns false after Join() or Cancel() was called. This may return true
281
+ * even if no workers are running and IsCompleted() returns true
282
+ */
283
+ virtual bool IsValid() = 0;
284
+
285
+ /**
286
+ * Returns true if job priority can be changed.
287
+ */
288
+ virtual bool UpdatePriorityEnabled() const { return false; }
289
+
290
+ /**
291
+ * Update this Job's priority.
292
+ */
293
+ virtual void UpdatePriority(TaskPriority new_priority) {}
294
+ };
295
+
296
+ /**
297
+ * A JobTask represents work to run in parallel from Platform::PostJob().
298
+ */
299
+ class JobTask {
300
+ public:
301
+ virtual ~JobTask() = default;
302
+
303
+ virtual void Run(JobDelegate* delegate) = 0;
304
+
305
+ /**
306
+ * Controls the maximum number of threads calling Run() concurrently, given
307
+ * the number of threads currently assigned to this job and executing Run().
308
+ * Run() is only invoked if the number of threads previously running Run() was
309
+ * less than the value returned. In general, this should return the latest
310
+ * number of incomplete work items (smallest unit of work) left to process,
311
+ * including items that are currently in progress. |worker_count| is the
312
+ * number of threads currently assigned to this job which some callers may
313
+ * need to determine their return value. Since GetMaxConcurrency() is a leaf
314
+ * function, it must not call back any JobHandle methods.
315
+ */
316
+ virtual size_t GetMaxConcurrency(size_t worker_count) const = 0;
317
+ };
318
+
319
+ // Allows a thread to temporarily boost another thread's priority to match its
320
+ // own priority. The priority is reset when the object is destroyed, which must
321
+ // happens on the boosted thread.
322
+ class ScopedBoostablePriority {
323
+ public:
324
+ ScopedBoostablePriority() = default;
325
+ virtual ~ScopedBoostablePriority() = default;
326
+ ScopedBoostablePriority(const ScopedBoostablePriority&) = delete;
327
+ ScopedBoostablePriority& operator=(const ScopedBoostablePriority& other) =
328
+ delete;
329
+
330
+ // Boosts the priority of the thread where this ScopedBoostablePriority was
331
+ // created. Can be called from any thread, but requires proper external
332
+ // synchronization with the constructor, destructor and any other call to
333
+ // BoostPriority/Reset(). If called multiple times, only the first call takes
334
+ // effect.
335
+ virtual bool BoostPriority() = 0;
336
+
337
+ // Resets the priority of the thread where this ScopedBoostablePriority was
338
+ // created to its original priority.
339
+ virtual void Reset() = 0;
340
+ };
341
+
342
+ /**
343
+ * A "blocking call" refers to any call that causes the calling thread to wait
344
+ * off-CPU. It includes but is not limited to calls that wait on synchronous
345
+ * file I/O operations: read or write a file from disk, interact with a pipe or
346
+ * a socket, rename or delete a file, enumerate files in a directory, etc.
347
+ * Acquiring a low contention lock is not considered a blocking call.
348
+ */
349
+
350
+ /**
351
+ * BlockingType indicates the likelihood that a blocking call will actually
352
+ * block.
353
+ */
354
+ enum class BlockingType {
355
+ // The call might block (e.g. file I/O that might hit in memory cache).
356
+ kMayBlock,
357
+ // The call will definitely block (e.g. cache already checked and now pinging
358
+ // server synchronously).
359
+ kWillBlock
360
+ };
361
+
362
+ /**
363
+ * This class is instantiated with CreateBlockingScope() in every scope where a
364
+ * blocking call is made and serves as a precise annotation of the scope that
365
+ * may/will block. May be implemented by an embedder to adjust the thread count.
366
+ * CPU usage should be minimal within that scope. ScopedBlockingCalls can be
367
+ * nested.
368
+ */
369
+ class ScopedBlockingCall {
370
+ public:
371
+ virtual ~ScopedBlockingCall() = default;
372
+ };
373
+
374
+ /**
375
+ * The interface represents complex arguments to trace events.
376
+ */
377
+ class ConvertableToTraceFormat {
378
+ public:
379
+ virtual ~ConvertableToTraceFormat() = default;
380
+
381
+ /**
382
+ * Append the class info to the provided |out| string. The appended
383
+ * data must be a valid JSON object. Strings must be properly quoted, and
384
+ * escaped. There is no processing applied to the content after it is
385
+ * appended.
386
+ */
387
+ virtual void AppendAsTraceFormat(std::string* out) const = 0;
388
+ };
389
+
390
+ /**
391
+ * V8 Tracing controller.
392
+ *
393
+ * Can be implemented by an embedder to record trace events from V8.
394
+ *
395
+ * Will become obsolete in Perfetto build (v8_use_perfetto = true).
396
+ */
397
+ class TracingController {
398
+ public:
399
+ virtual ~TracingController() = default;
400
+
401
+ // In Perfetto mode, trace events are written using Perfetto's Track Event
402
+ // API directly without going through the embedder. However, it is still
403
+ // possible to observe tracing being enabled and disabled.
404
+ #if !defined(V8_USE_PERFETTO)
405
+ /**
406
+ * Called by TRACE_EVENT* macros, don't call this directly.
407
+ * The name parameter is a category group for example:
408
+ * TRACE_EVENT0("v8,parse", "V8.Parse")
409
+ * The pointer returned points to a value with zero or more of the bits
410
+ * defined in CategoryGroupEnabledFlags.
411
+ **/
412
+ virtual const uint8_t* GetCategoryGroupEnabled(const char* name) {
413
+ static uint8_t no = 0;
414
+ return &no;
415
+ }
416
+
417
+ /**
418
+ * Adds a trace event to the platform tracing system. These function calls are
419
+ * usually the result of a TRACE_* macro from trace-event-no-perfetto.h when
420
+ * tracing and the category of the particular trace are enabled. It is not
421
+ * advisable to call these functions on their own; they are really only meant
422
+ * to be used by the trace macros. The returned handle can be used by
423
+ * UpdateTraceEventDuration to update the duration of COMPLETE events.
424
+ */
425
+ virtual uint64_t AddTraceEvent(
426
+ char phase, const uint8_t* category_enabled_flag, const char* name,
427
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
428
+ const char** arg_names, const uint8_t* arg_types,
429
+ const uint64_t* arg_values,
430
+ std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
431
+ unsigned int flags) {
432
+ return 0;
433
+ }
434
+ virtual uint64_t AddTraceEventWithTimestamp(
435
+ char phase, const uint8_t* category_enabled_flag, const char* name,
436
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
437
+ const char** arg_names, const uint8_t* arg_types,
438
+ const uint64_t* arg_values,
439
+ std::unique_ptr<ConvertableToTraceFormat>* arg_convertables,
440
+ unsigned int flags, int64_t timestamp) {
441
+ return 0;
442
+ }
443
+
444
+ /**
445
+ * Sets the duration field of a COMPLETE trace event. It must be called with
446
+ * the handle returned from AddTraceEvent().
447
+ **/
448
+ virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
449
+ const char* name, uint64_t handle) {}
450
+ #endif // !defined(V8_USE_PERFETTO)
451
+
452
+ class TraceStateObserver {
453
+ public:
454
+ virtual ~TraceStateObserver() = default;
455
+ virtual void OnTraceEnabled() = 0;
456
+ virtual void OnTraceDisabled() = 0;
457
+ };
458
+
459
+ /**
460
+ * Adds tracing state change observer.
461
+ * Does nothing in Perfetto SDK build (v8_use_perfetto = true).
462
+ */
463
+ virtual void AddTraceStateObserver(TraceStateObserver*) {}
464
+
465
+ /**
466
+ * Removes tracing state change observer.
467
+ * Does nothing in Perfetto SDK build (v8_use_perfetto = true).
468
+ */
469
+ virtual void RemoveTraceStateObserver(TraceStateObserver*) {}
470
+ };
471
+
472
+ // Opaque type representing a handle to a shared memory region.
473
+ class SharedMemoryHandle {
474
+ public:
475
+ // For the handle itself, we use the underlying type (e.g. unsigned int)
476
+ // instead of e.g. mach_port_t to avoid pulling in large OS header files into
477
+ // this header file. Instead, the users of these routines are expected to
478
+ // include the respective OS headers in addition to this one.
479
+
480
+ #if V8_OS_DARWIN
481
+ // A mach_port_t referencing a memory entry object.
482
+ using PlatformHandle = unsigned int;
483
+ #elif V8_OS_FUCHSIA
484
+ // A zx_handle_t to a VMO.
485
+ using PlatformHandle = uint32_t;
486
+ #elif V8_OS_WIN
487
+ // A Windows HANDLE to a file mapping object.
488
+ using PlatformHandle = void*;
489
+ #else
490
+ // A file descriptor.
491
+ using PlatformHandle = int;
492
+ #endif
493
+
494
+ static constexpr SharedMemoryHandle FromPlatformHandle(
495
+ PlatformHandle handle) {
496
+ return SharedMemoryHandle(handle);
497
+ }
498
+
499
+ PlatformHandle GetPlatformHandle() const { return handle_; }
500
+
501
+ private:
502
+ SharedMemoryHandle() = delete;
503
+ explicit constexpr SharedMemoryHandle(PlatformHandle handle)
504
+ : handle_(handle) {}
505
+
506
+ PlatformHandle handle_;
507
+ };
508
+
509
+ #define DEFINE_SHARED_MEMORY_HANDLE_WRAPPERS(Wrap, Unwrap) \
510
+ V8_DEPRECATE_SOON("Use SharedMemoryHandle::FromPlatformHandle instead") \
511
+ inline SharedMemoryHandle Wrap(SharedMemoryHandle::PlatformHandle handle) { \
512
+ return SharedMemoryHandle::FromPlatformHandle(handle); \
513
+ } \
514
+ V8_DEPRECATE_SOON("Use SharedMemoryHandle::GetPlatformHandle instead") \
515
+ inline SharedMemoryHandle::PlatformHandle Unwrap( \
516
+ SharedMemoryHandle handle) { \
517
+ return handle.GetPlatformHandle(); \
518
+ }
519
+
520
+ #if V8_OS_DARWIN
521
+ DEFINE_SHARED_MEMORY_HANDLE_WRAPPERS(SharedMemoryHandleFromMachMemoryEntry,
522
+ MachMemoryEntryFromSharedMemoryHandle)
523
+ #elif V8_OS_FUCHSIA
524
+ DEFINE_SHARED_MEMORY_HANDLE_WRAPPERS(SharedMemoryHandleFromVMO,
525
+ VMOFromSharedMemoryHandle)
526
+ #elif V8_OS_WIN
527
+ DEFINE_SHARED_MEMORY_HANDLE_WRAPPERS(SharedMemoryHandleFromFileMapping,
528
+ FileMappingFromSharedMemoryHandle)
529
+ #else
530
+ DEFINE_SHARED_MEMORY_HANDLE_WRAPPERS(SharedMemoryHandleFromFileDescriptor,
531
+ FileDescriptorFromSharedMemoryHandle)
532
+ #endif
533
+
534
+ #undef DEFINE_SHARED_MEMORY_HANDLE_WRAPPERS
535
+
536
+ // TODO(https://crbug.com/463925491): Remove this type alias once Chromium's
537
+ // "gin" V8 binding migrates off it.
538
+ using PlatformSharedMemoryHandle = std::optional<SharedMemoryHandle>;
539
+ V8_DEPRECATE_SOON("Use std::nullopt instead")
540
+ static constexpr PlatformSharedMemoryHandle kInvalidSharedMemoryHandle =
541
+ std::nullopt;
542
+
543
+ /**
544
+ * A V8 memory page allocator.
545
+ *
546
+ * Can be implemented by an embedder to manage large host OS allocations.
547
+ */
548
+ class PageAllocator {
549
+ public:
550
+ virtual ~PageAllocator() = default;
551
+
552
+ /**
553
+ * Gets the page granularity for AllocatePages and FreePages. Addresses and
554
+ * lengths for those calls should be multiples of AllocatePageSize().
555
+ */
556
+ virtual size_t AllocatePageSize() = 0;
557
+
558
+ /**
559
+ * Gets the page granularity for SetPermissions and ReleasePages. Addresses
560
+ * and lengths for those calls should be multiples of CommitPageSize().
561
+ */
562
+ virtual size_t CommitPageSize() = 0;
563
+
564
+ /**
565
+ * Sets the random seed so that GetRandomMmapAddr() will generate repeatable
566
+ * sequences of random mmap addresses.
567
+ */
568
+ virtual void SetRandomMmapSeed(int64_t seed) = 0;
569
+
570
+ /**
571
+ * Returns a randomized address, suitable for memory allocation under ASLR.
572
+ * The address will be aligned to AllocatePageSize.
573
+ */
574
+ virtual void* GetRandomMmapAddr() = 0;
575
+
576
+ /**
577
+ * Memory permissions.
578
+ */
579
+ enum Permission {
580
+ kNoAccess,
581
+ kRead,
582
+ kReadWrite,
583
+ kReadWriteExecute,
584
+ kReadExecute,
585
+ // Set this when reserving memory that will later require kReadWriteExecute
586
+ // permissions. The resulting behavior is platform-specific, currently
587
+ // this is used to set the MAP_JIT flag on Apple Silicon.
588
+ // TODO(jkummerow): Remove this when Wasm has a platform-independent
589
+ // w^x implementation.
590
+ // TODO(saelo): Remove this once all JIT pages are allocated through the
591
+ // VirtualAddressSpace API.
592
+ kNoAccessWillJitLater
593
+ };
594
+
595
+ /**
596
+ * Optional hints for AllocatePages().
597
+ */
598
+ class AllocationHint final {
599
+ public:
600
+ AllocationHint() = default;
601
+
602
+ V8_WARN_UNUSED_RESULT constexpr AllocationHint WithAddress(
603
+ void* address) const {
604
+ return AllocationHint(address, may_grow_);
605
+ }
606
+
607
+ V8_WARN_UNUSED_RESULT constexpr AllocationHint WithMayGrow() const {
608
+ return AllocationHint(address_, true);
609
+ }
610
+
611
+ bool MayGrow() const { return may_grow_; }
612
+ void* Address() const { return address_; }
613
+
614
+ private:
615
+ constexpr AllocationHint(void* address, bool may_grow)
616
+ : address_(address), may_grow_(may_grow) {}
617
+
618
+ void* address_ = nullptr;
619
+ bool may_grow_ = false;
620
+ };
621
+
622
+ /**
623
+ * Allocates memory in range with the given alignment and permission.
624
+ */
625
+ virtual void* AllocatePages(void* address, size_t length, size_t alignment,
626
+ Permission permissions) = 0;
627
+
628
+ /**
629
+ * Allocates memory in range with the given alignment and permission. In
630
+ * addition to AllocatePages it allows to pass in allocation hints. The
631
+ * underlying implementation may not make use of hints.
632
+ */
633
+ virtual void* AllocatePages(size_t length, size_t alignment,
634
+ Permission permissions, AllocationHint hint) {
635
+ return AllocatePages(hint.Address(), length, alignment, permissions);
636
+ }
637
+
638
+ /**
639
+ * Resizes the previously allocated memory at the given address. Returns true
640
+ * if the allocation could be resized. Returns false if this operation is
641
+ * either not supported or the object could not be resized in-place.
642
+ */
643
+ virtual bool ResizeAllocationAt(void* address, size_t old_length,
644
+ size_t new_length, Permission permissions) {
645
+ return false;
646
+ }
647
+
648
+ /**
649
+ * Frees memory in a range that was allocated by a call to AllocatePages.
650
+ */
651
+ virtual bool FreePages(void* address, size_t length) = 0;
652
+
653
+ /**
654
+ * Releases memory in a range that was allocated by a call to AllocatePages.
655
+ */
656
+ virtual bool ReleasePages(void* address, size_t length,
657
+ size_t new_length) = 0;
658
+
659
+ /**
660
+ * Sets permissions on pages in an allocated range.
661
+ */
662
+ virtual bool SetPermissions(void* address, size_t length,
663
+ Permission permissions) = 0;
664
+
665
+ /**
666
+ * Recommits discarded pages in the given range with given permissions.
667
+ * Discarded pages must be recommitted with their original permissions
668
+ * before they are used again.
669
+ */
670
+ virtual bool RecommitPages(void* address, size_t length,
671
+ Permission permissions) {
672
+ // TODO(v8:12797): make it pure once it's implemented on Chromium side.
673
+ return false;
674
+ }
675
+
676
+ /**
677
+ * Frees memory in the given [address, address + size) range. address and size
678
+ * should be operating system page-aligned. The next write to this
679
+ * memory area brings the memory transparently back. This should be treated as
680
+ * a hint to the OS that the pages are no longer needed. It does not guarantee
681
+ * that the pages will be discarded immediately or at all.
682
+ */
683
+ virtual bool DiscardSystemPages(void* address, size_t size) { return true; }
684
+
685
+ /**
686
+ * Decommits any wired memory pages in the given range, allowing the OS to
687
+ * reclaim them, and marks the region as inacessible (kNoAccess). The address
688
+ * range stays reserved and can be accessed again later by changing its
689
+ * permissions. However, in that case the memory content is guaranteed to be
690
+ * zero-initialized again. The memory must have been previously allocated by a
691
+ * call to AllocatePages. Returns true on success, false otherwise.
692
+ */
693
+ virtual bool DecommitPages(void* address, size_t size) = 0;
694
+
695
+ /**
696
+ * Block any modifications to the given mapping such as changing permissions
697
+ * or unmapping the pages on supported platforms.
698
+ * The address space reservation will exist until the process ends, but it's
699
+ * possible to release the memory using DiscardSystemPages. Note that this
700
+ * might require write permissions to the page as e.g. on Linux, mseal will
701
+ * block discarding sealed anonymous memory.
702
+ */
703
+ virtual bool SealPages(void* address, size_t length) {
704
+ // TODO(360048056): make it pure once it's implemented on Chromium side.
705
+ return false;
706
+ }
707
+
708
+ /**
709
+ * INTERNAL ONLY: This interface has not been stabilised and may change
710
+ * without notice from one release to another without being deprecated first.
711
+ */
712
+ class SharedMemoryMapping {
713
+ public:
714
+ // Implementations are expected to free the shared memory mapping in the
715
+ // destructor.
716
+ virtual ~SharedMemoryMapping() = default;
717
+ virtual void* GetMemory() const = 0;
718
+ };
719
+
720
+ /**
721
+ * INTERNAL ONLY: This interface has not been stabilised and may change
722
+ * without notice from one release to another without being deprecated first.
723
+ */
724
+ class SharedMemory {
725
+ public:
726
+ // Implementations are expected to free the shared memory in the destructor.
727
+ virtual ~SharedMemory() = default;
728
+ virtual std::unique_ptr<SharedMemoryMapping> RemapTo(
729
+ void* new_address) const = 0;
730
+ virtual void* GetMemory() const = 0;
731
+ virtual size_t GetSize() const = 0;
732
+ };
733
+
734
+ /**
735
+ * INTERNAL ONLY: This interface has not been stabilised and may change
736
+ * without notice from one release to another without being deprecated first.
737
+ *
738
+ * Reserve pages at a fixed address returning whether the reservation is
739
+ * possible. The reserved memory is detached from the PageAllocator and so
740
+ * should not be freed by it. It's intended for use with
741
+ * SharedMemory::RemapTo, where ~SharedMemoryMapping would free the memory.
742
+ */
743
+ virtual bool ReserveForSharedMemoryMapping(void* address, size_t size) {
744
+ return false;
745
+ }
746
+
747
+ /**
748
+ * INTERNAL ONLY: This interface has not been stabilised and may change
749
+ * without notice from one release to another without being deprecated first.
750
+ *
751
+ * Allocates shared memory pages. Not all PageAllocators need support this and
752
+ * so this method need not be overridden.
753
+ * Allocates a new read-only shared memory region of size |length| and copies
754
+ * the memory at |original_address| into it.
755
+ */
756
+ virtual std::unique_ptr<SharedMemory> AllocateSharedPages(
757
+ size_t length, const void* original_address) {
758
+ return {};
759
+ }
760
+
761
+ /**
762
+ * INTERNAL ONLY: This interface has not been stabilised and may change
763
+ * without notice from one release to another without being deprecated first.
764
+ *
765
+ * If not overridden and changed to return true, V8 will not attempt to call
766
+ * AllocateSharedPages or RemapSharedPages. If overridden, AllocateSharedPages
767
+ * and RemapSharedPages must also be overridden.
768
+ */
769
+ virtual bool CanAllocateSharedPages() { return false; }
770
+ };
771
+
772
+ /**
773
+ * An allocator that uses per-thread permissions to protect the memory.
774
+ *
775
+ * The implementation is platform/hardware specific, e.g. using pkeys on x64.
776
+ *
777
+ * INTERNAL ONLY: This interface has not been stabilised and may change
778
+ * without notice from one release to another without being deprecated first.
779
+ */
780
+ class ThreadIsolatedAllocator {
781
+ public:
782
+ virtual ~ThreadIsolatedAllocator() = default;
783
+
784
+ virtual void* Allocate(size_t size) = 0;
785
+
786
+ virtual void Free(void* object) = 0;
787
+
788
+ enum class Type {
789
+ kPkey,
790
+ };
791
+
792
+ virtual Type Type() const = 0;
793
+
794
+ /**
795
+ * Return the pkey used to implement the thread isolation if Type == kPkey.
796
+ */
797
+ virtual int Pkey() const { return -1; }
798
+ };
799
+
800
+ /**
801
+ * Possible permissions for memory pages.
802
+ */
803
+ enum class PagePermissions {
804
+ kNoAccess = 0,
805
+ kRead = 1,
806
+ kWrite = 2,
807
+ kExecute = 4,
808
+ kReadWrite = kRead | kWrite,
809
+ kReadExecute = kRead | kExecute,
810
+ kWriteExecute = kWrite | kExecute,
811
+ kReadWriteExecute = kRead | kWrite | kExecute,
812
+ };
813
+
814
+ inline constexpr PagePermissions operator|(PagePermissions lhs,
815
+ PagePermissions rhs) {
816
+ return static_cast<PagePermissions>(static_cast<int>(lhs) |
817
+ static_cast<int>(rhs));
818
+ }
819
+
820
+ inline constexpr PagePermissions operator&(PagePermissions lhs,
821
+ PagePermissions rhs) {
822
+ return static_cast<PagePermissions>(static_cast<int>(lhs) &
823
+ static_cast<int>(rhs));
824
+ }
825
+
826
+ inline PagePermissions& operator|=(PagePermissions& lhs, PagePermissions rhs) {
827
+ lhs = lhs | rhs;
828
+ return lhs;
829
+ }
830
+
831
+ /**
832
+ * Helper routine to determine whether one set of page permissions (the lhs) is
833
+ * a subset of another one (the rhs).
834
+ */
835
+ inline constexpr bool IsSubset(PagePermissions lhs, PagePermissions rhs) {
836
+ return (lhs & rhs) == lhs;
837
+ }
838
+
839
+ /**
840
+ * Class to manage a virtual memory address space.
841
+ *
842
+ * This class represents a contiguous region of virtual address space in which
843
+ * sub-spaces and (private or shared) memory pages can be allocated, freed, and
844
+ * modified. This interface is meant to eventually replace the PageAllocator
845
+ * interface, and can be used as an alternative in the meantime.
846
+ *
847
+ * This API is not yet stable and may change without notice!
848
+ */
849
+ class VirtualAddressSpace {
850
+ public:
851
+ using Address = uintptr_t;
852
+
853
+ VirtualAddressSpace(size_t page_size, size_t allocation_granularity,
854
+ Address base, size_t size,
855
+ PagePermissions max_page_permissions)
856
+ : page_size_(page_size),
857
+ allocation_granularity_(allocation_granularity),
858
+ base_(base),
859
+ size_(size),
860
+ max_page_permissions_(max_page_permissions) {}
861
+
862
+ virtual ~VirtualAddressSpace() = default;
863
+
864
+ /**
865
+ * The page size used inside this space. Guaranteed to be a power of two.
866
+ * Used as granularity for all page-related operations except for allocation,
867
+ * which use the allocation_granularity(), see below.
868
+ *
869
+ * \returns the page size in bytes.
870
+ */
871
+ size_t page_size() const { return page_size_; }
872
+
873
+ /**
874
+ * The granularity of page allocations and, by extension, of subspace
875
+ * allocations. This is guaranteed to be a power of two and a multiple of the
876
+ * page_size(). In practice, this is equal to the page size on most OSes, but
877
+ * on Windows it is usually 64KB, while the page size is 4KB.
878
+ *
879
+ * \returns the allocation granularity in bytes.
880
+ */
881
+ size_t allocation_granularity() const { return allocation_granularity_; }
882
+
883
+ /**
884
+ * The base address of the address space managed by this instance.
885
+ *
886
+ * \returns the base address of this address space.
887
+ */
888
+ Address base() const { return base_; }
889
+
890
+ /**
891
+ * The size of the address space managed by this instance.
892
+ *
893
+ * \returns the size of this address space in bytes.
894
+ */
895
+ size_t size() const { return size_; }
896
+
897
+ /**
898
+ * The maximum page permissions that pages allocated inside this space can
899
+ * obtain.
900
+ *
901
+ * \returns the maximum page permissions.
902
+ */
903
+ PagePermissions max_page_permissions() const { return max_page_permissions_; }
904
+
905
+ /**
906
+ * Whether the |address| is inside the address space managed by this instance.
907
+ *
908
+ * \returns true if it is inside the address space, false if not.
909
+ */
910
+ bool Contains(Address address) const {
911
+ return (address >= base()) && (address < base() + size());
912
+ }
913
+
914
+ /**
915
+ * Sets the random seed so that GetRandomPageAddress() will generate
916
+ * repeatable sequences of random addresses.
917
+ *
918
+ * \param The seed for the PRNG.
919
+ */
920
+ virtual void SetRandomSeed(int64_t seed) = 0;
921
+
922
+ /**
923
+ * Returns a random address inside this address space, suitable for page
924
+ * allocations hints.
925
+ *
926
+ * \returns a random address aligned to allocation_granularity().
927
+ */
928
+ virtual Address RandomPageAddress() = 0;
929
+
930
+ /**
931
+ * Allocates private memory pages with the given alignment and permissions.
932
+ *
933
+ * \param hint If nonzero, the allocation is attempted to be placed at the
934
+ * given address first. If that fails, the allocation is attempted to be
935
+ * placed elsewhere, possibly nearby, but that is not guaranteed. Specifying
936
+ * zero for the hint always causes this function to choose a random address.
937
+ * The hint, if specified, must be aligned to the specified alignment.
938
+ *
939
+ * \param size The size of the allocation in bytes. Must be a multiple of the
940
+ * allocation_granularity().
941
+ *
942
+ * \param alignment The alignment of the allocation in bytes. Must be a
943
+ * multiple of the allocation_granularity() and should be a power of two.
944
+ *
945
+ * \param permissions The page permissions of the newly allocated pages.
946
+ *
947
+ * \returns the start address of the allocated pages on success, zero on
948
+ * failure.
949
+ */
950
+ static constexpr Address kNoHint = 0;
951
+ virtual V8_WARN_UNUSED_RESULT Address
952
+ AllocatePages(Address hint, size_t size, size_t alignment,
953
+ PagePermissions permissions) = 0;
954
+
955
+ /**
956
+ * Frees previously allocated pages.
957
+ *
958
+ * This function will terminate the process on failure as this implies a bug
959
+ * in the client. As such, there is no return value.
960
+ *
961
+ * \param address The start address of the pages to free. This address must
962
+ * have been obtained through a call to AllocatePages.
963
+ *
964
+ * \param size The size in bytes of the region to free. This must match the
965
+ * size passed to AllocatePages when the pages were allocated.
966
+ */
967
+ virtual void FreePages(Address address, size_t size) = 0;
968
+
969
+ /**
970
+ * Sets permissions of all allocated pages in the given range.
971
+ *
972
+ * This operation can fail due to OOM, in which case false is returned. If
973
+ * the operation fails for a reason other than OOM, this function will
974
+ * terminate the process as this implies a bug in the client.
975
+ *
976
+ * \param address The start address of the range. Must be aligned to
977
+ * page_size().
978
+ *
979
+ * \param size The size in bytes of the range. Must be a multiple
980
+ * of page_size().
981
+ *
982
+ * \param permissions The new permissions for the range.
983
+ *
984
+ * \returns true on success, false on OOM.
985
+ */
986
+ virtual V8_WARN_UNUSED_RESULT bool SetPagePermissions(
987
+ Address address, size_t size, PagePermissions permissions) = 0;
988
+
989
+ /**
990
+ * Creates a guard region at the specified address.
991
+ *
992
+ * Guard regions are guaranteed to cause a fault when accessed and generally
993
+ * do not count towards any memory consumption limits. Further, allocating
994
+ * guard regions can usually not fail in subspaces if the region does not
995
+ * overlap with another region, subspace, or page allocation.
996
+ *
997
+ * \param address The start address of the guard region. Must be aligned to
998
+ * the allocation_granularity().
999
+ *
1000
+ * \param size The size of the guard region in bytes. Must be a multiple of
1001
+ * the allocation_granularity().
1002
+ *
1003
+ * \returns true on success, false otherwise.
1004
+ */
1005
+ virtual V8_WARN_UNUSED_RESULT bool AllocateGuardRegion(Address address,
1006
+ size_t size) = 0;
1007
+
1008
+ /**
1009
+ * Frees an existing guard region.
1010
+ *
1011
+ * This function will terminate the process on failure as this implies a bug
1012
+ * in the client. As such, there is no return value.
1013
+ *
1014
+ * \param address The start address of the guard region to free. This address
1015
+ * must have previously been used as address parameter in a successful
1016
+ * invocation of AllocateGuardRegion.
1017
+ *
1018
+ * \param size The size in bytes of the guard region to free. This must match
1019
+ * the size passed to AllocateGuardRegion when the region was created.
1020
+ */
1021
+ virtual void FreeGuardRegion(Address address, size_t size) = 0;
1022
+
1023
+ /**
1024
+ * Allocates shared memory pages with the given permissions.
1025
+ *
1026
+ * \param hint Placement hint. See AllocatePages.
1027
+ *
1028
+ * \param size The size of the allocation in bytes. Must be a multiple of the
1029
+ * allocation_granularity().
1030
+ *
1031
+ * \param permissions The page permissions of the newly allocated pages.
1032
+ *
1033
+ * \param handle A platform-specific handle to a shared memory object. See
1034
+ * the SharedMemoryHandleFromX routines above for ways to obtain these.
1035
+ *
1036
+ * \param offset The offset in the shared memory object at which the mapping
1037
+ * should start. Must be a multiple of the allocation_granularity().
1038
+ *
1039
+ * \returns the start address of the allocated pages on success, zero on
1040
+ * failure.
1041
+ */
1042
+ virtual V8_WARN_UNUSED_RESULT Address
1043
+ AllocateSharedPages(Address hint, size_t size, PagePermissions permissions,
1044
+ SharedMemoryHandle handle, uint64_t offset) = 0;
1045
+
1046
+ // TODO(https://crbug.com/463925491): Remove me once API users change from
1047
+ // PlatformSharedMemoryHandle to SharedMemoryHandle.
1048
+ V8_DEPRECATE_SOON("Use AllocateSharedPages() with SharedMemoryHandle")
1049
+ V8_WARN_UNUSED_RESULT Address AllocateSharedPages(
1050
+ Address hint, size_t size, PagePermissions permissions,
1051
+ std::optional<SharedMemoryHandle> handle, uint64_t offset) {
1052
+ return AllocateSharedPages(hint, size, permissions, *handle, offset);
1053
+ }
1054
+
1055
+ /**
1056
+ * Frees previously allocated shared pages.
1057
+ *
1058
+ * This function will terminate the process on failure as this implies a bug
1059
+ * in the client. As such, there is no return value.
1060
+ *
1061
+ * \param address The start address of the pages to free. This address must
1062
+ * have been obtained through a call to AllocateSharedPages.
1063
+ *
1064
+ * \param size The size in bytes of the region to free. This must match the
1065
+ * size passed to AllocateSharedPages when the pages were allocated.
1066
+ */
1067
+ virtual void FreeSharedPages(Address address, size_t size) = 0;
1068
+
1069
+ /**
1070
+ * Memory protection key support.
1071
+ *
1072
+ * If supported by the hardware and operating system, virtual address spaces
1073
+ * can use memory protection keys in addition to the regular page
1074
+ * permissions. The MemoryProtectionKeyId type identifies a memory protection
1075
+ * key and is used by the related APIs in this class.
1076
+ *
1077
+ * TODO(saelo): consider renaming to just MemoryProtectionKey, but currently
1078
+ * there's a naming conflict with base::MemoryProtectionKey.
1079
+ */
1080
+ using MemoryProtectionKeyId = int;
1081
+
1082
+ /**
1083
+ * The memory protection key used by this space, if any.
1084
+ *
1085
+ * If this space uses a memory protection key, then all memory pages in it
1086
+ * will have this key set. In that case, this API will return that key.
1087
+ *
1088
+ * \returns the memory protection key used by this space or std::nullopt.
1089
+ */
1090
+ virtual std::optional<MemoryProtectionKeyId> ActiveMemoryProtectionKey() = 0;
1091
+
1092
+ /**
1093
+ * Whether this instance can allocate subspaces or not.
1094
+ *
1095
+ * \returns true if subspaces can be allocated, false if not.
1096
+ */
1097
+ virtual bool CanAllocateSubspaces() = 0;
1098
+
1099
+ /*
1100
+ * Allocate a subspace.
1101
+ *
1102
+ * The address space of a subspace stays reserved in the parent space for the
1103
+ * lifetime of the subspace. As such, it is guaranteed that page allocations
1104
+ * on the parent space cannot end up inside a subspace.
1105
+ *
1106
+ * \param hint Hints where the subspace should be allocated. See
1107
+ * AllocatePages() for more details.
1108
+ *
1109
+ * \param size The size in bytes of the subspace. Must be a multiple of the
1110
+ * allocation_granularity().
1111
+ *
1112
+ * \param alignment The alignment of the subspace in bytes. Must be a multiple
1113
+ * of the allocation_granularity() and should be a power of two.
1114
+ *
1115
+ * \param max_page_permissions The maximum permissions that pages allocated in
1116
+ * the subspace can obtain.
1117
+ *
1118
+ * \param key Optional memory protection key for the subspace. If used, the
1119
+ * returned subspace will use this key for all its memory pages.
1120
+ *
1121
+ * \param handle Optional file descriptor for the subspace. If used, the
1122
+ * returned subspace will use this file descriptor with 0 offset as the
1123
+ * space's underlying file.
1124
+ *
1125
+ * \returns a new subspace or nullptr on failure.
1126
+ */
1127
+ virtual std::unique_ptr<VirtualAddressSpace> AllocateSubspace(
1128
+ Address hint, size_t size, size_t alignment,
1129
+ PagePermissions max_page_permissions,
1130
+ std::optional<MemoryProtectionKeyId> key = std::nullopt,
1131
+ std::optional<SharedMemoryHandle> handle = std::nullopt) = 0;
1132
+
1133
+ //
1134
+ // TODO(v8) maybe refactor the methods below before stabilizing the API. For
1135
+ // example by combining them into some form of page operation method that
1136
+ // takes a command enum as parameter.
1137
+ //
1138
+
1139
+ /**
1140
+ * Recommits discarded pages in the given range with given permissions.
1141
+ * Discarded pages must be recommitted with their original permissions
1142
+ * before they are used again.
1143
+ *
1144
+ * \param address The start address of the range. Must be aligned to
1145
+ * page_size().
1146
+ *
1147
+ * \param size The size in bytes of the range. Must be a multiple
1148
+ * of page_size().
1149
+ *
1150
+ * \param permissions The permissions for the range that the pages must have.
1151
+ *
1152
+ * \returns true on success, false otherwise.
1153
+ */
1154
+ virtual V8_WARN_UNUSED_RESULT bool RecommitPages(
1155
+ Address address, size_t size, PagePermissions permissions) = 0;
1156
+
1157
+ /**
1158
+ * Frees memory in the given [address, address + size) range. address and
1159
+ * size should be aligned to the page_size(). The next write to this memory
1160
+ * area brings the memory transparently back. This should be treated as a
1161
+ * hint to the OS that the pages are no longer needed. It does not guarantee
1162
+ * that the pages will be discarded immediately or at all.
1163
+ *
1164
+ * \returns true on success, false otherwise. Since this method is only a
1165
+ * hint, a successful invocation does not imply that pages have been removed.
1166
+ */
1167
+ virtual V8_WARN_UNUSED_RESULT bool DiscardSystemPages(Address address,
1168
+ size_t size) {
1169
+ return true;
1170
+ }
1171
+ /**
1172
+ * Decommits any wired memory pages in the given range, allowing the OS to
1173
+ * reclaim them, and marks the region as inacessible (kNoAccess). The address
1174
+ * range stays reserved and can be accessed again later by changing its
1175
+ * permissions. However, in that case the memory content is guaranteed to be
1176
+ * zero-initialized again. The memory must have been previously allocated by a
1177
+ * call to AllocatePages.
1178
+ *
1179
+ * \returns true on success, false otherwise.
1180
+ */
1181
+ virtual V8_WARN_UNUSED_RESULT bool DecommitPages(Address address,
1182
+ size_t size) = 0;
1183
+
1184
+ /**
1185
+ * Sets a name for the address space.
1186
+ *
1187
+ * This is mostly useful for debugging tools. If supported by the system, the
1188
+ * name will for example show up in /proc/$pid/maps next to the virtual
1189
+ * address reservation:
1190
+ *
1191
+ * 2ae700000000-2ae700010000 r--p 00000000 00:00 0 [anon:foo-bar]
1192
+ *
1193
+ * \param name The name of the address space. The name must only contain
1194
+ * alphanumeric characters or dashes.
1195
+ *
1196
+ * \returns true on success, false otherwise.
1197
+ */
1198
+ virtual bool SetName(const std::string& name) { return false; }
1199
+
1200
+ private:
1201
+ const size_t page_size_;
1202
+ const size_t allocation_granularity_;
1203
+ const Address base_;
1204
+ const size_t size_;
1205
+ const PagePermissions max_page_permissions_;
1206
+ };
1207
+
1208
+ /**
1209
+ * Observer used by V8 to notify the embedder about entering/leaving sections
1210
+ * with high throughput of malloc/free operations.
1211
+ */
1212
+ class HighAllocationThroughputObserver {
1213
+ public:
1214
+ virtual void EnterSection() {}
1215
+ virtual void LeaveSection() {}
1216
+ };
1217
+
1218
+ /**
1219
+ * V8 Platform abstraction layer.
1220
+ *
1221
+ * The embedder has to provide an implementation of this interface before
1222
+ * initializing the rest of V8.
1223
+ */
1224
+ class Platform {
1225
+ public:
1226
+ virtual ~Platform() = default;
1227
+
1228
+ /**
1229
+ * Allows the embedder to manage memory page allocations.
1230
+ * Returning nullptr will cause V8 to use the default page allocator.
1231
+ */
1232
+ virtual PageAllocator* GetPageAllocator() { return nullptr; }
1233
+
1234
+ /**
1235
+ * Allows the embedder to provide an allocator that uses per-thread memory
1236
+ * permissions to protect allocations.
1237
+ * Returning nullptr will cause V8 to disable protections that rely on this
1238
+ * feature.
1239
+ */
1240
+ virtual ThreadIsolatedAllocator* GetThreadIsolatedAllocator() {
1241
+ return nullptr;
1242
+ }
1243
+
1244
+ /**
1245
+ * Enables the embedder to respond in cases where V8 can't allocate large
1246
+ * blocks of memory. V8 retries the failed allocation once after calling this
1247
+ * method. On success, execution continues; otherwise V8 exits with a fatal
1248
+ * error.
1249
+ * Embedder overrides of this function must NOT call back into V8.
1250
+ */
1251
+ virtual void OnCriticalMemoryPressure() {}
1252
+
1253
+ /**
1254
+ * Gets the max number of worker threads that may be used to execute
1255
+ * concurrent work scheduled for any single TaskPriority by
1256
+ * Call(BlockingTask)OnWorkerThread() or PostJob(). This can be used to
1257
+ * estimate the number of tasks a work package should be split into. A return
1258
+ * value of 0 means that there are no worker threads available. Note that a
1259
+ * value of 0 won't prohibit V8 from posting tasks using |CallOnWorkerThread|.
1260
+ */
1261
+ virtual int NumberOfWorkerThreads() = 0;
1262
+
1263
+ /**
1264
+ * Returns a TaskRunner which can be used to post a task on the foreground.
1265
+ * The TaskRunner's NonNestableTasksEnabled() must be true. This function
1266
+ * should only be called from a foreground thread.
1267
+ */
1268
+ std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(Isolate* isolate) {
1269
+ return GetForegroundTaskRunner(isolate, TaskPriority::kUserBlocking);
1270
+ }
1271
+
1272
+ /**
1273
+ * Returns a TaskRunner with a specific |priority| which can be used to post a
1274
+ * task on the foreground thread. The TaskRunner's NonNestableTasksEnabled()
1275
+ * must be true. This function should only be called from a foreground thread.
1276
+ */
1277
+ virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
1278
+ Isolate* isolate, TaskPriority priority) = 0;
1279
+
1280
+ /**
1281
+ * Schedules a task to be invoked on a worker thread.
1282
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1283
+ * CallOnWorkerThread().
1284
+ */
1285
+ V8_DEPRECATE_SOON("Use PostTaskOnWorkerThread instead.")
1286
+ void CallOnWorkerThread(std::unique_ptr<Task> task,
1287
+ SourceLocation location = SourceLocation::Current()) {
1288
+ PostTaskOnWorkerThreadImpl(TaskPriority::kUserVisible, std::move(task),
1289
+ location);
1290
+ }
1291
+
1292
+ /**
1293
+ * Schedules a task that blocks the main thread to be invoked with
1294
+ * high-priority on a worker thread.
1295
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1296
+ * CallBlockingTaskOnWorkerThread().
1297
+ */
1298
+ V8_DEPRECATE_SOON("Use PostTaskOnWorkerThread instead.")
1299
+ void CallBlockingTaskOnWorkerThread(
1300
+ std::unique_ptr<Task> task,
1301
+ SourceLocation location = SourceLocation::Current()) {
1302
+ // Embedders may optionally override this to process these tasks in a high
1303
+ // priority pool.
1304
+ PostTaskOnWorkerThreadImpl(TaskPriority::kUserBlocking, std::move(task),
1305
+ location);
1306
+ }
1307
+
1308
+ /**
1309
+ * Schedules a task to be invoked with low-priority on a worker thread.
1310
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1311
+ * CallLowPriorityTaskOnWorkerThread().
1312
+ */
1313
+ V8_DEPRECATE_SOON("Use PostTaskOnWorkerThread instead.")
1314
+ void CallLowPriorityTaskOnWorkerThread(
1315
+ std::unique_ptr<Task> task,
1316
+ SourceLocation location = SourceLocation::Current()) {
1317
+ // Embedders may optionally override this to process these tasks in a low
1318
+ // priority pool.
1319
+ PostTaskOnWorkerThreadImpl(TaskPriority::kBestEffort, std::move(task),
1320
+ location);
1321
+ }
1322
+
1323
+ /**
1324
+ * Schedules a task to be invoked on a worker thread after |delay_in_seconds|
1325
+ * expires.
1326
+ * Embedders should override PostDelayedTaskOnWorkerThreadImpl() instead of
1327
+ * CallDelayedOnWorkerThread().
1328
+ */
1329
+ V8_DEPRECATE_SOON("Use PostDelayedTaskOnWorkerThread instead.")
1330
+ void CallDelayedOnWorkerThread(
1331
+ std::unique_ptr<Task> task, double delay_in_seconds,
1332
+ SourceLocation location = SourceLocation::Current()) {
1333
+ PostDelayedTaskOnWorkerThreadImpl(TaskPriority::kUserVisible,
1334
+ std::move(task), delay_in_seconds,
1335
+ location);
1336
+ }
1337
+
1338
+ /**
1339
+ * Schedules a task to be invoked on a worker thread.
1340
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1341
+ * PostTaskOnWorkerThread().
1342
+ */
1343
+ void PostTaskOnWorkerThread(
1344
+ TaskPriority priority, std::unique_ptr<Task> task,
1345
+ SourceLocation location = SourceLocation::Current()) {
1346
+ PostTaskOnWorkerThreadImpl(priority, std::move(task), location);
1347
+ }
1348
+
1349
+ /**
1350
+ * Schedules a task to be invoked on a worker thread after |delay_in_seconds|
1351
+ * expires.
1352
+ * Embedders should override PostDelayedTaskOnWorkerThreadImpl() instead of
1353
+ * PostDelayedTaskOnWorkerThread().
1354
+ */
1355
+ void PostDelayedTaskOnWorkerThread(
1356
+ TaskPriority priority, std::unique_ptr<Task> task,
1357
+ double delay_in_seconds,
1358
+ SourceLocation location = SourceLocation::Current()) {
1359
+ PostDelayedTaskOnWorkerThreadImpl(priority, std::move(task),
1360
+ delay_in_seconds, location);
1361
+ }
1362
+
1363
+ /**
1364
+ * Returns true if idle tasks are enabled for the given |isolate|.
1365
+ */
1366
+ virtual bool IdleTasksEnabled(Isolate* isolate) { return false; }
1367
+
1368
+ /**
1369
+ * Posts |job_task| to run in parallel. Returns a JobHandle associated with
1370
+ * the Job, which can be joined or canceled.
1371
+ * This avoids degenerate cases:
1372
+ * - Calling CallOnWorkerThread() for each work item, causing significant
1373
+ * overhead.
1374
+ * - Fixed number of CallOnWorkerThread() calls that split the work and might
1375
+ * run for a long time. This is problematic when many components post
1376
+ * "num cores" tasks and all expect to use all the cores. In these cases,
1377
+ * the scheduler lacks context to be fair to multiple same-priority requests
1378
+ * and/or ability to request lower priority work to yield when high priority
1379
+ * work comes in.
1380
+ * A canonical implementation of |job_task| looks like:
1381
+ * class MyJobTask : public JobTask {
1382
+ * public:
1383
+ * MyJobTask(...) : worker_queue_(...) {}
1384
+ * // JobTask:
1385
+ * void Run(JobDelegate* delegate) override {
1386
+ * while (!delegate->ShouldYield()) {
1387
+ * // Smallest unit of work.
1388
+ * auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
1389
+ * if (!work_item) return;
1390
+ * ProcessWork(work_item);
1391
+ * }
1392
+ * }
1393
+ *
1394
+ * size_t GetMaxConcurrency() const override {
1395
+ * return worker_queue_.GetSize(); // Thread safe.
1396
+ * }
1397
+ * };
1398
+ * auto handle = PostJob(TaskPriority::kUserVisible,
1399
+ * std::make_unique<MyJobTask>(...));
1400
+ * handle->Join();
1401
+ *
1402
+ * PostJob() and methods of the returned JobHandle/JobDelegate, must never be
1403
+ * called while holding a lock that could be acquired by JobTask::Run or
1404
+ * JobTask::GetMaxConcurrency -- that could result in a deadlock. This is
1405
+ * because [1] JobTask::GetMaxConcurrency may be invoked while holding
1406
+ * internal lock (A), hence JobTask::GetMaxConcurrency can only use a lock (B)
1407
+ * if that lock is *never* held while calling back into JobHandle from any
1408
+ * thread (A=>B/B=>A deadlock) and [2] JobTask::Run or
1409
+ * JobTask::GetMaxConcurrency may be invoked synchronously from JobHandle
1410
+ * (B=>JobHandle::foo=>B deadlock).
1411
+ * Embedders should override CreateJobImpl() instead of PostJob().
1412
+ */
1413
+ std::unique_ptr<JobHandle> PostJob(
1414
+ TaskPriority priority, std::unique_ptr<JobTask> job_task,
1415
+ SourceLocation location = SourceLocation::Current()) {
1416
+ auto handle = CreateJob(priority, std::move(job_task), location);
1417
+ handle->NotifyConcurrencyIncrease();
1418
+ return handle;
1419
+ }
1420
+
1421
+ /**
1422
+ * Creates and returns a JobHandle associated with a Job. Unlike PostJob(),
1423
+ * this doesn't immediately schedules |worker_task| to run; the Job is then
1424
+ * scheduled by calling either NotifyConcurrencyIncrease() or Join().
1425
+ *
1426
+ * A sufficient CreateJob() implementation that uses the default Job provided
1427
+ * in libplatform looks like:
1428
+ * std::unique_ptr<JobHandle> CreateJob(
1429
+ * TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
1430
+ * return v8::platform::NewDefaultJobHandle(
1431
+ * this, priority, std::move(job_task), NumberOfWorkerThreads());
1432
+ * }
1433
+ *
1434
+ * Embedders should override CreateJobImpl() instead of CreateJob().
1435
+ */
1436
+ std::unique_ptr<JobHandle> CreateJob(
1437
+ TaskPriority priority, std::unique_ptr<JobTask> job_task,
1438
+ SourceLocation location = SourceLocation::Current()) {
1439
+ return CreateJobImpl(priority, std::move(job_task), location);
1440
+ }
1441
+
1442
+ /**
1443
+ * Instantiates a ScopedBoostablePriority to boost a thread's priority.
1444
+ */
1445
+ virtual std::unique_ptr<ScopedBoostablePriority>
1446
+ CreateBoostablePriorityScope() {
1447
+ return nullptr;
1448
+ }
1449
+
1450
+ /**
1451
+ * Instantiates a ScopedBlockingCall to annotate a scope that may/will block.
1452
+ */
1453
+ virtual std::unique_ptr<ScopedBlockingCall> CreateBlockingScope(
1454
+ BlockingType blocking_type) {
1455
+ return nullptr;
1456
+ }
1457
+
1458
+ /**
1459
+ * Monotonically increasing time in seconds from an arbitrary fixed point in
1460
+ * the past. This function is expected to return at least
1461
+ * millisecond-precision values. For this reason,
1462
+ * it is recommended that the fixed point be no further in the past than
1463
+ * the epoch.
1464
+ **/
1465
+ virtual double MonotonicallyIncreasingTime() = 0;
1466
+
1467
+ /**
1468
+ * Current wall-clock time in milliseconds since epoch. Use
1469
+ * CurrentClockTimeMillisHighResolution() when higher precision is
1470
+ * required.
1471
+ */
1472
+ virtual int64_t CurrentClockTimeMilliseconds() {
1473
+ return static_cast<int64_t>(floor(CurrentClockTimeMillis()));
1474
+ }
1475
+
1476
+ /**
1477
+ * This function is deprecated and will be deleted. Use either
1478
+ * CurrentClockTimeMilliseconds() or
1479
+ * CurrentClockTimeMillisecondsHighResolution().
1480
+ */
1481
+ virtual double CurrentClockTimeMillis() = 0;
1482
+
1483
+ /**
1484
+ * Same as CurrentClockTimeMilliseconds(), but with more precision.
1485
+ */
1486
+ virtual double CurrentClockTimeMillisecondsHighResolution() {
1487
+ return CurrentClockTimeMillis();
1488
+ }
1489
+
1490
+ typedef void (*StackTracePrinter)();
1491
+
1492
+ /**
1493
+ * Returns a function pointer that print a stack trace of the current stack
1494
+ * on invocation. Disables printing of the stack trace if nullptr.
1495
+ */
1496
+ virtual StackTracePrinter GetStackTracePrinter() { return nullptr; }
1497
+
1498
+ /**
1499
+ * Returns an instance of a v8::TracingController. This must be non-nullptr.
1500
+ */
1501
+ virtual TracingController* GetTracingController() = 0;
1502
+
1503
+ /**
1504
+ * Tells the embedder to generate and upload a crashdump during an unexpected
1505
+ * but non-critical scenario.
1506
+ */
1507
+ virtual void DumpWithoutCrashing() {}
1508
+
1509
+ /**
1510
+ * Allows the embedder to observe sections with high throughput allocation
1511
+ * operations.
1512
+ */
1513
+ virtual HighAllocationThroughputObserver*
1514
+ GetHighAllocationThroughputObserver() {
1515
+ static HighAllocationThroughputObserver default_observer;
1516
+ return &default_observer;
1517
+ }
1518
+
1519
+ protected:
1520
+ /**
1521
+ * Default implementation of current wall-clock time in milliseconds
1522
+ * since epoch. Useful for implementing |CurrentClockTimeMillis| if
1523
+ * nothing special needed.
1524
+ */
1525
+ V8_EXPORT static double SystemClockTimeMillis();
1526
+
1527
+ /**
1528
+ * Creates and returns a JobHandle associated with a Job.
1529
+ */
1530
+ virtual std::unique_ptr<JobHandle> CreateJobImpl(
1531
+ TaskPriority priority, std::unique_ptr<JobTask> job_task,
1532
+ const SourceLocation& location) = 0;
1533
+
1534
+ /**
1535
+ * Schedules a task with |priority| to be invoked on a worker thread.
1536
+ */
1537
+ virtual void PostTaskOnWorkerThreadImpl(TaskPriority priority,
1538
+ std::unique_ptr<Task> task,
1539
+ const SourceLocation& location) = 0;
1540
+
1541
+ /**
1542
+ * Schedules a task with |priority| to be invoked on a worker thread after
1543
+ * |delay_in_seconds| expires.
1544
+ */
1545
+ virtual void PostDelayedTaskOnWorkerThreadImpl(
1546
+ TaskPriority priority, std::unique_ptr<Task> task,
1547
+ double delay_in_seconds, const SourceLocation& location) = 0;
1548
+ };
1549
+
1550
+ } // namespace v8
1551
+
1552
+ #endif // V8_V8_PLATFORM_H_