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
105
109 static void SetFlagsFromString(const char* str);
110 static void SetFlagsFromString(const char* str, size_t length);
111
115 static void SetFlagsFromCommandLine(int* argc, char** argv,
116 bool remove_flags);
117
119 static const char* GetVersion();
120
125 V8_INLINE static bool Initialize() {
126#ifdef V8_TARGET_OS_ANDROID
127 const bool kV8TargetOsIsAndroid = true;
128#else
129 const bool kV8TargetOsIsAndroid = false;
130#endif
131
132#ifdef V8_ENABLE_CHECKS
133 const bool kV8EnableChecks = true;
134#else
135 const bool kV8EnableChecks = false;
136#endif
137
138 const int kBuildConfiguration =
139 (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
140 (internal::SmiValuesAre31Bits() ? k31BitSmis : 0) |
141 (internal::SandboxIsEnabled() ? kSandbox : 0) |
142 (kV8TargetOsIsAndroid ? kTargetOsIsAndroid : 0) |
143 (kV8EnableChecks ? kEnableChecks : 0);
144 return Initialize(kBuildConfiguration);
145 }
146
151 static void SetEntropySource(EntropySource source);
152
158 ReturnAddressLocationResolver return_address_resolver);
159
169 static bool Dispose();
170
178 static bool InitializeICU(const char* icu_data_file = nullptr);
179
192 static bool InitializeICUDefaultLocation(const char* exec_path,
193 const char* icu_data_file = nullptr);
194
210 static void InitializeExternalStartupData(const char* directory_path);
211 static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
212
217 static void InitializePlatform(Platform* platform);
218
223 static void DisposePlatform();
224
225#if defined(V8_ENABLE_SANDBOX)
234 enum class SandboxMode : uint8_t {
239 kSecure = 0,
243 kInsecure = 1,
248 kInsecurePartialReservationSmiInaccessible = 2,
252 kInsecureFullReservationSmiAccessible = 3,
257 kInsecurePartialReservationSmiAccessible = 4,
258
259 kMaxValue = kInsecurePartialReservationSmiAccessible,
260 };
261
265 static SandboxMode GetSandboxMode();
266
277 static bool IsSandboxConfiguredSecurely();
278
291 static VirtualAddressSpace* GetSandboxAddressSpace();
292
299 static size_t GetSandboxSizeInBytes();
300
311 static size_t GetSandboxReservationSizeInBytes();
312
324 static void SetInSandboxAllocator(std::shared_ptr<Allocator> allocator);
325#endif // V8_ENABLE_SANDBOX
326
327 enum class WasmMemoryType {
328 kMemory32,
329 kMemory64,
330 };
331
354 size_t byte_capacity);
355
362 static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
363
364#if defined(V8_OS_WIN)
374 static void SetUnhandledExceptionCallback(
375 UnhandledExceptionCallback callback);
376#endif
377
384
389
390 private:
391 V8();
392
393 enum BuildConfigurationFeatures {
394 kPointerCompression = 1 << 0,
395 k31BitSmis = 1 << 1,
396 kSandbox = 1 << 2,
397 kTargetOsIsAndroid = 1 << 3,
398 kEnableChecks = 1 << 4,
399 };
400
405 static bool Initialize(int build_config);
406
407 friend class Context;
408 template <class K, class V, class T>
410};
411
412} // namespace v8
413
414#endif // INCLUDE_V8_INITIALIZATION_H_
Definition: v8-context.h:55
Definition: v8-util.h:166
Definition: v8-platform.h:1287
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:125
static void SetCrashKeyCallbacks(AllocateCrashKeyCallback allocate, SetCrashKeyCallback set)
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:327
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:903
v8::PageAllocator PageAllocator
Definition: platform.h:22
Definition: libplatform.h:15
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:242
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
void(*)(CrashKey key, std::string_view value) SetCrashKeyCallback
Definition: v8-callbacks.h:282
uintptr_t(*)(uintptr_t return_addr_location) ReturnAddressLocationResolver
Definition: v8-initialization.h:51
CrashKey(*)(const char key[], CrashKeySize size) AllocateCrashKeyCallback
Definition: v8-callbacks.h:281
bool(*)(unsigned char *buffer, size_t length) EntropySource
Definition: v8-initialization.h:35
#define V8_EXPORT
Definition: v8config.h:875
#define V8_INLINE
Definition: v8config.h:519