/src/curl_fuzzer/ngtcp2_contract_shim.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | #include <ngtcp2/ngtcp2.h> |
8 | | |
9 | | #include <array> |
10 | | #include <atomic> |
11 | | #include <cstddef> |
12 | | #include <cstdio> |
13 | | #include <cstdlib> |
14 | | #include <mutex> |
15 | | #include <type_traits> |
16 | | |
17 | | namespace { |
18 | | |
19 | | enum class TransactionOrigin { |
20 | | Stream, |
21 | | Datagram, |
22 | | }; |
23 | | |
24 | | enum class ContractState { |
25 | | Coalescing, |
26 | | CloseOnly, |
27 | | }; |
28 | | |
29 | | struct ConnectionContract { |
30 | | const ngtcp2_conn *conn = nullptr; |
31 | | const char *write_api = nullptr; |
32 | | ngtcp2_ssize error_result = 0; |
33 | | const ngtcp2_path *path = nullptr; |
34 | | const ngtcp2_pkt_info *pi = nullptr; |
35 | | const uint8_t *dest = nullptr; |
36 | | size_t destlen = 0; |
37 | | ngtcp2_tstamp timestamp = 0; |
38 | | TransactionOrigin origin = TransactionOrigin::Stream; |
39 | | ContractState state = ContractState::Coalescing; |
40 | | }; |
41 | | |
42 | | struct ContinuationState { |
43 | | bool active = false; |
44 | | TransactionOrigin origin = TransactionOrigin::Stream; |
45 | | }; |
46 | | |
47 | | // Fault injection must not disable or perturb the monitor itself. |
48 | | constexpr std::size_t kMaximumTrackedConnections = 256; |
49 | | std::array<ConnectionContract, kMaximumTrackedConnections> contracts{}; |
50 | | std::mutex contracts_mutex; |
51 | | std::atomic<std::size_t> contract_count{0}; |
52 | | |
53 | | #if defined(NGTCP2_CONTRACT_TESTING) |
54 | | struct ForcedWriteResult { |
55 | | bool active = false; |
56 | | ngtcp2_ssize result = 0; |
57 | | ngtcp2_ssize data_length = -1; |
58 | | int accepted = 0; |
59 | | }; |
60 | | |
61 | | thread_local ForcedWriteResult forced_stream_result; |
62 | | thread_local ForcedWriteResult forced_datagram_result; |
63 | | |
64 | | bool TakeForcedStreamResult(ngtcp2_ssize *result, ngtcp2_ssize *data_length) { |
65 | | if (!forced_stream_result.active) |
66 | | return false; |
67 | | *result = forced_stream_result.result; |
68 | | if (data_length != nullptr) |
69 | | *data_length = forced_stream_result.data_length; |
70 | | forced_stream_result.active = false; |
71 | | return true; |
72 | | } |
73 | | |
74 | | bool TakeForcedDatagramResult(ngtcp2_ssize *result, int *accepted) { |
75 | | if (!forced_datagram_result.active) |
76 | | return false; |
77 | | *result = forced_datagram_result.result; |
78 | | if (accepted != nullptr) |
79 | | *accepted = forced_datagram_result.accepted; |
80 | | forced_datagram_result.active = false; |
81 | | return true; |
82 | | } |
83 | | #endif |
84 | | |
85 | | // Static libngtcp2 contains calls to its public APIs. --wrap redirects those |
86 | | // calls too, so nested calls made by a real ngtcp2 function bypass the monitor |
87 | | // and cannot be mistaken for application calls while a restriction is active. |
88 | | thread_local unsigned real_call_depth = 0; |
89 | | |
90 | | class RealCallScope { |
91 | | public: |
92 | 1.13M | RealCallScope() { ++real_call_depth; } |
93 | 1.13M | ~RealCallScope() { --real_call_depth; } |
94 | | |
95 | | RealCallScope(const RealCallScope &) = delete; |
96 | | RealCallScope &operator=(const RealCallScope &) = delete; |
97 | | }; |
98 | | |
99 | 1.20M | bool IsRealCallActive() { return real_call_depth != 0; } |
100 | | |
101 | 23.0k | ConnectionContract *FindContract(const ngtcp2_conn *conn) { |
102 | 1.31M | for (ConnectionContract &contract : contracts) { |
103 | 1.31M | if (contract.conn == conn) |
104 | 17.9k | return &contract; |
105 | 1.31M | } |
106 | 5.07k | return nullptr; |
107 | 23.0k | } |
108 | | |
109 | | [[noreturn]] void AbortForbiddenCall(const char *attempted_api, |
110 | 0 | const ConnectionContract &transaction) { |
111 | 0 | if (transaction.state == ContractState::CloseOnly) { |
112 | 0 | std::fprintf(stderr, |
113 | 0 | "ngtcp2 contract assertion failed: %s called on connection " |
114 | 0 | "%p after %s returned %td; the connection is close-only, " |
115 | 0 | "and only connection close, terminal status inspection, or " |
116 | 0 | "connection teardown is allowed\n", |
117 | 0 | attempted_api, static_cast<const void *>(transaction.conn), |
118 | 0 | transaction.write_api, transaction.error_result); |
119 | 0 | std::fflush(stderr); |
120 | 0 | std::abort(); |
121 | 0 | } |
122 | 0 | std::fprintf(stderr, |
123 | 0 | "ngtcp2 contract assertion failed: %s called on connection " |
124 | 0 | "%p while a packet started by %s is being coalesced; only " |
125 | 0 | "writev_stream/writev_datagram continuation, connection " |
126 | 0 | "close, stream shutdown, or connection teardown is allowed\n", |
127 | 0 | attempted_api, static_cast<const void *>(transaction.conn), |
128 | 0 | transaction.write_api); |
129 | 0 | std::fflush(stderr); |
130 | 0 | std::abort(); |
131 | 0 | } |
132 | | |
133 | | [[noreturn]] void AbortTupleMismatch(const char *attempted_api, |
134 | | const char *field, |
135 | 0 | const ConnectionContract &transaction) { |
136 | 0 | std::fprintf(stderr, |
137 | 0 | "ngtcp2 contract assertion failed: %s changed %s on " |
138 | 0 | "connection %p while continuing a packet started by %s; " |
139 | 0 | "conn, path, pi, dest, destlen, and timestamp must remain " |
140 | 0 | "identical\n", |
141 | 0 | attempted_api, field, |
142 | 0 | static_cast<const void *>(transaction.conn), |
143 | 0 | transaction.write_api); |
144 | 0 | std::fflush(stderr); |
145 | 0 | std::abort(); |
146 | 0 | } |
147 | | |
148 | | [[noreturn]] void AbortPostcondition(const char *api, ngtcp2_ssize result, |
149 | 0 | const char *postcondition) { |
150 | 0 | std::fprintf(stderr, |
151 | 0 | "ngtcp2 contract assertion failed: %s returned %td but %s\n", |
152 | 0 | api, result, postcondition); |
153 | 0 | std::fflush(stderr); |
154 | 0 | std::abort(); |
155 | 0 | } |
156 | | |
157 | 0 | [[noreturn]] void AbortTrackingOverflow(const ConnectionContract &value) { |
158 | 0 | std::fprintf(stderr, |
159 | 0 | "ngtcp2 contract assertion failed: cannot track connection " |
160 | 0 | "%p after %s established a restricted state; contract table " |
161 | 0 | "is full\n", |
162 | 0 | static_cast<const void *>(value.conn), value.write_api); |
163 | 0 | std::fflush(stderr); |
164 | 0 | std::abort(); |
165 | 0 | } |
166 | | |
167 | | void CheckNoTransaction(const ngtcp2_conn *conn, const char *attempted_api, |
168 | | bool allow_coalescing = false, |
169 | 949k | bool allow_close_only = false) { |
170 | 949k | if (conn == nullptr || contract_count.load(std::memory_order_acquire) == 0) |
171 | 949k | return; |
172 | | |
173 | 23 | ConnectionContract value; |
174 | 23 | { |
175 | 23 | std::lock_guard<std::mutex> lock(contracts_mutex); |
176 | 23 | const ConnectionContract *contract = FindContract(conn); |
177 | 23 | if (contract != nullptr) |
178 | 23 | value = *contract; |
179 | 23 | } |
180 | 23 | if (value.conn == nullptr) |
181 | 0 | return; |
182 | 23 | if ((allow_coalescing && value.state == ContractState::Coalescing) || |
183 | 23 | (allow_close_only && value.state == ContractState::CloseOnly)) |
184 | 23 | return; |
185 | 0 | AbortForbiddenCall(attempted_api, value); |
186 | 0 | } |
187 | | |
188 | | ContinuationState CheckContinuation(const ngtcp2_conn *conn, |
189 | | const ngtcp2_path *path, |
190 | | const ngtcp2_pkt_info *pi, |
191 | | const uint8_t *dest, size_t destlen, |
192 | | ngtcp2_tstamp timestamp, |
193 | 168k | const char *attempted_api) { |
194 | 168k | if (conn == nullptr || contract_count.load(std::memory_order_acquire) == 0) |
195 | 159k | return ContinuationState{}; |
196 | | |
197 | 8.96k | ConnectionContract value; |
198 | 8.96k | { |
199 | 8.96k | std::lock_guard<std::mutex> lock(contracts_mutex); |
200 | 8.96k | const ConnectionContract *contract = FindContract(conn); |
201 | 8.96k | if (contract == nullptr) |
202 | 0 | return ContinuationState{}; |
203 | 8.96k | value = *contract; |
204 | 8.96k | } |
205 | | |
206 | 8.96k | if (value.state == ContractState::CloseOnly) |
207 | 0 | AbortForbiddenCall(attempted_api, value); |
208 | | |
209 | 8.96k | if (value.path != path) |
210 | 0 | AbortTupleMismatch(attempted_api, "path", value); |
211 | 8.96k | if (value.pi != pi) |
212 | 0 | AbortTupleMismatch(attempted_api, "packet info", value); |
213 | 8.96k | if (value.dest != dest) |
214 | 0 | AbortTupleMismatch(attempted_api, "destination buffer", value); |
215 | 8.96k | if (value.destlen != destlen) |
216 | 0 | AbortTupleMismatch(attempted_api, "destination length", value); |
217 | 8.96k | if (value.timestamp != timestamp) |
218 | 0 | AbortTupleMismatch(attempted_api, "timestamp", value); |
219 | 8.96k | ContinuationState state; |
220 | 8.96k | state.active = true; |
221 | 8.96k | state.origin = value.origin; |
222 | 8.96k | return state; |
223 | 8.96k | } |
224 | | |
225 | 172k | void ForgetContract(const ngtcp2_conn *conn) { |
226 | 172k | if (conn == nullptr || contract_count.load(std::memory_order_acquire) == 0) |
227 | 167k | return; |
228 | | |
229 | 5.07k | std::lock_guard<std::mutex> lock(contracts_mutex); |
230 | 5.07k | ConnectionContract *contract = FindContract(conn); |
231 | 5.07k | if (contract != nullptr) { |
232 | 5.07k | *contract = ConnectionContract{}; |
233 | 5.07k | contract_count.fetch_sub(1, std::memory_order_release); |
234 | 5.07k | } |
235 | 5.07k | } |
236 | | |
237 | 8.99k | void StoreContract(ConnectionContract value, bool preserve_origin) { |
238 | 8.99k | bool added = false; |
239 | 8.99k | bool table_full = false; |
240 | 8.99k | { |
241 | 8.99k | std::lock_guard<std::mutex> lock(contracts_mutex); |
242 | 8.99k | ConnectionContract *contract = FindContract(value.conn); |
243 | 8.99k | if (contract == nullptr) { |
244 | 5.07k | for (ConnectionContract &entry : contracts) { |
245 | 5.07k | if (entry.conn == nullptr) { |
246 | 5.07k | contract = &entry; |
247 | 5.07k | added = true; |
248 | 5.07k | break; |
249 | 5.07k | } |
250 | 5.07k | } |
251 | 5.07k | } |
252 | 8.99k | if (contract != nullptr) { |
253 | 8.99k | if (!added && preserve_origin && |
254 | 3.91k | contract->state == ContractState::Coalescing) { |
255 | 3.91k | value.write_api = contract->write_api; |
256 | 3.91k | value.origin = contract->origin; |
257 | 3.91k | } |
258 | 8.99k | *contract = value; |
259 | 8.99k | if (added) |
260 | 5.07k | contract_count.fetch_add(1, std::memory_order_release); |
261 | 8.99k | } else |
262 | 0 | table_full = true; |
263 | 8.99k | } |
264 | 8.99k | if (table_full) |
265 | 0 | AbortTrackingOverflow(value); |
266 | 8.99k | } |
267 | | |
268 | | void RecordTransaction(const ngtcp2_conn *conn, const char *write_api, |
269 | | const ngtcp2_path *path, const ngtcp2_pkt_info *pi, |
270 | | const uint8_t *dest, size_t destlen, |
271 | | ngtcp2_tstamp timestamp, TransactionOrigin origin, |
272 | 168k | bool keep_open) { |
273 | 168k | if (conn == nullptr) |
274 | 0 | return; |
275 | 168k | if (!keep_open) { |
276 | 159k | ForgetContract(conn); |
277 | 159k | return; |
278 | 159k | } |
279 | | |
280 | 8.96k | ConnectionContract value; |
281 | 8.96k | value.conn = conn; |
282 | 8.96k | value.write_api = write_api; |
283 | 8.96k | value.path = path; |
284 | 8.96k | value.pi = pi; |
285 | 8.96k | value.dest = dest; |
286 | 8.96k | value.destlen = destlen; |
287 | 8.96k | value.timestamp = timestamp; |
288 | 8.96k | value.origin = origin; |
289 | 8.96k | StoreContract(value, true); |
290 | 8.96k | } |
291 | | |
292 | | void RecordCloseOnly(const ngtcp2_conn *conn, const char *write_api, |
293 | 23 | ngtcp2_ssize error_result) { |
294 | 23 | if (conn == nullptr) |
295 | 0 | return; |
296 | | |
297 | 23 | ConnectionContract value; |
298 | 23 | value.conn = conn; |
299 | 23 | value.write_api = write_api; |
300 | 23 | value.error_result = error_result; |
301 | 23 | value.state = ContractState::CloseOnly; |
302 | 23 | StoreContract(value, false); |
303 | 23 | } |
304 | | |
305 | 177k | bool IsStreamContinuationResult(ngtcp2_ssize result) { |
306 | 177k | return result == NGTCP2_ERR_WRITE_MORE || |
307 | 159k | result == NGTCP2_ERR_STREAM_DATA_BLOCKED || |
308 | 159k | result == NGTCP2_ERR_STREAM_NOT_FOUND || |
309 | 159k | result == NGTCP2_ERR_STREAM_SHUT_WR; |
310 | 177k | } |
311 | | |
312 | 168k | bool IsFatalResult(ngtcp2_ssize result) { return result < NGTCP2_ERR_FATAL; } |
313 | | |
314 | | void ValidateStreamPostcondition(const char *api, ngtcp2_ssize result, |
315 | 168k | const ngtcp2_ssize *pdatalen) { |
316 | 168k | if (pdatalen == nullptr) |
317 | 0 | return; |
318 | 168k | if (result == NGTCP2_ERR_WRITE_MORE && *pdatalen < 0) |
319 | 0 | AbortPostcondition(api, result, |
320 | 0 | "pdatalen is negative instead of nonnegative"); |
321 | 168k | if ((result == NGTCP2_ERR_STREAM_DATA_BLOCKED || |
322 | 168k | result == NGTCP2_ERR_STREAM_NOT_FOUND || |
323 | 168k | result == NGTCP2_ERR_STREAM_SHUT_WR) && |
324 | 3 | *pdatalen != -1) |
325 | 0 | AbortPostcondition(api, result, "pdatalen is not -1"); |
326 | 168k | } |
327 | | |
328 | | void ValidateDatagramPostcondition(const char *api, ngtcp2_ssize result, |
329 | 0 | const int *paccepted) { |
330 | 0 | if (result == 0 && paccepted != nullptr && *paccepted != 0) |
331 | 0 | AbortPostcondition(api, result, "paccepted is nonzero instead of zero"); |
332 | 0 | if (result == NGTCP2_ERR_WRITE_MORE && paccepted != nullptr && |
333 | 0 | *paccepted == 0) |
334 | 0 | AbortPostcondition(api, result, "paccepted is zero"); |
335 | 0 | } |
336 | | |
337 | | } // namespace |
338 | | |
339 | | #if defined(NGTCP2_CONTRACT_TESTING) |
340 | | extern "C" void |
341 | | curl_fuzzer_ngtcp2_contract_test_force_stream_result(ngtcp2_ssize result, |
342 | | ngtcp2_ssize data_length) { |
343 | | forced_stream_result.active = true; |
344 | | forced_stream_result.result = result; |
345 | | forced_stream_result.data_length = data_length; |
346 | | } |
347 | | |
348 | | extern "C" void |
349 | | curl_fuzzer_ngtcp2_contract_test_force_datagram_result(ngtcp2_ssize result, |
350 | | int accepted) { |
351 | | forced_datagram_result.active = true; |
352 | | forced_datagram_result.result = result; |
353 | | forced_datagram_result.accepted = accepted; |
354 | | } |
355 | | #endif |
356 | | |
357 | | // GNU ld and lld provide each __real_* symbol when the final link uses the |
358 | | // matching --wrap option. decltype ties these declarations to the installed |
359 | | // ngtcp2 headers and makes signature drift a compile-time failure. |
360 | | #define DECLARE_REAL(name) extern "C" decltype(name) __real_##name |
361 | | |
362 | | DECLARE_REAL(ngtcp2_conn_client_new_versioned); |
363 | | DECLARE_REAL(ngtcp2_conn_server_new_versioned); |
364 | | DECLARE_REAL(ngtcp2_conn_del); |
365 | | DECLARE_REAL(ngtcp2_conn_decode_and_set_0rtt_transport_params); |
366 | | DECLARE_REAL(ngtcp2_conn_encode_0rtt_transport_params); |
367 | | DECLARE_REAL(ngtcp2_conn_extend_max_offset); |
368 | | DECLARE_REAL(ngtcp2_conn_extend_max_stream_offset); |
369 | | DECLARE_REAL(ngtcp2_conn_get_ccerr); |
370 | | DECLARE_REAL(ngtcp2_conn_get_cwnd_left); |
371 | | DECLARE_REAL(ngtcp2_conn_get_expiry); |
372 | | DECLARE_REAL(ngtcp2_conn_get_expiry2); |
373 | | DECLARE_REAL(ngtcp2_conn_get_handshake_completed); |
374 | | DECLARE_REAL(ngtcp2_conn_get_max_data_left); |
375 | | DECLARE_REAL(ngtcp2_conn_get_max_tx_udp_payload_size); |
376 | | DECLARE_REAL(ngtcp2_conn_get_path_max_tx_udp_payload_size); |
377 | | DECLARE_REAL(ngtcp2_conn_get_remote_transport_params); |
378 | | DECLARE_REAL(ngtcp2_conn_get_send_quantum); |
379 | | DECLARE_REAL(ngtcp2_conn_get_stream_user_data); |
380 | | DECLARE_REAL(ngtcp2_conn_get_streams_uni_left); |
381 | | DECLARE_REAL(ngtcp2_conn_get_timestamp); |
382 | | DECLARE_REAL(ngtcp2_conn_get_tls_alert); |
383 | | DECLARE_REAL(ngtcp2_conn_get_tls_early_data_rejected2); |
384 | | DECLARE_REAL(ngtcp2_conn_handle_expiry); |
385 | | DECLARE_REAL(ngtcp2_conn_in_draining_period); |
386 | | DECLARE_REAL(ngtcp2_conn_open_bidi_stream); |
387 | | DECLARE_REAL(ngtcp2_conn_open_uni_stream); |
388 | | DECLARE_REAL(ngtcp2_conn_read_pkt_versioned); |
389 | | DECLARE_REAL(ngtcp2_conn_set_keep_alive_timeout); |
390 | | DECLARE_REAL(ngtcp2_conn_set_stream_user_data); |
391 | | DECLARE_REAL(ngtcp2_conn_set_tls_native_handle); |
392 | | DECLARE_REAL(ngtcp2_conn_shutdown_stream); |
393 | | DECLARE_REAL(ngtcp2_conn_shutdown_stream_read); |
394 | | DECLARE_REAL(ngtcp2_conn_shutdown_stream_write); |
395 | | DECLARE_REAL(ngtcp2_conn_update_pkt_tx_time); |
396 | | DECLARE_REAL(ngtcp2_conn_write_connection_close_versioned); |
397 | | DECLARE_REAL(ngtcp2_conn_write_datagram_versioned); |
398 | | DECLARE_REAL(ngtcp2_conn_write_pkt_versioned); |
399 | | DECLARE_REAL(ngtcp2_conn_write_stream_versioned); |
400 | | DECLARE_REAL(ngtcp2_conn_writev_datagram_versioned); |
401 | | DECLARE_REAL(ngtcp2_conn_writev_stream_versioned); |
402 | | |
403 | | #undef DECLARE_REAL |
404 | | |
405 | | #define ASSERT_SIGNATURE(name) \ |
406 | | static_assert(std::is_same<decltype(name), decltype(__wrap_##name)>::value, \ |
407 | | #name " signature changed") |
408 | | |
409 | | extern "C" int __wrap_ngtcp2_conn_client_new_versioned( |
410 | | ngtcp2_conn **pconn, const ngtcp2_cid *dcid, const ngtcp2_cid *scid, |
411 | | const ngtcp2_path *path, uint32_t version, int callbacks_version, |
412 | | const ngtcp2_callbacks *callbacks, int settings_version, |
413 | | const ngtcp2_settings *settings, int transport_params_version, |
414 | | const ngtcp2_transport_params *params, const ngtcp2_mem *mem, |
415 | 3.34k | void *user_data) { |
416 | 3.34k | if (IsRealCallActive()) |
417 | 0 | return __real_ngtcp2_conn_client_new_versioned( |
418 | 0 | pconn, dcid, scid, path, version, callbacks_version, callbacks, |
419 | 0 | settings_version, settings, transport_params_version, params, mem, |
420 | 0 | user_data); |
421 | 3.34k | int result; |
422 | 3.34k | { |
423 | 3.34k | RealCallScope real_call; |
424 | 3.34k | result = __real_ngtcp2_conn_client_new_versioned( |
425 | 3.34k | pconn, dcid, scid, path, version, callbacks_version, callbacks, |
426 | 3.34k | settings_version, settings, transport_params_version, params, mem, |
427 | 3.34k | user_data); |
428 | 3.34k | } |
429 | 3.34k | if (result == 0 && pconn != nullptr) |
430 | 3.33k | ForgetContract(*pconn); |
431 | 3.34k | return result; |
432 | 3.34k | } |
433 | | ASSERT_SIGNATURE(ngtcp2_conn_client_new_versioned); |
434 | | |
435 | | extern "C" int __wrap_ngtcp2_conn_server_new_versioned( |
436 | | ngtcp2_conn **pconn, const ngtcp2_cid *dcid, const ngtcp2_cid *scid, |
437 | | const ngtcp2_path *path, uint32_t version, int callbacks_version, |
438 | | const ngtcp2_callbacks *callbacks, int settings_version, |
439 | | const ngtcp2_settings *settings, int transport_params_version, |
440 | | const ngtcp2_transport_params *params, const ngtcp2_mem *mem, |
441 | 1.96k | void *user_data) { |
442 | 1.96k | if (IsRealCallActive()) |
443 | 0 | return __real_ngtcp2_conn_server_new_versioned( |
444 | 0 | pconn, dcid, scid, path, version, callbacks_version, callbacks, |
445 | 0 | settings_version, settings, transport_params_version, params, mem, |
446 | 0 | user_data); |
447 | 1.96k | int result; |
448 | 1.96k | { |
449 | 1.96k | RealCallScope real_call; |
450 | 1.96k | result = __real_ngtcp2_conn_server_new_versioned( |
451 | 1.96k | pconn, dcid, scid, path, version, callbacks_version, callbacks, |
452 | 1.96k | settings_version, settings, transport_params_version, params, mem, |
453 | 1.96k | user_data); |
454 | 1.96k | } |
455 | 1.96k | if (result == 0 && pconn != nullptr) |
456 | 1.96k | ForgetContract(*pconn); |
457 | 1.96k | return result; |
458 | 1.96k | } |
459 | | ASSERT_SIGNATURE(ngtcp2_conn_server_new_versioned); |
460 | | |
461 | 7.83k | extern "C" void __wrap_ngtcp2_conn_del(ngtcp2_conn *conn) { |
462 | 7.83k | if (IsRealCallActive()) { |
463 | 0 | __real_ngtcp2_conn_del(conn); |
464 | 0 | return; |
465 | 0 | } |
466 | 7.83k | ForgetContract(conn); |
467 | 7.83k | RealCallScope real_call; |
468 | 7.83k | __real_ngtcp2_conn_del(conn); |
469 | 7.83k | } |
470 | | ASSERT_SIGNATURE(ngtcp2_conn_del); |
471 | | |
472 | | #define DEFINE_CHECKED_WRAPPER(name, parameters, arguments, conn_argument) \ |
473 | | extern "C" auto __wrap_##name parameters \ |
474 | 963k | ->decltype(__real_##name arguments) { \ |
475 | 963k | if (IsRealCallActive()) \ |
476 | 963k | return __real_##name arguments; \ |
477 | 963k | CheckNoTransaction(conn_argument, #name); \ |
478 | 915k | RealCallScope real_call; \ |
479 | 915k | return __real_##name arguments; \ |
480 | 963k | } \ Unexecuted instantiation: __wrap_ngtcp2_conn_decode_and_set_0rtt_transport_params __wrap_ngtcp2_conn_encode_0rtt_transport_params Line | Count | Source | 474 | 1.90k | ->decltype(__real_##name arguments) { \ | 475 | 1.90k | if (IsRealCallActive()) \ | 476 | 1.90k | return __real_##name arguments; \ | 477 | 1.90k | CheckNoTransaction(conn_argument, #name); \ | 478 | 0 | RealCallScope real_call; \ | 479 | 0 | return __real_##name arguments; \ | 480 | 1.90k | } \ |
__wrap_ngtcp2_conn_extend_max_stream_offset Line | Count | Source | 474 | 23.2k | ->decltype(__real_##name arguments) { \ | 475 | 23.2k | if (IsRealCallActive()) \ | 476 | 23.2k | return __real_##name arguments; \ | 477 | 23.2k | CheckNoTransaction(conn_argument, #name); \ | 478 | 1.91k | RealCallScope real_call; \ | 479 | 1.91k | return __real_##name arguments; \ | 480 | 23.2k | } \ |
__wrap_ngtcp2_conn_get_cwnd_left Line | Count | Source | 474 | 740 | ->decltype(__real_##name arguments) { \ | 475 | 740 | if (IsRealCallActive()) \ | 476 | 740 | return __real_##name arguments; \ | 477 | 740 | CheckNoTransaction(conn_argument, #name); \ | 478 | 740 | RealCallScope real_call; \ | 479 | 740 | return __real_##name arguments; \ | 480 | 740 | } \ |
__wrap_ngtcp2_conn_get_expiry Line | Count | Source | 474 | 127k | ->decltype(__real_##name arguments) { \ | 475 | 127k | if (IsRealCallActive()) \ | 476 | 127k | return __real_##name arguments; \ | 477 | 127k | CheckNoTransaction(conn_argument, #name); \ | 478 | 127k | RealCallScope real_call; \ | 479 | 127k | return __real_##name arguments; \ | 480 | 127k | } \ |
__wrap_ngtcp2_conn_get_expiry2 Line | Count | Source | 474 | 41.0k | ->decltype(__real_##name arguments) { \ | 475 | 41.0k | if (IsRealCallActive()) \ | 476 | 41.0k | return __real_##name arguments; \ | 477 | 41.0k | CheckNoTransaction(conn_argument, #name); \ | 478 | 41.0k | RealCallScope real_call; \ | 479 | 41.0k | return __real_##name arguments; \ | 480 | 41.0k | } \ |
__wrap_ngtcp2_conn_get_handshake_completed Line | Count | Source | 474 | 112k | ->decltype(__real_##name arguments) { \ | 475 | 112k | if (IsRealCallActive()) \ | 476 | 112k | return __real_##name arguments; \ | 477 | 112k | CheckNoTransaction(conn_argument, #name); \ | 478 | 112k | RealCallScope real_call; \ | 479 | 112k | return __real_##name arguments; \ | 480 | 112k | } \ |
__wrap_ngtcp2_conn_get_max_data_left Line | Count | Source | 474 | 30.3k | ->decltype(__real_##name arguments) { \ | 475 | 30.3k | if (IsRealCallActive()) \ | 476 | 30.3k | return __real_##name arguments; \ | 477 | 30.3k | CheckNoTransaction(conn_argument, #name); \ | 478 | 30.3k | RealCallScope real_call; \ | 479 | 30.3k | return __real_##name arguments; \ | 480 | 30.3k | } \ |
__wrap_ngtcp2_conn_get_max_tx_udp_payload_size Line | Count | Source | 474 | 128k | ->decltype(__real_##name arguments) { \ | 475 | 128k | if (IsRealCallActive()) \ | 476 | 128k | return __real_##name arguments; \ | 477 | 128k | CheckNoTransaction(conn_argument, #name); \ | 478 | 128k | RealCallScope real_call; \ | 479 | 128k | return __real_##name arguments; \ | 480 | 128k | } \ |
__wrap_ngtcp2_conn_get_path_max_tx_udp_payload_size Line | Count | Source | 474 | 236k | ->decltype(__real_##name arguments) { \ | 475 | 236k | if (IsRealCallActive()) \ | 476 | 236k | return __real_##name arguments; \ | 477 | 236k | CheckNoTransaction(conn_argument, #name); \ | 478 | 236k | RealCallScope real_call; \ | 479 | 236k | return __real_##name arguments; \ | 480 | 236k | } \ |
__wrap_ngtcp2_conn_get_remote_transport_params Line | Count | Source | 474 | 3.66k | ->decltype(__real_##name arguments) { \ | 475 | 3.66k | if (IsRealCallActive()) \ | 476 | 3.66k | return __real_##name arguments; \ | 477 | 3.66k | CheckNoTransaction(conn_argument, #name); \ | 478 | 3.51k | RealCallScope real_call; \ | 479 | 3.51k | return __real_##name arguments; \ | 480 | 3.66k | } \ |
__wrap_ngtcp2_conn_get_send_quantum Line | Count | Source | 474 | 128k | ->decltype(__real_##name arguments) { \ | 475 | 128k | if (IsRealCallActive()) \ | 476 | 128k | return __real_##name arguments; \ | 477 | 128k | CheckNoTransaction(conn_argument, #name); \ | 478 | 128k | RealCallScope real_call; \ | 479 | 128k | return __real_##name arguments; \ | 480 | 128k | } \ |
Unexecuted instantiation: __wrap_ngtcp2_conn_get_stream_user_data __wrap_ngtcp2_conn_get_streams_uni_left Line | Count | Source | 474 | 1.96k | ->decltype(__real_##name arguments) { \ | 475 | 1.96k | if (IsRealCallActive()) \ | 476 | 1.96k | return __real_##name arguments; \ | 477 | 1.96k | CheckNoTransaction(conn_argument, #name); \ | 478 | 0 | RealCallScope real_call; \ | 479 | 0 | return __real_##name arguments; \ | 480 | 1.96k | } \ |
__wrap_ngtcp2_conn_get_timestamp Line | Count | Source | 474 | 10.7k | ->decltype(__real_##name arguments) { \ | 475 | 10.7k | if (IsRealCallActive()) \ | 476 | 10.7k | return __real_##name arguments; \ | 477 | 10.7k | CheckNoTransaction(conn_argument, #name); \ | 478 | 0 | RealCallScope real_call; \ | 479 | 0 | return __real_##name arguments; \ | 480 | 10.7k | } \ |
Unexecuted instantiation: __wrap_ngtcp2_conn_get_tls_early_data_rejected2 __wrap_ngtcp2_conn_handle_expiry Line | Count | Source | 474 | 4.21k | ->decltype(__real_##name arguments) { \ | 475 | 4.21k | if (IsRealCallActive()) \ | 476 | 4.21k | return __real_##name arguments; \ | 477 | 4.21k | CheckNoTransaction(conn_argument, #name); \ | 478 | 4.21k | RealCallScope real_call; \ | 479 | 4.21k | return __real_##name arguments; \ | 480 | 4.21k | } \ |
__wrap_ngtcp2_conn_open_bidi_stream Line | Count | Source | 474 | 1.92k | ->decltype(__real_##name arguments) { \ | 475 | 1.92k | if (IsRealCallActive()) \ | 476 | 1.92k | return __real_##name arguments; \ | 477 | 1.92k | CheckNoTransaction(conn_argument, #name); \ | 478 | 1.92k | RealCallScope real_call; \ | 479 | 1.92k | return __real_##name arguments; \ | 480 | 1.92k | } \ |
__wrap_ngtcp2_conn_open_uni_stream Line | Count | Source | 474 | 12.1k | ->decltype(__real_##name arguments) { \ | 475 | 12.1k | if (IsRealCallActive()) \ | 476 | 12.1k | return __real_##name arguments; \ | 477 | 12.1k | CheckNoTransaction(conn_argument, #name); \ | 478 | 385 | RealCallScope real_call; \ | 479 | 385 | return __real_##name arguments; \ | 480 | 12.1k | } \ |
__wrap_ngtcp2_conn_read_pkt_versioned Line | Count | Source | 474 | 49.6k | ->decltype(__real_##name arguments) { \ | 475 | 49.6k | if (IsRealCallActive()) \ | 476 | 49.6k | return __real_##name arguments; \ | 477 | 49.6k | CheckNoTransaction(conn_argument, #name); \ | 478 | 49.6k | RealCallScope real_call; \ | 479 | 49.6k | return __real_##name arguments; \ | 480 | 49.6k | } \ |
__wrap_ngtcp2_conn_set_stream_user_data Line | Count | Source | 474 | 850 | ->decltype(__real_##name arguments) { \ | 475 | 850 | if (IsRealCallActive()) \ | 476 | 850 | return __real_##name arguments; \ | 477 | 850 | CheckNoTransaction(conn_argument, #name); \ | 478 | 850 | RealCallScope real_call; \ | 479 | 850 | return __real_##name arguments; \ | 480 | 850 | } \ |
__wrap_ngtcp2_conn_write_pkt_versioned Line | Count | Source | 474 | 48.4k | ->decltype(__real_##name arguments) { \ | 475 | 48.4k | if (IsRealCallActive()) \ | 476 | 48.4k | return __real_##name arguments; \ | 477 | 48.4k | CheckNoTransaction(conn_argument, #name); \ | 478 | 48.4k | RealCallScope real_call; \ | 479 | 48.4k | return __real_##name arguments; \ | 480 | 48.4k | } \ |
|
481 | | ASSERT_SIGNATURE(name) |
482 | | |
483 | | #define DEFINE_CHECKED_VOID_WRAPPER(name, parameters, arguments, \ |
484 | | conn_argument) \ |
485 | 53.8k | extern "C" void __wrap_##name parameters { \ |
486 | 53.8k | if (IsRealCallActive()) { \ |
487 | 21.3k | __real_##name arguments; \ |
488 | 21.3k | return; \ |
489 | 21.3k | } \ |
490 | 53.8k | CheckNoTransaction(conn_argument, #name); \ |
491 | 32.5k | RealCallScope real_call; \ |
492 | 32.5k | __real_##name arguments; \ |
493 | 32.5k | } \ __wrap_ngtcp2_conn_extend_max_offset Line | Count | Source | 485 | 21.3k | extern "C" void __wrap_##name parameters { \ | 486 | 21.3k | if (IsRealCallActive()) { \ | 487 | 21.3k | __real_##name arguments; \ | 488 | 21.3k | return; \ | 489 | 21.3k | } \ | 490 | 21.3k | CheckNoTransaction(conn_argument, #name); \ | 491 | 0 | RealCallScope real_call; \ | 492 | 0 | __real_##name arguments; \ | 493 | 0 | } \ |
__wrap_ngtcp2_conn_set_keep_alive_timeout Line | Count | Source | 485 | 3.51k | extern "C" void __wrap_##name parameters { \ | 486 | 3.51k | if (IsRealCallActive()) { \ | 487 | 0 | __real_##name arguments; \ | 488 | 0 | return; \ | 489 | 0 | } \ | 490 | 3.51k | CheckNoTransaction(conn_argument, #name); \ | 491 | 3.51k | RealCallScope real_call; \ | 492 | 3.51k | __real_##name arguments; \ | 493 | 3.51k | } \ |
__wrap_ngtcp2_conn_set_tls_native_handle Line | Count | Source | 485 | 5.30k | extern "C" void __wrap_##name parameters { \ | 486 | 5.30k | if (IsRealCallActive()) { \ | 487 | 0 | __real_##name arguments; \ | 488 | 0 | return; \ | 489 | 0 | } \ | 490 | 5.30k | CheckNoTransaction(conn_argument, #name); \ | 491 | 5.30k | RealCallScope real_call; \ | 492 | 5.30k | __real_##name arguments; \ | 493 | 5.30k | } \ |
__wrap_ngtcp2_conn_update_pkt_tx_time Line | Count | Source | 485 | 23.7k | extern "C" void __wrap_##name parameters { \ | 486 | 23.7k | if (IsRealCallActive()) { \ | 487 | 0 | __real_##name arguments; \ | 488 | 0 | return; \ | 489 | 0 | } \ | 490 | 23.7k | CheckNoTransaction(conn_argument, #name); \ | 491 | 23.7k | RealCallScope real_call; \ | 492 | 23.7k | __real_##name arguments; \ | 493 | 23.7k | } \ |
|
494 | | ASSERT_SIGNATURE(name) |
495 | | |
496 | | #define DEFINE_TERMINAL_INSPECTION_WRAPPER(name, parameters, arguments, \ |
497 | | conn_argument) \ |
498 | | extern "C" auto __wrap_##name parameters \ |
499 | 508 | ->decltype(__real_##name arguments) { \ |
500 | 508 | if (IsRealCallActive()) \ |
501 | 508 | return __real_##name arguments; \ |
502 | 508 | CheckNoTransaction(conn_argument, #name, false, true); \ |
503 | 508 | RealCallScope real_call; \ |
504 | 508 | return __real_##name arguments; \ |
505 | 508 | } \ Unexecuted instantiation: __wrap_ngtcp2_conn_get_ccerr __wrap_ngtcp2_conn_in_draining_period Line | Count | Source | 499 | 501 | ->decltype(__real_##name arguments) { \ | 500 | 501 | if (IsRealCallActive()) \ | 501 | 501 | return __real_##name arguments; \ | 502 | 501 | CheckNoTransaction(conn_argument, #name, false, true); \ | 503 | 501 | RealCallScope real_call; \ | 504 | 501 | return __real_##name arguments; \ | 505 | 501 | } \ |
__wrap_ngtcp2_conn_get_tls_alert Line | Count | Source | 499 | 7 | ->decltype(__real_##name arguments) { \ | 500 | 7 | if (IsRealCallActive()) \ | 501 | 7 | return __real_##name arguments; \ | 502 | 7 | CheckNoTransaction(conn_argument, #name, false, true); \ | 503 | 7 | RealCallScope real_call; \ | 504 | 7 | return __real_##name arguments; \ | 505 | 7 | } \ |
|
506 | | ASSERT_SIGNATURE(name) |
507 | | |
508 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_decode_and_set_0rtt_transport_params, |
509 | | (ngtcp2_conn * conn, const uint8_t *data, |
510 | | size_t datalen), |
511 | | (conn, data, datalen), conn); |
512 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_encode_0rtt_transport_params, |
513 | | (ngtcp2_conn * conn, uint8_t *dest, size_t destlen), |
514 | | (conn, dest, destlen), conn); |
515 | | DEFINE_CHECKED_VOID_WRAPPER(ngtcp2_conn_extend_max_offset, |
516 | | (ngtcp2_conn * conn, uint64_t datalen), |
517 | | (conn, datalen), conn); |
518 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_extend_max_stream_offset, |
519 | | (ngtcp2_conn * conn, int64_t stream_id, |
520 | | uint64_t datalen), |
521 | | (conn, stream_id, datalen), conn); |
522 | | DEFINE_TERMINAL_INSPECTION_WRAPPER(ngtcp2_conn_get_ccerr, (ngtcp2_conn * conn), |
523 | | (conn), conn); |
524 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_cwnd_left, (ngtcp2_conn * conn), (conn), |
525 | | conn); |
526 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_expiry, (ngtcp2_conn * conn), (conn), |
527 | | conn); |
528 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_expiry2, (const ngtcp2_conn *conn), |
529 | | (conn), conn); |
530 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_handshake_completed, |
531 | | (ngtcp2_conn * conn), (conn), conn); |
532 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_max_data_left, (ngtcp2_conn * conn), |
533 | | (conn), conn); |
534 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_max_tx_udp_payload_size, |
535 | | (ngtcp2_conn * conn), (conn), conn); |
536 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_path_max_tx_udp_payload_size, |
537 | | (ngtcp2_conn * conn), (conn), conn); |
538 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_remote_transport_params, |
539 | | (ngtcp2_conn * conn), (conn), conn); |
540 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_send_quantum, (ngtcp2_conn * conn), |
541 | | (conn), conn); |
542 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_stream_user_data, |
543 | | (ngtcp2_conn * conn, int64_t stream_id), |
544 | | (conn, stream_id), conn); |
545 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_streams_uni_left, (ngtcp2_conn * conn), |
546 | | (conn), conn); |
547 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_timestamp, (const ngtcp2_conn *conn), |
548 | | (conn), conn); |
549 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_get_tls_early_data_rejected2, |
550 | | (const ngtcp2_conn *conn), (conn), conn); |
551 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_handle_expiry, |
552 | | (ngtcp2_conn * conn, ngtcp2_tstamp timestamp), |
553 | | (conn, timestamp), conn); |
554 | | DEFINE_TERMINAL_INSPECTION_WRAPPER(ngtcp2_conn_in_draining_period, |
555 | | (ngtcp2_conn * conn), (conn), conn); |
556 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_open_bidi_stream, |
557 | | (ngtcp2_conn * conn, int64_t *stream_id, |
558 | | void *stream_user_data), |
559 | | (conn, stream_id, stream_user_data), conn); |
560 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_open_uni_stream, |
561 | | (ngtcp2_conn * conn, int64_t *stream_id, |
562 | | void *stream_user_data), |
563 | | (conn, stream_id, stream_user_data), conn); |
564 | | DEFINE_CHECKED_WRAPPER( |
565 | | ngtcp2_conn_read_pkt_versioned, |
566 | | (ngtcp2_conn * conn, const ngtcp2_path *path, int pkt_info_version, |
567 | | const ngtcp2_pkt_info *pi, const uint8_t *packet, size_t packet_length, |
568 | | ngtcp2_tstamp timestamp), |
569 | | (conn, path, pkt_info_version, pi, packet, packet_length, timestamp), conn); |
570 | | DEFINE_CHECKED_VOID_WRAPPER(ngtcp2_conn_set_keep_alive_timeout, |
571 | | (ngtcp2_conn * conn, ngtcp2_duration timeout), |
572 | | (conn, timeout), conn); |
573 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_set_stream_user_data, |
574 | | (ngtcp2_conn * conn, int64_t stream_id, |
575 | | void *stream_user_data), |
576 | | (conn, stream_id, stream_user_data), conn); |
577 | | DEFINE_CHECKED_VOID_WRAPPER(ngtcp2_conn_set_tls_native_handle, |
578 | | (ngtcp2_conn * conn, void *tls_native_handle), |
579 | | (conn, tls_native_handle), conn); |
580 | | DEFINE_CHECKED_VOID_WRAPPER(ngtcp2_conn_update_pkt_tx_time, |
581 | | (ngtcp2_conn * conn, ngtcp2_tstamp timestamp), |
582 | | (conn, timestamp), conn); |
583 | | DEFINE_CHECKED_WRAPPER(ngtcp2_conn_write_pkt_versioned, |
584 | | (ngtcp2_conn * conn, ngtcp2_path *path, |
585 | | int pkt_info_version, ngtcp2_pkt_info *pi, |
586 | | uint8_t *dest, size_t destlen, ngtcp2_tstamp timestamp), |
587 | | (conn, path, pkt_info_version, pi, dest, destlen, |
588 | | timestamp), |
589 | | conn); |
590 | | |
591 | | DEFINE_TERMINAL_INSPECTION_WRAPPER(ngtcp2_conn_get_tls_alert, |
592 | | (ngtcp2_conn * conn), (conn), conn); |
593 | | |
594 | | #undef DEFINE_TERMINAL_INSPECTION_WRAPPER |
595 | | #undef DEFINE_CHECKED_VOID_WRAPPER |
596 | | #undef DEFINE_CHECKED_WRAPPER |
597 | | |
598 | | #define DEFINE_ALLOWED_SHUTDOWN_WRAPPER(name) \ |
599 | | extern "C" int __wrap_##name(ngtcp2_conn *conn, uint32_t flags, \ |
600 | 1.06k | int64_t stream_id, uint64_t app_error_code) { \ |
601 | 1.06k | if (IsRealCallActive()) \ |
602 | 1.06k | return __real_##name(conn, flags, stream_id, app_error_code); \ |
603 | 1.06k | CheckNoTransaction(conn, #name, true, false); \ |
604 | 1.06k | RealCallScope real_call; \ |
605 | 1.06k | return __real_##name(conn, flags, stream_id, app_error_code); \ |
606 | 1.06k | } \ __wrap_ngtcp2_conn_shutdown_stream Line | Count | Source | 600 | 850 | int64_t stream_id, uint64_t app_error_code) { \ | 601 | 850 | if (IsRealCallActive()) \ | 602 | 850 | return __real_##name(conn, flags, stream_id, app_error_code); \ | 603 | 850 | CheckNoTransaction(conn, #name, true, false); \ | 604 | 850 | RealCallScope real_call; \ | 605 | 850 | return __real_##name(conn, flags, stream_id, app_error_code); \ | 606 | 850 | } \ |
Unexecuted instantiation: __wrap_ngtcp2_conn_shutdown_stream_read __wrap_ngtcp2_conn_shutdown_stream_write Line | Count | Source | 600 | 211 | int64_t stream_id, uint64_t app_error_code) { \ | 601 | 211 | if (IsRealCallActive()) \ | 602 | 211 | return __real_##name(conn, flags, stream_id, app_error_code); \ | 603 | 211 | CheckNoTransaction(conn, #name, true, false); \ | 604 | 211 | RealCallScope real_call; \ | 605 | 211 | return __real_##name(conn, flags, stream_id, app_error_code); \ | 606 | 211 | } \ |
|
607 | | ASSERT_SIGNATURE(name) |
608 | | |
609 | | DEFINE_ALLOWED_SHUTDOWN_WRAPPER(ngtcp2_conn_shutdown_stream); |
610 | | DEFINE_ALLOWED_SHUTDOWN_WRAPPER(ngtcp2_conn_shutdown_stream_read); |
611 | | DEFINE_ALLOWED_SHUTDOWN_WRAPPER(ngtcp2_conn_shutdown_stream_write); |
612 | | |
613 | | #undef DEFINE_ALLOWED_SHUTDOWN_WRAPPER |
614 | | |
615 | | extern "C" ngtcp2_ssize __wrap_ngtcp2_conn_write_connection_close_versioned( |
616 | | ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version, |
617 | | ngtcp2_pkt_info *pi, uint8_t *dest, size_t destlen, |
618 | 1.98k | const ngtcp2_ccerr *ccerr, ngtcp2_tstamp timestamp) { |
619 | 1.98k | if (IsRealCallActive()) |
620 | 3 | return __real_ngtcp2_conn_write_connection_close_versioned( |
621 | 3 | conn, path, pkt_info_version, pi, dest, destlen, ccerr, timestamp); |
622 | 1.98k | ngtcp2_ssize result; |
623 | 1.98k | { |
624 | 1.98k | RealCallScope real_call; |
625 | 1.98k | result = __real_ngtcp2_conn_write_connection_close_versioned( |
626 | 1.98k | conn, path, pkt_info_version, pi, dest, destlen, ccerr, timestamp); |
627 | 1.98k | } |
628 | 1.98k | return result; |
629 | 1.98k | } |
630 | | ASSERT_SIGNATURE(ngtcp2_conn_write_connection_close_versioned); |
631 | | |
632 | | #if defined(NGTCP2_CONTRACT_TESTING) |
633 | | #define NGTCP2_CONTRACT_TAKE_FORCED_STREAM(result, data_length, forced) \ |
634 | | forced = TakeForcedStreamResult(&(result), (data_length)) |
635 | | #define NGTCP2_CONTRACT_TAKE_FORCED_DATAGRAM(result, accepted, forced) \ |
636 | | forced = TakeForcedDatagramResult(&(result), (accepted)) |
637 | | #else |
638 | | #define NGTCP2_CONTRACT_TAKE_FORCED_STREAM(result, data_length, forced) \ |
639 | 168k | do { \ |
640 | 168k | } while (false) |
641 | | #define NGTCP2_CONTRACT_TAKE_FORCED_DATAGRAM(result, accepted, forced) \ |
642 | 0 | do { \ |
643 | 0 | } while (false) |
644 | | #endif |
645 | | |
646 | | #define DEFINE_STREAM_WRITE_WRAPPER(name, data_type, data_name, count_name) \ |
647 | | extern "C" ngtcp2_ssize __wrap_##name( \ |
648 | | ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version, \ |
649 | | ngtcp2_pkt_info *pi, uint8_t *dest, size_t destlen, \ |
650 | | ngtcp2_ssize *pdatalen, uint32_t flags, int64_t stream_id, \ |
651 | 168k | data_type *data_name, size_t count_name, ngtcp2_tstamp timestamp) { \ |
652 | 168k | if (IsRealCallActive()) \ |
653 | 168k | return __real_##name(conn, path, pkt_info_version, pi, dest, destlen, \ |
654 | 0 | pdatalen, flags, stream_id, data_name, count_name, \ |
655 | 0 | timestamp); \ |
656 | 168k | const ContinuationState continuation = \ |
657 | 168k | CheckContinuation(conn, path, pi, dest, destlen, timestamp, #name); \ |
658 | 168k | ngtcp2_ssize result; \ |
659 | 168k | bool forced = false; \ |
660 | 168k | (void)forced; \ |
661 | 168k | /* Test builds can inject documented outcomes without constructing a */ \ |
662 | 168k | /* complete encrypted QUIC session. */ \ |
663 | 168k | /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ |
664 | 168k | NGTCP2_CONTRACT_TAKE_FORCED_STREAM(result, pdatalen, forced); \ |
665 | 168k | if (!forced) { \ |
666 | 168k | RealCallScope real_call; \ |
667 | 168k | result = __real_##name(conn, path, pkt_info_version, pi, dest, destlen, \ |
668 | 168k | pdatalen, flags, stream_id, data_name, \ |
669 | 168k | count_name, timestamp); \ |
670 | 168k | } \ |
671 | 168k | ValidateStreamPostcondition(#name, result, pdatalen); \ |
672 | 168k | const TransactionOrigin origin = \ |
673 | 168k | continuation.active ? continuation.origin : TransactionOrigin::Stream; \ |
674 | 168k | const bool stream_coalescing = \ |
675 | 168k | origin == TransactionOrigin::Stream && \ |
676 | 168k | (continuation.active || (flags & NGTCP2_WRITE_STREAM_FLAG_MORE) != 0); \ |
677 | 168k | const bool connection_error = \ |
678 | 168k | IsFatalResult(result) || (stream_coalescing && result < 0 && \ |
679 | 168k | !IsStreamContinuationResult(result)); \ |
680 | 168k | if (connection_error) { \ |
681 | 23 | RecordCloseOnly(conn, #name, result); \ |
682 | 23 | return result; \ |
683 | 23 | } \ |
684 | 168k | const bool keep_open = \ |
685 | 168k | (IsStreamContinuationResult(result) && \ |
686 | 168k | (continuation.active || \ |
687 | 8.96k | (flags & NGTCP2_WRITE_STREAM_FLAG_MORE) != 0)) || \ |
688 | 168k | (continuation.active && \ |
689 | 159k | continuation.origin == TransactionOrigin::Datagram && result <= 0); \ |
690 | 168k | RecordTransaction(conn, #name, path, pi, dest, destlen, timestamp, origin, \ |
691 | 168k | keep_open); \ |
692 | 168k | return result; \ |
693 | 168k | } \ Unexecuted instantiation: __wrap_ngtcp2_conn_write_stream_versioned __wrap_ngtcp2_conn_writev_stream_versioned Line | Count | Source | 651 | 168k | data_type *data_name, size_t count_name, ngtcp2_tstamp timestamp) { \ | 652 | 168k | if (IsRealCallActive()) \ | 653 | 168k | return __real_##name(conn, path, pkt_info_version, pi, dest, destlen, \ | 654 | 0 | pdatalen, flags, stream_id, data_name, count_name, \ | 655 | 0 | timestamp); \ | 656 | 168k | const ContinuationState continuation = \ | 657 | 168k | CheckContinuation(conn, path, pi, dest, destlen, timestamp, #name); \ | 658 | 168k | ngtcp2_ssize result; \ | 659 | 168k | bool forced = false; \ | 660 | 168k | (void)forced; \ | 661 | 168k | /* Test builds can inject documented outcomes without constructing a */ \ | 662 | 168k | /* complete encrypted QUIC session. */ \ | 663 | 168k | /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ | 664 | 168k | NGTCP2_CONTRACT_TAKE_FORCED_STREAM(result, pdatalen, forced); \ | 665 | 168k | if (!forced) { \ | 666 | 168k | RealCallScope real_call; \ | 667 | 168k | result = __real_##name(conn, path, pkt_info_version, pi, dest, destlen, \ | 668 | 168k | pdatalen, flags, stream_id, data_name, \ | 669 | 168k | count_name, timestamp); \ | 670 | 168k | } \ | 671 | 168k | ValidateStreamPostcondition(#name, result, pdatalen); \ | 672 | 168k | const TransactionOrigin origin = \ | 673 | 168k | continuation.active ? continuation.origin : TransactionOrigin::Stream; \ | 674 | 168k | const bool stream_coalescing = \ | 675 | 168k | origin == TransactionOrigin::Stream && \ | 676 | 168k | (continuation.active || (flags & NGTCP2_WRITE_STREAM_FLAG_MORE) != 0); \ | 677 | 168k | const bool connection_error = \ | 678 | 168k | IsFatalResult(result) || (stream_coalescing && result < 0 && \ | 679 | 168k | !IsStreamContinuationResult(result)); \ | 680 | 168k | if (connection_error) { \ | 681 | 23 | RecordCloseOnly(conn, #name, result); \ | 682 | 23 | return result; \ | 683 | 23 | } \ | 684 | 168k | const bool keep_open = \ | 685 | 168k | (IsStreamContinuationResult(result) && \ | 686 | 168k | (continuation.active || \ | 687 | 8.96k | (flags & NGTCP2_WRITE_STREAM_FLAG_MORE) != 0)) || \ | 688 | 168k | (continuation.active && \ | 689 | 159k | continuation.origin == TransactionOrigin::Datagram && result <= 0); \ | 690 | 168k | RecordTransaction(conn, #name, path, pi, dest, destlen, timestamp, origin, \ | 691 | 168k | keep_open); \ | 692 | 168k | return result; \ | 693 | 168k | } \ |
|
694 | | ASSERT_SIGNATURE(name) |
695 | | |
696 | | DEFINE_STREAM_WRITE_WRAPPER(ngtcp2_conn_write_stream_versioned, const uint8_t, |
697 | | data, datalen); |
698 | | DEFINE_STREAM_WRITE_WRAPPER(ngtcp2_conn_writev_stream_versioned, |
699 | | const ngtcp2_vec, data, datacnt); |
700 | | |
701 | | #undef DEFINE_STREAM_WRITE_WRAPPER |
702 | | |
703 | | #define DEFINE_DATAGRAM_WRITE_WRAPPER(name, data_type, data_name, count_name) \ |
704 | | extern "C" ngtcp2_ssize __wrap_##name( \ |
705 | | ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version, \ |
706 | | ngtcp2_pkt_info *pi, uint8_t *dest, size_t destlen, int *paccepted, \ |
707 | | uint32_t flags, uint64_t datagram_id, data_type *data_name, \ |
708 | 0 | size_t count_name, ngtcp2_tstamp timestamp) { \ |
709 | 0 | if (IsRealCallActive()) \ |
710 | 0 | return __real_##name(conn, path, pkt_info_version, pi, dest, destlen, \ |
711 | 0 | paccepted, flags, datagram_id, data_name, \ |
712 | 0 | count_name, timestamp); \ |
713 | 0 | const ContinuationState continuation = \ |
714 | 0 | CheckContinuation(conn, path, pi, dest, destlen, timestamp, #name); \ |
715 | 0 | ngtcp2_ssize result; \ |
716 | 0 | bool forced = false; \ |
717 | 0 | (void)forced; \ |
718 | 0 | NGTCP2_CONTRACT_TAKE_FORCED_DATAGRAM(result, paccepted, forced); \ |
719 | 0 | if (!forced) { \ |
720 | 0 | RealCallScope real_call; \ |
721 | 0 | result = __real_##name(conn, path, pkt_info_version, pi, dest, destlen, \ |
722 | 0 | paccepted, flags, datagram_id, data_name, \ |
723 | 0 | count_name, timestamp); \ |
724 | 0 | } \ |
725 | 0 | ValidateDatagramPostcondition(#name, result, paccepted); \ |
726 | 0 | if (IsFatalResult(result)) { \ |
727 | 0 | RecordCloseOnly(conn, #name, result); \ |
728 | 0 | return result; \ |
729 | 0 | } \ |
730 | 0 | const bool keep_open = \ |
731 | 0 | result == NGTCP2_ERR_WRITE_MORE || \ |
732 | 0 | (continuation.active && \ |
733 | 0 | continuation.origin == TransactionOrigin::Datagram && result <= 0); \ |
734 | 0 | RecordTransaction(conn, #name, path, pi, dest, destlen, timestamp, \ |
735 | 0 | continuation.active ? continuation.origin \ |
736 | 0 | : TransactionOrigin::Datagram, \ |
737 | 0 | keep_open); \ |
738 | 0 | return result; \ |
739 | 0 | } \ Unexecuted instantiation: __wrap_ngtcp2_conn_write_datagram_versioned Unexecuted instantiation: __wrap_ngtcp2_conn_writev_datagram_versioned |
740 | | ASSERT_SIGNATURE(name) |
741 | | |
742 | | DEFINE_DATAGRAM_WRITE_WRAPPER(ngtcp2_conn_write_datagram_versioned, |
743 | | const uint8_t, data, datalen); |
744 | | DEFINE_DATAGRAM_WRITE_WRAPPER(ngtcp2_conn_writev_datagram_versioned, |
745 | | const ngtcp2_vec, data, datacnt); |
746 | | |
747 | | #undef DEFINE_DATAGRAM_WRITE_WRAPPER |
748 | | #undef NGTCP2_CONTRACT_TAKE_FORCED_DATAGRAM |
749 | | #undef NGTCP2_CONTRACT_TAKE_FORCED_STREAM |
750 | | #undef ASSERT_SIGNATURE |