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 PageAllocator;
26class Platform;
27template <class K, class V, class T>
28class PersistentValueMapBase;
29
34using EntropySource = bool (*)(unsigned char* buffer, size_t length);
35
50 uintptr_t (*)(uintptr_t return_addr_location);
51
52using DcheckErrorCallback = void (*)(const char* file, int line,
53 const char* message);
54
55using V8FatalErrorCallback = void (*)(const char* file, int line,
56 const char* message);
57
62 public:
78 static void SetSnapshotDataBlob(StartupData* startup_blob);
79
82
88
92 static void SetFlagsFromString(const char* str);
93 static void SetFlagsFromString(const char* str, size_t length);
94
98 static void SetFlagsFromCommandLine(int* argc, char** argv,
99 bool remove_flags);
100
102 static const char* GetVersion();
103
108 V8_INLINE static bool Initialize() {
109#ifdef V8_TARGET_OS_ANDROID
110 const bool kV8TargetOsIsAndroid = true;
111#else
112 const bool kV8TargetOsIsAndroid = false;
113#endif
114
115#ifdef V8_ENABLE_CHECKS
116 const bool kV8EnableChecks = true;
117#else
118 const bool kV8EnableChecks = false;
119#endif
120
121 const int kBuildConfiguration =
122 (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
123 (internal::SmiValuesAre31Bits() ? k31BitSmis : 0) |
124 (internal::SandboxIsEnabled() ? kSandbox : 0) |
125 (kV8TargetOsIsAndroid ? kTargetOsIsAndroid : 0) |
126 (kV8EnableChecks ? kEnableChecks : 0);
127 return Initialize(kBuildConfiguration);
128 }
129
134 static void SetEntropySource(EntropySource source);
135
141 ReturnAddressLocationResolver return_address_resolver);
142
152 static bool Dispose();
153
161 static bool InitializeICU(const char* icu_data_file = nullptr);
162
175 static bool InitializeICUDefaultLocation(const char* exec_path,
176 const char* icu_data_file = nullptr);
177
193 static void InitializeExternalStartupData(const char* directory_path);
194 static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
195
200 static void InitializePlatform(Platform* platform);
201
206 static void DisposePlatform();
207
208#if defined(V8_ENABLE_SANDBOX)
225 static bool IsSandboxConfiguredSecurely();
226
239 static VirtualAddressSpace* GetSandboxAddressSpace();
240
247 static size_t GetSandboxSizeInBytes();
248
259 static size_t GetSandboxReservationSizeInBytes();
260#endif // V8_ENABLE_SANDBOX
261
268 static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler);
269
270#if defined(V8_OS_WIN)
280 static void SetUnhandledExceptionCallback(
281 UnhandledExceptionCallback callback);
282#endif
283
290
295
296 private:
297 V8();
298
299 enum BuildConfigurationFeatures {
300 kPointerCompression = 1 << 0,
301 k31BitSmis = 1 << 1,
302 kSandbox = 1 << 2,
303 kTargetOsIsAndroid = 1 << 3,
304 kEnableChecks = 1 << 4,
305 };
306
311 static bool Initialize(int build_config);
312
313 friend class Context;
314 template <class K, class V, class T>
316};
317
318} // namespace v8
319
320#endif // INCLUDE_V8_INITIALIZATION_H_
Definition: v8-context.h:48
Definition: v8-util.h:166
Definition: v8-platform.h:1058
Definition: v8-statistics.h:116
Definition: v8-snapshot.h:21
Definition: v8-initialization.h:61
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 void InitializeExternalStartupDataFromFile(const char *snapshot_blob)
static bool EnableWebAssemblyTrapHandler(bool use_v8_signal_handler)
static bool Initialize()
Definition: v8-initialization.h:108
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)
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:740
v8::PageAllocator PageAllocator
Definition: platform.h:22
Definition: libplatform.h:15
void(*)(const char *location, const OOMDetails &details) OOMErrorCallback
Definition: v8-callbacks.h:228
void(*)(const char *file, int line, const char *message) V8FatalErrorCallback
Definition: v8-initialization.h:56
void(*)(const char *file, int line, const char *message) DcheckErrorCallback
Definition: v8-initialization.h:53
uintptr_t(*)(uintptr_t return_addr_location) ReturnAddressLocationResolver
Definition: v8-initialization.h:50
bool(*)(unsigned char *buffer, size_t length) EntropySource
Definition: v8-initialization.h:34
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499