@encharm/cws 4.5.1 → 4.5.3

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 (249) hide show
  1. package/README.md +3 -5
  2. package/binding.gyp +1 -1
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +20 -0
  5. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +931 -0
  7. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  8. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +20 -0
  9. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  10. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +931 -0
  11. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  12. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  13. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  14. package/package.json +1 -1
  15. package/src/Addon.h +6 -1
  16. package/src/headers/24/acorn_version.h +6 -0
  17. package/src/headers/24/addon_permission.h +31 -0
  18. package/src/headers/24/agent.h +195 -0
  19. package/src/headers/24/aliased_buffer-inl.h +244 -0
  20. package/src/headers/24/aliased_buffer.h +206 -0
  21. package/src/headers/24/aliased_struct-inl.h +54 -0
  22. package/src/headers/24/aliased_struct.h +63 -0
  23. package/src/headers/24/amaro_version.h +6 -0
  24. package/src/headers/24/application.h +165 -0
  25. package/src/headers/24/async_context_frame.h +33 -0
  26. package/src/headers/24/async_wrap-inl.h +96 -0
  27. package/src/headers/24/async_wrap.h +244 -0
  28. package/src/headers/24/base_object-inl.h +330 -0
  29. package/src/headers/24/base_object.h +338 -0
  30. package/src/headers/24/base_object_types.h +74 -0
  31. package/src/headers/24/bindingdata.h +272 -0
  32. package/src/headers/24/blob_serializer_deserializer-inl.h +385 -0
  33. package/src/headers/24/blob_serializer_deserializer.h +132 -0
  34. package/src/headers/24/callback_queue-inl.h +97 -0
  35. package/src/headers/24/callback_queue.h +79 -0
  36. package/src/headers/24/cares_wrap.h +447 -0
  37. package/src/headers/24/child_process_permission.h +31 -0
  38. package/src/headers/24/cid.h +127 -0
  39. package/src/headers/24/cjs_module_lexer_version.h +6 -0
  40. package/src/headers/24/cleanup_queue-inl.h +36 -0
  41. package/src/headers/24/cleanup_queue.h +79 -0
  42. package/src/headers/24/compile_cache.h +113 -0
  43. package/src/headers/24/connect_wrap.h +26 -0
  44. package/src/headers/24/connection_wrap.h +30 -0
  45. package/src/headers/24/cppgc_helpers-inl.h +65 -0
  46. package/src/headers/24/cppgc_helpers.h +162 -0
  47. package/src/headers/24/crypto/crypto_aes.h +97 -0
  48. package/src/headers/24/crypto/crypto_argon2.h +86 -0
  49. package/src/headers/24/crypto/crypto_bio.h +193 -0
  50. package/src/headers/24/crypto/crypto_chacha20_poly1305.h +64 -0
  51. package/src/headers/24/crypto/crypto_cipher.h +281 -0
  52. package/src/headers/24/crypto/crypto_clienthello-inl.h +90 -0
  53. package/src/headers/24/crypto/crypto_clienthello.h +131 -0
  54. package/src/headers/24/crypto/crypto_common.h +48 -0
  55. package/src/headers/24/crypto/crypto_context.h +171 -0
  56. package/src/headers/24/crypto/crypto_dh.h +126 -0
  57. package/src/headers/24/crypto/crypto_dsa.h +50 -0
  58. package/src/headers/24/crypto/crypto_ec.h +163 -0
  59. package/src/headers/24/crypto/crypto_hash.h +89 -0
  60. package/src/headers/24/crypto/crypto_hkdf.h +61 -0
  61. package/src/headers/24/crypto/crypto_hmac.h +92 -0
  62. package/src/headers/24/crypto/crypto_kem.h +113 -0
  63. package/src/headers/24/crypto/crypto_keygen.h +290 -0
  64. package/src/headers/24/crypto/crypto_keys.h +392 -0
  65. package/src/headers/24/crypto/crypto_ml_dsa.h +21 -0
  66. package/src/headers/24/crypto/crypto_pbkdf2.h +74 -0
  67. package/src/headers/24/crypto/crypto_random.h +124 -0
  68. package/src/headers/24/crypto/crypto_rsa.h +136 -0
  69. package/src/headers/24/crypto/crypto_scrypt.h +85 -0
  70. package/src/headers/24/crypto/crypto_sig.h +156 -0
  71. package/src/headers/24/crypto/crypto_spkac.h +21 -0
  72. package/src/headers/24/crypto/crypto_timing.h +20 -0
  73. package/src/headers/24/crypto/crypto_tls.h +309 -0
  74. package/src/headers/24/crypto/crypto_util.h +598 -0
  75. package/src/headers/24/crypto/crypto_x509.h +140 -0
  76. package/src/headers/24/data.h +148 -0
  77. package/src/headers/24/debug_utils-inl.h +232 -0
  78. package/src/headers/24/debug_utils.h +193 -0
  79. package/src/headers/24/defs.h +254 -0
  80. package/src/headers/24/diagnosticfilename-inl.h +33 -0
  81. package/src/headers/24/embedded_data.h +17 -0
  82. package/src/headers/24/encoding_binding.h +60 -0
  83. package/src/headers/24/endpoint.h +421 -0
  84. package/src/headers/24/env-inl.h +935 -0
  85. package/src/headers/24/env.h +1257 -0
  86. package/src/headers/24/env_properties.h +561 -0
  87. package/src/headers/24/fs_permission.h +167 -0
  88. package/src/headers/24/handle_wrap.h +123 -0
  89. package/src/headers/24/histogram-inl.h +107 -0
  90. package/src/headers/24/histogram.h +279 -0
  91. package/src/headers/24/http3.h +44 -0
  92. package/src/headers/24/inspector_agent.h +165 -0
  93. package/src/headers/24/inspector_io.h +78 -0
  94. package/src/headers/24/inspector_permission.h +31 -0
  95. package/src/headers/24/inspector_profiler.h +149 -0
  96. package/src/headers/24/inspector_socket.h +60 -0
  97. package/src/headers/24/inspector_socket_server.h +110 -0
  98. package/src/headers/24/io_agent.h +30 -0
  99. package/src/headers/24/js_native_api.h +615 -0
  100. package/src/headers/24/js_native_api_types.h +211 -0
  101. package/src/headers/24/js_native_api_v8.h +485 -0
  102. package/src/headers/24/js_native_api_v8_internals.h +45 -0
  103. package/src/headers/24/js_stream.h +52 -0
  104. package/src/headers/24/json_parser.h +40 -0
  105. package/src/headers/24/json_utils.h +172 -0
  106. package/src/headers/24/logstream.h +81 -0
  107. package/src/headers/24/main_thread_interface.h +116 -0
  108. package/src/headers/24/memory_tracker-inl.h +454 -0
  109. package/src/headers/24/memory_tracker.h +333 -0
  110. package/src/headers/24/module_wrap.h +229 -0
  111. package/src/headers/24/ncrypto.h +1625 -0
  112. package/src/headers/24/network_agent.h +118 -0
  113. package/src/headers/24/network_inspector.h +45 -0
  114. package/src/headers/24/network_resource_manager.h +29 -0
  115. package/src/headers/24/node.h +1620 -0
  116. package/src/headers/24/node_api.h +269 -0
  117. package/src/headers/24/node_api_internals.h +46 -0
  118. package/src/headers/24/node_api_types.h +52 -0
  119. package/src/headers/24/node_binding.h +163 -0
  120. package/src/headers/24/node_blob.h +159 -0
  121. package/src/headers/24/node_bob-inl.h +36 -0
  122. package/src/headers/24/node_bob.h +107 -0
  123. package/src/headers/24/node_buffer.h +92 -0
  124. package/src/headers/24/node_builtins.h +223 -0
  125. package/src/headers/24/node_config_file.h +65 -0
  126. package/src/headers/24/node_constants.h +82 -0
  127. package/src/headers/24/node_context_data.h +168 -0
  128. package/src/headers/24/node_contextify.h +261 -0
  129. package/src/headers/24/node_crypto.h +62 -0
  130. package/src/headers/24/node_debug.h +25 -0
  131. package/src/headers/24/node_dir.h +52 -0
  132. package/src/headers/24/node_dotenv.h +45 -0
  133. package/src/headers/24/node_errors.h +391 -0
  134. package/src/headers/24/node_exit_code.h +54 -0
  135. package/src/headers/24/node_external_reference.h +167 -0
  136. package/src/headers/24/node_file-inl.h +412 -0
  137. package/src/headers/24/node_file.h +540 -0
  138. package/src/headers/24/node_http2.h +1175 -0
  139. package/src/headers/24/node_http2_state.h +159 -0
  140. package/src/headers/24/node_http_common-inl.h +198 -0
  141. package/src/headers/24/node_http_common.h +535 -0
  142. package/src/headers/24/node_i18n.h +132 -0
  143. package/src/headers/24/node_internals.h +476 -0
  144. package/src/headers/24/node_json.h +24 -0
  145. package/src/headers/24/node_large_page.h +34 -0
  146. package/src/headers/24/node_locks.h +180 -0
  147. package/src/headers/24/node_main_instance.h +67 -0
  148. package/src/headers/24/node_mem-inl.h +112 -0
  149. package/src/headers/24/node_mem.h +45 -0
  150. package/src/headers/24/node_messaging.h +389 -0
  151. package/src/headers/24/node_metadata.h +164 -0
  152. package/src/headers/24/node_modules.h +93 -0
  153. package/src/headers/24/node_mutex.h +323 -0
  154. package/src/headers/24/node_object_wrap.h +132 -0
  155. package/src/headers/24/node_options-inl.h +524 -0
  156. package/src/headers/24/node_options.h +682 -0
  157. package/src/headers/24/node_perf.h +166 -0
  158. package/src/headers/24/node_perf_common.h +102 -0
  159. package/src/headers/24/node_platform.h +286 -0
  160. package/src/headers/24/node_process-inl.h +26 -0
  161. package/src/headers/24/node_process.h +111 -0
  162. package/src/headers/24/node_realm-inl.h +153 -0
  163. package/src/headers/24/node_realm.h +236 -0
  164. package/src/headers/24/node_report.h +43 -0
  165. package/src/headers/24/node_revert.h +82 -0
  166. package/src/headers/24/node_root_certs.h +3546 -0
  167. package/src/headers/24/node_sea.h +74 -0
  168. package/src/headers/24/node_shadow_realm.h +46 -0
  169. package/src/headers/24/node_snapshot_builder.h +57 -0
  170. package/src/headers/24/node_snapshotable.h +174 -0
  171. package/src/headers/24/node_sockaddr-inl.h +257 -0
  172. package/src/headers/24/node_sockaddr.h +394 -0
  173. package/src/headers/24/node_sqlite.h +270 -0
  174. package/src/headers/24/node_stat_watcher.h +73 -0
  175. package/src/headers/24/node_string.h +101 -0
  176. package/src/headers/24/node_task_runner.h +92 -0
  177. package/src/headers/24/node_threadsafe_cow-inl.h +54 -0
  178. package/src/headers/24/node_threadsafe_cow.h +105 -0
  179. package/src/headers/24/node_trace_buffer.h +83 -0
  180. package/src/headers/24/node_trace_writer.h +75 -0
  181. package/src/headers/24/node_union_bytes.h +81 -0
  182. package/src/headers/24/node_url.h +101 -0
  183. package/src/headers/24/node_url_pattern.h +118 -0
  184. package/src/headers/24/node_v8.h +77 -0
  185. package/src/headers/24/node_v8_platform-inl.h +185 -0
  186. package/src/headers/24/node_version.h +110 -0
  187. package/src/headers/24/node_wasi.h +185 -0
  188. package/src/headers/24/node_wasm_web_api.h +55 -0
  189. package/src/headers/24/node_watchdog.h +154 -0
  190. package/src/headers/24/node_webstorage.h +60 -0
  191. package/src/headers/24/node_worker.h +159 -0
  192. package/src/headers/24/packet.h +155 -0
  193. package/src/headers/24/path.h +33 -0
  194. package/src/headers/24/permission/addon_permission.h +31 -0
  195. package/src/headers/24/permission/child_process_permission.h +31 -0
  196. package/src/headers/24/permission/fs_permission.h +167 -0
  197. package/src/headers/24/permission/inspector_permission.h +31 -0
  198. package/src/headers/24/permission/permission.h +100 -0
  199. package/src/headers/24/permission/permission_base.h +65 -0
  200. package/src/headers/24/permission/wasi_permission.h +31 -0
  201. package/src/headers/24/permission/worker_permission.h +31 -0
  202. package/src/headers/24/permission.h +100 -0
  203. package/src/headers/24/permission_base.h +65 -0
  204. package/src/headers/24/pipe_wrap.h +80 -0
  205. package/src/headers/24/preferredaddress.h +72 -0
  206. package/src/headers/24/protocol_helper.h +27 -0
  207. package/src/headers/24/queue.h +306 -0
  208. package/src/headers/24/req_wrap-inl.h +176 -0
  209. package/src/headers/24/req_wrap.h +79 -0
  210. package/src/headers/24/runtime_agent.h +41 -0
  211. package/src/headers/24/session.h +528 -0
  212. package/src/headers/24/sessionticket.h +108 -0
  213. package/src/headers/24/spawn_sync.h +243 -0
  214. package/src/headers/24/stream_base-inl.h +173 -0
  215. package/src/headers/24/stream_base.h +478 -0
  216. package/src/headers/24/stream_pipe.h +76 -0
  217. package/src/headers/24/stream_wrap.h +132 -0
  218. package/src/headers/24/streams.h +370 -0
  219. package/src/headers/24/string_bytes.h +109 -0
  220. package/src/headers/24/string_decoder-inl.h +31 -0
  221. package/src/headers/24/string_decoder.h +49 -0
  222. package/src/headers/24/target_agent.h +75 -0
  223. package/src/headers/24/tcp_wrap.h +105 -0
  224. package/src/headers/24/threadpoolwork-inl.h +70 -0
  225. package/src/headers/24/timer_wrap-inl.h +32 -0
  226. package/src/headers/24/timer_wrap.h +87 -0
  227. package/src/headers/24/timers.h +75 -0
  228. package/src/headers/24/tlscontext.h +228 -0
  229. package/src/headers/24/tokens.h +256 -0
  230. package/src/headers/24/trace_event.h +722 -0
  231. package/src/headers/24/trace_event_common.h +1109 -0
  232. package/src/headers/24/traced_value.h +129 -0
  233. package/src/headers/24/tracing/agent.h +195 -0
  234. package/src/headers/24/tracing/trace_event.h +722 -0
  235. package/src/headers/24/tracing_agent.h +43 -0
  236. package/src/headers/24/transportparams.h +166 -0
  237. package/src/headers/24/tty_wrap.h +65 -0
  238. package/src/headers/24/udp_wrap.h +230 -0
  239. package/src/headers/24/undici_version.h +6 -0
  240. package/src/headers/24/util-inl.h +711 -0
  241. package/src/headers/24/util.h +1016 -0
  242. package/src/headers/24/v8-external-memory-accounter.h +60 -0
  243. package/src/headers/24/v8-fast-api-calls.h +819 -0
  244. package/src/headers/24/v8-inspector.h +426 -0
  245. package/src/headers/24/wasi_permission.h +31 -0
  246. package/src/headers/24/worker_agent.h +40 -0
  247. package/src/headers/24/worker_inspector.h +124 -0
  248. package/src/headers/24/worker_permission.h +31 -0
  249. package/src/headers/24/zlib_version.h +6 -0
@@ -0,0 +1,185 @@
1
+ #ifndef SRC_NODE_WASI_H_
2
+ #define SRC_NODE_WASI_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object.h"
7
+ #include "node_mem.h"
8
+ #include "uvwasi.h"
9
+ #include "v8-fast-api-calls.h"
10
+
11
+ namespace node {
12
+ namespace wasi {
13
+
14
+ struct WasmMemory {
15
+ char* data;
16
+ size_t size;
17
+ };
18
+
19
+ class WASI : public BaseObject,
20
+ public mem::NgLibMemoryManager<WASI, uvwasi_mem_t> {
21
+ public:
22
+ WASI(Environment* env,
23
+ v8::Local<v8::Object> object,
24
+ uvwasi_options_t* options);
25
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
26
+
27
+ void MemoryInfo(MemoryTracker* tracker) const override;
28
+ SET_MEMORY_INFO_NAME(WASI)
29
+ SET_SELF_SIZE(WASI)
30
+
31
+ static uint32_t ArgsGet(WASI&, WasmMemory, uint32_t, uint32_t);
32
+ static uint32_t ArgsSizesGet(WASI&, WasmMemory, uint32_t, uint32_t);
33
+ static uint32_t ClockResGet(WASI&, WasmMemory, uint32_t, uint32_t);
34
+ static uint32_t ClockTimeGet(WASI&, WasmMemory, uint32_t, uint64_t, uint32_t);
35
+ static uint32_t EnvironGet(WASI&, WasmMemory, uint32_t, uint32_t);
36
+ static uint32_t EnvironSizesGet(WASI&, WasmMemory, uint32_t, uint32_t);
37
+ static uint32_t FdAdvise(
38
+ WASI&, WasmMemory, uint32_t, uint64_t, uint64_t, uint32_t);
39
+ static uint32_t FdAllocate(WASI&, WasmMemory, uint32_t, uint64_t, uint64_t);
40
+ static uint32_t FdClose(WASI&, WasmMemory, uint32_t);
41
+ static uint32_t FdDatasync(WASI&, WasmMemory, uint32_t);
42
+ static uint32_t FdFdstatGet(WASI&, WasmMemory, uint32_t, uint32_t);
43
+ static uint32_t FdFdstatSetFlags(WASI&, WasmMemory, uint32_t, uint32_t);
44
+ static uint32_t FdFdstatSetRights(
45
+ WASI&, WasmMemory, uint32_t, uint64_t, uint64_t);
46
+ static uint32_t FdFilestatGet(WASI&, WasmMemory, uint32_t, uint32_t);
47
+ static uint32_t FdFilestatSetSize(WASI&, WasmMemory, uint32_t, uint64_t);
48
+ static uint32_t FdFilestatSetTimes(
49
+ WASI&, WasmMemory, uint32_t, uint64_t, uint64_t, uint32_t);
50
+ static uint32_t FdPread(WASI&,
51
+ WasmMemory memory,
52
+ uint32_t,
53
+ uint32_t,
54
+ uint32_t,
55
+ uint64_t,
56
+ uint32_t);
57
+ static uint32_t FdPrestatGet(WASI&, WasmMemory, uint32_t, uint32_t);
58
+ static uint32_t FdPrestatDirName(
59
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
60
+ static uint32_t FdPwrite(
61
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint64_t, uint32_t);
62
+ static uint32_t FdRead(
63
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t);
64
+ static uint32_t FdReaddir(
65
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint64_t, uint32_t);
66
+ static uint32_t FdRenumber(WASI&, WasmMemory, uint32_t, uint32_t);
67
+ static uint32_t FdSeek(
68
+ WASI&, WasmMemory, uint32_t, int64_t, uint32_t, uint32_t);
69
+ static uint32_t FdSync(WASI&, WasmMemory, uint32_t);
70
+ static uint32_t FdTell(WASI&, WasmMemory, uint32_t, uint32_t);
71
+ static uint32_t FdWrite(
72
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t);
73
+ static uint32_t PathCreateDirectory(
74
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
75
+ static uint32_t PathFilestatGet(
76
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
77
+ static uint32_t PathFilestatSetTimes(WASI&,
78
+ WasmMemory,
79
+ uint32_t,
80
+ uint32_t,
81
+ uint32_t,
82
+ uint32_t,
83
+ uint64_t,
84
+ uint64_t,
85
+ uint32_t);
86
+ static uint32_t PathLink(WASI&,
87
+ WasmMemory,
88
+ uint32_t,
89
+ uint32_t,
90
+ uint32_t,
91
+ uint32_t,
92
+ uint32_t,
93
+ uint32_t,
94
+ uint32_t);
95
+ static uint32_t PathOpen(WASI&,
96
+ WasmMemory,
97
+ uint32_t,
98
+ uint32_t,
99
+ uint32_t,
100
+ uint32_t,
101
+ uint32_t,
102
+ uint64_t,
103
+ uint64_t,
104
+ uint32_t,
105
+ uint32_t);
106
+ static uint32_t PathReadlink(WASI&,
107
+ WasmMemory,
108
+ uint32_t,
109
+ uint32_t,
110
+ uint32_t,
111
+ uint32_t,
112
+ uint32_t,
113
+ uint32_t);
114
+ static uint32_t PathRemoveDirectory(
115
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
116
+ static uint32_t PathRename(WASI&,
117
+ WasmMemory,
118
+ uint32_t,
119
+ uint32_t,
120
+ uint32_t,
121
+ uint32_t,
122
+ uint32_t,
123
+ uint32_t);
124
+ static uint32_t PathSymlink(
125
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
126
+ static uint32_t PathUnlinkFile(
127
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
128
+ static uint32_t PollOneoff(
129
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t);
130
+ static void ProcExit(WASI&, WasmMemory, uint32_t);
131
+ static uint32_t ProcRaise(WASI&, WasmMemory, uint32_t);
132
+ static uint32_t RandomGet(WASI&, WasmMemory, uint32_t, uint32_t);
133
+ static uint32_t SchedYield(WASI&, WasmMemory);
134
+ static uint32_t SockAccept(WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
135
+ static uint32_t SockRecv(WASI&,
136
+ WasmMemory,
137
+ uint32_t,
138
+ uint32_t,
139
+ uint32_t,
140
+ uint32_t,
141
+ uint32_t,
142
+ uint32_t);
143
+ static uint32_t SockSend(
144
+ WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
145
+ static uint32_t SockShutdown(WASI&, WasmMemory, uint32_t, uint32_t);
146
+
147
+ static void _SetMemory(const v8::FunctionCallbackInfo<v8::Value>& args);
148
+
149
+ // Implementation for mem::NgLibMemoryManager
150
+ void CheckAllocatedSize(size_t previous_size) const;
151
+ void IncreaseAllocatedSize(size_t size);
152
+ void DecreaseAllocatedSize(size_t size);
153
+
154
+ // <typename FT, FT F> as a C++14 desugaring of `<auto F>`
155
+ template <typename FT, FT F, typename R, typename... Args>
156
+ class WasiFunction {
157
+ public:
158
+ static void SetFunction(Environment*,
159
+ const char*,
160
+ v8::Local<v8::FunctionTemplate>);
161
+
162
+ private:
163
+ static R FastCallback(v8::Local<v8::Object> unused,
164
+ v8::Local<v8::Object> receiver,
165
+ Args...,
166
+ v8::FastApiCallbackOptions&);
167
+
168
+ static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>&);
169
+ };
170
+
171
+ private:
172
+ ~WASI() override;
173
+ uvwasi_t uvw_;
174
+ v8::Global<v8::WasmMemoryObject> memory_;
175
+ uvwasi_mem_t alloc_info_;
176
+ size_t current_uvwasi_memory_ = 0;
177
+ };
178
+
179
+
180
+ } // namespace wasi
181
+ } // namespace node
182
+
183
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
184
+
185
+ #endif // SRC_NODE_WASI_H_
@@ -0,0 +1,55 @@
1
+ #ifndef SRC_NODE_WASM_WEB_API_H_
2
+ #define SRC_NODE_WASM_WEB_API_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object-inl.h"
7
+ #include "v8.h"
8
+
9
+ namespace node {
10
+ namespace wasm_web_api {
11
+
12
+ // Wrapper for interacting with a v8::WasmStreaming instance from JavaScript.
13
+ class WasmStreamingObject final : public BaseObject {
14
+ public:
15
+ static v8::Local<v8::Function> Initialize(Environment* env);
16
+
17
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
18
+
19
+ void MemoryInfo(MemoryTracker* tracker) const override;
20
+ SET_MEMORY_INFO_NAME(WasmStreamingObject)
21
+ SET_SELF_SIZE(WasmStreamingObject)
22
+
23
+ static v8::MaybeLocal<v8::Object> Create(
24
+ Environment* env, std::shared_ptr<v8::WasmStreaming> streaming);
25
+
26
+ private:
27
+ WasmStreamingObject(Environment* env, v8::Local<v8::Object> object)
28
+ : BaseObject(env, object) {
29
+ MakeWeak();
30
+ }
31
+
32
+ ~WasmStreamingObject() override {}
33
+
34
+ private:
35
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
36
+ static void SetURL(const v8::FunctionCallbackInfo<v8::Value>& args);
37
+ static void Push(const v8::FunctionCallbackInfo<v8::Value>& args);
38
+ static void Finish(const v8::FunctionCallbackInfo<v8::Value>& args);
39
+ static void Abort(const v8::FunctionCallbackInfo<v8::Value>& args);
40
+
41
+ std::shared_ptr<v8::WasmStreaming> streaming_;
42
+ size_t wasm_size_ = 0;
43
+ };
44
+
45
+ // This is a v8::WasmStreamingCallback implementation that must be passed to
46
+ // v8::Isolate::SetWasmStreamingCallback when setting up the isolate in order to
47
+ // enable the WebAssembly.(compile|instantiate)Streaming APIs.
48
+ void StartStreamingCompilation(const v8::FunctionCallbackInfo<v8::Value>& args);
49
+
50
+ } // namespace wasm_web_api
51
+ } // namespace node
52
+
53
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
54
+
55
+ #endif // SRC_NODE_WASM_WEB_API_H_
@@ -0,0 +1,154 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_NODE_WATCHDOG_H_
23
+ #define SRC_NODE_WATCHDOG_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include <vector>
28
+ #include "handle_wrap.h"
29
+ #include "memory_tracker-inl.h"
30
+ #include "node_mutex.h"
31
+ #include "uv.h"
32
+ #include "v8.h"
33
+
34
+ #ifdef __POSIX__
35
+ #include <pthread.h>
36
+ #endif
37
+
38
+ namespace node {
39
+
40
+ enum class SignalPropagation {
41
+ kContinuePropagation,
42
+ kStopPropagation,
43
+ };
44
+
45
+ class Watchdog {
46
+ public:
47
+ explicit Watchdog(v8::Isolate* isolate,
48
+ uint64_t ms,
49
+ bool* timed_out = nullptr);
50
+ ~Watchdog();
51
+ v8::Isolate* isolate() { return isolate_; }
52
+
53
+ private:
54
+ static void Run(void* arg);
55
+ static void Timer(uv_timer_t* timer);
56
+
57
+ v8::Isolate* isolate_;
58
+ uv_thread_t thread_;
59
+ uv_loop_t loop_;
60
+ uv_async_t async_;
61
+ uv_timer_t timer_;
62
+ bool* timed_out_;
63
+ };
64
+
65
+ class SigintWatchdogBase {
66
+ public:
67
+ virtual ~SigintWatchdogBase() = default;
68
+ virtual SignalPropagation HandleSigint() = 0;
69
+ };
70
+
71
+ class SigintWatchdog : public SigintWatchdogBase {
72
+ public:
73
+ explicit SigintWatchdog(v8::Isolate* isolate,
74
+ bool* received_signal = nullptr);
75
+ ~SigintWatchdog();
76
+ v8::Isolate* isolate() { return isolate_; }
77
+ SignalPropagation HandleSigint() override;
78
+
79
+ private:
80
+ v8::Isolate* isolate_;
81
+ bool* received_signal_;
82
+ };
83
+
84
+ class TraceSigintWatchdog : public HandleWrap, public SigintWatchdogBase {
85
+ public:
86
+ static void Init(Environment* env, v8::Local<v8::Object> target);
87
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
88
+ static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
89
+ static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args);
90
+
91
+ SignalPropagation HandleSigint() override;
92
+
93
+ inline void MemoryInfo(node::MemoryTracker* tracker) const override {
94
+ tracker->TrackInlineField("handle_", handle_);
95
+ }
96
+ SET_MEMORY_INFO_NAME(TraceSigintWatchdog)
97
+ SET_SELF_SIZE(TraceSigintWatchdog)
98
+
99
+ private:
100
+ enum class SignalFlags { None, FromIdle, FromInterrupt };
101
+
102
+ TraceSigintWatchdog(Environment* env, v8::Local<v8::Object> object);
103
+ void HandleInterrupt();
104
+
105
+ bool interrupting = false;
106
+ uv_async_t handle_;
107
+ SignalFlags signal_flag_ = SignalFlags::None;
108
+ };
109
+
110
+ class SigintWatchdogHelper {
111
+ public:
112
+ static SigintWatchdogHelper* GetInstance() { return &instance; }
113
+ static Mutex& GetInstanceActionMutex() { return instance_action_mutex_; }
114
+ void Register(SigintWatchdogBase* watchdog);
115
+ void Unregister(SigintWatchdogBase* watchdog);
116
+ bool HasPendingSignal();
117
+
118
+ int Start();
119
+ bool Stop();
120
+
121
+ private:
122
+ SigintWatchdogHelper();
123
+ ~SigintWatchdogHelper();
124
+
125
+ static bool InformWatchdogsAboutSignal();
126
+ static SigintWatchdogHelper instance;
127
+ static Mutex instance_action_mutex_;
128
+
129
+ int start_stop_count_;
130
+
131
+ Mutex mutex_;
132
+ Mutex list_mutex_;
133
+ std::vector<SigintWatchdogBase*> watchdogs_;
134
+ bool has_pending_signal_;
135
+
136
+ #ifdef __POSIX__
137
+ pthread_t thread_;
138
+ uv_sem_t sem_;
139
+ bool has_running_thread_;
140
+ bool stopping_;
141
+
142
+ static void* RunSigintWatchdog(void* arg);
143
+ static void HandleSignal(int signum, siginfo_t* info, void* ucontext);
144
+ #else
145
+ bool watchdog_disabled_;
146
+ static BOOL WINAPI WinCtrlCHandlerRoutine(DWORD dwCtrlType);
147
+ #endif
148
+ };
149
+
150
+ } // namespace node
151
+
152
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
153
+
154
+ #endif // SRC_NODE_WATCHDOG_H_
@@ -0,0 +1,60 @@
1
+ #ifndef SRC_NODE_WEBSTORAGE_H_
2
+ #define SRC_NODE_WEBSTORAGE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "base_object.h"
7
+ #include "node_mem.h"
8
+ #include "sqlite3.h"
9
+ #include "util.h"
10
+
11
+ namespace node {
12
+ namespace webstorage {
13
+
14
+ struct conn_deleter {
15
+ void operator()(sqlite3* conn) const noexcept {
16
+ CHECK_EQ(sqlite3_close(conn), SQLITE_OK);
17
+ }
18
+ };
19
+ using conn_unique_ptr = std::unique_ptr<sqlite3, conn_deleter>;
20
+
21
+ struct stmt_deleter {
22
+ void operator()(sqlite3_stmt* stmt) const noexcept { sqlite3_finalize(stmt); }
23
+ };
24
+ using stmt_unique_ptr = std::unique_ptr<sqlite3_stmt, stmt_deleter>;
25
+
26
+ static constexpr std::string_view kInMemoryPath = ":memory:";
27
+
28
+ class Storage : public BaseObject {
29
+ public:
30
+ Storage(Environment* env,
31
+ v8::Local<v8::Object> object,
32
+ std::string_view location);
33
+ void MemoryInfo(MemoryTracker* tracker) const override;
34
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
35
+
36
+ v8::Maybe<void> Clear();
37
+ v8::MaybeLocal<v8::Array> Enumerate();
38
+ v8::MaybeLocal<v8::Value> Length();
39
+ v8::MaybeLocal<v8::Value> Load(v8::Local<v8::Name> key);
40
+ v8::MaybeLocal<v8::Value> LoadKey(const int index);
41
+ v8::Maybe<void> Remove(v8::Local<v8::Name> key);
42
+ v8::Maybe<void> Store(v8::Local<v8::Name> key, v8::Local<v8::Value> value);
43
+
44
+ SET_MEMORY_INFO_NAME(Storage)
45
+ SET_SELF_SIZE(Storage)
46
+
47
+ private:
48
+ v8::Maybe<void> Open();
49
+
50
+ ~Storage() override;
51
+ std::string location_;
52
+ conn_unique_ptr db_;
53
+ v8::Global<v8::Map> symbols_;
54
+ };
55
+
56
+ } // namespace webstorage
57
+ } // namespace node
58
+
59
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
60
+ #endif // SRC_NODE_WEBSTORAGE_H_
@@ -0,0 +1,159 @@
1
+ #ifndef SRC_NODE_WORKER_H_
2
+ #define SRC_NODE_WORKER_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <optional>
7
+ #include <unordered_map>
8
+ #include "node_exit_code.h"
9
+ #include "node_messaging.h"
10
+ #include "uv.h"
11
+
12
+ namespace node {
13
+
14
+ struct SnapshotData;
15
+ namespace worker {
16
+
17
+ class WorkerThreadData;
18
+
19
+ enum ResourceLimits {
20
+ kMaxYoungGenerationSizeMb,
21
+ kMaxOldGenerationSizeMb,
22
+ kCodeRangeSizeMb,
23
+ kStackSizeMb,
24
+ kTotalResourceLimitCount
25
+ };
26
+
27
+ // A worker thread, as represented in its parent thread.
28
+ class Worker : public AsyncWrap {
29
+ public:
30
+ Worker(Environment* env,
31
+ v8::Local<v8::Object> wrap,
32
+ const std::string& url,
33
+ const std::string& name,
34
+ std::shared_ptr<PerIsolateOptions> per_isolate_opts,
35
+ std::vector<std::string>&& exec_argv,
36
+ std::shared_ptr<KVStore> env_vars,
37
+ const SnapshotData* snapshot_data,
38
+ const bool is_internal);
39
+ ~Worker() override;
40
+
41
+ // Run the worker. This is only called from the worker thread.
42
+ void Run();
43
+
44
+ // Forcibly exit the thread with a specified exit code. This may be called
45
+ // from any thread. `error_code` and `error_message` can be used to create
46
+ // a custom `'error'` event before emitting `'exit'`.
47
+ void Exit(ExitCode code,
48
+ const char* error_code = nullptr,
49
+ const char* error_message = nullptr);
50
+
51
+ // Wait for the worker thread to stop (in a blocking manner).
52
+ void JoinThread();
53
+
54
+ template <typename Fn>
55
+ inline bool RequestInterrupt(Fn&& cb);
56
+
57
+ SET_NO_MEMORY_INFO()
58
+ SET_MEMORY_INFO_NAME(Worker)
59
+ SET_SELF_SIZE(Worker)
60
+ bool IsNotIndicativeOfMemoryLeakAtExit() const override;
61
+
62
+ bool is_stopped() const;
63
+ const SnapshotData* snapshot_data() const { return snapshot_data_; }
64
+ bool is_internal() const { return is_internal_; }
65
+ std::string_view name() const { return name_; }
66
+
67
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
68
+ static void CloneParentEnvVars(
69
+ const v8::FunctionCallbackInfo<v8::Value>& args);
70
+ static void SetEnvVars(const v8::FunctionCallbackInfo<v8::Value>& args);
71
+ static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args);
72
+ static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args);
73
+ static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
74
+ static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
75
+ static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
76
+ static void GetResourceLimits(
77
+ const v8::FunctionCallbackInfo<v8::Value>& args);
78
+ v8::Local<v8::Float64Array> GetResourceLimits(v8::Isolate* isolate) const;
79
+ static void TakeHeapSnapshot(const v8::FunctionCallbackInfo<v8::Value>& args);
80
+ static void LoopIdleTime(const v8::FunctionCallbackInfo<v8::Value>& args);
81
+ static void LoopStartTime(const v8::FunctionCallbackInfo<v8::Value>& args);
82
+ static void GetHeapStatistics(
83
+ const v8::FunctionCallbackInfo<v8::Value>& args);
84
+ static void CpuUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
85
+
86
+ private:
87
+ bool CreateEnvMessagePort(Environment* env);
88
+ static size_t NearHeapLimit(void* data, size_t current_heap_limit,
89
+ size_t initial_heap_limit);
90
+
91
+ std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
92
+ std::vector<std::string> exec_argv_;
93
+ std::vector<std::string> argv_;
94
+
95
+ MultiIsolatePlatform* platform_;
96
+ v8::Isolate* isolate_ = nullptr;
97
+ std::optional<uv_thread_t> tid_; // Set while the thread is running
98
+
99
+ std::unique_ptr<InspectorParentHandle> inspector_parent_handle_;
100
+
101
+ // This mutex protects access to all variables listed below it.
102
+ mutable Mutex mutex_;
103
+
104
+ const char* custom_error_ = nullptr;
105
+ std::string custom_error_str_;
106
+ ExitCode exit_code_ = ExitCode::kNoFailure;
107
+ ThreadId thread_id_;
108
+ uintptr_t stack_base_ = 0;
109
+ // Optional name used for debugging in inspector and trace events.
110
+ std::string name_;
111
+
112
+ // Custom resource constraints:
113
+ double resource_limits_[kTotalResourceLimitCount];
114
+ void UpdateResourceConstraints(v8::ResourceConstraints* constraints);
115
+
116
+ // Full size of the thread's stack.
117
+ size_t stack_size_ = 4 * 1024 * 1024;
118
+ // Stack buffer size that is not available to the JS engine.
119
+ static constexpr size_t kStackBufferSize = 192 * 1024;
120
+
121
+ std::unique_ptr<MessagePortData> child_port_data_;
122
+ std::shared_ptr<KVStore> env_vars_;
123
+ EmbedderPreloadCallback embedder_preload_;
124
+
125
+ // A raw flag that is used by creator and worker threads to
126
+ // sync up on pre-mature termination of worker - while in the
127
+ // warmup phase. Once the worker is fully warmed up, use the
128
+ // async handle of the worker's Environment for the same purpose.
129
+ bool stopped_ = true;
130
+
131
+ bool has_ref_ = true;
132
+ uint64_t environment_flags_ = EnvironmentFlags::kNoFlags;
133
+
134
+ // The real Environment of the worker object. It has a lesser
135
+ // lifespan than the worker object itself - comes to life
136
+ // when the worker thread creates a new Environment, and gets
137
+ // destroyed alongwith the worker thread.
138
+ Environment* env_ = nullptr;
139
+
140
+ const SnapshotData* snapshot_data_ = nullptr;
141
+ const bool is_internal_;
142
+ friend class WorkerThreadData;
143
+ };
144
+
145
+ template <typename Fn>
146
+ bool Worker::RequestInterrupt(Fn&& cb) {
147
+ Mutex::ScopedLock lock(mutex_);
148
+ if (env_ == nullptr) return false;
149
+ env_->RequestInterrupt(std::move(cb));
150
+ return true;
151
+ }
152
+
153
+ } // namespace worker
154
+ } // namespace node
155
+
156
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
157
+
158
+
159
+ #endif // SRC_NODE_WORKER_H_