@encharm/cws 4.5.3 → 4.6.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.
Files changed (288) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/CLAUDE.md +81 -0
  3. package/README.md +10 -3
  4. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  8. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  12. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  16. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  20. package/package.json +1 -1
  21. package/src/Addon.cpp +2 -1
  22. package/src/Addon.h +70 -14
  23. package/src/Hub.h +1 -0
  24. package/src/Networking.h +11 -0
  25. package/src/Socket.h +201 -6
  26. package/src/WebSocket.cpp +4 -1
  27. package/src/cSNode.cpp +2 -0
  28. package/src/cSNode.h +4 -0
  29. package/src/headers/26/acorn_version.h +6 -0
  30. package/src/headers/26/aliased_buffer-inl.h +264 -0
  31. package/src/headers/26/aliased_buffer.h +205 -0
  32. package/src/headers/26/aliased_struct-inl.h +143 -0
  33. package/src/headers/26/aliased_struct.h +248 -0
  34. package/src/headers/26/amaro_version.h +6 -0
  35. package/src/headers/26/async_context_frame.h +33 -0
  36. package/src/headers/26/async_wrap-inl.h +123 -0
  37. package/src/headers/26/async_wrap.h +254 -0
  38. package/src/headers/26/base_object-inl.h +333 -0
  39. package/src/headers/26/base_object.h +339 -0
  40. package/src/headers/26/base_object_types.h +76 -0
  41. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  42. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  43. package/src/headers/26/builtin_info.h +57 -0
  44. package/src/headers/26/callback_queue-inl.h +97 -0
  45. package/src/headers/26/callback_queue.h +79 -0
  46. package/src/headers/26/cares_wrap.h +475 -0
  47. package/src/headers/26/cleanup_queue-inl.h +36 -0
  48. package/src/headers/26/cleanup_queue.h +79 -0
  49. package/src/headers/26/compile_cache.h +134 -0
  50. package/src/headers/26/connect_wrap.h +26 -0
  51. package/src/headers/26/connection_wrap.h +30 -0
  52. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  53. package/src/headers/26/cppgc_helpers.h +162 -0
  54. package/src/headers/26/crypto/crypto_aes.h +107 -0
  55. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  56. package/src/headers/26/crypto/crypto_bio.h +193 -0
  57. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  58. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  59. package/src/headers/26/crypto/crypto_common.h +48 -0
  60. package/src/headers/26/crypto/crypto_context.h +219 -0
  61. package/src/headers/26/crypto/crypto_dh.h +104 -0
  62. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  63. package/src/headers/26/crypto/crypto_ec.h +102 -0
  64. package/src/headers/26/crypto/crypto_hash.h +157 -0
  65. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  66. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  67. package/src/headers/26/crypto/crypto_kem.h +131 -0
  68. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  69. package/src/headers/26/crypto/crypto_keys.h +366 -0
  70. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  71. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  72. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  73. package/src/headers/26/crypto/crypto_random.h +127 -0
  74. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  75. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  76. package/src/headers/26/crypto/crypto_sig.h +159 -0
  77. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  78. package/src/headers/26/crypto/crypto_timing.h +20 -0
  79. package/src/headers/26/crypto/crypto_tls.h +342 -0
  80. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  81. package/src/headers/26/crypto/crypto_util.h +775 -0
  82. package/src/headers/26/crypto/crypto_x509.h +140 -0
  83. package/src/headers/26/dataqueue/queue.h +311 -0
  84. package/src/headers/26/debug_utils-inl.h +291 -0
  85. package/src/headers/26/debug_utils.h +200 -0
  86. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  87. package/src/headers/26/embedded_data.h +17 -0
  88. package/src/headers/26/encoding_binding.h +59 -0
  89. package/src/headers/26/env-inl.h +956 -0
  90. package/src/headers/26/env.h +1294 -0
  91. package/src/headers/26/env_properties.h +562 -0
  92. package/src/headers/26/ffi/data.h +30 -0
  93. package/src/headers/26/ffi/fast.h +96 -0
  94. package/src/headers/26/ffi/jit_memory.h +26 -0
  95. package/src/headers/26/ffi/types.h +99 -0
  96. package/src/headers/26/handle_wrap.h +123 -0
  97. package/src/headers/26/histogram-inl.h +211 -0
  98. package/src/headers/26/histogram.h +474 -0
  99. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  100. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  101. package/src/headers/26/inspector/io_agent.h +30 -0
  102. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  103. package/src/headers/26/inspector/network_agent.h +110 -0
  104. package/src/headers/26/inspector/network_inspector.h +45 -0
  105. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  106. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  107. package/src/headers/26/inspector/node_json.h +24 -0
  108. package/src/headers/26/inspector/node_string.h +101 -0
  109. package/src/headers/26/inspector/notification_emitter.h +38 -0
  110. package/src/headers/26/inspector/protocol_helper.h +27 -0
  111. package/src/headers/26/inspector/runtime_agent.h +41 -0
  112. package/src/headers/26/inspector/storage_agent.h +33 -0
  113. package/src/headers/26/inspector/target_agent.h +59 -0
  114. package/src/headers/26/inspector/target_manager.h +70 -0
  115. package/src/headers/26/inspector/tracing_agent.h +43 -0
  116. package/src/headers/26/inspector/worker_agent.h +40 -0
  117. package/src/headers/26/inspector/worker_inspector.h +124 -0
  118. package/src/headers/26/inspector_agent.h +168 -0
  119. package/src/headers/26/inspector_io.h +78 -0
  120. package/src/headers/26/inspector_profiler.h +149 -0
  121. package/src/headers/26/inspector_socket.h +60 -0
  122. package/src/headers/26/inspector_socket_server.h +110 -0
  123. package/src/headers/26/js_native_api.h +634 -0
  124. package/src/headers/26/js_native_api_types.h +244 -0
  125. package/src/headers/26/js_native_api_v8.h +485 -0
  126. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  127. package/src/headers/26/js_stream.h +57 -0
  128. package/src/headers/26/json_utils.h +172 -0
  129. package/src/headers/26/large_pages/node_large_page.h +34 -0
  130. package/src/headers/26/lru_cache-inl.h +69 -0
  131. package/src/headers/26/memory_tracker-inl.h +461 -0
  132. package/src/headers/26/memory_tracker.h +341 -0
  133. package/src/headers/26/module_wrap.h +231 -0
  134. package/src/headers/26/ncrypto.h +2008 -0
  135. package/src/headers/26/node.h +1693 -0
  136. package/src/headers/26/node_api.h +265 -0
  137. package/src/headers/26/node_api_internals.h +48 -0
  138. package/src/headers/26/node_api_types.h +58 -0
  139. package/src/headers/26/node_binding.h +170 -0
  140. package/src/headers/26/node_blob.h +160 -0
  141. package/src/headers/26/node_bob-inl.h +36 -0
  142. package/src/headers/26/node_bob.h +107 -0
  143. package/src/headers/26/node_buffer.h +92 -0
  144. package/src/headers/26/node_builtins.h +239 -0
  145. package/src/headers/26/node_concepts.h +46 -0
  146. package/src/headers/26/node_config_file.h +77 -0
  147. package/src/headers/26/node_constants.h +82 -0
  148. package/src/headers/26/node_context_data.h +171 -0
  149. package/src/headers/26/node_contextify.h +261 -0
  150. package/src/headers/26/node_crypto.h +66 -0
  151. package/src/headers/26/node_debug.h +30 -0
  152. package/src/headers/26/node_diagnostics_channel.h +121 -0
  153. package/src/headers/26/node_dir.h +52 -0
  154. package/src/headers/26/node_dotenv.h +45 -0
  155. package/src/headers/26/node_errors.h +378 -0
  156. package/src/headers/26/node_exit_code.h +54 -0
  157. package/src/headers/26/node_external_reference.h +171 -0
  158. package/src/headers/26/node_ffi.h +212 -0
  159. package/src/headers/26/node_file-inl.h +421 -0
  160. package/src/headers/26/node_file.h +561 -0
  161. package/src/headers/26/node_file_utils.h +39 -0
  162. package/src/headers/26/node_hash.h +212 -0
  163. package/src/headers/26/node_http2.h +1202 -0
  164. package/src/headers/26/node_http2_state.h +159 -0
  165. package/src/headers/26/node_http_common-inl.h +199 -0
  166. package/src/headers/26/node_http_common.h +535 -0
  167. package/src/headers/26/node_i18n.h +132 -0
  168. package/src/headers/26/node_internals.h +485 -0
  169. package/src/headers/26/node_locks.h +184 -0
  170. package/src/headers/26/node_main_instance.h +67 -0
  171. package/src/headers/26/node_mem-inl.h +113 -0
  172. package/src/headers/26/node_mem.h +45 -0
  173. package/src/headers/26/node_messaging.h +389 -0
  174. package/src/headers/26/node_metadata.h +172 -0
  175. package/src/headers/26/node_modules.h +102 -0
  176. package/src/headers/26/node_mutex.h +323 -0
  177. package/src/headers/26/node_object_wrap.h +145 -0
  178. package/src/headers/26/node_options-inl.h +524 -0
  179. package/src/headers/26/node_options.h +710 -0
  180. package/src/headers/26/node_perf.h +167 -0
  181. package/src/headers/26/node_perf_common.h +103 -0
  182. package/src/headers/26/node_platform.h +290 -0
  183. package/src/headers/26/node_process-inl.h +26 -0
  184. package/src/headers/26/node_process.h +112 -0
  185. package/src/headers/26/node_profiling.h +38 -0
  186. package/src/headers/26/node_realm-inl.h +156 -0
  187. package/src/headers/26/node_realm.h +236 -0
  188. package/src/headers/26/node_report.h +43 -0
  189. package/src/headers/26/node_revert.h +82 -0
  190. package/src/headers/26/node_root_certs.h +2937 -0
  191. package/src/headers/26/node_sea.h +101 -0
  192. package/src/headers/26/node_shadow_realm.h +46 -0
  193. package/src/headers/26/node_snapshot_builder.h +57 -0
  194. package/src/headers/26/node_snapshotable.h +167 -0
  195. package/src/headers/26/node_sockaddr-inl.h +248 -0
  196. package/src/headers/26/node_sockaddr.h +459 -0
  197. package/src/headers/26/node_sqlite.h +607 -0
  198. package/src/headers/26/node_stat_watcher.h +73 -0
  199. package/src/headers/26/node_task_runner.h +92 -0
  200. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  201. package/src/headers/26/node_threadsafe_cow.h +105 -0
  202. package/src/headers/26/node_union_bytes.h +81 -0
  203. package/src/headers/26/node_url.h +101 -0
  204. package/src/headers/26/node_url_pattern.h +118 -0
  205. package/src/headers/26/node_v8.h +78 -0
  206. package/src/headers/26/node_v8_embedder.h +26 -0
  207. package/src/headers/26/node_v8_platform-inl.h +96 -0
  208. package/src/headers/26/node_version.h +116 -0
  209. package/src/headers/26/node_wasi.h +184 -0
  210. package/src/headers/26/node_wasm_web_api.h +55 -0
  211. package/src/headers/26/node_watchdog.h +164 -0
  212. package/src/headers/26/node_webstorage.h +62 -0
  213. package/src/headers/26/node_worker.h +162 -0
  214. package/src/headers/26/path.h +36 -0
  215. package/src/headers/26/permission/boolean_permission.h +50 -0
  216. package/src/headers/26/permission/fs_permission.h +192 -0
  217. package/src/headers/26/permission/permission.h +155 -0
  218. package/src/headers/26/permission/permission_base.h +79 -0
  219. package/src/headers/26/pipe_wrap.h +80 -0
  220. package/src/headers/26/quic/application.h +279 -0
  221. package/src/headers/26/quic/arena.h +373 -0
  222. package/src/headers/26/quic/bindingdata.h +440 -0
  223. package/src/headers/26/quic/cid.h +127 -0
  224. package/src/headers/26/quic/data.h +358 -0
  225. package/src/headers/26/quic/defs.h +417 -0
  226. package/src/headers/26/quic/endpoint.h +519 -0
  227. package/src/headers/26/quic/guard.h +5 -0
  228. package/src/headers/26/quic/http3.h +25 -0
  229. package/src/headers/26/quic/packet.h +166 -0
  230. package/src/headers/26/quic/preferredaddress.h +72 -0
  231. package/src/headers/26/quic/session.h +770 -0
  232. package/src/headers/26/quic/session_manager.h +107 -0
  233. package/src/headers/26/quic/sessionticket.h +110 -0
  234. package/src/headers/26/quic/streams.h +518 -0
  235. package/src/headers/26/quic/tlscontext.h +353 -0
  236. package/src/headers/26/quic/tokens.h +263 -0
  237. package/src/headers/26/quic/transportparams.h +184 -0
  238. package/src/headers/26/req_wrap-inl.h +175 -0
  239. package/src/headers/26/req_wrap.h +79 -0
  240. package/src/headers/26/spawn_sync.h +243 -0
  241. package/src/headers/26/stream_base-inl.h +170 -0
  242. package/src/headers/26/stream_base.h +487 -0
  243. package/src/headers/26/stream_pipe.h +76 -0
  244. package/src/headers/26/stream_wrap.h +137 -0
  245. package/src/headers/26/string_bytes.h +114 -0
  246. package/src/headers/26/string_decoder-inl.h +31 -0
  247. package/src/headers/26/string_decoder.h +49 -0
  248. package/src/headers/26/tcp_wrap.h +138 -0
  249. package/src/headers/26/threadpoolwork-inl.h +70 -0
  250. package/src/headers/26/timer_wrap-inl.h +32 -0
  251. package/src/headers/26/timer_wrap.h +87 -0
  252. package/src/headers/26/timers.h +70 -0
  253. package/src/headers/26/tracing/agent.h +125 -0
  254. package/src/headers/26/tracing/agent_legacy.h +146 -0
  255. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  256. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  257. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  258. package/src/headers/26/tracing/trace_event.h +27 -0
  259. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  260. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  261. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  262. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  263. package/src/headers/26/tracing/traced_value.h +167 -0
  264. package/src/headers/26/tty_wrap.h +65 -0
  265. package/src/headers/26/udp_wrap.h +231 -0
  266. package/src/headers/26/undici_version.h +6 -0
  267. package/src/headers/26/util-inl.h +788 -0
  268. package/src/headers/26/util.h +1207 -0
  269. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  270. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  271. package/src/headers/26/v8-fast-api-calls.h +784 -0
  272. package/src/headers/26/v8-inspector-protocol.h +13 -0
  273. package/src/headers/26/v8-inspector.h +458 -0
  274. package/src/headers/26/v8-metrics.h +273 -0
  275. package/src/headers/26/v8-trace-categories.h +28 -0
  276. package/src/headers/26/v8-unwinder-state.h +30 -0
  277. package/src/headers/26/v8-util.h +549 -0
  278. package/src/headers/26/v8-value-serializer-version.h +24 -0
  279. package/src/headers/26/v8-version-string.h +38 -0
  280. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  281. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  282. package/src/headers/26/zlib_version.h +6 -0
  283. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
  284. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
  285. package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
  286. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
  287. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
  288. package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
@@ -0,0 +1,96 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #include "ffi.h"
6
+ #include "v8-fast-api-calls.h"
7
+
8
+ #include <cstddef>
9
+ #include <cstdint>
10
+ #include <memory>
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ namespace node::ffi {
15
+
16
+ struct FFIFunction;
17
+
18
+ enum class FastFFIType : uint8_t {
19
+ kVoid,
20
+ kInt8,
21
+ kUint8,
22
+ kInt16,
23
+ kUint16,
24
+ kInt32,
25
+ kUint32,
26
+ kInt64,
27
+ kUint64,
28
+ kFloat32,
29
+ kFloat64,
30
+ kPointer,
31
+ kBuffer,
32
+ };
33
+
34
+ struct FastFFITrampoline {
35
+ void* code = nullptr;
36
+ size_t size = 0;
37
+ };
38
+
39
+ struct FastFFITrampolineConfig {
40
+ void* target;
41
+ const bool* closed;
42
+ v8::Isolate* isolate;
43
+ };
44
+
45
+ struct FastFFIMetadata {
46
+ FastFFIMetadata() = default;
47
+ ~FastFFIMetadata();
48
+
49
+ FastFFIMetadata(const FastFFIMetadata&) = delete;
50
+ FastFFIMetadata& operator=(const FastFFIMetadata&) = delete;
51
+
52
+ FastFFITrampoline trampoline;
53
+ std::vector<v8::CTypeInfo> arg_info;
54
+ std::unique_ptr<v8::CFunctionInfo> c_function_info;
55
+ v8::CFunction c_function;
56
+ bool guards_library = false;
57
+ };
58
+
59
+ // Public detection queries.
60
+
61
+ // Returns true if the fast-call path is available at all on this process
62
+ // (platform stub emitter exists + JIT memory self-test passed). Independent
63
+ // of any particular signature — if this returns false, no signature can
64
+ // use the fast-call path.
65
+ bool IsFastCallSupported();
66
+ bool IsFastLibraryGuardSupported();
67
+
68
+ bool SignatureNeedsRawPointerConversions(const FFIFunction& fn);
69
+ bool SignatureNeedsFastIntegerValidation(const FFIFunction& fn);
70
+ bool IsPointerTypeName(const std::string& name);
71
+ bool SignatureNeedsFastBufferInvoke(const FFIFunction& fn);
72
+ std::shared_ptr<FFIFunction> CloneWithRawPointerArgNames(
73
+ const std::shared_ptr<FFIFunction>& fn);
74
+ std::shared_ptr<FFIFunction> CloneWithFastBufferArgNames(
75
+ const std::shared_ptr<FFIFunction>& fn);
76
+ std::unique_ptr<FastFFIMetadata> CreateFastFFIMetadata(const FFIFunction& fn,
77
+ const bool* closed,
78
+ v8::Isolate* isolate);
79
+
80
+ } // namespace node::ffi
81
+
82
+ extern "C" {
83
+ uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
84
+ v8::FastApiCallbackOptions* options,
85
+ uint32_t index);
86
+ void node_ffi_fast_library_closed(v8::Isolate* isolate);
87
+ bool node_ffi_create_fast_trampoline(
88
+ const node::ffi::FastFFITrampolineConfig& config,
89
+ const node::ffi::FastFFIType* args,
90
+ size_t argc,
91
+ node::ffi::FastFFIType result,
92
+ node::ffi::FastFFITrampoline* out);
93
+ void node_ffi_free_fast_trampoline(node::ffi::FastFFITrampoline* trampoline);
94
+ }
95
+
96
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ namespace node::ffi {
6
+
7
+ // Returns true if executable memory allocation (mmap + mprotect to RX) works
8
+ // on this process. Runs a one-time self-test that allocates a tiny stub,
9
+ // writes a ret-style instruction, and transitions it to RX. The page is not
10
+ // executed: a successful RX transition is the support signal, and executing a
11
+ // freshly generated probe could crash the process on systems that block it.
12
+ //
13
+ // Catches:
14
+ // - macOS MAP_JIT entitlement missing
15
+ // - Hardened-runtime restrictions
16
+ // - SELinux execmem denial
17
+ // - Other OS-level restrictions on executable memory
18
+ //
19
+ // The self-test runs exactly once (std::call_once) and the result is cached
20
+ // process-wide. Subsequent calls return the cached value without re-running
21
+ // the test.
22
+ bool IsJitMemorySupported();
23
+
24
+ } // namespace node::ffi
25
+
26
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,99 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #include "base_object.h"
6
+ #include "ffi.h"
7
+
8
+ #include <cstdint>
9
+ #include <string>
10
+ #include <vector>
11
+
12
+ namespace node::ffi {
13
+
14
+ struct FFIFunction;
15
+
16
+ bool ThrowIfContainsNullBytes(Environment* env,
17
+ const Utf8Value& value,
18
+ std::string_view label);
19
+
20
+ struct FunctionSignature {
21
+ ffi_type* return_type;
22
+ std::vector<ffi_type*> args;
23
+ std::string return_type_name;
24
+ std::vector<std::string> arg_type_names;
25
+ };
26
+ v8::Maybe<FunctionSignature> ParseFunctionSignature(
27
+ Environment* env, std::string_view name, v8::Local<v8::Object> signature);
28
+
29
+ v8::Maybe<ffi_type*> ToFFIType(Environment* env, std::string_view type_str);
30
+
31
+ enum class FFIArgumentCategory {
32
+ Regular,
33
+ String,
34
+ };
35
+ v8::Maybe<FFIArgumentCategory> ToFFIArgument(Environment* env,
36
+ unsigned int index,
37
+ ffi_type* type,
38
+ v8::Local<v8::Value> arg,
39
+ void* ret);
40
+
41
+ v8::Local<v8::Value> ToJSArgument(v8::Isolate* isolate,
42
+ ffi_type* type,
43
+ void* data);
44
+
45
+ bool ToJSReturnValue(Environment* env,
46
+ const v8::FunctionCallbackInfo<v8::Value>& args,
47
+ ffi_type* type,
48
+ void* result);
49
+
50
+ bool ToFFIReturnValue(v8::Local<v8::Value> result, ffi_type* type, void* ret);
51
+
52
+ bool SignaturesMatch(const FFIFunction& fn,
53
+ ffi_type* return_type,
54
+ const std::vector<ffi_type*>& args);
55
+
56
+ // Returns true if `fn` can be invoked via the V8 fast-call path. On
57
+ // false, `*out_reason` is set to a static string describing why
58
+ // (never null after this returns; callers may pass nullptr to ignore).
59
+ //
60
+ // Eligibility checks: every arg type and the return type are
61
+ // numeric-or-pointer, no `function`-typed args/return, arg count
62
+ // within V8 fast-call cap (8), and register-passed arg counts within
63
+ // per-ABI limits. Trampoline emitters currently exist for AArch64
64
+ // (≤ 7 GP + ≤ 8 FP), x86_64 SysV (≤ 6 GP + ≤ 8 FP; buffer args cap GP at 5 and
65
+ // cannot coexist with FP args), Win64 x64 (≤ 3 register-only scalar args), and
66
+ // PPC64LE ELFv2, LoongArch64, and RISC-V 64 (≤ 7 GP + ≤ 8 FP scalar args, no
67
+ // narrow returns), and s390x (≤ 4 GP + ≤ 4 FP scalar args, no narrow returns).
68
+ // Platforms without an emitter are reported ineligible so the caller falls back
69
+ // to libffi.
70
+ bool IsFastCallEligible(const FFIFunction& fn, const char** out_reason);
71
+
72
+ // True if the FFI type can be read from / written to a raw byte buffer
73
+ // without needing V8 operations (conversion, allocation, etc.).
74
+ bool IsSBEligibleFFIType(ffi_type* type);
75
+
76
+ // True if the signature's return type and all argument types are SB-eligible.
77
+ bool IsSBEligibleSignature(const FFIFunction& fn);
78
+
79
+ // True if any argument is pointer-typed. For these, the JS wrapper must
80
+ // do a runtime type check to decide fast vs. slow path per call.
81
+ bool SignatureHasPointerArgs(const FFIFunction& fn);
82
+
83
+ // Read a value of the given FFI type from buffer at the given byte offset
84
+ // into the output pointer (sized as uint64_t to hold any numeric type).
85
+ void ReadFFIArgFromBuffer(ffi_type* type,
86
+ const uint8_t* buffer,
87
+ size_t offset,
88
+ void* out);
89
+
90
+ // Write a return value of the given FFI type from the ffi_call result
91
+ // into the buffer at the given byte offset.
92
+ void WriteFFIReturnToBuffer(ffi_type* type,
93
+ const void* result,
94
+ uint8_t* buffer,
95
+ size_t offset);
96
+
97
+ } // namespace node::ffi
98
+
99
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,123 @@
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_HANDLE_WRAP_H_
23
+ #define SRC_HANDLE_WRAP_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "async_wrap.h"
28
+ #include "util.h"
29
+ #include "uv.h"
30
+ #include "v8.h"
31
+
32
+ namespace node {
33
+
34
+ class Environment;
35
+ class ExternalReferenceRegistry;
36
+
37
+ // Rules:
38
+ //
39
+ // - Do not throw from handle methods. Set errno.
40
+ //
41
+ // - MakeCallback may only be made directly off the event loop.
42
+ // That is there can be no JavaScript stack frames underneath it.
43
+ // (Is there any way to assert that?)
44
+ //
45
+ // - No use of v8::WeakReferenceCallback. The close callback signifies that
46
+ // we're done with a handle - external resources can be freed.
47
+ //
48
+ // - Reusable?
49
+ //
50
+ // - The uv_close_cb is used to free the c++ object. The close callback
51
+ // is not made into javascript land.
52
+ //
53
+ // - uv_ref, uv_unref counts are managed at this layer to avoid needless
54
+ // js/c++ boundary crossing. At the javascript layer that should all be
55
+ // taken care of.
56
+
57
+ class HandleWrap : public AsyncWrap {
58
+ public:
59
+ static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
60
+ static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
61
+ static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
62
+ static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
63
+
64
+ static inline bool IsAlive(const HandleWrap* wrap) {
65
+ return wrap != nullptr &&
66
+ wrap->IsDoneInitializing() &&
67
+ wrap->state_ != kClosed;
68
+ }
69
+
70
+ static inline bool HasRef(const HandleWrap* wrap) {
71
+ return IsAlive(wrap) && uv_has_ref(wrap->GetHandle());
72
+ }
73
+
74
+ inline uv_handle_t* GetHandle() const { return handle_; }
75
+
76
+ virtual void Close(
77
+ v8::Local<v8::Value> close_callback = v8::Local<v8::Value>());
78
+
79
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
80
+ IsolateData* isolate_data);
81
+ static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
82
+ Environment* env);
83
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
84
+
85
+ protected:
86
+ HandleWrap(Environment* env,
87
+ v8::Local<v8::Object> object,
88
+ uv_handle_t* handle,
89
+ AsyncWrap::ProviderType provider);
90
+ virtual void OnClose() {}
91
+ void OnGCCollect() final;
92
+ bool IsNotIndicativeOfMemoryLeakAtExit() const override;
93
+
94
+ void MarkAsInitialized();
95
+ void MarkAsUninitialized();
96
+
97
+ inline bool IsHandleClosing() const {
98
+ return state_ == kClosing || state_ == kClosed;
99
+ }
100
+
101
+ static void OnClose(uv_handle_t* handle);
102
+ enum { kInitialized, kClosing, kClosed } state_;
103
+
104
+ private:
105
+ friend class Environment;
106
+ friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
107
+
108
+ // handle_wrap_queue_ needs to be at a fixed offset from the start of the
109
+ // class because it is used by src/node_postmortem_metadata.cc to calculate
110
+ // offsets and generate debug symbols for HandleWrap, which assumes that the
111
+ // position of members in memory are predictable. For more information please
112
+ // refer to `doc/contributing/node-postmortem-support.md`
113
+ friend int GenDebugSymbols();
114
+ ListNode<HandleWrap> handle_wrap_queue_;
115
+ uv_handle_t* const handle_;
116
+ };
117
+
118
+
119
+ } // namespace node
120
+
121
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
122
+
123
+ #endif // SRC_HANDLE_WRAP_H_
@@ -0,0 +1,211 @@
1
+ #ifndef SRC_HISTOGRAM_INL_H_
2
+ #define SRC_HISTOGRAM_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "histogram.h"
7
+ #include "base_object-inl.h"
8
+ #include "node_internals.h"
9
+
10
+ namespace node {
11
+
12
+ void Histogram::UpdateEwma(double value) {
13
+ // Called inside a write lock. No-op when EWMA is disabled.
14
+ if (ewma_alpha_ <= 0) return;
15
+ if (!ewma_initialized_) {
16
+ ewma_mean_ = value;
17
+ ewma_variance_ = 0;
18
+ ewma_initialized_ = true;
19
+ if (threshold_ > 0) {
20
+ ewma_error_rate_ = (value > static_cast<double>(threshold_)) ? 1.0 : 0.0;
21
+ }
22
+ return;
23
+ }
24
+ double diff = value - ewma_mean_;
25
+ ewma_mean_ += ewma_alpha_ * diff;
26
+ ewma_variance_ =
27
+ (1.0 - ewma_alpha_) * (ewma_variance_ + ewma_alpha_ * diff * diff);
28
+
29
+ // Binary EWMA for SLO error rate: feed 1 if over threshold, 0 otherwise.
30
+ if (threshold_ > 0) {
31
+ double exceeded = (value > static_cast<double>(threshold_)) ? 1.0 : 0.0;
32
+ ewma_error_rate_ += ewma_alpha_ * (exceeded - ewma_error_rate_);
33
+ }
34
+ }
35
+
36
+ void Histogram::Reset() {
37
+ RwLock::ScopedWriteLock lock(mutex_);
38
+ hdr_reset(histogram_.get());
39
+ exceeds_ = 0;
40
+ prev_ = 0;
41
+ ewma_mean_ = 0;
42
+ ewma_variance_ = 0;
43
+ ewma_error_rate_ = 0;
44
+ ewma_initialized_ = false;
45
+ }
46
+
47
+ double Histogram::Add(const Histogram& other) {
48
+ auto do_add = [&]() {
49
+ exceeds_ += other.exceeds_;
50
+ if (other.prev_ > prev_) prev_ = other.prev_;
51
+ // hdr_add merges all bucket counts and total_count internally.
52
+ return static_cast<double>(
53
+ hdr_add(histogram_.get(), other.histogram_.get()));
54
+ };
55
+
56
+ // When adding a histogram to itself, a single write lock suffices.
57
+ if (this == &other) {
58
+ RwLock::ScopedWriteLock lock(mutex_);
59
+ return do_add();
60
+ }
61
+
62
+ // Write-lock this (modified), read-lock other (only read).
63
+ // Lock in pointer order to prevent deadlock.
64
+ if (this < &other) {
65
+ RwLock::ScopedWriteLock lock1(mutex_);
66
+ RwLock::ScopedReadLock lock2(other.mutex_);
67
+ return do_add();
68
+ }
69
+
70
+ RwLock::ScopedReadLock lock1(other.mutex_);
71
+ RwLock::ScopedWriteLock lock2(mutex_);
72
+ return do_add();
73
+ }
74
+
75
+ size_t Histogram::Count() const {
76
+ RwLock::ScopedReadLock lock(mutex_);
77
+ return static_cast<size_t>(histogram_->total_count);
78
+ }
79
+
80
+ size_t Histogram::Exceeds() const {
81
+ RwLock::ScopedReadLock lock(mutex_);
82
+ return exceeds_;
83
+ }
84
+
85
+ int64_t Histogram::Min() const {
86
+ RwLock::ScopedReadLock lock(mutex_);
87
+ return hdr_min(histogram_.get());
88
+ }
89
+
90
+ int64_t Histogram::Max() const {
91
+ RwLock::ScopedReadLock lock(mutex_);
92
+ return hdr_max(histogram_.get());
93
+ }
94
+
95
+ double Histogram::Mean() const {
96
+ RwLock::ScopedReadLock lock(mutex_);
97
+ return hdr_mean(histogram_.get());
98
+ }
99
+
100
+ double Histogram::Stddev() const {
101
+ RwLock::ScopedReadLock lock(mutex_);
102
+ return hdr_stddev(histogram_.get());
103
+ }
104
+
105
+ double Histogram::EwmaMean() const {
106
+ RwLock::ScopedReadLock lock(mutex_);
107
+ return ewma_initialized_ ? ewma_mean_ : 0;
108
+ }
109
+
110
+ double Histogram::EwmaStddev() const {
111
+ RwLock::ScopedReadLock lock(mutex_);
112
+ return ewma_initialized_ ? std::sqrt(ewma_variance_) : 0;
113
+ }
114
+
115
+ double Histogram::EwmaErrorRate() const {
116
+ RwLock::ScopedReadLock lock(mutex_);
117
+ return ewma_initialized_ ? ewma_error_rate_ : 0;
118
+ }
119
+
120
+ int64_t Histogram::Percentile(double percentile) const {
121
+ RwLock::ScopedReadLock lock(mutex_);
122
+ CHECK_GT(percentile, 0);
123
+ CHECK_LE(percentile, 100);
124
+ return hdr_value_at_percentile(histogram_.get(), percentile);
125
+ }
126
+
127
+ template <typename Iterator>
128
+ void Histogram::Percentiles(Iterator&& fn) const {
129
+ RwLock::ScopedReadLock lock(mutex_);
130
+ hdr_iter iter;
131
+ hdr_iter_percentile_init(&iter, histogram_.get(), 1);
132
+ while (hdr_iter_next(&iter)) {
133
+ double key = iter.specifics.percentiles.percentile;
134
+ fn(key, iter.value);
135
+ }
136
+ }
137
+
138
+ int64_t Histogram::CountAt(int64_t value) const {
139
+ RwLock::ScopedReadLock lock(mutex_);
140
+ return hdr_count_at_value(histogram_.get(), value);
141
+ }
142
+
143
+ bool Histogram::RecordCorrected(int64_t value, int64_t expected_interval) {
144
+ RwLock::ScopedWriteLock lock(mutex_);
145
+ bool recorded =
146
+ hdr_record_corrected_value(histogram_.get(), value, expected_interval);
147
+ if (!recorded)
148
+ exceeds_++;
149
+ else
150
+ UpdateEwma(static_cast<double>(value));
151
+ return recorded;
152
+ }
153
+
154
+ bool Histogram::Record(int64_t value) {
155
+ RwLock::ScopedWriteLock lock(mutex_);
156
+ bool recorded = hdr_record_value(histogram_.get(), value);
157
+ if (!recorded)
158
+ exceeds_++;
159
+ else
160
+ UpdateEwma(static_cast<double>(value));
161
+ return recorded;
162
+ }
163
+
164
+ uint64_t Histogram::RecordDelta() {
165
+ RwLock::ScopedWriteLock lock(mutex_);
166
+ uint64_t time = uv_hrtime();
167
+ int64_t delta = 0;
168
+ if (prev_ > 0) {
169
+ CHECK_GE(time, prev_);
170
+ delta = time - prev_;
171
+ if (!hdr_record_value(histogram_.get(), delta))
172
+ exceeds_++;
173
+ else
174
+ UpdateEwma(static_cast<double>(delta));
175
+ }
176
+ prev_ = time;
177
+ return delta;
178
+ }
179
+
180
+ size_t Histogram::GetMemorySize() const {
181
+ RwLock::ScopedReadLock lock(mutex_);
182
+ return hdr_get_memory_size(histogram_.get());
183
+ }
184
+
185
+ template <typename Iterator>
186
+ void Histogram::LinearBuckets(int64_t step_size, Iterator&& fn) const {
187
+ RwLock::ScopedReadLock lock(mutex_);
188
+ hdr_iter iter;
189
+ hdr_iter_linear_init(&iter, histogram_.get(), step_size);
190
+ while (hdr_iter_next(&iter)) {
191
+ fn(iter.value, iter.specifics.linear.count_added_in_this_iteration_step);
192
+ }
193
+ }
194
+
195
+ template <typename Iterator>
196
+ void Histogram::LogBuckets(int64_t first_bucket,
197
+ double log_base,
198
+ Iterator&& fn) const {
199
+ RwLock::ScopedReadLock lock(mutex_);
200
+ hdr_iter iter;
201
+ hdr_iter_log_init(&iter, histogram_.get(), first_bucket, log_base);
202
+ while (hdr_iter_next(&iter)) {
203
+ fn(iter.value, iter.specifics.log.count_added_in_this_iteration_step);
204
+ }
205
+ }
206
+
207
+ } // namespace node
208
+
209
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
210
+
211
+ #endif // SRC_HISTOGRAM_INL_H_