/src/curl_fuzzer/proto_fuzzer/curl_global_lifecycle.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | /// @file |
8 | | /// @brief Process-wide libcurl initialization and final cleanup. |
9 | | |
10 | | #ifndef PROTO_FUZZER_CURL_GLOBAL_LIFECYCLE_H_ |
11 | | #define PROTO_FUZZER_CURL_GLOBAL_LIFECYCLE_H_ |
12 | | |
13 | | namespace proto_fuzzer { |
14 | | |
15 | | /** Own the proto runtime's one curl global initialization. */ |
16 | | class CurlGlobalLifecycle final { |
17 | | public: |
18 | | /** Process-exit cleanup callback, injectable for lifecycle regression tests. */ |
19 | | using CleanupFunction = void (*)(); |
20 | | |
21 | | explicit CurlGlobalLifecycle(CleanupFunction cleanup = nullptr) noexcept; |
22 | | ~CurlGlobalLifecycle(); |
23 | | |
24 | | CurlGlobalLifecycle(const CurlGlobalLifecycle&) = delete; |
25 | | CurlGlobalLifecycle& operator=(const CurlGlobalLifecycle&) = delete; |
26 | | CurlGlobalLifecycle(CurlGlobalLifecycle&&) = delete; |
27 | | CurlGlobalLifecycle& operator=(CurlGlobalLifecycle&&) = delete; |
28 | | |
29 | | /** @return Whether this object owns a successful curl initialization. */ |
30 | 0 | bool initialized() const noexcept { return initialized_; } |
31 | | |
32 | | void FinalizeForProcessExit() noexcept; |
33 | | |
34 | | private: |
35 | | friend void FinalizeRegisteredCurlGlobalLifecyclesForExit() noexcept; |
36 | | |
37 | | CleanupFunction cleanup_; |
38 | | CurlGlobalLifecycle* next_registered_ = nullptr; |
39 | | unsigned int initialization_count_ = 0; |
40 | | bool initialized_ = false; |
41 | | }; |
42 | | |
43 | | void FinalizeRegisteredCurlGlobalLifecyclesForExit() noexcept; |
44 | | |
45 | | } // namespace proto_fuzzer |
46 | | |
47 | | #endif // PROTO_FUZZER_CURL_GLOBAL_LIFECYCLE_H_ |