@elurjs/android 0.0.0-stage → 0.2.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.
- package/README.md +10 -2
- package/index.mjs +11 -0
- package/package.json +29 -4
- package/template/.gitkeep +0 -0
- package/template/app/build.gradle.kts +192 -0
- package/template/app/proguard-rules-elur.pro +12 -0
- package/template/app/proguard-rules.pro +3 -0
- package/template/app/src/main/AndroidManifest.xml +81 -0
- package/template/app/src/main/assets/oss-notices.txt +153 -0
- package/template/app/src/main/assets/tck_pixel.png +0 -0
- package/template/app/src/main/cpp/CMakeLists.txt +117 -0
- package/template/app/src/main/cpp/dlEncoder.h +117 -0
- package/template/app/src/main/cpp/dlEncoderJsi.cpp +315 -0
- package/template/app/src/main/cpp/dlEncoderQjs.cpp +394 -0
- package/template/app/src/main/cpp/dlOps.inc +145 -0
- package/template/app/src/main/cpp/elurBridge.cpp +1350 -0
- package/template/app/src/main/cpp/elurBridgeHermes.cpp +1294 -0
- package/template/app/src/main/cpp/elurSkia.cpp +287 -0
- package/template/app/src/main/cpp/elurSkiaTree.cpp +448 -0
- package/template/app/src/main/cpp/elurUiWorklet.cpp +1233 -0
- package/template/app/src/main/cpp/elurYoga.cpp +1060 -0
- package/template/app/src/main/cpp/elurYoga.h +82 -0
- package/template/app/src/main/cpp/hermes-libs/LICENSE +21 -0
- package/template/app/src/main/cpp/hermes-libs/arm64-v8a/libhermesvm.so +0 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/AsyncDebuggerAPI.h +276 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/CompileJS.h +97 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/DebuggerAPI.h +502 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CrashManager.h +107 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/CtorConfig.h +145 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/DebuggerTypes.h +193 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCConfig.h +211 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/GCTripwireContext.h +40 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/HermesExport.h +14 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/JSOutOfMemoryError.h +27 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/RuntimeConfig.h +141 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/Public/SamplingProfiler.h +270 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/RuntimeTaskRunner.h +64 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTrace.h +1566 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/SynthTraceParser.h +37 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/ThreadSafetyAnalysis.h +75 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/TimerStats.h +23 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/TraceInterpreter.h +334 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/TracingRuntime.h +328 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPAgent.h +131 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CDPDebugAPI.h +73 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/CallbackOStream.h +89 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ConsoleMessage.h +135 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainAgent.h +280 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DebuggerDomainCoordinator.h +137 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainAgent.h +107 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/DomainState.h +140 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/HeapProfilerDomainAgent.h +71 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/JSONValueInterfaces.h +40 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageConverters.h +82 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageInterfaces.h +72 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypes.h +1279 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/MessageTypesInlines.h +313 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/ProfilerDomainAgent.h +38 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectConverters.h +77 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RemoteObjectsTable.h +127 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/cdp/RuntimeDomainAgent.h +138 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Dummy.h +24 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Extensions.h +20 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/ExtensionsBytecode.h +23 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/Intrinsics.h +44 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/JSIUtils.h +123 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/TextEncoder.h +29 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribDummy.h +24 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/ContribExtensions.h +23 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoder.h +30 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/extensions/contrib/TextDecoderUtils.h +113 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes.h +242 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes/hermes_tracing.h +52 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIHelpers.h +295 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/HermesABIRuntimeWrapper.h +25 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_abi.h +642 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_abi/hermes_vtable.h +29 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/HermesSandboxRuntime.h +41 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_compiled.h +12 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled-impl.h +8516 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled.h +137 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled-impl.h +3945 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled.h +119 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-fb.h +124 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt-impl.h +66 -0
- package/template/app/src/main/cpp/hermes-libs/include/hermes_sandbox/external/wasm-rt.h +456 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/JSIDynamic.h +26 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/decorator.h +1157 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/hermes-interfaces.h +242 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/instrumentation.h +132 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi-inl.h +434 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/jsi.h +2266 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/jsilib.h +59 -0
- package/template/app/src/main/cpp/hermes-libs/include/jsi/threadsafe.h +79 -0
- package/template/app/src/main/cpp/hermes-libs/jsi-impl/jsi.cpp +1111 -0
- package/template/app/src/main/cpp/hermes-libs/x86_64/libhermesvm.so +0 -0
- package/template/app/src/main/java/com/elur/universal/BinaryCodec.kt +121 -0
- package/template/app/src/main/java/com/elur/universal/DlDecoder.kt +260 -0
- package/template/app/src/main/java/com/elur/universal/DlOpsDecode.kt +158 -0
- package/template/app/src/main/java/com/elur/universal/ElurBoxDrawable.kt +161 -0
- package/template/app/src/main/java/com/elur/universal/ElurBridge.kt +238 -0
- package/template/app/src/main/java/com/elur/universal/ElurBridgeHermes.kt +223 -0
- package/template/app/src/main/java/com/elur/universal/ElurCanvasView.kt +202 -0
- package/template/app/src/main/java/com/elur/universal/ElurCryptoModule.kt +206 -0
- package/template/app/src/main/java/com/elur/universal/ElurCustomLayout.kt +185 -0
- package/template/app/src/main/java/com/elur/universal/ElurEditText.kt +17 -0
- package/template/app/src/main/java/com/elur/universal/ElurFontRegistry.kt +190 -0
- package/template/app/src/main/java/com/elur/universal/ElurHttpModule.kt +306 -0
- package/template/app/src/main/java/com/elur/universal/ElurImageService.kt +348 -0
- package/template/app/src/main/java/com/elur/universal/ElurLicensesActivity.kt +84 -0
- package/template/app/src/main/java/com/elur/universal/ElurListView.kt +954 -0
- package/template/app/src/main/java/com/elur/universal/ElurManifest.kt +117 -0
- package/template/app/src/main/java/com/elur/universal/ElurMetrics.kt +325 -0
- package/template/app/src/main/java/com/elur/universal/ElurModuleRegistrar.kt +14 -0
- package/template/app/src/main/java/com/elur/universal/ElurPermissionGate.kt +36 -0
- package/template/app/src/main/java/com/elur/universal/ElurRenderer.kt +6164 -0
- package/template/app/src/main/java/com/elur/universal/ElurRowYoga.kt +130 -0
- package/template/app/src/main/java/com/elur/universal/ElurScrollView.kt +240 -0
- package/template/app/src/main/java/com/elur/universal/ElurShellView.kt +117 -0
- package/template/app/src/main/java/com/elur/universal/ElurSkiaCanvasView.kt +162 -0
- package/template/app/src/main/java/com/elur/universal/ElurSkiaTreeRenderer.kt +968 -0
- package/template/app/src/main/java/com/elur/universal/ElurStateModule.kt +69 -0
- package/template/app/src/main/java/com/elur/universal/ElurSwipeDriver.kt +34 -0
- package/template/app/src/main/java/com/elur/universal/ElurTckModule.kt +99 -0
- package/template/app/src/main/java/com/elur/universal/ElurTextMeasure.kt +16 -0
- package/template/app/src/main/java/com/elur/universal/ElurTrace.kt +24 -0
- package/template/app/src/main/java/com/elur/universal/ElurUiModule.kt +48 -0
- package/template/app/src/main/java/com/elur/universal/ElurUiWorklet.kt +305 -0
- package/template/app/src/main/java/com/elur/universal/JsBridge.kt +67 -0
- package/template/app/src/main/java/com/elur/universal/JsThread.kt +189 -0
- package/template/app/src/main/java/com/elur/universal/MainActivity.kt +844 -0
- package/template/app/src/main/java/com/elur/universal/ModuleRegistry.kt +701 -0
- package/template/app/src/main/java/com/elur/universal/YogaRowScope.kt +97 -0
- package/template/app/src/main/res/values/ids.xml +10 -0
- package/template/app/src/main/res/values/strings.xml +8 -0
- package/template/app/src/main/res/values-es/strings.xml +5 -0
- package/template/app/src/main/res/xml/network_security_config.xml +10 -0
- package/template/build.gradle.kts +5 -0
- package/template/gradle/libs.versions.toml +12 -0
- package/template/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/template/gradle.properties +23 -0
- package/template/gradlew +251 -0
- package/template/gradlew.bat +94 -0
- package/template/settings.gradle.kts +32 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* Automatically generated by wasm2c */
|
|
2
|
+
#ifndef HERMES_SANDBOX_IMPL_OPT_COMPILED_H_GENERATED_
|
|
3
|
+
#define HERMES_SANDBOX_IMPL_OPT_COMPILED_H_GENERATED_
|
|
4
|
+
|
|
5
|
+
#include "wasm-rt.h"
|
|
6
|
+
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
|
|
9
|
+
#ifndef WASM_RT_CORE_TYPES_DEFINED
|
|
10
|
+
#define WASM_RT_CORE_TYPES_DEFINED
|
|
11
|
+
typedef uint8_t u8;
|
|
12
|
+
typedef int8_t s8;
|
|
13
|
+
typedef uint16_t u16;
|
|
14
|
+
typedef int16_t s16;
|
|
15
|
+
typedef uint32_t u32;
|
|
16
|
+
typedef int32_t s32;
|
|
17
|
+
typedef uint64_t u64;
|
|
18
|
+
typedef int64_t s64;
|
|
19
|
+
typedef float f32;
|
|
20
|
+
typedef double f64;
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
#ifdef __cplusplus
|
|
24
|
+
extern "C" {
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
struct w2c_env;
|
|
28
|
+
struct w2c_hermes__import;
|
|
29
|
+
struct w2c_wasi__snapshot__preview1;
|
|
30
|
+
|
|
31
|
+
typedef struct w2c_hermes {
|
|
32
|
+
struct w2c_env* w2c_env_instance;
|
|
33
|
+
struct w2c_hermes__import* w2c_hermes__import_instance;
|
|
34
|
+
struct w2c_wasi__snapshot__preview1* w2c_wasi__snapshot__preview1_instance;
|
|
35
|
+
u32 w2c_0x5F_stack_pointer;
|
|
36
|
+
u32 w2c_0x5F_stack_end;
|
|
37
|
+
u32 w2c_0x5F_stack_base;
|
|
38
|
+
wasm_rt_memory_t w2c_memory;
|
|
39
|
+
wasm_rt_funcref_table_t w2c_0x5F_indirect_function_table;
|
|
40
|
+
} w2c_hermes;
|
|
41
|
+
|
|
42
|
+
void wasm2c_hermes_instantiate(w2c_hermes*, struct w2c_env*, struct w2c_hermes__import*, struct w2c_wasi__snapshot__preview1*);
|
|
43
|
+
void wasm2c_hermes_free(w2c_hermes*);
|
|
44
|
+
wasm_rt_func_type_t wasm2c_hermes_get_func_type(uint32_t param_count, uint32_t result_count, ...);
|
|
45
|
+
|
|
46
|
+
/* import: 'env' 'emscripten_notify_memory_growth' */
|
|
47
|
+
void w2c_env_emscripten_notify_memory_growth(struct w2c_env*, u32);
|
|
48
|
+
|
|
49
|
+
/* import: 'hermes_import' 'getentropy' */
|
|
50
|
+
u32 w2c_hermes__import_getentropy(struct w2c_hermes__import*, u32, u32);
|
|
51
|
+
|
|
52
|
+
/* import: 'hermes_import' 'test_and_clear_timeout' */
|
|
53
|
+
u32 w2c_hermes__import_test_and_clear_timeout(struct w2c_hermes__import*);
|
|
54
|
+
|
|
55
|
+
/* import: 'hermes_import' 'test_timeout' */
|
|
56
|
+
u32 w2c_hermes__import_test_timeout(struct w2c_hermes__import*);
|
|
57
|
+
|
|
58
|
+
/* import: 'wasi_snapshot_preview1' 'clock_time_get' */
|
|
59
|
+
u32 w2c_wasi__snapshot__preview1_clock_time_get(struct w2c_wasi__snapshot__preview1*, u32, u64, u32);
|
|
60
|
+
|
|
61
|
+
/* import: 'wasi_snapshot_preview1' 'environ_get' */
|
|
62
|
+
u32 w2c_wasi__snapshot__preview1_environ_get(struct w2c_wasi__snapshot__preview1*, u32, u32);
|
|
63
|
+
|
|
64
|
+
/* import: 'wasi_snapshot_preview1' 'environ_sizes_get' */
|
|
65
|
+
u32 w2c_wasi__snapshot__preview1_environ_sizes_get(struct w2c_wasi__snapshot__preview1*, u32, u32);
|
|
66
|
+
|
|
67
|
+
/* import: 'wasi_snapshot_preview1' 'fd_close' */
|
|
68
|
+
u32 w2c_wasi__snapshot__preview1_fd_close(struct w2c_wasi__snapshot__preview1*, u32);
|
|
69
|
+
|
|
70
|
+
/* import: 'wasi_snapshot_preview1' 'fd_fdstat_get' */
|
|
71
|
+
u32 w2c_wasi__snapshot__preview1_fd_fdstat_get(struct w2c_wasi__snapshot__preview1*, u32, u32);
|
|
72
|
+
|
|
73
|
+
/* import: 'wasi_snapshot_preview1' 'fd_seek' */
|
|
74
|
+
u32 w2c_wasi__snapshot__preview1_fd_seek(struct w2c_wasi__snapshot__preview1*, u32, u64, u32, u32);
|
|
75
|
+
|
|
76
|
+
/* import: 'wasi_snapshot_preview1' 'fd_write' */
|
|
77
|
+
u32 w2c_wasi__snapshot__preview1_fd_write(struct w2c_wasi__snapshot__preview1*, u32, u32, u32, u32);
|
|
78
|
+
|
|
79
|
+
/* import: 'wasi_snapshot_preview1' 'proc_exit' */
|
|
80
|
+
void w2c_wasi__snapshot__preview1_proc_exit(struct w2c_wasi__snapshot__preview1*, u32);
|
|
81
|
+
|
|
82
|
+
/* export: 'memory' */
|
|
83
|
+
wasm_rt_memory_t* w2c_hermes_memory(w2c_hermes* instance);
|
|
84
|
+
|
|
85
|
+
/* export: 'get_global_base' */
|
|
86
|
+
u32 w2c_hermes_get_global_base(w2c_hermes*);
|
|
87
|
+
|
|
88
|
+
/* export: 'get_hermes_abi_vtable' */
|
|
89
|
+
u32 w2c_hermes_get_hermes_abi_vtable(w2c_hermes*);
|
|
90
|
+
|
|
91
|
+
/* export: '_initialize' */
|
|
92
|
+
void w2c_hermes_0x5Finitialize(w2c_hermes*);
|
|
93
|
+
|
|
94
|
+
/* export: '__indirect_function_table' */
|
|
95
|
+
wasm_rt_funcref_table_t* w2c_hermes_0x5F_indirect_function_table(w2c_hermes* instance);
|
|
96
|
+
|
|
97
|
+
/* export: 'malloc' */
|
|
98
|
+
u32 w2c_hermes_malloc(w2c_hermes*, u32);
|
|
99
|
+
|
|
100
|
+
/* export: 'free' */
|
|
101
|
+
void w2c_hermes_free(w2c_hermes*, u32);
|
|
102
|
+
|
|
103
|
+
/* export: 'realloc' */
|
|
104
|
+
u32 w2c_hermes_realloc(w2c_hermes*, u32, u32);
|
|
105
|
+
|
|
106
|
+
/* export: 'stackSave' */
|
|
107
|
+
u32 w2c_hermes_stackSave(w2c_hermes*);
|
|
108
|
+
|
|
109
|
+
/* export: 'stackRestore' */
|
|
110
|
+
void w2c_hermes_stackRestore(w2c_hermes*, u32);
|
|
111
|
+
|
|
112
|
+
/* export: 'stackAlloc' */
|
|
113
|
+
u32 w2c_hermes_stackAlloc(w2c_hermes*, u32);
|
|
114
|
+
|
|
115
|
+
#ifdef __cplusplus
|
|
116
|
+
}
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
#endif /* HERMES_SANDBOX_IMPL_OPT_COMPILED_H_GENERATED_ */
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef WASM_RT_FB_H
|
|
9
|
+
#define WASM_RT_FB_H
|
|
10
|
+
|
|
11
|
+
#include "wasm-rt-impl.h"
|
|
12
|
+
|
|
13
|
+
#if __STDC_VERSION__ < 201112L || __STDC_NO_ATOMICS__ == 1
|
|
14
|
+
typedef unsigned int seed_t;
|
|
15
|
+
#else
|
|
16
|
+
#include <stdatomic.h>
|
|
17
|
+
typedef atomic_uint seed_t;
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#if defined(__linux__) || defined(__ANDROID__)
|
|
21
|
+
#include <sys/random.h>
|
|
22
|
+
#include <sys/syscall.h>
|
|
23
|
+
#include <unistd.h>
|
|
24
|
+
#elif defined(__APPLE__)
|
|
25
|
+
#include <time.h>
|
|
26
|
+
#include <unistd.h>
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#if (defined(__linux__) || defined(__ANDROID__)) && defined(__aarch64__)
|
|
30
|
+
/* On Linux on ARM64 we most likely have at least 39 bits of virtual address
|
|
31
|
+
* space https://github.com/torvalds/linux/blob/v6.7/arch/arm64/Kconfig#L1262 If
|
|
32
|
+
* our mmap hint is above 2**39 it will likely fail. */
|
|
33
|
+
#define MAX_ADDR_HINT 0x37FFFFFFFF
|
|
34
|
+
#elif defined(__APPLE__) && defined(__aarch64__)
|
|
35
|
+
/* On ios/arm64 assume we have at least 39 bits of virtual address space (
|
|
36
|
+
* similar to linux on arm64). This should be true for all iOS versions >=14
|
|
37
|
+
* (https://github.com/golang/go/issues/46860), older versions <14 are
|
|
38
|
+
* unsupported. Note that the effective addressable space might vary, depending
|
|
39
|
+
* on apps entitelmnets as well as various other factors, hence we go for a
|
|
40
|
+
* conservative 39 bit address space limit, which is sufficient for most
|
|
41
|
+
* applications and should be good enough for this purpose.
|
|
42
|
+
*/
|
|
43
|
+
#define MAX_ADDR_HINT 0x37FFFFFFFF
|
|
44
|
+
#elif (defined(__linux__) || defined(__ANDROID__)) && defined(__amd64__)
|
|
45
|
+
#define MAX_ADDR_HINT 0x3FFFFFFFFFFF
|
|
46
|
+
#elif defined(_WIN64)
|
|
47
|
+
/* On Windows use a 37 bit address space limit as this is the lowest
|
|
48
|
+
* configuration for Windows Home
|
|
49
|
+
* https://learn.microsoft.com/en-us/windows/win32/memory/memory-limits-for-windows-releases
|
|
50
|
+
*/
|
|
51
|
+
#define MAX_ADDR_HINT 0x1FFFFFFFFF
|
|
52
|
+
#else
|
|
53
|
+
/* For other non-explicitly listed configuration, be extra conservative and use
|
|
54
|
+
* a 32 bit address space limit. */
|
|
55
|
+
#define MAX_ADDR_HINT 0xFFFFFFFF
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Generates a random 32-bit unsigned integer using the most appropriate method
|
|
60
|
+
available on the current platform.
|
|
61
|
+
*
|
|
62
|
+
* On Linux and Android, it uses the getrandom() system call to generate
|
|
63
|
+
* cryptographically secure random numbers. If getrandom() is not available or
|
|
64
|
+
* fails, it falls back to rand_r().
|
|
65
|
+
* On Windows, it uses the rand_s() function to generate cryptographically
|
|
66
|
+
* secure random numbers.
|
|
67
|
+
*
|
|
68
|
+
* Returns a random 32-bit unsigned integer.
|
|
69
|
+
*/
|
|
70
|
+
uint32_t rand_u32() {
|
|
71
|
+
uint32_t val;
|
|
72
|
+
int ret;
|
|
73
|
+
#if defined(__ANDROID__) && __ANDROID_API__ < 28
|
|
74
|
+
ret =
|
|
75
|
+
syscall(__NR_getrandom, &val, sizeof(val), GRND_NONBLOCK) != sizeof(val);
|
|
76
|
+
#elif defined(__linux__) || defined(__ANDROID__)
|
|
77
|
+
ret = getrandom(&val, sizeof(val), GRND_NONBLOCK) != sizeof(val);
|
|
78
|
+
#elif defined(_WIN32)
|
|
79
|
+
{
|
|
80
|
+
uint32_t val1, val2;
|
|
81
|
+
rand_s(&val1);
|
|
82
|
+
rand_s(&val2);
|
|
83
|
+
val = (uint64_t)(((uint64_t)val2 << 31) ^ (uint64_t)val1);
|
|
84
|
+
}
|
|
85
|
+
#else
|
|
86
|
+
/* Fallback to rand_r() (thread-safe variant of rand) which is not
|
|
87
|
+
* cryptographically secure but should be fine for this purpose.
|
|
88
|
+
*/
|
|
89
|
+
static seed_t seed = 0;
|
|
90
|
+
if (seed == 0) {
|
|
91
|
+
seed = time(NULL) ^ clock();
|
|
92
|
+
}
|
|
93
|
+
val =
|
|
94
|
+
((((uint32_t)rand_r(&seed) & 0xFFFF) << 16) |
|
|
95
|
+
((uint32_t)rand_r(&seed) & 0xFFFF));
|
|
96
|
+
#endif
|
|
97
|
+
(void)ret;
|
|
98
|
+
return val;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generates a random memory address hint for mmap, masking off the lower bits
|
|
103
|
+
* to align with the system's page size. Returnr a void pointer to the generated
|
|
104
|
+
* memory address hint.
|
|
105
|
+
*/
|
|
106
|
+
void *get_mmap_hint() {
|
|
107
|
+
uint64_t addr = (uint64_t)(rand_u32());
|
|
108
|
+
if (sizeof(size_t) == 8) {
|
|
109
|
+
addr = (addr << 32) | ((uint64_t)((rand_u32())));
|
|
110
|
+
addr &= MAX_ADDR_HINT;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#if defined(_WIN32)
|
|
114
|
+
SYSTEM_INFO systemInfo;
|
|
115
|
+
GetSystemInfo(&systemInfo);
|
|
116
|
+
uintptr_t pageSize = systemInfo.dwPageSize;
|
|
117
|
+
#else
|
|
118
|
+
uintptr_t pageSize = sysconf(_SC_PAGESIZE);
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
void *hint = (void *)((addr) & ~(pageSize - 1));
|
|
122
|
+
return hint;
|
|
123
|
+
}
|
|
124
|
+
#endif // WASM_RT_FB_H
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2018 WebAssembly Community Group participants
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef WASM_RT_IMPL_H_
|
|
18
|
+
#define WASM_RT_IMPL_H_
|
|
19
|
+
|
|
20
|
+
#include "wasm-rt.h"
|
|
21
|
+
|
|
22
|
+
#ifdef _WIN32
|
|
23
|
+
#include <windows.h>
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#ifdef __cplusplus
|
|
27
|
+
extern "C" {
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
/** A setjmp buffer used for handling traps. */
|
|
31
|
+
extern WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf g_wasm_rt_jmp_buf;
|
|
32
|
+
|
|
33
|
+
#if WASM_RT_USE_STACK_DEPTH_COUNT
|
|
34
|
+
/** Saved call stack depth that will be restored in case a trap occurs. */
|
|
35
|
+
extern WASM_RT_THREAD_LOCAL uint32_t wasm_rt_saved_call_stack_depth;
|
|
36
|
+
#define WASM_RT_SAVE_STACK_DEPTH() \
|
|
37
|
+
wasm_rt_saved_call_stack_depth = wasm_rt_call_stack_depth
|
|
38
|
+
#else
|
|
39
|
+
#define WASM_RT_SAVE_STACK_DEPTH() (void)0
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Convenience macro to use before calling a wasm function. On first execution
|
|
44
|
+
* it will return `WASM_RT_TRAP_NONE` (i.e. 0). If the function traps, it will
|
|
45
|
+
* jump back and return the trap that occurred.
|
|
46
|
+
*
|
|
47
|
+
* ```
|
|
48
|
+
* wasm_rt_trap_t code = wasm_rt_impl_try();
|
|
49
|
+
* if (code != 0) {
|
|
50
|
+
* printf("A trap occurred with code: %d\n", code);
|
|
51
|
+
* ...
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* // Call the potentially-trapping function.
|
|
55
|
+
* my_wasm_func();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
#define wasm_rt_impl_try() \
|
|
59
|
+
(WASM_RT_SAVE_STACK_DEPTH(), wasm_rt_set_unwind_target(&g_wasm_rt_jmp_buf), \
|
|
60
|
+
WASM_RT_SETJMP(g_wasm_rt_jmp_buf))
|
|
61
|
+
|
|
62
|
+
#ifdef __cplusplus
|
|
63
|
+
}
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#endif /* WASM_RT_IMPL_H_ */
|