io.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/io/io.h>
  6. #include <aws/io/logging.h>
  7. #include <aws/cal/cal.h>
  8. #define AWS_DEFINE_ERROR_INFO_IO(CODE, STR) [(CODE)-0x0400] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-io")
  9. #define AWS_DEFINE_ERROR_PKCS11_CKR(CKR) \
  10. AWS_DEFINE_ERROR_INFO_IO( \
  11. AWS_ERROR_PKCS11_##CKR, "A PKCS#11 (Cryptoki) library function failed with return value " #CKR)
  12. /* clang-format off */
  13. static struct aws_error_info s_errors[] = {
  14. AWS_DEFINE_ERROR_INFO_IO(
  15. AWS_IO_CHANNEL_ERROR_ERROR_CANT_ACCEPT_INPUT,
  16. "Channel cannot accept input"),
  17. AWS_DEFINE_ERROR_INFO_IO(
  18. AWS_IO_CHANNEL_UNKNOWN_MESSAGE_TYPE,
  19. "Channel unknown message type"),
  20. AWS_DEFINE_ERROR_INFO_IO(
  21. AWS_IO_CHANNEL_READ_WOULD_EXCEED_WINDOW,
  22. "A channel handler attempted to propagate a read larger than the upstream window"),
  23. AWS_DEFINE_ERROR_INFO_IO(
  24. AWS_IO_EVENT_LOOP_ALREADY_ASSIGNED,
  25. "An attempt was made to assign an io handle to an event loop, but the handle was already assigned."),
  26. AWS_DEFINE_ERROR_INFO_IO(
  27. AWS_IO_EVENT_LOOP_SHUTDOWN,
  28. "Event loop has shutdown and a resource was still using it, the resource has been removed from the loop."),
  29. AWS_DEFINE_ERROR_INFO_IO(
  30. AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
  31. "TLS (SSL) negotiation failed"),
  32. AWS_DEFINE_ERROR_INFO_IO(
  33. AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
  34. "Attempt to read/write, but TLS (SSL) hasn't been negotiated"),
  35. AWS_DEFINE_ERROR_INFO_IO(
  36. AWS_IO_TLS_ERROR_WRITE_FAILURE,
  37. "Failed to write to TLS handler"),
  38. AWS_DEFINE_ERROR_INFO_IO(
  39. AWS_IO_TLS_ERROR_ALERT_RECEIVED,
  40. "Fatal TLS Alert was received"),
  41. AWS_DEFINE_ERROR_INFO_IO(
  42. AWS_IO_TLS_CTX_ERROR,
  43. "Failed to create tls context"),
  44. AWS_DEFINE_ERROR_INFO_IO(
  45. AWS_IO_TLS_VERSION_UNSUPPORTED,
  46. "A TLS version was specified that is currently not supported. Consider using AWS_IO_TLS_VER_SYS_DEFAULTS, "
  47. " and when this lib or the operating system is updated, it will automatically be used."),
  48. AWS_DEFINE_ERROR_INFO_IO(
  49. AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
  50. "A TLS Cipher Preference was specified that is currently not supported by the current platform. Consider "
  51. " using AWS_IO_TLS_CIPHER_SYSTEM_DEFAULT, and when this lib or the operating system is updated, it will "
  52. "automatically be used."),
  53. AWS_DEFINE_ERROR_INFO_IO(
  54. AWS_IO_MISSING_ALPN_MESSAGE,
  55. "An ALPN message was expected but not received"),
  56. AWS_DEFINE_ERROR_INFO_IO(
  57. AWS_IO_UNHANDLED_ALPN_PROTOCOL_MESSAGE,
  58. "An ALPN message was received but a handler was not created by the user"),
  59. AWS_DEFINE_ERROR_INFO_IO(
  60. AWS_IO_FILE_VALIDATION_FAILURE,
  61. "A file was read and the input did not match the expected value"),
  62. AWS_DEFINE_ERROR_INFO_IO(
  63. AWS_ERROR_IO_EVENT_LOOP_THREAD_ONLY,
  64. "Attempt to perform operation that must be run inside the event loop thread"),
  65. AWS_DEFINE_ERROR_INFO_IO(
  66. AWS_ERROR_IO_ALREADY_SUBSCRIBED,
  67. "Already subscribed to receive events"),
  68. AWS_DEFINE_ERROR_INFO_IO(
  69. AWS_ERROR_IO_NOT_SUBSCRIBED,
  70. "Not subscribed to receive events"),
  71. AWS_DEFINE_ERROR_INFO_IO(
  72. AWS_ERROR_IO_OPERATION_CANCELLED,
  73. "Operation cancelled before it could complete"),
  74. AWS_DEFINE_ERROR_INFO_IO(
  75. AWS_IO_READ_WOULD_BLOCK,
  76. "Read operation would block, try again later"),
  77. AWS_DEFINE_ERROR_INFO_IO(
  78. AWS_IO_BROKEN_PIPE,
  79. "Attempt to read or write to io handle that has already been closed."),
  80. AWS_DEFINE_ERROR_INFO_IO(
  81. AWS_IO_SOCKET_UNSUPPORTED_ADDRESS_FAMILY,
  82. "Socket, unsupported address family."),
  83. AWS_DEFINE_ERROR_INFO_IO(
  84. AWS_IO_SOCKET_INVALID_OPERATION_FOR_TYPE,
  85. "Invalid socket operation for socket type."),
  86. AWS_DEFINE_ERROR_INFO_IO(
  87. AWS_IO_SOCKET_CONNECTION_REFUSED,
  88. "socket connection refused."),
  89. AWS_DEFINE_ERROR_INFO_IO(
  90. AWS_IO_SOCKET_TIMEOUT,
  91. "socket operation timed out."),
  92. AWS_DEFINE_ERROR_INFO_IO(
  93. AWS_IO_SOCKET_NO_ROUTE_TO_HOST,
  94. "socket connect failure, no route to host."),
  95. AWS_DEFINE_ERROR_INFO_IO(
  96. AWS_IO_SOCKET_NETWORK_DOWN,
  97. "network is down."),
  98. AWS_DEFINE_ERROR_INFO_IO(
  99. AWS_IO_SOCKET_CLOSED,
  100. "socket is closed."),
  101. AWS_DEFINE_ERROR_INFO_IO(
  102. AWS_IO_SOCKET_NOT_CONNECTED,
  103. "socket not connected."),
  104. AWS_DEFINE_ERROR_INFO_IO(
  105. AWS_IO_SOCKET_INVALID_OPTIONS,
  106. "Invalid socket options."),
  107. AWS_DEFINE_ERROR_INFO_IO(
  108. AWS_IO_SOCKET_ADDRESS_IN_USE,
  109. "Socket address already in use."),
  110. AWS_DEFINE_ERROR_INFO_IO(
  111. AWS_IO_SOCKET_INVALID_ADDRESS,
  112. "Invalid socket address."),
  113. AWS_DEFINE_ERROR_INFO_IO(
  114. AWS_IO_SOCKET_ILLEGAL_OPERATION_FOR_STATE,
  115. "Illegal operation for socket state."),
  116. AWS_DEFINE_ERROR_INFO_IO(
  117. AWS_IO_SOCKET_CONNECT_ABORTED,
  118. "Incoming connection was aborted."),
  119. AWS_DEFINE_ERROR_INFO_IO (
  120. AWS_IO_DNS_QUERY_FAILED,
  121. "A query to dns failed to resolve."),
  122. AWS_DEFINE_ERROR_INFO_IO(
  123. AWS_IO_DNS_INVALID_NAME,
  124. "Host name was invalid for dns resolution."),
  125. AWS_DEFINE_ERROR_INFO_IO(
  126. AWS_IO_DNS_NO_ADDRESS_FOR_HOST,
  127. "No address was found for the supplied host name."),
  128. AWS_DEFINE_ERROR_INFO_IO(
  129. AWS_IO_DNS_HOST_REMOVED_FROM_CACHE,
  130. "The entries for host name were removed from the local dns cache."),
  131. AWS_DEFINE_ERROR_INFO_IO(
  132. AWS_IO_STREAM_INVALID_SEEK_POSITION,
  133. "The seek position was outside of a stream's bounds"),
  134. AWS_DEFINE_ERROR_INFO_IO(
  135. AWS_IO_STREAM_READ_FAILED,
  136. "Stream failed to read from the underlying io source"),
  137. AWS_DEFINE_ERROR_INFO_IO(
  138. DEPRECATED_AWS_IO_INVALID_FILE_HANDLE,
  139. "Operation failed because the file handle was invalid"),
  140. AWS_DEFINE_ERROR_INFO_IO(
  141. AWS_IO_SHARED_LIBRARY_LOAD_FAILURE,
  142. "System call error during attempt to load shared library"),
  143. AWS_DEFINE_ERROR_INFO_IO(
  144. AWS_IO_SHARED_LIBRARY_FIND_SYMBOL_FAILURE,
  145. "System call error during attempt to find shared library symbol"),
  146. AWS_DEFINE_ERROR_INFO_IO(
  147. AWS_IO_TLS_NEGOTIATION_TIMEOUT,
  148. "Channel shutdown due to tls negotiation timeout"),
  149. AWS_DEFINE_ERROR_INFO_IO(
  150. AWS_IO_TLS_ALERT_NOT_GRACEFUL,
  151. "Channel shutdown due to tls alert. The alert was not for a graceful shutdown."),
  152. AWS_DEFINE_ERROR_INFO_IO(
  153. AWS_IO_MAX_RETRIES_EXCEEDED,
  154. "Retry cannot be attempted because the maximum number of retries has been exceeded."),
  155. AWS_DEFINE_ERROR_INFO_IO(
  156. AWS_IO_RETRY_PERMISSION_DENIED,
  157. "Retry cannot be attempted because the retry strategy has prevented the operation."),
  158. AWS_DEFINE_ERROR_INFO_IO(
  159. AWS_IO_TLS_DIGEST_ALGORITHM_UNSUPPORTED,
  160. "TLS digest was created with an unsupported algorithm"),
  161. AWS_DEFINE_ERROR_INFO_IO(
  162. AWS_IO_TLS_SIGNATURE_ALGORITHM_UNSUPPORTED,
  163. "TLS signature algorithm is currently unsupported."),
  164. AWS_DEFINE_ERROR_INFO_IO(
  165. AWS_ERROR_PKCS11_VERSION_UNSUPPORTED,
  166. "The PKCS#11 library uses an unsupported API version."),
  167. AWS_DEFINE_ERROR_INFO_IO(
  168. AWS_ERROR_PKCS11_TOKEN_NOT_FOUND,
  169. "Could not pick PKCS#11 token matching search criteria (none found, or multiple found)"),
  170. AWS_DEFINE_ERROR_INFO_IO(
  171. AWS_ERROR_PKCS11_KEY_NOT_FOUND,
  172. "Could not pick PKCS#11 key matching search criteria (none found, or multiple found)"),
  173. AWS_DEFINE_ERROR_INFO_IO(
  174. AWS_ERROR_PKCS11_KEY_TYPE_UNSUPPORTED,
  175. "PKCS#11 key type not supported"),
  176. AWS_DEFINE_ERROR_INFO_IO(
  177. AWS_ERROR_PKCS11_UNKNOWN_CRYPTOKI_RETURN_VALUE,
  178. "A PKCS#11 (Cryptoki) library function failed with an unknown return value (CKR_). See log for more details."),
  179. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_CANCEL),
  180. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_HOST_MEMORY),
  181. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SLOT_ID_INVALID),
  182. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_GENERAL_ERROR),
  183. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_FUNCTION_FAILED),
  184. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ARGUMENTS_BAD),
  185. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_NO_EVENT),
  186. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_NEED_TO_CREATE_THREADS),
  187. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_CANT_LOCK),
  188. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ATTRIBUTE_READ_ONLY),
  189. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ATTRIBUTE_SENSITIVE),
  190. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ATTRIBUTE_TYPE_INVALID),
  191. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ATTRIBUTE_VALUE_INVALID),
  192. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ACTION_PROHIBITED),
  193. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_DATA_INVALID),
  194. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_DATA_LEN_RANGE),
  195. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_DEVICE_ERROR),
  196. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_DEVICE_MEMORY),
  197. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_DEVICE_REMOVED),
  198. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ENCRYPTED_DATA_INVALID),
  199. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_ENCRYPTED_DATA_LEN_RANGE),
  200. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_FUNCTION_CANCELED),
  201. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_FUNCTION_NOT_PARALLEL),
  202. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_FUNCTION_NOT_SUPPORTED),
  203. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_HANDLE_INVALID),
  204. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_SIZE_RANGE),
  205. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_TYPE_INCONSISTENT),
  206. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_NOT_NEEDED),
  207. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_CHANGED),
  208. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_NEEDED),
  209. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_INDIGESTIBLE),
  210. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_FUNCTION_NOT_PERMITTED),
  211. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_NOT_WRAPPABLE),
  212. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_KEY_UNEXTRACTABLE),
  213. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_MECHANISM_INVALID),
  214. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_MECHANISM_PARAM_INVALID),
  215. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_OBJECT_HANDLE_INVALID),
  216. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_OPERATION_ACTIVE),
  217. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_OPERATION_NOT_INITIALIZED),
  218. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PIN_INCORRECT),
  219. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PIN_INVALID),
  220. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PIN_LEN_RANGE),
  221. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PIN_EXPIRED),
  222. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PIN_LOCKED),
  223. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_CLOSED),
  224. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_COUNT),
  225. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_HANDLE_INVALID),
  226. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_PARALLEL_NOT_SUPPORTED),
  227. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_READ_ONLY),
  228. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_EXISTS),
  229. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_READ_ONLY_EXISTS),
  230. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SESSION_READ_WRITE_SO_EXISTS),
  231. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SIGNATURE_INVALID),
  232. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SIGNATURE_LEN_RANGE),
  233. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_TEMPLATE_INCOMPLETE),
  234. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_TEMPLATE_INCONSISTENT),
  235. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_TOKEN_NOT_PRESENT),
  236. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_TOKEN_NOT_RECOGNIZED),
  237. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_TOKEN_WRITE_PROTECTED),
  238. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_UNWRAPPING_KEY_HANDLE_INVALID),
  239. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_UNWRAPPING_KEY_SIZE_RANGE),
  240. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT),
  241. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_USER_ALREADY_LOGGED_IN),
  242. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_USER_NOT_LOGGED_IN),
  243. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_USER_PIN_NOT_INITIALIZED),
  244. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_USER_TYPE_INVALID),
  245. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_USER_ANOTHER_ALREADY_LOGGED_IN),
  246. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_USER_TOO_MANY_TYPES),
  247. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_WRAPPED_KEY_INVALID),
  248. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_WRAPPED_KEY_LEN_RANGE),
  249. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_WRAPPING_KEY_HANDLE_INVALID),
  250. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_WRAPPING_KEY_SIZE_RANGE),
  251. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_WRAPPING_KEY_TYPE_INCONSISTENT),
  252. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_RANDOM_SEED_NOT_SUPPORTED),
  253. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_RANDOM_NO_RNG),
  254. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_DOMAIN_PARAMS_INVALID),
  255. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_CURVE_NOT_SUPPORTED),
  256. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_BUFFER_TOO_SMALL),
  257. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_SAVED_STATE_INVALID),
  258. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_INFORMATION_SENSITIVE),
  259. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_STATE_UNSAVEABLE),
  260. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_CRYPTOKI_NOT_INITIALIZED),
  261. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_CRYPTOKI_ALREADY_INITIALIZED),
  262. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_MUTEX_BAD),
  263. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_MUTEX_NOT_LOCKED),
  264. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_NEW_PIN_MODE),
  265. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_NEXT_OTP),
  266. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_EXCEEDED_MAX_ITERATIONS),
  267. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_FIPS_SELF_TEST_FAILED),
  268. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_LIBRARY_LOAD_FAILED),
  269. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PIN_TOO_WEAK),
  270. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_PUBLIC_KEY_INVALID),
  271. AWS_DEFINE_ERROR_PKCS11_CKR(CKR_FUNCTION_REJECTED),
  272. AWS_DEFINE_ERROR_INFO_IO(
  273. AWS_ERROR_IO_PINNED_EVENT_LOOP_MISMATCH,
  274. "A connection was requested on an event loop that is not associated with the client bootstrap's event loop group."),
  275. AWS_DEFINE_ERROR_INFO_IO(
  276. AWS_ERROR_PKCS11_ENCODING_ERROR,
  277. "A PKCS#11 (Cryptoki) library function was unable to ASN.1 (DER) encode a data structure. See log for more details."),
  278. AWS_DEFINE_ERROR_INFO_IO(
  279. AWS_IO_TLS_ERROR_DEFAULT_TRUST_STORE_NOT_FOUND,
  280. "Default TLS trust store not found on this system."
  281. " Trusted CA certificates must be installed,"
  282. " or \"override default trust store\" must be used while creating the TLS context."),
  283. AWS_DEFINE_ERROR_INFO_IO(
  284. AWS_IO_STREAM_SEEK_FAILED,
  285. "Stream failed to seek from the underlying I/O source."),
  286. AWS_DEFINE_ERROR_INFO_IO(
  287. AWS_IO_STREAM_GET_LENGTH_FAILED,
  288. "Stream failed to get length from the underlying I/O source."),
  289. AWS_DEFINE_ERROR_INFO_IO(
  290. AWS_IO_STREAM_SEEK_UNSUPPORTED,
  291. "Seek is not supported in the underlying I/O source."),
  292. AWS_DEFINE_ERROR_INFO_IO(
  293. AWS_IO_STREAM_GET_LENGTH_UNSUPPORTED,
  294. "Get length is not supported in the underlying I/O source."),
  295. };
  296. /* clang-format on */
  297. static struct aws_error_info_list s_list = {
  298. .error_list = s_errors,
  299. .count = sizeof(s_errors) / sizeof(struct aws_error_info),
  300. };
  301. static struct aws_log_subject_info s_io_log_subject_infos[] = {
  302. DEFINE_LOG_SUBJECT_INFO(
  303. AWS_LS_IO_GENERAL,
  304. "aws-c-io",
  305. "Subject for IO logging that doesn't belong to any particular category"),
  306. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_EVENT_LOOP, "event-loop", "Subject for Event-loop specific logging."),
  307. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_SOCKET, "socket", "Subject for Socket specific logging."),
  308. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_SOCKET_HANDLER, "socket-handler", "Subject for a socket channel handler."),
  309. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_TLS, "tls-handler", "Subject for TLS-related logging"),
  310. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_ALPN, "alpn", "Subject for ALPN-related logging"),
  311. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_DNS, "dns", "Subject for DNS-related logging"),
  312. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_PKI, "pki-utils", "Subject for Pki utilities."),
  313. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_CHANNEL, "channel", "Subject for Channels"),
  314. DEFINE_LOG_SUBJECT_INFO(
  315. AWS_LS_IO_CHANNEL_BOOTSTRAP,
  316. "channel-bootstrap",
  317. "Subject for channel bootstrap (client and server modes)"),
  318. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_FILE_UTILS, "file-utils", "Subject for file operations"),
  319. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_SHARED_LIBRARY, "shared-library", "Subject for shared library operations"),
  320. DEFINE_LOG_SUBJECT_INFO(
  321. AWS_LS_IO_EXPONENTIAL_BACKOFF_RETRY_STRATEGY,
  322. "exp-backoff-strategy",
  323. "Subject for exponential backoff retry strategy"),
  324. DEFINE_LOG_SUBJECT_INFO(
  325. AWS_LS_IO_STANDARD_RETRY_STRATEGY,
  326. "standard-retry-strategy",
  327. "Subject for standard retry strategy"),
  328. DEFINE_LOG_SUBJECT_INFO(AWS_LS_IO_PKCS11, "pkcs11", "Subject for PKCS#11 library operations"),
  329. };
  330. static struct aws_log_subject_info_list s_io_log_subject_list = {
  331. .subject_list = s_io_log_subject_infos,
  332. .count = AWS_ARRAY_SIZE(s_io_log_subject_infos),
  333. };
  334. static bool s_io_library_initialized = false;
  335. void aws_tls_init_static_state(struct aws_allocator *alloc);
  336. void aws_tls_clean_up_static_state(void);
  337. void aws_io_library_init(struct aws_allocator *allocator) {
  338. if (!s_io_library_initialized) {
  339. s_io_library_initialized = true;
  340. aws_common_library_init(allocator);
  341. aws_cal_library_init(allocator);
  342. aws_register_error_info(&s_list);
  343. aws_register_log_subject_info_list(&s_io_log_subject_list);
  344. aws_tls_init_static_state(allocator);
  345. }
  346. }
  347. void aws_io_library_clean_up(void) {
  348. if (s_io_library_initialized) {
  349. s_io_library_initialized = false;
  350. aws_thread_join_all_managed();
  351. aws_tls_clean_up_static_state();
  352. aws_unregister_error_info(&s_list);
  353. aws_unregister_log_subject_info_list(&s_io_log_subject_list);
  354. aws_cal_library_clean_up();
  355. aws_common_library_clean_up();
  356. }
  357. }
  358. void aws_io_fatal_assert_library_initialized(void) {
  359. if (!s_io_library_initialized) {
  360. AWS_LOGF_FATAL(
  361. AWS_LS_IO_GENERAL, "aws_io_library_init() must be called before using any functionality in aws-c-io.");
  362. AWS_FATAL_ASSERT(s_io_library_initialized);
  363. }
  364. }