@encharm/cws 4.3.0 → 4.4.1

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 (238) hide show
  1. package/README.md +5 -7
  2. package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
  3. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  4. package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
  6. package/dist/bindings/cws_darwin_x64_node108.node +0 -0
  7. package/dist/bindings/cws_darwin_x64_node115.node +0 -0
  8. package/dist/bindings/cws_darwin_x64_node83.node +0 -0
  9. package/dist/bindings/cws_darwin_x64_node93.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node108.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  12. package/dist/bindings/cws_linux_arm64_node83.node +0 -0
  13. package/dist/bindings/cws_linux_arm64_node93.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node108.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  16. package/dist/bindings/cws_linux_x64_node83.node +0 -0
  17. package/dist/bindings/cws_linux_x64_node93.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node108.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  20. package/dist/bindings/cws_win32_x64_node83.node +0 -0
  21. package/dist/bindings/cws_win32_x64_node93.node +0 -0
  22. package/dist/shared.js +1 -1
  23. package/package.json +5 -5
  24. package/src/Addon.cpp +4 -12
  25. package/src/Addon.h +67 -91
  26. package/src/Socket.h +1 -0
  27. package/src/cSNode.cpp +3 -8
  28. package/src/headers/20/acorn_version.h +6 -0
  29. package/src/headers/20/aliased_buffer-inl.h +243 -0
  30. package/src/headers/20/aliased_buffer.h +206 -0
  31. package/src/headers/20/aliased_struct-inl.h +54 -0
  32. package/src/headers/20/aliased_struct.h +63 -0
  33. package/src/headers/20/async_wrap-inl.h +93 -0
  34. package/src/headers/20/async_wrap.h +252 -0
  35. package/src/headers/20/base64-inl.h +193 -0
  36. package/src/headers/20/base64.h +53 -0
  37. package/src/headers/20/base64_version.h +6 -0
  38. package/src/headers/20/base_object-inl.h +316 -0
  39. package/src/headers/20/base_object.h +320 -0
  40. package/src/headers/20/base_object_types.h +73 -0
  41. package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
  42. package/src/headers/20/blob_serializer_deserializer.h +132 -0
  43. package/src/headers/20/callback_queue-inl.h +97 -0
  44. package/src/headers/20/callback_queue.h +79 -0
  45. package/src/headers/20/cares_wrap.h +524 -0
  46. package/src/headers/20/cjs_module_lexer_version.h +6 -0
  47. package/src/headers/20/cleanup_queue-inl.h +62 -0
  48. package/src/headers/20/cleanup_queue.h +85 -0
  49. package/src/headers/20/connect_wrap.h +26 -0
  50. package/src/headers/20/connection_wrap.h +30 -0
  51. package/src/headers/20/cppgc/DEPS +8 -0
  52. package/src/headers/20/cppgc/OWNERS +2 -0
  53. package/src/headers/20/cppgc/README.md +135 -0
  54. package/src/headers/20/cppgc/allocation.h +310 -0
  55. package/src/headers/20/cppgc/common.h +28 -0
  56. package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
  57. package/src/headers/20/cppgc/custom-space.h +97 -0
  58. package/src/headers/20/cppgc/default-platform.h +67 -0
  59. package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
  60. package/src/headers/20/cppgc/explicit-management.h +100 -0
  61. package/src/headers/20/cppgc/garbage-collected.h +106 -0
  62. package/src/headers/20/cppgc/heap-consistency.h +309 -0
  63. package/src/headers/20/cppgc/heap-handle.h +48 -0
  64. package/src/headers/20/cppgc/heap-state.h +82 -0
  65. package/src/headers/20/cppgc/heap-statistics.h +120 -0
  66. package/src/headers/20/cppgc/heap.h +202 -0
  67. package/src/headers/20/cppgc/internal/api-constants.h +68 -0
  68. package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
  69. package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
  70. package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
  71. package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
  72. package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
  73. package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
  74. package/src/headers/20/cppgc/internal/gc-info.h +157 -0
  75. package/src/headers/20/cppgc/internal/logging.h +50 -0
  76. package/src/headers/20/cppgc/internal/member-storage.h +248 -0
  77. package/src/headers/20/cppgc/internal/name-trait.h +137 -0
  78. package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
  79. package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
  80. package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
  81. package/src/headers/20/cppgc/liveness-broker.h +78 -0
  82. package/src/headers/20/cppgc/macros.h +35 -0
  83. package/src/headers/20/cppgc/member.h +604 -0
  84. package/src/headers/20/cppgc/name-provider.h +65 -0
  85. package/src/headers/20/cppgc/object-size-trait.h +58 -0
  86. package/src/headers/20/cppgc/persistent.h +373 -0
  87. package/src/headers/20/cppgc/platform.h +158 -0
  88. package/src/headers/20/cppgc/prefinalizer.h +75 -0
  89. package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
  90. package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
  91. package/src/headers/20/cppgc/source-location.h +92 -0
  92. package/src/headers/20/cppgc/testing.h +106 -0
  93. package/src/headers/20/cppgc/trace-trait.h +120 -0
  94. package/src/headers/20/cppgc/type-traits.h +250 -0
  95. package/src/headers/20/cppgc/visitor.h +426 -0
  96. package/src/headers/20/crypto/crypto_clienthello.h +131 -0
  97. package/src/headers/20/crypto/crypto_context.h +160 -0
  98. package/src/headers/20/crypto/crypto_keys.h +419 -0
  99. package/src/headers/20/crypto/crypto_tls.h +304 -0
  100. package/src/headers/20/crypto/crypto_util.h +806 -0
  101. package/src/headers/20/crypto_clienthello.h +131 -0
  102. package/src/headers/20/debug_utils-inl.h +226 -0
  103. package/src/headers/20/debug_utils.h +188 -0
  104. package/src/headers/20/diagnosticfilename-inl.h +33 -0
  105. package/src/headers/20/encoding_binding.h +59 -0
  106. package/src/headers/20/env-inl.h +923 -0
  107. package/src/headers/20/env.h +1193 -0
  108. package/src/headers/20/env_properties.h +446 -0
  109. package/src/headers/20/handle_wrap.h +123 -0
  110. package/src/headers/20/histogram-inl.h +107 -0
  111. package/src/headers/20/histogram.h +240 -0
  112. package/src/headers/20/inspector_agent.h +144 -0
  113. package/src/headers/20/inspector_io.h +78 -0
  114. package/src/headers/20/inspector_profiler.h +149 -0
  115. package/src/headers/20/inspector_socket.h +60 -0
  116. package/src/headers/20/inspector_socket_server.h +110 -0
  117. package/src/headers/20/js_native_api.h +601 -0
  118. package/src/headers/20/js_native_api_types.h +168 -0
  119. package/src/headers/20/js_native_api_v8.h +463 -0
  120. package/src/headers/20/js_native_api_v8_internals.h +45 -0
  121. package/src/headers/20/js_stream.h +52 -0
  122. package/src/headers/20/json_parser.h +38 -0
  123. package/src/headers/20/json_utils.h +172 -0
  124. package/src/headers/20/memory_tracker-inl.h +356 -0
  125. package/src/headers/20/memory_tracker.h +289 -0
  126. package/src/headers/20/module_wrap.h +117 -0
  127. package/src/headers/20/node.h +1516 -0
  128. package/src/headers/20/node_api.h +261 -0
  129. package/src/headers/20/node_api_internals.h +42 -0
  130. package/src/headers/20/node_api_types.h +52 -0
  131. package/src/headers/20/node_binding.h +142 -0
  132. package/src/headers/20/node_blob.h +159 -0
  133. package/src/headers/20/node_bob-inl.h +36 -0
  134. package/src/headers/20/node_bob.h +107 -0
  135. package/src/headers/20/node_buffer.h +92 -0
  136. package/src/headers/20/node_builtins.h +197 -0
  137. package/src/headers/20/node_constants.h +82 -0
  138. package/src/headers/20/node_context_data.h +98 -0
  139. package/src/headers/20/node_contextify.h +206 -0
  140. package/src/headers/20/node_crypto.h +56 -0
  141. package/src/headers/20/node_dir.h +52 -0
  142. package/src/headers/20/node_dotenv.h +37 -0
  143. package/src/headers/20/node_errors.h +313 -0
  144. package/src/headers/20/node_exit_code.h +54 -0
  145. package/src/headers/20/node_external_reference.h +172 -0
  146. package/src/headers/20/node_file-inl.h +389 -0
  147. package/src/headers/20/node_file.h +537 -0
  148. package/src/headers/20/node_http2.h +1146 -0
  149. package/src/headers/20/node_http2_state.h +147 -0
  150. package/src/headers/20/node_http_common-inl.h +201 -0
  151. package/src/headers/20/node_http_common.h +532 -0
  152. package/src/headers/20/node_i18n.h +145 -0
  153. package/src/headers/20/node_internals.h +443 -0
  154. package/src/headers/20/node_main_instance.h +67 -0
  155. package/src/headers/20/node_mem-inl.h +112 -0
  156. package/src/headers/20/node_mem.h +45 -0
  157. package/src/headers/20/node_messaging.h +377 -0
  158. package/src/headers/20/node_metadata.h +138 -0
  159. package/src/headers/20/node_mutex.h +323 -0
  160. package/src/headers/20/node_object_wrap.h +132 -0
  161. package/src/headers/20/node_options-inl.h +478 -0
  162. package/src/headers/20/node_options.h +538 -0
  163. package/src/headers/20/node_perf.h +166 -0
  164. package/src/headers/20/node_perf_common.h +98 -0
  165. package/src/headers/20/node_platform.h +195 -0
  166. package/src/headers/20/node_process-inl.h +26 -0
  167. package/src/headers/20/node_process.h +99 -0
  168. package/src/headers/20/node_realm-inl.h +139 -0
  169. package/src/headers/20/node_realm.h +184 -0
  170. package/src/headers/20/node_report.h +42 -0
  171. package/src/headers/20/node_revert.h +82 -0
  172. package/src/headers/20/node_root_certs.h +3443 -0
  173. package/src/headers/20/node_sea.h +56 -0
  174. package/src/headers/20/node_shadow_realm.h +46 -0
  175. package/src/headers/20/node_snapshot_builder.h +54 -0
  176. package/src/headers/20/node_snapshotable.h +164 -0
  177. package/src/headers/20/node_sockaddr-inl.h +266 -0
  178. package/src/headers/20/node_sockaddr.h +405 -0
  179. package/src/headers/20/node_stat_watcher.h +73 -0
  180. package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
  181. package/src/headers/20/node_threadsafe_cow.h +105 -0
  182. package/src/headers/20/node_union_bytes.h +81 -0
  183. package/src/headers/20/node_url.h +92 -0
  184. package/src/headers/20/node_v8.h +77 -0
  185. package/src/headers/20/node_v8_platform-inl.h +205 -0
  186. package/src/headers/20/node_version.h +109 -0
  187. package/src/headers/20/node_wasi.h +184 -0
  188. package/src/headers/20/node_wasm_web_api.h +55 -0
  189. package/src/headers/20/node_watchdog.h +154 -0
  190. package/src/headers/20/node_worker.h +151 -0
  191. package/src/headers/20/permission/child_process_permission.h +29 -0
  192. package/src/headers/20/permission/fs_permission.h +154 -0
  193. package/src/headers/20/permission/inspector_permission.h +29 -0
  194. package/src/headers/20/permission/permission.h +74 -0
  195. package/src/headers/20/permission/permission_base.h +53 -0
  196. package/src/headers/20/permission/worker_permission.h +29 -0
  197. package/src/headers/20/pipe_wrap.h +80 -0
  198. package/src/headers/20/req_wrap-inl.h +171 -0
  199. package/src/headers/20/req_wrap.h +77 -0
  200. package/src/headers/20/spawn_sync.h +242 -0
  201. package/src/headers/20/stream_base-inl.h +173 -0
  202. package/src/headers/20/stream_base.h +469 -0
  203. package/src/headers/20/stream_pipe.h +76 -0
  204. package/src/headers/20/stream_wrap.h +131 -0
  205. package/src/headers/20/string_bytes.h +120 -0
  206. package/src/headers/20/string_decoder-inl.h +37 -0
  207. package/src/headers/20/string_decoder.h +50 -0
  208. package/src/headers/20/string_search.h +638 -0
  209. package/src/headers/20/tcp_wrap.h +105 -0
  210. package/src/headers/20/threadpoolwork-inl.h +70 -0
  211. package/src/headers/20/timer_wrap-inl.h +32 -0
  212. package/src/headers/20/timer_wrap.h +85 -0
  213. package/src/headers/20/timers.h +70 -0
  214. package/src/headers/20/tracing/agent.h +195 -0
  215. package/src/headers/20/tracing/node_trace_buffer.h +83 -0
  216. package/src/headers/20/tracing/node_trace_writer.h +75 -0
  217. package/src/headers/20/tracing/trace_event.h +720 -0
  218. package/src/headers/20/tracing/trace_event_common.h +1109 -0
  219. package/src/headers/20/tracing/traced_value.h +70 -0
  220. package/src/headers/20/tty_wrap.h +65 -0
  221. package/src/headers/20/udp_wrap.h +227 -0
  222. package/src/headers/20/undici_version.h +6 -0
  223. package/src/headers/20/util-inl.h +623 -0
  224. package/src/headers/20/util.h +988 -0
  225. package/src/headers/20/v8-cppgc.h +245 -0
  226. package/src/headers/20/v8-fast-api-calls.h +957 -0
  227. package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
  228. package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
  229. package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
  230. package/dist/bindings/cws_darwin_x64_node64.node +0 -0
  231. package/dist/bindings/cws_darwin_x64_node72.node +0 -0
  232. package/dist/bindings/cws_darwin_x64_node79.node +0 -0
  233. package/dist/bindings/cws_linux_x64_node64.node +0 -0
  234. package/dist/bindings/cws_linux_x64_node72.node +0 -0
  235. package/dist/bindings/cws_linux_x64_node79.node +0 -0
  236. package/dist/bindings/cws_win32_x64_node64.node +0 -0
  237. package/dist/bindings/cws_win32_x64_node72.node +0 -0
  238. package/dist/bindings/cws_win32_x64_node79.node +0 -0
@@ -0,0 +1,131 @@
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_CRYPTO_CRYPTO_CLIENTHELLO_H_
23
+ #define SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include <cstddef> // size_t
28
+ #include <cstdint>
29
+
30
+ namespace node {
31
+ namespace crypto {
32
+ // Parse the client hello so we can do async session resumption. OpenSSL's
33
+ // session resumption uses synchronous callbacks, see SSL_CTX_sess_set_get_cb
34
+ // and get_session_cb.
35
+ //
36
+ // TLS1.3 handshakes masquerade as TLS1.2 session resumption, and to do this,
37
+ // they always include a session_id in the ClientHello, making up a bogus value
38
+ // if necessary. The parser can't know if its a bogus id, and will cause a
39
+ // 'newSession' event to be emitted. This should do no harm, the id won't be
40
+ // found, and the handshake will continue.
41
+ class ClientHelloParser {
42
+ public:
43
+ inline ClientHelloParser();
44
+
45
+ class ClientHello {
46
+ public:
47
+ inline uint8_t session_size() const { return session_size_; }
48
+ inline const uint8_t* session_id() const { return session_id_; }
49
+ inline bool has_ticket() const { return has_ticket_; }
50
+ inline uint8_t servername_size() const { return servername_size_; }
51
+ inline const uint8_t* servername() const { return servername_; }
52
+
53
+ private:
54
+ uint8_t session_size_;
55
+ const uint8_t* session_id_;
56
+ bool has_ticket_;
57
+ uint8_t servername_size_;
58
+ const uint8_t* servername_;
59
+
60
+ friend class ClientHelloParser;
61
+ };
62
+
63
+ typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
64
+ typedef void (*OnEndCb)(void* arg);
65
+
66
+ void Parse(const uint8_t* data, size_t avail);
67
+
68
+ inline void Reset();
69
+ inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* cb_arg);
70
+ inline void End();
71
+ inline bool IsPaused() const;
72
+ inline bool IsEnded() const;
73
+
74
+ private:
75
+ static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
76
+ static const size_t kMaxSSLExFrameLen = 32 * 1024;
77
+ static const uint8_t kServernameHostname = 0;
78
+ static const size_t kMinStatusRequestSize = 5;
79
+
80
+ enum ParseState {
81
+ kWaiting,
82
+ kTLSHeader,
83
+ kPaused,
84
+ kEnded
85
+ };
86
+
87
+ enum FrameType {
88
+ kChangeCipherSpec = 20,
89
+ kAlert = 21,
90
+ kHandshake = 22,
91
+ kApplicationData = 23,
92
+ kOther = 255
93
+ };
94
+
95
+ enum HandshakeType {
96
+ kClientHello = 1
97
+ };
98
+
99
+ enum ExtensionType {
100
+ kServerName = 0,
101
+ kTLSSessionTicket = 35
102
+ };
103
+
104
+ bool ParseRecordHeader(const uint8_t* data, size_t avail);
105
+ void ParseHeader(const uint8_t* data, size_t avail);
106
+ void ParseExtension(const uint16_t type,
107
+ const uint8_t* data,
108
+ size_t len);
109
+ bool ParseTLSClientHello(const uint8_t* data, size_t avail);
110
+
111
+ ParseState state_;
112
+ OnHelloCb onhello_cb_;
113
+ OnEndCb onend_cb_;
114
+ void* cb_arg_;
115
+ size_t frame_len_ = 0;
116
+ size_t body_offset_ = 0;
117
+ size_t extension_offset_ = 0;
118
+ uint8_t session_size_ = 0;
119
+ const uint8_t* session_id_ = nullptr;
120
+ uint16_t servername_size_ = 0;
121
+ const uint8_t* servername_ = nullptr;
122
+ uint16_t tls_ticket_size_ = -1;
123
+ const uint8_t* tls_ticket_ = nullptr;
124
+ };
125
+
126
+ } // namespace crypto
127
+ } // namespace node
128
+
129
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
130
+
131
+ #endif // SRC_CRYPTO_CRYPTO_CLIENTHELLO_H_
@@ -0,0 +1,226 @@
1
+ #ifndef SRC_DEBUG_UTILS_INL_H_
2
+ #define SRC_DEBUG_UTILS_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "debug_utils.h"
7
+ #include "env.h"
8
+
9
+ #include <type_traits>
10
+
11
+ namespace node {
12
+
13
+ struct ToStringHelper {
14
+ template <typename T>
15
+ static std::string Convert(
16
+ const T& value,
17
+ std::string(T::* to_string)() const = &T::ToString) {
18
+ return (value.*to_string)();
19
+ }
20
+ template <typename T,
21
+ typename test_for_number = typename std::
22
+ enable_if<std::is_arithmetic<T>::value, bool>::type,
23
+ typename dummy = bool>
24
+ static std::string Convert(const T& value) { return std::to_string(value); }
25
+ static std::string Convert(const char* value) {
26
+ return value != nullptr ? value : "(null)";
27
+ }
28
+ static std::string Convert(const std::string& value) { return value; }
29
+ static std::string Convert(std::string_view value) {
30
+ return std::string(value);
31
+ }
32
+ static std::string Convert(bool value) { return value ? "true" : "false"; }
33
+ template <unsigned BASE_BITS,
34
+ typename T,
35
+ typename = std::enable_if_t<std::is_integral_v<T>>>
36
+ static std::string BaseConvert(const T& value) {
37
+ auto v = static_cast<uint64_t>(value);
38
+ char ret[3 * sizeof(T)];
39
+ char* ptr = ret + 3 * sizeof(T) - 1;
40
+ *ptr = '\0';
41
+ const char* digits = "0123456789abcdef";
42
+ do {
43
+ unsigned digit = v & ((1 << BASE_BITS) - 1);
44
+ *--ptr =
45
+ (BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
46
+ } while ((v >>= BASE_BITS) != 0);
47
+ return ptr;
48
+ }
49
+ template <unsigned BASE_BITS,
50
+ typename T,
51
+ typename = std::enable_if_t<!std::is_integral_v<T>>>
52
+ static std::string BaseConvert(T value) {
53
+ return Convert(std::forward<T>(value));
54
+ }
55
+ };
56
+
57
+ template <typename T>
58
+ std::string ToString(const T& value) {
59
+ return ToStringHelper::Convert(value);
60
+ }
61
+
62
+ template <unsigned BASE_BITS, typename T>
63
+ std::string ToBaseString(const T& value) {
64
+ return ToStringHelper::BaseConvert<BASE_BITS>(value);
65
+ }
66
+
67
+ inline std::string SPrintFImpl(const char* format) {
68
+ const char* p = strchr(format, '%');
69
+ if (LIKELY(p == nullptr)) return format;
70
+ CHECK_EQ(p[1], '%'); // Only '%%' allowed when there are no arguments.
71
+
72
+ return std::string(format, p + 1) + SPrintFImpl(p + 2);
73
+ }
74
+
75
+ template <typename Arg, typename... Args>
76
+ std::string COLD_NOINLINE SPrintFImpl( // NOLINT(runtime/string)
77
+ const char* format, Arg&& arg, Args&&... args) {
78
+ const char* p = strchr(format, '%');
79
+ CHECK_NOT_NULL(p); // If you hit this, you passed in too many arguments.
80
+ std::string ret(format, p);
81
+ // Ignore long / size_t modifiers
82
+ while (strchr("lz", *++p) != nullptr) {}
83
+ switch (*p) {
84
+ case '%': {
85
+ return ret + '%' + SPrintFImpl(p + 1,
86
+ std::forward<Arg>(arg),
87
+ std::forward<Args>(args)...);
88
+ }
89
+ default: {
90
+ return ret + '%' + SPrintFImpl(p,
91
+ std::forward<Arg>(arg),
92
+ std::forward<Args>(args)...);
93
+ }
94
+ case 'd':
95
+ case 'i':
96
+ case 'u':
97
+ case 's':
98
+ ret += ToString(arg);
99
+ break;
100
+ case 'o':
101
+ ret += ToBaseString<3>(arg);
102
+ break;
103
+ case 'x':
104
+ ret += ToBaseString<4>(arg);
105
+ break;
106
+ case 'X':
107
+ ret += node::ToUpper(ToBaseString<4>(arg));
108
+ break;
109
+ case 'p': {
110
+ CHECK(std::is_pointer<typename std::remove_reference<Arg>::type>::value);
111
+ char out[20];
112
+ int n = snprintf(out,
113
+ sizeof(out),
114
+ "%p",
115
+ *reinterpret_cast<const void* const*>(&arg));
116
+ CHECK_GE(n, 0);
117
+ ret += out;
118
+ break;
119
+ }
120
+ }
121
+ return ret + SPrintFImpl(p + 1, std::forward<Args>(args)...);
122
+ }
123
+
124
+ template <typename... Args>
125
+ std::string COLD_NOINLINE SPrintF( // NOLINT(runtime/string)
126
+ const char* format, Args&&... args) {
127
+ return SPrintFImpl(format, std::forward<Args>(args)...);
128
+ }
129
+
130
+ template <typename... Args>
131
+ void COLD_NOINLINE FPrintF(FILE* file, const char* format, Args&&... args) {
132
+ FWrite(file, SPrintF(format, std::forward<Args>(args)...));
133
+ }
134
+
135
+ template <typename... Args>
136
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
137
+ DebugCategory cat,
138
+ const char* format,
139
+ Args&&... args) {
140
+ if (!UNLIKELY(list->enabled(cat))) return;
141
+ FPrintF(stderr, format, std::forward<Args>(args)...);
142
+ }
143
+
144
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
145
+ DebugCategory cat,
146
+ const char* message) {
147
+ if (!UNLIKELY(list->enabled(cat))) return;
148
+ FPrintF(stderr, "%s", message);
149
+ }
150
+
151
+ template <typename... Args>
152
+ inline void FORCE_INLINE
153
+ Debug(Environment* env, DebugCategory cat, const char* format, Args&&... args) {
154
+ Debug(env->enabled_debug_list(), cat, format, std::forward<Args>(args)...);
155
+ }
156
+
157
+ inline void FORCE_INLINE Debug(Environment* env,
158
+ DebugCategory cat,
159
+ const char* message) {
160
+ Debug(env->enabled_debug_list(), cat, message);
161
+ }
162
+
163
+ template <typename... Args>
164
+ inline void Debug(Environment* env,
165
+ DebugCategory cat,
166
+ const std::string& format,
167
+ Args&&... args) {
168
+ Debug(env->enabled_debug_list(),
169
+ cat,
170
+ format.c_str(),
171
+ std::forward<Args>(args)...);
172
+ }
173
+
174
+ // Used internally by the 'real' Debug(AsyncWrap*, ...) functions below, so that
175
+ // the FORCE_INLINE flag on them doesn't apply to the contents of this function
176
+ // as well.
177
+ // We apply COLD_NOINLINE to tell the compiler that it's not worth optimizing
178
+ // this function for speed and it should rather focus on keeping it out of
179
+ // hot code paths. In particular, we want to keep the string concatenating code
180
+ // out of the function containing the original `Debug()` call.
181
+ template <typename... Args>
182
+ void COLD_NOINLINE UnconditionalAsyncWrapDebug(AsyncWrap* async_wrap,
183
+ const char* format,
184
+ Args&&... args) {
185
+ Debug(async_wrap->env(),
186
+ static_cast<DebugCategory>(async_wrap->provider_type()),
187
+ async_wrap->diagnostic_name() + " " + format + "\n",
188
+ std::forward<Args>(args)...);
189
+ }
190
+
191
+ template <typename... Args>
192
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
193
+ const char* format,
194
+ Args&&... args) {
195
+ DCHECK_NOT_NULL(async_wrap);
196
+ DebugCategory cat = static_cast<DebugCategory>(async_wrap->provider_type());
197
+ if (!UNLIKELY(async_wrap->env()->enabled_debug_list()->enabled(cat))) return;
198
+ UnconditionalAsyncWrapDebug(async_wrap, format, std::forward<Args>(args)...);
199
+ }
200
+
201
+ template <typename... Args>
202
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
203
+ const std::string& format,
204
+ Args&&... args) {
205
+ Debug(async_wrap, format.c_str(), std::forward<Args>(args)...);
206
+ }
207
+
208
+ namespace per_process {
209
+
210
+ template <typename... Args>
211
+ inline void FORCE_INLINE Debug(DebugCategory cat,
212
+ const char* format,
213
+ Args&&... args) {
214
+ Debug(&enabled_debug_list, cat, format, std::forward<Args>(args)...);
215
+ }
216
+
217
+ inline void FORCE_INLINE Debug(DebugCategory cat, const char* message) {
218
+ Debug(&enabled_debug_list, cat, message);
219
+ }
220
+
221
+ } // namespace per_process
222
+ } // namespace node
223
+
224
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
225
+
226
+ #endif // SRC_DEBUG_UTILS_INL_H_
@@ -0,0 +1,188 @@
1
+ #ifndef SRC_DEBUG_UTILS_H_
2
+ #define SRC_DEBUG_UTILS_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "async_wrap.h"
7
+ #include "util.h"
8
+
9
+ #include <algorithm>
10
+ #include <sstream>
11
+ #include <string>
12
+
13
+ // Use FORCE_INLINE on functions that have a debug-category-enabled check first
14
+ // and then ideally only a single function call following it, to maintain
15
+ // performance for the common case (no debugging used).
16
+ #ifdef __GNUC__
17
+ #define FORCE_INLINE __attribute__((always_inline))
18
+ #define COLD_NOINLINE __attribute__((cold, noinline))
19
+ #else
20
+ #define FORCE_INLINE
21
+ #define COLD_NOINLINE
22
+ #endif
23
+
24
+ namespace node {
25
+ class Environment;
26
+
27
+ template <typename T>
28
+ inline std::string ToString(const T& value);
29
+
30
+ // C++-style variant of sprintf()/fprintf() that:
31
+ // - Returns an std::string
32
+ // - Handles \0 bytes correctly
33
+ // - Supports %p and %s. %d, %i and %u are aliases for %s.
34
+ // - Accepts any class that has a ToString() method for stringification.
35
+ template <typename... Args>
36
+ inline std::string SPrintF(const char* format, Args&&... args);
37
+ template <typename... Args>
38
+ inline void FPrintF(FILE* file, const char* format, Args&&... args);
39
+ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str);
40
+
41
+ // Listing the AsyncWrap provider types first enables us to cast directly
42
+ // from a provider type to a debug category.
43
+ #define DEBUG_CATEGORY_NAMES(V) \
44
+ NODE_ASYNC_PROVIDER_TYPES(V) \
45
+ V(DIAGNOSTICS) \
46
+ V(HUGEPAGES) \
47
+ V(INSPECTOR_SERVER) \
48
+ V(INSPECTOR_PROFILER) \
49
+ V(CODE_CACHE) \
50
+ V(NGTCP2_DEBUG) \
51
+ V(SEA) \
52
+ V(WASI) \
53
+ V(MKSNAPSHOT) \
54
+ V(SNAPSHOT_SERDES) \
55
+ V(PERMISSION_MODEL)
56
+
57
+ enum class DebugCategory : unsigned int {
58
+ #define V(name) name,
59
+ DEBUG_CATEGORY_NAMES(V)
60
+ #undef V
61
+ };
62
+
63
+ #define V(name) +1
64
+ constexpr unsigned int kDebugCategoryCount = DEBUG_CATEGORY_NAMES(V);
65
+ #undef V
66
+
67
+ class NODE_EXTERN_PRIVATE EnabledDebugList {
68
+ public:
69
+ bool FORCE_INLINE enabled(DebugCategory category) const {
70
+ DCHECK_LT(static_cast<unsigned int>(category), kDebugCategoryCount);
71
+ return enabled_[static_cast<unsigned int>(category)];
72
+ }
73
+
74
+ // Uses NODE_DEBUG_NATIVE to initialize the categories. The env_vars variable
75
+ // is parsed if it is not a nullptr, otherwise the system environment
76
+ // variables are parsed.
77
+ void Parse(std::shared_ptr<KVStore> env_vars = nullptr,
78
+ v8::Isolate* isolate = nullptr);
79
+
80
+ private:
81
+ // Enable all categories matching cats.
82
+ void Parse(const std::string& cats);
83
+ void set_enabled(DebugCategory category) {
84
+ DCHECK_LT(static_cast<unsigned int>(category), kDebugCategoryCount);
85
+ enabled_[static_cast<int>(category)] = true;
86
+ }
87
+
88
+ bool enabled_[kDebugCategoryCount] = {false};
89
+ };
90
+
91
+ template <typename... Args>
92
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
93
+ DebugCategory cat,
94
+ const char* format,
95
+ Args&&... args);
96
+
97
+ inline void FORCE_INLINE Debug(EnabledDebugList* list,
98
+ DebugCategory cat,
99
+ const char* message);
100
+
101
+ template <typename... Args>
102
+ inline void FORCE_INLINE
103
+ Debug(Environment* env, DebugCategory cat, const char* format, Args&&... args);
104
+
105
+ inline void FORCE_INLINE Debug(Environment* env,
106
+ DebugCategory cat,
107
+ const char* message);
108
+
109
+ template <typename... Args>
110
+ inline void Debug(Environment* env,
111
+ DebugCategory cat,
112
+ const std::string& format,
113
+ Args&&... args);
114
+
115
+ // Used internally by the 'real' Debug(AsyncWrap*, ...) functions below, so that
116
+ // the FORCE_INLINE flag on them doesn't apply to the contents of this function
117
+ // as well.
118
+ // We apply COLD_NOINLINE to tell the compiler that it's not worth optimizing
119
+ // this function for speed and it should rather focus on keeping it out of
120
+ // hot code paths. In particular, we want to keep the string concatenating code
121
+ // out of the function containing the original `Debug()` call.
122
+ template <typename... Args>
123
+ void COLD_NOINLINE UnconditionalAsyncWrapDebug(AsyncWrap* async_wrap,
124
+ const char* format,
125
+ Args&&... args);
126
+
127
+ template <typename... Args>
128
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
129
+ const char* format,
130
+ Args&&... args);
131
+
132
+ template <typename... Args>
133
+ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
134
+ const std::string& format,
135
+ Args&&... args);
136
+
137
+ // Debug helper for inspecting the currently running `node` executable.
138
+ class NativeSymbolDebuggingContext {
139
+ public:
140
+ static std::unique_ptr<NativeSymbolDebuggingContext> New();
141
+
142
+ class SymbolInfo {
143
+ public:
144
+ std::string name;
145
+ std::string filename;
146
+ size_t line = 0;
147
+ size_t dis = 0;
148
+
149
+ std::string Display() const;
150
+ };
151
+
152
+ NativeSymbolDebuggingContext() = default;
153
+ virtual ~NativeSymbolDebuggingContext() = default;
154
+
155
+ virtual SymbolInfo LookupSymbol(void* address) { return {}; }
156
+ virtual bool IsMapped(void* address) { return false; }
157
+ virtual int GetStackTrace(void** frames, int count) { return 0; }
158
+
159
+ NativeSymbolDebuggingContext(const NativeSymbolDebuggingContext&) = delete;
160
+ NativeSymbolDebuggingContext(NativeSymbolDebuggingContext&&) = delete;
161
+ NativeSymbolDebuggingContext operator=(NativeSymbolDebuggingContext&)
162
+ = delete;
163
+ NativeSymbolDebuggingContext operator=(NativeSymbolDebuggingContext&&)
164
+ = delete;
165
+ static std::vector<std::string> GetLoadedLibraries();
166
+ };
167
+
168
+ // Variant of `uv_loop_close` that tries to be as helpful as possible
169
+ // about giving information on currently existing handles, if there are any,
170
+ // but still aborts the process.
171
+ void CheckedUvLoopClose(uv_loop_t* loop);
172
+ void PrintLibuvHandleInformation(uv_loop_t* loop, FILE* stream);
173
+
174
+ namespace per_process {
175
+ extern NODE_EXTERN_PRIVATE EnabledDebugList enabled_debug_list;
176
+
177
+ template <typename... Args>
178
+ inline void FORCE_INLINE Debug(DebugCategory cat,
179
+ const char* format,
180
+ Args&&... args);
181
+
182
+ inline void FORCE_INLINE Debug(DebugCategory cat, const char* message);
183
+ } // namespace per_process
184
+ } // namespace node
185
+
186
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
187
+
188
+ #endif // SRC_DEBUG_UTILS_H_
@@ -0,0 +1,33 @@
1
+ #ifndef SRC_DIAGNOSTICFILENAME_INL_H_
2
+ #define SRC_DIAGNOSTICFILENAME_INL_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "node_internals.h"
7
+ namespace node {
8
+
9
+ class Environment;
10
+
11
+ inline DiagnosticFilename::DiagnosticFilename(
12
+ Environment* env,
13
+ const char* prefix,
14
+ const char* ext) :
15
+ filename_(MakeFilename(env->thread_id(), prefix, ext)) {
16
+ }
17
+
18
+ inline DiagnosticFilename::DiagnosticFilename(
19
+ uint64_t thread_id,
20
+ const char* prefix,
21
+ const char* ext) :
22
+ filename_(MakeFilename(thread_id, prefix, ext)) {
23
+ }
24
+
25
+ inline const char* DiagnosticFilename::operator*() const {
26
+ return filename_.c_str();
27
+ }
28
+
29
+ } // namespace node
30
+
31
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
32
+
33
+ #endif // SRC_DIAGNOSTICFILENAME_INL_H_
@@ -0,0 +1,59 @@
1
+ #ifndef SRC_ENCODING_BINDING_H_
2
+ #define SRC_ENCODING_BINDING_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <cinttypes>
7
+ #include "aliased_buffer.h"
8
+ #include "node_snapshotable.h"
9
+ #include "v8-fast-api-calls.h"
10
+
11
+ namespace node {
12
+ class ExternalReferenceRegistry;
13
+
14
+ namespace encoding_binding {
15
+ class BindingData : public SnapshotableObject {
16
+ public:
17
+ struct InternalFieldInfo : public node::InternalFieldInfoBase {
18
+ AliasedBufferIndex encode_into_results_buffer;
19
+ };
20
+
21
+ BindingData(Realm* realm,
22
+ v8::Local<v8::Object> obj,
23
+ InternalFieldInfo* info = nullptr);
24
+ SERIALIZABLE_OBJECT_METHODS()
25
+ SET_BINDING_ID(encoding_binding_data)
26
+
27
+ void MemoryInfo(MemoryTracker* tracker) const override;
28
+ SET_SELF_SIZE(BindingData)
29
+ SET_MEMORY_INFO_NAME(BindingData)
30
+
31
+ static void EncodeInto(const v8::FunctionCallbackInfo<v8::Value>& args);
32
+ static void EncodeUtf8String(const v8::FunctionCallbackInfo<v8::Value>& args);
33
+ static void DecodeUTF8(const v8::FunctionCallbackInfo<v8::Value>& args);
34
+
35
+ static void ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
36
+ static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);
37
+
38
+ static void CreatePerIsolateProperties(IsolateData* isolate_data,
39
+ v8::Local<v8::ObjectTemplate> target);
40
+ static void CreatePerContextProperties(v8::Local<v8::Object> target,
41
+ v8::Local<v8::Value> unused,
42
+ v8::Local<v8::Context> context,
43
+ void* priv);
44
+ static void RegisterTimerExternalReferences(
45
+ ExternalReferenceRegistry* registry);
46
+
47
+ private:
48
+ static constexpr size_t kEncodeIntoResultsLength = 2;
49
+ AliasedUint32Array encode_into_results_buffer_;
50
+ InternalFieldInfo* internal_field_info_ = nullptr;
51
+ };
52
+
53
+ } // namespace encoding_binding
54
+
55
+ } // namespace node
56
+
57
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
58
+
59
+ #endif // SRC_ENCODING_BINDING_H_