Loading...
Searching...
No Matches
v8-initialization.h
Go to the documentation of this file.
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_INITIALIZATION_H_
6#define INCLUDE_V8_INITIALIZATION_H_
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include "v8-callbacks.h" // NOLINT(build/include_directory)
12#include "v8-internal.h" // NOLINT(build/include_directory)
13#include "v8-isolate.h" // NOLINT(build/include_directory)
14#include "v8-platform.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17// We reserve the V8_* prefix for macros defined in V8 public API and
18// assume there are no name conflicts with the embedder's code.
19
23namespace v8 {
24
25class Allocator;
26class PageAllocator;
27class Platform;
28template <class K, class V, class T>
29class PersistentValueMapBase;
30
35using EntropySource = bool (*)(unsigned char* buffer, size_t length);
36
51 uintptr_t (*)(uintptr_t return_addr_location);
52
53using DcheckErrorCallback = void (*)(const char* file, int line,
54 const char* message);
55
56using V8FatalErrorCallback = void (*)(const char* file, int line,
57 const char* message);
58
63 public:
79 static void SetSnapshotDataBlob(StartupData* startup_blob);
80
83
89
93 static void SetFlagsFromString(const char* str);
94 static void SetFlagsFromString(const char* str, size_t length);
95
99 static void SetFlagsFromCommandLine(int* argc, char** argv,
100 bool remove_flags);
101
103 static const char* GetVersion();
104
109 V8_INLINE static bool Initialize() {
110#ifdef V8_TARGET_OS_ANDROID
111 const bool kV8TargetOsIsAndroid = true;
112#else
113 const bool kV8TargetOsIsAndroid = false;
114#endif
115
116#ifdef V8_ENABLE_CHECKS
117 const bool kV8EnableChecks = true;
118#else
119 const bool kV8EnableChecks = false;
120#endif
121
122 const int kBuildConfiguration =
123 (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
124 (internal::SmiValuesAre31Bits() ? k31BitSmis : 0) |
125 (internal::SandboxIsEnabled() ? kSandbox : 0) |
126 (kV8TargetOsIsAndroid ? kTargetOsIsAndroid : 0) |
127 (kV8EnableChecks ? kEnableChecks : 0);
128 return Initialize(kBuildConfiguration);
129 }
130
135 static void SetEntropySource(EntropySource source);
136
142 ReturnAddressLocationResolver return_address_resolver);
143
153 static bool Dispose();
154
162 static bool InitializeICU(const char* icu_data_file = nullptr);
163
176 static bool InitializeICUDefaultLocation(const char* exec_path,
177 const char* icu_data_file = nullptr);
178
194 static void InitializeExternalStartupData(const char* directory_path);
195 static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
196
201 static void InitializePlatform(Platform* platform);
202
207 static void DisposePlatform();
208
209#if defined(V8_ENABLE_SANDBOX)
218 enum class SandboxMode : uint8_t {
223 kSecure = 0,
227 kInsecure = 1,
232 kInsecurePartialReservationSmiInaccessible = 2,
236 kInsecureFullReservationSmiAccessible = 3,
241 kInsecurePartialReservationSmiAccessible = 4,
242
243 kMaxValue = kInsecurePartialReservationSmiAccessible,
244 };
245
249 static SandboxMode GetSandboxMode();
250
261 static bool IsSandboxConfiguredSecurely();
262
275 static VirtualAddressSpace* GetSandboxAddressSpace();
276
283 static size_t GetSandboxSizeInBytes();
284
295 static size_t GetSandboxReservationSizeInBytes();
296
308 static void SetInSandboxAllocator(std::shared_ptr<Allocator> allocator);
309#endif // V8_ENABLE_SANDBOX
310
311 enum class WasmMemoryType {
312 kMemory32,
313 kMemory64,
314 };
315
338 size_t byte_capacity);
339
346 static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
347
348#if defined(V8_OS_WIN)
358 static void SetUnhandledExceptionCallback(
359 UnhandledExceptionCallback callback);
360#endif
361
368
373
374 private:
375 V8();
376
377 enum BuildConfigurationFeatures {
378 kPointerCompression = 1 << 0,
379 k31BitSmis = 1 << 1,
380 kSandbox = 1 << 2,
381 kTargetOsIsAndroid = 1 << 3,
382 kEnableChecks = 1 << 4,
383 };
384
389 static bool Initialize(int build_config);
390
391 friend class Context;
392 template <class K, class V, class T>
394};
395
396} // namespace v8
397
398#endif // INCLUDE_V8_INITIALIZATION_H_
Definition: v8-context.h:48
Definition: v8-util.h:166
Definition: v8-platform.h:1269
Definition: v8-statistics.h:116
Definition: v8-snapshot.h:21
Definition: v8-initialization.h:62
static void InitializePlatform(Platform *platform)
static void SetFatalErrorHandler(V8FatalErrorCallback that)
static const char * GetVersion()
static bool InitializeICUDefaultLocation(const char *exec_path, const char *icu_data_file=nullptr)
static void SetSnapshotDataBlob(StartupData *startup_blob)
static size_t GetWasmMemoryReservationSizeInBytes(WasmMemoryType type, size_t byte_capacity)
static void InitializeExternalStartupDataFromFile(const char *snapshot_blob)
static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler)
static bool Initialize()
Definition: v8-initialization.h:109
static void SetEntropySource(EntropySource source)
static bool Dispose()
static void SetDcheckErrorHandler(DcheckErrorCallback that)
static void SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
static void DisposePlatform()
static bool InitializeICU(const char *icu_data_file=nullptr)
static void GetSharedMemoryStatistics(SharedMemoryStatistics *statistics)
static void SetReturnAddressLocationResolver(ReturnAddressLocationResolver return_address_resolver)
WasmMemoryType
Definition: v8-initialization.h:311
static void SetFlagsFromString(const char *str, size_t length)
static void SetFatalMemoryErrorCallback(OOMErrorCallback callback)
static void InitializeExternalStartupData(const char *directory_path)
static void SetFlagsFromString(const char *str)
Definition: v8-platform.h:894
v8::PageAllocator PageAllocator
Definition: platform.h:22
Definition: libplatform.h:15
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:234
void(*)(const char *file, int line, const char *message) V8FatalErrorCallback
Definition: v8-initialization.h:57
void(*)(const char *file, int line, const char *message) DcheckErrorCallback
Definition: v8-initialization.h:54
uintptr_t(*)(uintptr_t return_addr_location) ReturnAddressLocationResolver
Definition: v8-initialization.h:51
bool(*)(unsigned char *buffer, size_t length) EntropySource
Definition: v8-initialization.h:35
#define V8_EXPORT
Definition: v8config.h:867
#define V8_INLINE
Definition: v8config.h:511