summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common
diff options
context:
space:
mode:
authordakovalkov <[email protected]>2023-12-03 13:33:55 +0300
committerdakovalkov <[email protected]>2023-12-03 14:04:39 +0300
commit2a718325637e5302334b6d0a6430f63168f8dbb3 (patch)
tree64be81080b7df9ec1d86d053a0c394ae53fcf1fe /contrib/restricted/aws/aws-c-common
parente0d94a470142d95c3007e9c5d80380994940664a (diff)
Update contrib/libs/aws-sdk-cpp to 1.11.37
Diffstat (limited to 'contrib/restricted/aws/aws-c-common')
-rw-r--r--contrib/restricted/aws/aws-c-common/CMakeLists.darwin-arm64.txt2
-rw-r--r--contrib/restricted/aws/aws-c-common/CMakeLists.darwin-x86_64.txt2
-rw-r--r--contrib/restricted/aws/aws-c-common/CMakeLists.linux-aarch64.txt2
-rw-r--r--contrib/restricted/aws/aws-c-common/CMakeLists.linux-x86_64.txt2
-rw-r--r--contrib/restricted/aws/aws-c-common/CMakeLists.windows-x86_64.txt2
-rw-r--r--contrib/restricted/aws/aws-c-common/README.md53
-rw-r--r--contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h2
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl7
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/assert.h20
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/bus.h97
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h6
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/common.h4
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/cpuid.h1
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h74
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/error.h5
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/external/cJSON.h3
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/file.h5
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/json.h4
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/logging.h6
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/macros.h4
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_builtin.inl26
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/math.h6
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/math.inl2
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/math.msvc.inl162
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h2
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/private/lookup3.inl4
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/string.h5
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/thread.h28
-rw-r--r--contrib/restricted/aws/aws-c-common/include/aws/common/uri.h2
-rw-r--r--contrib/restricted/aws/aws-c-common/source/allocator.c2
-rw-r--r--contrib/restricted/aws/aws-c-common/source/arch/intel/cpuid.c15
-rw-r--r--contrib/restricted/aws/aws-c-common/source/array_list.c5
-rw-r--r--contrib/restricted/aws/aws-c-common/source/bus.c724
-rw-r--r--contrib/restricted/aws/aws-c-common/source/byte_buf.c2
-rw-r--r--contrib/restricted/aws/aws-c-common/source/command_line_parser.c10
-rw-r--r--contrib/restricted/aws/aws-c-common/source/common.c8
-rw-r--r--contrib/restricted/aws/aws-c-common/source/date_time.c2
-rw-r--r--contrib/restricted/aws/aws-c-common/source/encoding.c115
-rw-r--r--contrib/restricted/aws/aws-c-common/source/error.c18
-rw-r--r--contrib/restricted/aws/aws-c-common/source/external/cJSON.c11
-rw-r--r--contrib/restricted/aws/aws-c-common/source/file.c29
-rw-r--r--contrib/restricted/aws/aws-c-common/source/json.c49
-rw-r--r--contrib/restricted/aws/aws-c-common/source/log_formatter.c2
-rw-r--r--contrib/restricted/aws/aws-c-common/source/log_writer.c5
-rw-r--r--contrib/restricted/aws/aws-c-common/source/logging.c13
-rw-r--r--contrib/restricted/aws/aws-c-common/source/memtrace.c81
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/file.c102
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/thread.c40
-rw-r--r--contrib/restricted/aws/aws-c-common/source/priority_queue.c10
-rw-r--r--contrib/restricted/aws/aws-c-common/source/uri.c22
-rw-r--r--contrib/restricted/aws/aws-c-common/source/xml_parser.c12
-rw-r--r--contrib/restricted/aws/aws-c-common/ya.make8
52 files changed, 663 insertions, 1160 deletions
diff --git a/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-arm64.txt b/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-arm64.txt
index 673acade924..4132ce81b18 100644
--- a/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-arm64.txt
+++ b/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-arm64.txt
@@ -10,6 +10,7 @@
add_library(restricted-aws-aws-c-common)
target_compile_options(restricted-aws-aws-c-common PRIVATE
-DAWS_COMMON_USE_IMPORT_EXPORT
+ -DAWS_PTHREAD_GETNAME_TAKES_3ARGS
-DAWS_PTHREAD_SETNAME_TAKES_2ARGS
-DCJSON_HIDE_SYMBOLS
-DHAVE_SYSCONF
@@ -29,7 +30,6 @@ target_sources(restricted-aws-aws-c-common PRIVATE
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/allocator_sba.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/array_list.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/assert.c
- ${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/bus.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/byte_buf.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/cache.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/codegen.c
diff --git a/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-x86_64.txt b/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-x86_64.txt
index c6d3f58fef0..a5385e5d753 100644
--- a/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-x86_64.txt
+++ b/contrib/restricted/aws/aws-c-common/CMakeLists.darwin-x86_64.txt
@@ -10,6 +10,7 @@
add_library(restricted-aws-aws-c-common)
target_compile_options(restricted-aws-aws-c-common PRIVATE
-DAWS_COMMON_USE_IMPORT_EXPORT
+ -DAWS_PTHREAD_GETNAME_TAKES_3ARGS
-DAWS_PTHREAD_SETNAME_TAKES_2ARGS
-DCJSON_HIDE_SYMBOLS
-DHAVE_SYSCONF
@@ -32,7 +33,6 @@ target_sources(restricted-aws-aws-c-common PRIVATE
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/allocator_sba.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/array_list.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/assert.c
- ${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/bus.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/byte_buf.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/cache.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/codegen.c
diff --git a/contrib/restricted/aws/aws-c-common/CMakeLists.linux-aarch64.txt b/contrib/restricted/aws/aws-c-common/CMakeLists.linux-aarch64.txt
index a146f742885..3bdc0bff17e 100644
--- a/contrib/restricted/aws/aws-c-common/CMakeLists.linux-aarch64.txt
+++ b/contrib/restricted/aws/aws-c-common/CMakeLists.linux-aarch64.txt
@@ -10,6 +10,7 @@
add_library(restricted-aws-aws-c-common)
target_compile_options(restricted-aws-aws-c-common PRIVATE
-DAWS_COMMON_USE_IMPORT_EXPORT
+ -DAWS_PTHREAD_GETNAME_TAKES_3ARGS
-DAWS_PTHREAD_SETNAME_TAKES_2ARGS
-DCJSON_HIDE_SYMBOLS
-DHAVE_SYSCONF
@@ -28,7 +29,6 @@ target_sources(restricted-aws-aws-c-common PRIVATE
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/allocator_sba.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/array_list.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/assert.c
- ${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/bus.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/byte_buf.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/cache.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/codegen.c
diff --git a/contrib/restricted/aws/aws-c-common/CMakeLists.linux-x86_64.txt b/contrib/restricted/aws/aws-c-common/CMakeLists.linux-x86_64.txt
index 2e36a7692bc..d33211d955d 100644
--- a/contrib/restricted/aws/aws-c-common/CMakeLists.linux-x86_64.txt
+++ b/contrib/restricted/aws/aws-c-common/CMakeLists.linux-x86_64.txt
@@ -10,6 +10,7 @@
add_library(restricted-aws-aws-c-common)
target_compile_options(restricted-aws-aws-c-common PRIVATE
-DAWS_COMMON_USE_IMPORT_EXPORT
+ -DAWS_PTHREAD_GETNAME_TAKES_3ARGS
-DAWS_PTHREAD_SETNAME_TAKES_2ARGS
-DCJSON_HIDE_SYMBOLS
-DHAVE_SYSCONF
@@ -31,7 +32,6 @@ target_sources(restricted-aws-aws-c-common PRIVATE
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/allocator_sba.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/array_list.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/assert.c
- ${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/bus.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/byte_buf.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/cache.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/codegen.c
diff --git a/contrib/restricted/aws/aws-c-common/CMakeLists.windows-x86_64.txt b/contrib/restricted/aws/aws-c-common/CMakeLists.windows-x86_64.txt
index 4477e48d94a..b137a4a3b86 100644
--- a/contrib/restricted/aws/aws-c-common/CMakeLists.windows-x86_64.txt
+++ b/contrib/restricted/aws/aws-c-common/CMakeLists.windows-x86_64.txt
@@ -10,6 +10,7 @@
add_library(restricted-aws-aws-c-common)
target_compile_options(restricted-aws-aws-c-common PRIVATE
-DAWS_COMMON_USE_IMPORT_EXPORT
+ -DAWS_PTHREAD_GETNAME_TAKES_3ARGS
-DAWS_PTHREAD_SETNAME_TAKES_2ARGS
-DCJSON_HIDE_SYMBOLS
-DHAVE_SYSCONF
@@ -28,7 +29,6 @@ target_sources(restricted-aws-aws-c-common PRIVATE
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/allocator_sba.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/array_list.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/assert.c
- ${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/bus.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/byte_buf.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/cache.c
${CMAKE_SOURCE_DIR}/contrib/restricted/aws/aws-c-common/source/codegen.c
diff --git a/contrib/restricted/aws/aws-c-common/README.md b/contrib/restricted/aws/aws-c-common/README.md
index be3db7e6207..fcedee6076b 100644
--- a/contrib/restricted/aws/aws-c-common/README.md
+++ b/contrib/restricted/aws/aws-c-common/README.md
@@ -2,8 +2,6 @@
[![GitHub](https://img.shields.io/github/license/awslabs/aws-c-common.svg)](https://github.com/awslabs/aws-c-common/blob/main/LICENSE)
-[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/awslabs/aws-c-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-c-common/context:cpp)
-[![Total alerts](https://img.shields.io/lgtm/alerts/g/awslabs/aws-c-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-c-common/alerts/)
Core c99 package for AWS SDK for C. Includes cross-platform primitives, configuration, data structures, and error handling.
@@ -192,14 +190,19 @@ Example:
* Don't typedef enums. It breaks forward declaration ability.
* typedef function definitions for use as function pointers as values and suffixed with _fn.
-Example:
-
- typedef int(fn_name_fn)(void *);
+ Do this:
-Not:
+ typedef int(fn_name_fn)(void *);
- typedef int(*fn_name_fn)(void *);
+ Not this:
+ typedef int(*fn_name_fn)(void *);
+
+* If a callback may be async, then always have it be async.
+ Callbacks that are sometimes async and sometimes sync are hard to code around and lead to bugs
+ (see [this blog post](https://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/)).
+ Unfortunately many callbacks in this codebase currently violate this rule,
+ so be careful. But do not add any more.
* Every source and header file must have a copyright header (The standard AWS one for apache 2).
* Use standard include guards (e.g. #IFNDEF HEADER_NAME #define HEADER_NAME etc...).
* Include order should be:
@@ -235,24 +238,24 @@ definition. This mainly applies to header files. Obviously, if you are writing a
platform, you have more liberty on this.
* When checking more than one error condition, check and log each condition separately with a unique message.
-Example:
-
- if (options->callback == NULL) {
- AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - callback is null");
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
-
- if (options->allocator == NULL) {
- AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - allocator is null");
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
-
-Not:
-
- if (options->callback == NULL || options->allocator == NULL) {
- AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - something is null");
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
+ Do this:
+
+ if (options->callback == NULL) {
+ AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - callback is null");
+ return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
+
+ if (options->allocator == NULL) {
+ AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - allocator is null");
+ return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
+
+ Not this:
+
+ if (options->callback == NULL || options->allocator == NULL) {
+ AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - something is null");
+ return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
## CBMC
diff --git a/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h b/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h
index f152531c172..69939cc4cbb 100644
--- a/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h
+++ b/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h
@@ -14,7 +14,7 @@
*/
#define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS
#define AWS_HAVE_GCC_INLINE_ASM
-/* #undef AWS_HAVE_MSVC_MULX */
+/* #undef AWS_HAVE_MSVC_INTRINSICS_X64 */
#define AWS_HAVE_POSIX_LARGE_FILE_SUPPORT
/* #undef AWS_HAVE_EXECINFO */
/* #undef AWS_HAVE_WINAPI_DESKTOP */
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl
index 4e64a96a665..8bd104c0953 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl
@@ -27,7 +27,7 @@ int aws_array_list_init_dynamic(
AWS_ZERO_STRUCT(*list);
- size_t allocation_size;
+ size_t allocation_size = 0;
if (aws_mul_size_checked(initial_item_allocation, item_size, &allocation_size)) {
goto error;
}
@@ -67,10 +67,13 @@ void aws_array_list_init_static(
AWS_FATAL_PRECONDITION(item_count > 0);
AWS_FATAL_PRECONDITION(item_size > 0);
+ AWS_ZERO_STRUCT(*list);
list->alloc = NULL;
- int no_overflow = !aws_mul_size_checked(item_count, item_size, &list->current_size);
+ size_t current_size = 0;
+ int no_overflow = !aws_mul_size_checked(item_count, item_size, &current_size);
AWS_FATAL_PRECONDITION(no_overflow);
+ list->current_size = current_size;
list->item_size = item_size;
list->length = 0;
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/assert.h b/contrib/restricted/aws/aws-c-common/include/aws/common/assert.h
index e7ce341ce04..9bd614c7b83 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/assert.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/assert.h
@@ -82,9 +82,11 @@ AWS_EXTERN_C_END
__pragma(warning(pop))
# else
# define AWS_FATAL_ASSERT(cond) \
- if (!(cond)) { \
- aws_fatal_assert(#cond, __FILE__, __LINE__); \
- }
+ do { \
+ if (!(cond)) { \
+ aws_fatal_assert(#cond, __FILE__, __LINE__); \
+ } \
+ } while (0)
# endif /* defined(_MSC_VER) */
#endif /* defined(CBMC) */
@@ -96,16 +98,20 @@ AWS_EXTERN_C_END
* Violations of the function contracts are undefined behaviour.
*/
#ifdef CBMC
+// clang-format off
+// disable clang format, since it likes to break formatting of stringize macro.
+// seems to be fixed in v15 plus, but we are not ready to update to it yet
# define AWS_PRECONDITION2(cond, explanation) __CPROVER_precondition((cond), (explanation))
-# define AWS_PRECONDITION1(cond) __CPROVER_precondition((cond), # cond " check failed")
+# define AWS_PRECONDITION1(cond) __CPROVER_precondition((cond), #cond " check failed")
# define AWS_FATAL_PRECONDITION2(cond, explanation) __CPROVER_precondition((cond), (explanation))
-# define AWS_FATAL_PRECONDITION1(cond) __CPROVER_precondition((cond), # cond " check failed")
+# define AWS_FATAL_PRECONDITION1(cond) __CPROVER_precondition((cond), #cond " check failed")
# define AWS_POSTCONDITION2(cond, explanation) __CPROVER_assert((cond), (explanation))
-# define AWS_POSTCONDITION1(cond) __CPROVER_assert((cond), # cond " check failed")
+# define AWS_POSTCONDITION1(cond) __CPROVER_assert((cond), #cond " check failed")
# define AWS_FATAL_POSTCONDITION2(cond, explanation) __CPROVER_assert((cond), (explanation))
-# define AWS_FATAL_POSTCONDITION1(cond) __CPROVER_assert((cond), # cond " check failed")
+# define AWS_FATAL_POSTCONDITION1(cond) __CPROVER_assert((cond), #cond " check failed")
# define AWS_MEM_IS_READABLE_CHECK(base, len) (((len) == 0) || (__CPROVER_r_ok((base), (len))))
# define AWS_MEM_IS_WRITABLE_CHECK(base, len) (((len) == 0) || (__CPROVER_r_ok((base), (len))))
+// clang-format on
#else
# define AWS_PRECONDITION2(cond, expl) AWS_ASSERT(cond)
# define AWS_PRECONDITION1(cond) AWS_ASSERT(cond)
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/bus.h b/contrib/restricted/aws/aws-c-common/include/aws/common/bus.h
deleted file mode 100644
index fe5127e6f79..00000000000
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/bus.h
+++ /dev/null
@@ -1,97 +0,0 @@
-#ifndef AWS_COMMON_BUS_H
-#define AWS_COMMON_BUS_H
-
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/common.h>
-
-/*
- * A message bus is a mapping of integer message addresses/types -> listeners/callbacks.
- * A listener can listen to a single message, or to all messages on a bus
- * Message addresses/types can be any 64-bit integer, starting at 1.
- * AWS_BUS_ADDRESS_ALL (0xffffffffffffffff) is reserved for broadcast to all listeners.
- * AWS_BUS_ADDRESS_CLOSE (0) is reserved for notifying listeners to clean up
- * Listeners will be sent a message of type AWS_BUS_ADDRESS_CLOSE when it is time to clean any state up.
- * Listeners are owned by the subscriber, and are no longer referenced by the bus once unsubscribed.
- * Under the AWS_BUS_ASYNC policy, message delivery happens in a separate thread from sending, so listeners are
- * responsible for their own thread safety.
- */
-struct aws_bus;
-
-enum aws_bus_policy {
- /**
- * Messages will be delivered, even if dynamic allocation is required. Default.
- */
- AWS_BUS_ASYNC_RELIABLE = 0x0,
- /**
- * Only memory from the bus's internal buffer will be used (if a buffer size is supplied at bus creation time).
- * If the buffer is full, older buffered messages will be discarded to make room for newer messages.
- */
- AWS_BUS_ASYNC_UNRELIABLE = 0x1,
- /**
- * Message delivery is immediate, and therefore reliable by definition
- */
- AWS_BUS_SYNC_RELIABLE = 0x2,
-};
-
-/**
- * Subscribing to AWS_BUS_ADDRESS_ALL will cause the listener to be invoked for every message sent to the bus
- * It is possible to send to AWS_BUS_ADDRESS_ALL, just be aware that this will only send to listeners subscribed
- * to AWS_BUS_ADDRESS_ALL.
- */
-#define AWS_BUS_ADDRESS_ALL ((uint64_t)-1)
-#define AWS_BUS_ADDRESS_CLOSE 0
-
-struct aws_bus_options {
- enum aws_bus_policy policy;
- /**
- * Size of buffer for unreliable message delivery queue.
- * Unused if policy is AWS_BUS_ASYNC_RELIABNLE or AWS_BUS_SYNC_RELIABLE
- * Messages are 40 bytes. Default buffer_size is 4K. The bus will not allocate memory beyond this size.
- */
- size_t buffer_size;
- /* Not supported yet, but event loop group for delivery */
- struct aws_event_loop_group *event_loop_group;
-};
-
-/* Signature for listener callbacks */
-typedef void(aws_bus_listener_fn)(uint64_t address, const void *payload, void *user_data);
-
-/**
- * Allocates and initializes a message bus
- */
-AWS_COMMON_API
-struct aws_bus *aws_bus_new(struct aws_allocator *allocator, const struct aws_bus_options *options);
-
-/**
- * Cleans up a message bus, including notifying all remaining listeners to close
- */
-AWS_COMMON_API
-void aws_bus_destroy(struct aws_bus *bus);
-
-/**
- * Subscribes a listener to a message type. user_data's lifetime is the responsibility of the subscriber.
- */
-AWS_COMMON_API
-int aws_bus_subscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *listener, void *user_data);
-
-/**
- * Unsubscribe a listener from a specific message. This is only necessary if the listener has lifetime concerns.
- * Otherwise, the listener will be called with an address of AWS_BUS_ADDRESS_CLOSE, which indicates that user_data
- * can be cleaned up if necessary and the listener will never be called again.
- */
-AWS_COMMON_API
-void aws_bus_unsubscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *listener, void *user_data);
-
-/**
- * Sends a message to any listeners. payload will live until delivered, and then the destructor (if
- * provided) will be called. Note that anything payload references must also live at least until it is destroyed.
- * Will return AWS_OP_ERR if the bus is closing/has been closed
- */
-AWS_COMMON_API
-int aws_bus_send(struct aws_bus *bus, uint64_t address, void *payload, void (*destructor)(void *));
-
-#endif /* AWS_COMMON_BUS_H */
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h b/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h
index 7184dcd68af..4e7454057b1 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h
@@ -13,7 +13,7 @@ enum aws_cli_options_has_arg {
};
/**
- * Invoked when a subcommand is encountered. argc and argv[] begins at the command encounterd.
+ * Invoked when a subcommand is encountered. argc and argv[] begins at the command encountered.
* command_name is the name of the command being handled.
*/
typedef int(aws_cli_options_subcommand_fn)(int argc, char *const argv[], const char *command_name, void *user_data);
@@ -56,7 +56,7 @@ AWS_COMMON_API extern const char *aws_cli_positional_arg;
/**
* A mostly compliant implementation of posix getopt_long(). Parses command-line arguments. argc is the number of
* command line arguments passed in argv. optstring contains the legitimate option characters. The option characters
- * coorespond to aws_cli_option::val. If the character is followed by a :, the option requires an argument. If it is
+ * correspond to aws_cli_option::val. If the character is followed by a :, the option requires an argument. If it is
* followed by '::', the argument is optional (not implemented yet).
*
* longopts, is an array of struct aws_cli_option. These are the allowed options for the program.
@@ -91,7 +91,7 @@ AWS_COMMON_API void aws_cli_reset_state(void);
* @param parse_cb, optional, specify NULL if you don't want to handle this. This argument is for parsing "meta"
* commands from the command line options prior to dispatch occurring.
* @param dispatch_table table containing functions and command name to dispatch on.
- * @param table_length numnber of entries in dispatch_table.
+ * @param table_length number of entries in dispatch_table.
* @return AWS_OP_SUCCESS(0) on success, AWS_OP_ERR(-1) on failure
*/
AWS_COMMON_API int aws_cli_dispatch_on_subcommand(
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/common.h b/contrib/restricted/aws/aws-c-common/include/aws/common/common.h
index 7968a5e0095..ce09ef226c5 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/common.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/common.h
@@ -26,14 +26,14 @@
AWS_EXTERN_C_BEGIN
/**
- * Initializes internal datastructures used by aws-c-common.
+ * Initializes internal data structures used by aws-c-common.
* Must be called before using any functionality in aws-c-common.
*/
AWS_COMMON_API
void aws_common_library_init(struct aws_allocator *allocator);
/**
- * Shuts down the internal datastructures used by aws-c-common.
+ * Shuts down the internal data structures used by aws-c-common.
*/
AWS_COMMON_API
void aws_common_library_clean_up(void);
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/cpuid.h b/contrib/restricted/aws/aws-c-common/include/aws/common/cpuid.h
index 30f8c0350f1..8b3ec883b9d 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/cpuid.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/cpuid.h
@@ -13,6 +13,7 @@ enum aws_cpu_feature_name {
AWS_CPU_FEATURE_SSE_4_2,
AWS_CPU_FEATURE_AVX2,
AWS_CPU_FEATURE_ARM_CRC,
+ AWS_CPU_FEATURE_BMI2,
AWS_CPU_FEATURE_COUNT,
};
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h b/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h
index 4e02c30b298..b707c70be41 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h
@@ -146,40 +146,82 @@ AWS_STATIC_IMPL enum aws_text_encoding aws_text_detect_encoding(const uint8_t *b
/*
* Returns true if aws_text_detect_encoding() determines the text is UTF8 or ASCII.
* Note that this immediately returns true if the UTF8 BOM is seen.
- * To fully validate every byte, use aws_text_is_valid_utf8().
+ * To fully validate every byte, use aws_decode_utf8().
*/
AWS_STATIC_IMPL bool aws_text_is_utf8(const uint8_t *bytes, size_t size);
+struct aws_utf8_decoder_options {
+ /**
+ * Optional.
+ * Callback invoked for each Unicode codepoint.
+ * Use this callback to store codepoints as they're decoded,
+ * or to perform additional validation. RFC-3629 is already enforced,
+ * which forbids codepoints between U+D800 and U+DFFF,
+ * but you may whish to forbid codepoints like U+0000.
+ *
+ * @return AWS_OP_SUCCESS to continue processing the string, otherwise
+ * return AWS_OP_ERROR and raise an error (i.e. AWS_ERROR_INVALID_UTF8)
+ * to stop processing the string and report failure.
+ */
+ int (*on_codepoint)(uint32_t codepoint, void *user_data);
+
+ /* Optional. Pointer passed to on_codepoint callback. */
+ void *user_data;
+};
+
/**
- * Scans every byte, and returns true if it is valid UTF8/ASCII as defined in RFC-3629.
+ * Decode a complete string of UTF8/ASCII text.
+ * Text is always validated according to RFC-3629 (you may perform additional
+ * validation in the on_codepoint callback).
* The text does not need to begin with a UTF8 BOM.
+ * If you need to decode text incrementally as you receive it, use aws_utf8_decoder_new() instead.
+ *
+ * @param bytes Text to decode.
+ * @param options Options for decoding. If NULL is passed, the text is simply validated.
+ *
+ * @return AWS_OP_SUCCESS if successful.
+ * An error is raised if the text is not valid, or the on_codepoint callback raises an error.
*/
-AWS_COMMON_API bool aws_text_is_valid_utf8(struct aws_byte_cursor bytes);
+AWS_COMMON_API int aws_decode_utf8(struct aws_byte_cursor bytes, const struct aws_utf8_decoder_options *options);
+
+struct aws_utf8_decoder;
/**
- * A UTF8 validator scans every byte of text, incrementally,
- * and raises AWS_ERROR_INVALID_UTF8 if isn't valid UTF8/ASCII as defined in RFC-3629.
+ * Create a UTF8/ASCII decoder, which can process text incrementally as you receive it.
+ * Text is always validated according to RFC-3629 (you may perform additional
+ * validation in the on_codepoint callback).
* The text does not need to begin with a UTF8 BOM.
- * To validate text all at once, simply use aws_text_is_valid_utf8().
+ * To decode text all at once, simply use aws_decode_utf8().
+ *
+ * Feed bytes into the decoder with aws_utf8_decoder_update(),
+ * and call aws_utf8_decoder_finalize() when the text is complete.
+ *
+ * @param allocator Allocator
+ * @param options Options for decoder. If NULL is passed, the text is simply validated.
*/
-struct aws_utf8_validator;
+AWS_COMMON_API struct aws_utf8_decoder *aws_utf8_decoder_new(
+ struct aws_allocator *allocator,
+ const struct aws_utf8_decoder_options *options);
-AWS_COMMON_API struct aws_utf8_validator *aws_utf8_validator_new(struct aws_allocator *allocator);
-AWS_COMMON_API void aws_utf8_validator_destroy(struct aws_utf8_validator *validator);
-AWS_COMMON_API void aws_utf8_validator_reset(struct aws_utf8_validator *validator);
+AWS_COMMON_API void aws_utf8_decoder_destroy(struct aws_utf8_decoder *decoder);
+AWS_COMMON_API void aws_utf8_decoder_reset(struct aws_utf8_decoder *decoder);
/**
- * Update the validator with more bytes of text.
- * Raises AWS_ERROR_INVALID_UTF8 if invalid UTF8 is encountered.
+ * Update the decoder with more bytes of text.
+ * The on_codepoint callback will be invoked for each codepoint encountered.
+ * Raises an error if invalid UTF8 is encountered or the on_codepoint callback reports an error.
+ *
+ * Note: You must call aws_utf8_decoder_finalize() when the text is 100% complete,
+ * to ensure the input was completely valid.
*/
-AWS_COMMON_API int aws_utf8_validator_update(struct aws_utf8_validator *validator, struct aws_byte_cursor bytes);
+AWS_COMMON_API int aws_utf8_decoder_update(struct aws_utf8_decoder *decoder, struct aws_byte_cursor bytes);
/**
- * Tell the validator that you've reached the end of your text.
+ * Tell the decoder that you've reached the end of your text.
* Raises AWS_ERROR_INVALID_UTF8 if the text did not end with a complete UTF8 codepoint.
- * This also resets the validator.
+ * This also resets the decoder.
*/
-AWS_COMMON_API int aws_utf8_validator_finalize(struct aws_utf8_validator *validator);
+AWS_COMMON_API int aws_utf8_decoder_finalize(struct aws_utf8_decoder *decoder);
#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/encoding.inl>
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/error.h b/contrib/restricted/aws/aws-c-common/include/aws/common/error.h
index 42ebb6eb5fb..00aa5f8bcab 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/error.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/error.h
@@ -129,7 +129,9 @@ AWS_COMMON_API
void aws_unregister_error_info(const struct aws_error_info_list *error_info);
/**
- * Convert a c library io error into an aws error.
+ * Convert a c library io error into an aws error, and raise it.
+ * If no conversion is found, AWS_ERROR_SYS_CALL_FAILURE is raised.
+ * Always returns AWS_OP_ERR.
*/
AWS_COMMON_API
int aws_translate_and_raise_io_error(int error_no);
@@ -196,6 +198,7 @@ enum aws_common_error {
AWS_ERROR_DIRECTORY_NOT_EMPTY,
AWS_ERROR_PLATFORM_NOT_SUPPORTED,
AWS_ERROR_INVALID_UTF8,
+ AWS_ERROR_GET_HOME_DIRECTORY_FAILED,
AWS_ERROR_END_COMMON_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_COMMON_PACKAGE_ID)
};
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/external/cJSON.h b/contrib/restricted/aws/aws-c-common/include/aws/common/external/cJSON.h
index 3210e8ab375..56959147708 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/external/cJSON.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/external/cJSON.h
@@ -25,6 +25,7 @@ THE SOFTWARE.
* (1) Address clang-tidy errors by renaming function parameters in a number of places
* to match their .c counterparts.
* (2) Misc tweaks to unchecked writes to make security static analysis happier
+ * (3) Remove cJSON_GetErrorPtr and global_error as they are not thread-safe.
*/
/* clang-format off */
@@ -181,8 +182,6 @@ CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
-/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
-CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/file.h b/contrib/restricted/aws/aws-c-common/include/aws/common/file.h
index 4bbc1540db3..6a47825173a 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/file.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/file.h
@@ -56,12 +56,15 @@ typedef bool(aws_on_directory_entry)(const struct aws_directory_entry *entry, vo
AWS_EXTERN_C_BEGIN
/**
- * Don't use this. It never should have been added in the first place. It's now deprecated.
+ * Deprecated - Use aws_fopen_safe() instead, avoid const char * in public APIs.
+ * Opens file at file_path using mode. Returns the FILE pointer if successful.
+ * Otherwise, aws_last_error() will contain the error that occurred
*/
AWS_COMMON_API FILE *aws_fopen(const char *file_path, const char *mode);
/**
* Opens file at file_path using mode. Returns the FILE pointer if successful.
+ * Otherwise, aws_last_error() will contain the error that occurred
*/
AWS_COMMON_API FILE *aws_fopen_safe(const struct aws_string *file_path, const struct aws_string *mode);
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/json.h b/contrib/restricted/aws/aws-c-common/include/aws/common/json.h
index 2061db173bd..e8a5f476dd8 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/json.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/json.h
@@ -11,6 +11,8 @@
struct aws_json_value;
+AWS_EXTERN_C_BEGIN
+
// ====================
// Create and pass type
@@ -412,4 +414,6 @@ AWS_COMMON_API
struct aws_json_value *aws_json_value_new_from_string(struct aws_allocator *allocator, struct aws_byte_cursor string);
// ====================
+AWS_EXTERN_C_END
+
#endif // AWS_COMMON_JSON_H
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/logging.h b/contrib/restricted/aws/aws-c-common/include/aws/common/logging.h
index 9a5bc8fad42..e5fbe88586c 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/logging.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/logging.h
@@ -126,17 +126,15 @@ struct aws_logger {
/**
* The base formatted logging macro that all other formatted logging macros resolve to.
* Checks for a logger and filters based on log level.
- *
*/
#define AWS_LOGF(log_level, subject, ...) \
- { \
+ do { \
AWS_ASSERT(log_level > 0); \
struct aws_logger *logger = aws_logger_get(); \
if (logger != NULL && logger->vtable->get_log_level(logger, (subject)) >= (log_level)) { \
logger->vtable->log(logger, log_level, subject, __VA_ARGS__); \
} \
- }
-
+ } while (0)
/**
* Unconditional logging macro that takes a logger and does not do a level check or a null check. Intended for
* situations when you need to log many things and do a single manual level check before beginning.
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/macros.h b/contrib/restricted/aws/aws-c-common/include/aws/common/macros.h
index 48f90ad501f..aacfb94167e 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/macros.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/macros.h
@@ -43,7 +43,7 @@ AWS_STATIC_ASSERT(CALL_OVERLOAD_TEST(1, 2, 3) == 3);
/**
* Format macro for strings of a specified length.
* Allows non null-terminated strings to be used with the printf family of functions.
- * Ex: printf("scheme is " PRInSTR, 4, "http://example.org"); // ouputs: "scheme is http"
+ * Ex: printf("scheme is " PRInSTR, 4, "http://example.org"); // outputs: "scheme is http"
*/
#define PRInSTR "%.*s"
@@ -70,7 +70,7 @@ AWS_STATIC_ASSERT(CALL_OVERLOAD_TEST(1, 2, 3) == 3);
# if defined(__cplusplus)
# define AWS_VARIABLE_LENGTH_ARRAY(type, name, length) type *name = alloca(sizeof(type) * (length))
# else
-# define AWS_VARIABLE_LENGTH_ARRAY(type, name, length) type name[length];
+# define AWS_VARIABLE_LENGTH_ARRAY(type, name, length) type name[length]
# endif /* defined(__cplusplus) */
# endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(_MSC_VER) */
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_builtin.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_builtin.inl
index 7be7126aef1..b834c5dc8be 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_builtin.inl
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_builtin.inl
@@ -21,18 +21,30 @@ AWS_EXTERN_C_BEGIN
* Search from the MSB to LSB, looking for a 1
*/
AWS_STATIC_IMPL size_t aws_clz_u32(uint32_t n) {
- return __builtin_clzl(n);
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
+ return __builtin_clz(n);
}
AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_clz(n);
}
AWS_STATIC_IMPL size_t aws_clz_u64(uint64_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_clzll(n);
}
AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_clzll(n);
}
@@ -48,18 +60,30 @@ AWS_STATIC_IMPL size_t aws_clz_size(size_t n) {
* Search from the LSB to MSB, looking for a 1
*/
AWS_STATIC_IMPL size_t aws_ctz_u32(uint32_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_ctzl(n);
}
AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_ctz(n);
}
AWS_STATIC_IMPL size_t aws_ctz_u64(uint64_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_ctzll(n);
}
AWS_STATIC_IMPL size_t aws_ctz_i64(int64_t n) {
+ if (n == 0) {
+ return sizeof(n) * 8;
+ }
return __builtin_ctzll(n);
}
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/math.h b/contrib/restricted/aws/aws-c-common/include/aws/common/math.h
index 108e9836396..2473dcf5e8d 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/math.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/math.h
@@ -28,7 +28,7 @@ AWS_EXTERN_C_BEGIN
#if defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) && (defined(__clang__) || !defined(__cplusplus)) || \
(defined(__x86_64__) || defined(__aarch64__)) && defined(AWS_HAVE_GCC_INLINE_ASM) || \
- defined(AWS_HAVE_MSVC_MULX) || defined(CBMC) || !defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS)
+ defined(AWS_HAVE_MSVC_INTRINSICS_X64) || defined(CBMC) || !defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS)
/* In all these cases, we can use fast static inline versions of this code */
# define AWS_COMMON_MATH_API AWS_STATIC_IMPL
#else
@@ -156,7 +156,7 @@ AWS_STATIC_IMPL bool aws_is_power_of_two(const size_t x);
AWS_STATIC_IMPL int aws_round_up_to_power_of_two(size_t n, size_t *result);
/**
- * Counts the number of leading 0 bits in an integer
+ * Counts the number of leading 0 bits in an integer. 0 will return the size of the integer in bits.
*/
AWS_STATIC_IMPL size_t aws_clz_u32(uint32_t n);
AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n);
@@ -165,7 +165,7 @@ AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n);
AWS_STATIC_IMPL size_t aws_clz_size(size_t n);
/**
- * Counts the number of trailing 0 bits in an integer
+ * Counts the number of trailing 0 bits in an integer. 0 will return the size of the integer in bits.
*/
AWS_STATIC_IMPL size_t aws_ctz_u32(uint32_t n);
AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n);
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/math.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/math.inl
index 9dbacedac23..2081fbccaf7 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/math.inl
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/math.inl
@@ -27,7 +27,7 @@ AWS_EXTERN_C_BEGIN
# include <aws/common/math.gcc_x64_asm.inl>
#elif defined(__aarch64__) && defined(AWS_HAVE_GCC_INLINE_ASM)
# include <aws/common/math.gcc_arm64_asm.inl>
-#elif defined(AWS_HAVE_MSVC_MULX)
+#elif defined(AWS_HAVE_MSVC_INTRINSICS_X64)
# include <aws/common/math.msvc.inl>
#elif defined(CBMC)
# include <aws/common/math.cbmc.inl>
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/math.msvc.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/math.msvc.inl
index 1faabe64aa7..0aad29e8ef0 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/math.msvc.inl
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/math.msvc.inl
@@ -11,6 +11,7 @@
* highlighting happier.
*/
#include <aws/common/common.h>
+#include <aws/common/cpuid.h>
#include <aws/common/math.h>
#include <immintrin.h>
@@ -40,51 +41,106 @@ AWS_STATIC_IMPL int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r) {
return AWS_OP_SUCCESS;
}
+static uint32_t (*s_mul_u32_saturating_fn_ptr)(uint32_t a, uint32_t b) = NULL;
+
+static uint32_t s_mulx_u32_saturating(uint32_t a, uint32_t b) {
+ uint32_t high_32;
+ uint32_t ret_val = _mulx_u32(a, b, &high_32);
+ return (high_32 == 0) ? ret_val : UINT32_MAX;
+}
+
+static uint32_t s_emulu_saturating(uint32_t a, uint32_t b) {
+ uint64_t result = __emulu(a, b);
+ return (result > UINT32_MAX) ? UINT32_MAX : (uint32_t)result;
+}
/**
* Multiplies a * b. If the result overflows, returns 2^32 - 1.
*/
AWS_STATIC_IMPL uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b) {
- uint32_t out;
- uint32_t ret_val = _mulx_u32(a, b, &out);
- return (out == 0) ? ret_val : UINT32_MAX;
+ if (AWS_UNLIKELY(!s_mul_u32_saturating_fn_ptr)) {
+ if (aws_cpu_has_feature(AWS_CPU_FEATURE_BMI2)) {
+ s_mul_u32_saturating_fn_ptr = s_mulx_u32_saturating;
+ } else {
+ /* If BMI2 unavailable, use __emulu instead */
+ s_mul_u32_saturating_fn_ptr = s_emulu_saturating;
+ }
+ }
+ return s_mul_u32_saturating_fn_ptr(a, b);
+}
+
+static int (*s_mul_u32_checked_fn_ptr)(uint32_t a, uint32_t b, uint32_t *r) = NULL;
+
+static int s_mulx_u32_checked(uint32_t a, uint32_t b, uint32_t *r) {
+ uint32_t high_32;
+ *r = _mulx_u32(a, b, &high_32);
+
+ if (high_32 != 0) {
+ return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
+ }
+ return AWS_OP_SUCCESS;
}
+static int s_emulu_checked(uint32_t a, uint32_t b, uint32_t *r) {
+ uint64_t result = __emulu(a, b);
+ if (result > UINT32_MAX) {
+ return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
+ }
+ *r = (uint32_t)result;
+ return AWS_OP_SUCCESS;
+}
/**
* If a * b overflows, returns AWS_OP_ERR; otherwise multiplies
* a * b, returns the result in *r, and returns AWS_OP_SUCCESS.
*/
AWS_STATIC_IMPL int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r) {
- uint32_t out;
- *r = _mulx_u32(a, b, &out);
-
- if (out != 0) {
- return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
+ if (AWS_UNLIKELY(!s_mul_u32_checked_fn_ptr)) {
+ if (aws_cpu_has_feature(AWS_CPU_FEATURE_BMI2)) {
+ s_mul_u32_checked_fn_ptr = s_mulx_u32_checked;
+ } else {
+ /* If BMI2 unavailable, use __emulu instead */
+ s_mul_u32_checked_fn_ptr = s_emulu_checked;
+ }
}
- return AWS_OP_SUCCESS;
+ return s_mul_u32_checked_fn_ptr(a, b, r);
}
/**
* If a + b overflows, returns AWS_OP_ERR; otherwise adds
* a + b, returns the result in *r, and returns AWS_OP_SUCCESS.
*/
-AWS_STATIC_IMPL int aws_add_u64_checked(uint32_t a, uint32_t b, uint32_t *r) {
- if (_addcarry_u64(0, a, b, *r)) {
+AWS_STATIC_IMPL int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r) {
+#if !defined(_MSC_VER) || _MSC_VER < 1920
+ /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */
+ if ((b > 0) && (a > (UINT64_MAX - b))) {
+ return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
+ }
+ *r = a + b;
+ return AWS_OP_SUCCESS;
+#else
+ if (_addcarry_u64((uint8_t)0, a, b, r)) {
return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
}
return AWS_OP_SUCCESS;
+#endif
}
/**
* Adds a + b. If the result overflows, returns 2^64 - 1.
*/
-AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint32_t a, uint32_t b) {
- uint32_t res;
-
- if (_addcarry_u64(0, a, b, &res)) {
+AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b) {
+#if !defined(_MSC_VER) || _MSC_VER < 1920
+ /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */
+ if ((b > 0) && (a > (UINT64_MAX - b))) {
+ return UINT64_MAX;
+ }
+ return a + b;
+#else
+ uint64_t res = 0;
+ if (_addcarry_u64((uint8_t)0, a, b, &res)) {
res = UINT64_MAX;
}
-
return res;
+#endif
}
/**
@@ -92,23 +148,37 @@ AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint32_t a, uint32_t b) {
* a + b, returns the result in *r, and returns AWS_OP_SUCCESS.
*/
AWS_STATIC_IMPL int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r) {
- if(_addcarry_u32(0, a, b, *r){
+#if !defined(_MSC_VER) || _MSC_VER < 1920
+ /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */
+ if ((b > 0) && (a > (UINT32_MAX - b))) {
return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
}
+ *r = a + b;
return AWS_OP_SUCCESS;
+#else
+ if (_addcarry_u32((uint8_t)0, a, b, r)) {
+ return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED);
+ }
+ return AWS_OP_SUCCESS;
+#endif
}
/**
* Adds a + b. If the result overflows, returns 2^32 - 1.
*/
-AWS_STATIC_IMPL uint64_t aws_add_u32_saturating(uint32_t a, uint32_t b) {
- uint32_t res;
-
- if (_addcarry_u32(0, a, b, &res)) {
+AWS_STATIC_IMPL uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b) {
+#if !defined(_MSC_VER) || _MSC_VER < 1920
+ /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */
+ if ((b > 0) && (a > (UINT32_MAX - b)))
+ return UINT32_MAX;
+ return a + b;
+#else
+ uint32_t res = 0;
+ if (_addcarry_u32((uint8_t)0, a, b, &res)) {
res = UINT32_MAX;
}
-
return res;
+#endif
}
/**
@@ -116,26 +186,34 @@ AWS_STATIC_IMPL uint64_t aws_add_u32_saturating(uint32_t a, uint32_t b) {
*/
AWS_STATIC_IMPL size_t aws_clz_u32(uint32_t n) {
unsigned long idx = 0;
- _BitScanReverse(&idx, n);
- return idx;
+ if (_BitScanReverse(&idx, n)) {
+ return 31 - idx;
+ }
+ return 32;
}
AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n) {
unsigned long idx = 0;
- _BitScanReverse(&idx, n);
- return idx;
+ if (_BitScanReverse(&idx, n)) {
+ return 31 - idx;
+ }
+ return 32;
}
AWS_STATIC_IMPL size_t aws_clz_u64(uint64_t n) {
unsigned long idx = 0;
- _BitScanReverse64(&idx, n);
- return idx;
+ if (_BitScanReverse64(&idx, n)) {
+ return 63 - idx;
+ }
+ return 64;
}
AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n) {
unsigned long idx = 0;
- _BitScanReverse64(&idx, n);
- return idx;
+ if (_BitScanReverse64(&idx, n)) {
+ return 63 - idx;
+ }
+ return 64;
}
AWS_STATIC_IMPL size_t aws_clz_size(size_t n) {
@@ -151,26 +229,34 @@ AWS_STATIC_IMPL size_t aws_clz_size(size_t n) {
*/
AWS_STATIC_IMPL size_t aws_ctz_u32(uint32_t n) {
unsigned long idx = 0;
- _BitScanForward(&idx, n);
- return idx;
+ if (_BitScanForward(&idx, n)) {
+ return idx;
+ }
+ return 32;
}
AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n) {
unsigned long idx = 0;
- _BitScanForward(&idx, n);
- return idx;
+ if (_BitScanForward(&idx, n)) {
+ return idx;
+ }
+ return 32;
}
AWS_STATIC_IMPL size_t aws_ctz_u64(uint64_t n) {
unsigned long idx = 0;
- _BitScanForward64(&idx, n);
- return idx;
+ if (_BitScanForward64(&idx, n)) {
+ return idx;
+ }
+ return 64;
}
AWS_STATIC_IMPL size_t aws_ctz_i64(int64_t n) {
unsigned long idx = 0;
- _BitScanForward64(&idx, n);
- return idx;
+ if (_BitScanForward64(&idx, n)) {
+ return idx;
+ }
+ return 64;
}
AWS_STATIC_IMPL size_t aws_ctz_size(size_t n) {
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h b/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h
index 86ffb1401f0..98169a7eeb0 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h
@@ -16,7 +16,7 @@ struct hash_table_entry {
};
/* Using a flexible array member is the C99 compliant way to have the hash_table_entries
- * immediatly follow the struct.
+ * immediately follow the struct.
*
* MSVC doesn't know this for some reason so we need to use a pragma to make
* it happy.
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/private/lookup3.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/private/lookup3.inl
index 50b269fc7b3..5695861c8fb 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/private/lookup3.inl
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/private/lookup3.inl
@@ -60,7 +60,7 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
# include <endian.h> /* attempt to define endianness */
#endif
-#if _MSC_VER
+#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4127) /*Disable "conditional expression is constant" */
#endif /* _MSC_VER */
@@ -1055,7 +1055,7 @@ int main()
#endif /* SELF_TEST */
-#if _MSC_VER
+#ifdef _MSC_VER
#pragma warning(pop)
#endif /* _MSC_VER */
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/string.h b/contrib/restricted/aws/aws-c-common/include/aws/common/string.h
index c73a24ad4a0..fbc513911f3 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/string.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/string.h
@@ -291,7 +291,10 @@ int aws_array_list_comparator_string(const void *a, const void *b);
const size_t len; \
const uint8_t bytes[sizeof(literal)]; \
} name##_s = {NULL, sizeof(literal) - 1, literal}; \
- static const struct aws_string *(name) = (struct aws_string *)(&name##_s)
+ static const struct aws_string *name = (struct aws_string *)(&name##_s) /* NOLINT(bugprone-macro-parentheses) */
+
+/* NOLINT above is because clang-tidy complains that (name) isn't in parentheses,
+ * but gcc8-c++ complains that the parentheses are unnecessary */
/*
* A related macro that declares the string pointer without static, allowing it to be externed as a global constant
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h b/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h
index 53aa6a6eef8..5b3014288ab 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h
@@ -6,6 +6,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/byte_buf.h>
+#include <aws/common/string.h>
#ifndef _WIN32
# include <pthread.h>
@@ -23,7 +24,7 @@ enum aws_thread_detach_state {
* in the managed thread system. The managed thread system provides logic to guarantee a join on all participating
* threads at the cost of laziness (the user cannot control when joins happen).
*
- * Manual - thread does not particpate in the managed thread system; any joins must be done by the user. This
+ * Manual - thread does not participate in the managed thread system; any joins must be done by the user. This
* is the default. The user must call aws_thread_clean_up(), but only after any desired join operation has completed.
* Not doing so will cause the windows handle to leak.
*
@@ -237,6 +238,31 @@ AWS_COMMON_API void aws_thread_increment_unjoined_count(void);
*/
AWS_COMMON_API void aws_thread_decrement_unjoined_count(void);
+/**
+ * Gets name of the current thread.
+ * Caller is responsible for destroying returned string.
+ * If thread does not have a name, AWS_OP_SUCCESS is returned and out_name is
+ * set to NULL.
+ * If underlying OS call fails, AWS_ERROR_SYS_CALL_FAILURE will be raised
+ * If OS does not support getting thread name, AWS_ERROR_PLATFORM_NOT_SUPPORTED
+ * will be raised
+ */
+AWS_COMMON_API int aws_thread_current_name(struct aws_allocator *allocator, struct aws_string **out_name);
+
+/**
+ * Gets name of the thread.
+ * Caller is responsible for destroying returned string.
+ * If thread does not have a name, AWS_OP_SUCCESS is returned and out_name is
+ * set to NULL.
+ * If underlying OS call fails, AWS_ERROR_SYS_CALL_FAILURE will be raised
+ * If OS does not support getting thread name, AWS_ERROR_PLATFORM_NOT_SUPPORTED
+ * will be raised
+ */
+AWS_COMMON_API int aws_thread_name(
+ struct aws_allocator *allocator,
+ aws_thread_id_t thread_id,
+ struct aws_string **out_name);
+
AWS_EXTERN_C_END
#endif /* AWS_COMMON_THREAD_H */
diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/uri.h b/contrib/restricted/aws/aws-c-common/include/aws/common/uri.h
index c2a55372cfd..9677276b873 100644
--- a/contrib/restricted/aws/aws-c-common/include/aws/common/uri.h
+++ b/contrib/restricted/aws/aws-c-common/include/aws/common/uri.h
@@ -87,7 +87,7 @@ AWS_COMMON_API const struct aws_byte_cursor *aws_uri_scheme(const struct aws_uri
AWS_COMMON_API const struct aws_byte_cursor *aws_uri_authority(const struct aws_uri *uri);
/**
- * Returns the path portion of the uri. If the original value was empty, this value will be "/".
+ * Returns the path portion of the uri, including any leading '/'. If not present, this value will be empty.
*/
AWS_COMMON_API const struct aws_byte_cursor *aws_uri_path(const struct aws_uri *uri);
diff --git a/contrib/restricted/aws/aws-c-common/source/allocator.c b/contrib/restricted/aws/aws-c-common/source/allocator.c
index a6726624702..67e8695996a 100644
--- a/contrib/restricted/aws/aws-c-common/source/allocator.c
+++ b/contrib/restricted/aws/aws-c-common/source/allocator.c
@@ -37,7 +37,7 @@ bool aws_allocator_is_valid(const struct aws_allocator *alloc) {
static void *s_default_malloc(struct aws_allocator *allocator, size_t size) {
(void)allocator;
/* larger allocations should be aligned so that AVX and friends can avoid
- * the extra preable during unaligned versions of memcpy/memset on big buffers
+ * the extra preamble during unaligned versions of memcpy/memset on big buffers
* This will also accelerate hardware CRC and SHA on ARM chips
*
* 64 byte alignment for > page allocations on 64 bit systems
diff --git a/contrib/restricted/aws/aws-c-common/source/arch/intel/cpuid.c b/contrib/restricted/aws/aws-c-common/source/arch/intel/cpuid.c
index ffc6e0d4c93..98c51b88d18 100644
--- a/contrib/restricted/aws/aws-c-common/source/arch/intel/cpuid.c
+++ b/contrib/restricted/aws/aws-c-common/source/arch/intel/cpuid.c
@@ -85,11 +85,26 @@ static bool s_has_avx2(void) {
return true;
}
+static bool s_has_bmi2(void) {
+ uint32_t abcd[4];
+
+ /* Check BMI2:
+ * CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]==1 */
+ uint32_t bmi2_mask = (1 << 8);
+ aws_run_cpuid(7, 0, abcd);
+ if ((abcd[1] & bmi2_mask) != bmi2_mask) {
+ return false;
+ }
+
+ return true;
+}
+
has_feature_fn *s_check_cpu_feature[AWS_CPU_FEATURE_COUNT] = {
[AWS_CPU_FEATURE_CLMUL] = s_has_clmul,
[AWS_CPU_FEATURE_SSE_4_1] = s_has_sse41,
[AWS_CPU_FEATURE_SSE_4_2] = s_has_sse42,
[AWS_CPU_FEATURE_AVX2] = s_has_avx2,
+ [AWS_CPU_FEATURE_BMI2] = s_has_bmi2,
};
bool aws_cpu_has_feature(enum aws_cpu_feature_name feature_name) {
diff --git a/contrib/restricted/aws/aws-c-common/source/array_list.c b/contrib/restricted/aws/aws-c-common/source/array_list.c
index 7e05636a750..45c8a3cc76f 100644
--- a/contrib/restricted/aws/aws-c-common/source/array_list.c
+++ b/contrib/restricted/aws/aws-c-common/source/array_list.c
@@ -10,7 +10,7 @@
int aws_array_list_calc_necessary_size(struct aws_array_list *AWS_RESTRICT list, size_t index, size_t *necessary_size) {
AWS_PRECONDITION(aws_array_list_is_valid(list));
- size_t index_inc;
+ size_t index_inc = 0;
if (aws_add_size_checked(index, 1, &index_inc)) {
AWS_POSTCONDITION(aws_array_list_is_valid(list));
return AWS_OP_ERR;
@@ -199,7 +199,8 @@ void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, siz
return;
}
- void *item1 = NULL, *item2 = NULL;
+ void *item1 = NULL;
+ void *item2 = NULL;
aws_array_list_get_at_ptr(list, &item1, a);
aws_array_list_get_at_ptr(list, &item2, b);
aws_array_list_mem_swap(item1, item2, list->item_size);
diff --git a/contrib/restricted/aws/aws-c-common/source/bus.c b/contrib/restricted/aws/aws-c-common/source/bus.c
deleted file mode 100644
index 68bb29deda1..00000000000
--- a/contrib/restricted/aws/aws-c-common/source/bus.c
+++ /dev/null
@@ -1,724 +0,0 @@
-/*
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License").
- * You may not use this file except in compliance with the License.
- * A copy of the License is located at
- *
- * http://aws.amazon.com/apache2.0
- *
- * or in the "license" file accompanying this file. This file is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-#include <aws/common/bus.h>
-
-#include <aws/common/allocator.h>
-#include <aws/common/atomics.h>
-#include <aws/common/byte_buf.h>
-#include <aws/common/condition_variable.h>
-#include <aws/common/hash_table.h>
-#include <aws/common/linked_list.h>
-#include <aws/common/logging.h>
-#include <aws/common/mutex.h>
-#include <aws/common/thread.h>
-
-#include <inttypes.h>
-
-#ifdef _MSC_VER
-# pragma warning(push)
-# pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */
-#endif
-
-struct aws_bus {
- struct aws_allocator *allocator;
-
- /* vtable and additional data structures for delivery policy */
- void *impl;
-};
-
-/* MUST be the first member of any impl to allow blind casting */
-struct bus_vtable {
- void (*clean_up)(struct aws_bus *bus);
-
- int (*send)(struct aws_bus *bus, uint64_t address, void *payload, void (*destructor)(void *));
-
- int (*subscribe)(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *callback, void *user_data);
-
- void (*unsubscribe)(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *callback, void *user_data);
-};
-
-/* each bound callback is stored as a bus_listener in the slots table */
-struct bus_listener {
- struct aws_linked_list_node list_node;
- void *user_data;
- aws_bus_listener_fn *deliver;
-};
-
-/* value type stored in each slot in the slots table in a bus */
-struct listener_list {
- struct aws_allocator *allocator;
- struct aws_linked_list listeners;
-};
-
-/* find a listener list (or NULL) by address */
-static struct listener_list *bus_find_listeners(struct aws_hash_table *slots, uint64_t address) {
- struct aws_hash_element *elem = NULL;
- if (aws_hash_table_find(slots, (void *)(uintptr_t)address, &elem)) {
- return NULL;
- }
-
- if (!elem) {
- return NULL;
- }
-
- struct listener_list *list = elem->value;
- return list;
-}
-
-/* find a listener list by address, or create/insert/return a new one */
-static struct listener_list *bus_find_or_create_listeners(
- struct aws_allocator *allocator,
- struct aws_hash_table *slots,
- uint64_t address) {
- struct listener_list *list = bus_find_listeners(slots, address);
- if (list) {
- return list;
- }
-
- list = aws_mem_calloc(allocator, 1, sizeof(struct listener_list));
- list->allocator = allocator;
- aws_linked_list_init(&list->listeners);
- aws_hash_table_put(slots, (void *)(uintptr_t)address, list, NULL);
- return list;
-}
-
-static void s_bus_deliver_msg_to_slot(
- struct aws_bus *bus,
- uint64_t slot,
- uint64_t address,
- struct aws_hash_table *slots,
- const void *payload) {
- (void)bus;
- struct listener_list *list = bus_find_listeners(slots, slot);
- if (!list) {
- return;
- }
- struct aws_linked_list_node *node = aws_linked_list_begin(&list->listeners);
- for (; node != aws_linked_list_end(&list->listeners); node = aws_linked_list_next(node)) {
- struct bus_listener *listener = AWS_CONTAINER_OF(node, struct bus_listener, list_node);
- listener->deliver(address, payload, listener->user_data);
- }
-}
-
-/* common delivery logic */
-static void s_bus_deliver_msg(
- struct aws_bus *bus,
- uint64_t address,
- struct aws_hash_table *slots,
- const void *payload) {
- s_bus_deliver_msg_to_slot(bus, AWS_BUS_ADDRESS_ALL, address, slots, payload);
- s_bus_deliver_msg_to_slot(bus, address, address, slots, payload);
-}
-
-/* common subscribe logic */
-static int s_bus_subscribe(
- struct aws_bus *bus,
- uint64_t address,
- struct aws_hash_table *slots,
- aws_bus_listener_fn *callback,
- void *user_data) {
-
- if (address == AWS_BUS_ADDRESS_CLOSE) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_BUS, "Cannot directly subscribe to AWS_BUS_ADDRESS_CLOSE(0)");
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
-
- struct listener_list *list = bus_find_or_create_listeners(bus->allocator, slots, address);
- struct bus_listener *listener = aws_mem_calloc(bus->allocator, 1, sizeof(struct bus_listener));
- listener->deliver = callback;
- listener->user_data = user_data;
- aws_linked_list_push_back(&list->listeners, &listener->list_node);
-
- return AWS_OP_SUCCESS;
-}
-
-/* common unsubscribe logic */
-static void s_bus_unsubscribe(
- struct aws_bus *bus,
- uint64_t address,
- struct aws_hash_table *slots,
- aws_bus_listener_fn *callback,
- void *user_data) {
- (void)bus;
-
- if (address == AWS_BUS_ADDRESS_CLOSE) {
- AWS_LOGF_WARN(AWS_LS_COMMON_BUS, "Attempted to unsubscribe from invalid address AWS_BUS_ADDRESS_CLOSE")
- return;
- }
-
- struct listener_list *list = bus_find_listeners(slots, address);
- if (!list) {
- return;
- }
-
- struct aws_linked_list_node *node;
- for (node = aws_linked_list_begin(&list->listeners); node != aws_linked_list_end(&list->listeners);
- node = aws_linked_list_next(node)) {
-
- struct bus_listener *listener = AWS_CONTAINER_OF(node, struct bus_listener, list_node);
- if (listener->deliver == callback && listener->user_data == user_data) {
- aws_linked_list_remove(node);
- aws_mem_release(list->allocator, listener);
- return;
- }
- }
-}
-
-/* destructor for listener lists in the slots tables */
-void s_bus_destroy_listener_list(void *data) {
- struct listener_list *list = data;
- AWS_PRECONDITION(list->allocator);
- /* call all listeners with an AWS_BUS_ADDRESS_CLOSE message type to clean up */
- while (!aws_linked_list_empty(&list->listeners)) {
- struct aws_linked_list_node *back = aws_linked_list_back(&list->listeners);
- struct bus_listener *listener = AWS_CONTAINER_OF(back, struct bus_listener, list_node);
- listener->deliver(AWS_BUS_ADDRESS_CLOSE, NULL, listener->user_data);
- aws_linked_list_pop_back(&list->listeners);
- aws_mem_release(list->allocator, listener);
- }
- aws_mem_release(list->allocator, list);
-}
-
-/*
- * AWS_BUS_SYNC implementation
- */
-struct bus_sync_impl {
- struct bus_vtable vtable;
- struct {
- /* Map of address -> list of listeners */
- struct aws_hash_table table;
- } slots;
-};
-
-static void s_bus_sync_clean_up(struct aws_bus *bus) {
- struct bus_sync_impl *impl = bus->impl;
- aws_hash_table_clean_up(&impl->slots.table);
- aws_mem_release(bus->allocator, impl);
-}
-
-static int s_bus_sync_send(struct aws_bus *bus, uint64_t address, void *payload, void (*destructor)(void *)) {
- struct bus_sync_impl *impl = bus->impl;
- s_bus_deliver_msg(bus, address, &impl->slots.table, payload);
- if (destructor) {
- destructor(payload);
- }
- return AWS_OP_SUCCESS;
-}
-
-static int s_bus_sync_subscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *callback, void *user_data) {
- struct bus_sync_impl *impl = bus->impl;
- return s_bus_subscribe(bus, address, &impl->slots.table, callback, user_data);
-}
-
-static void s_bus_sync_unsubscribe(
- struct aws_bus *bus,
- uint64_t address,
- aws_bus_listener_fn *callback,
- void *user_data) {
- struct bus_sync_impl *impl = bus->impl;
- s_bus_unsubscribe(bus, address, &impl->slots.table, callback, user_data);
-}
-
-static struct bus_vtable bus_sync_vtable = {
- .clean_up = s_bus_sync_clean_up,
- .send = s_bus_sync_send,
- .subscribe = s_bus_sync_subscribe,
- .unsubscribe = s_bus_sync_unsubscribe,
-};
-
-static void s_bus_sync_init(struct aws_bus *bus, const struct aws_bus_options *options) {
- (void)options;
-
- struct bus_sync_impl *impl = bus->impl = aws_mem_calloc(bus->allocator, 1, sizeof(struct bus_sync_impl));
- impl->vtable = bus_sync_vtable;
-
- if (aws_hash_table_init(
- &impl->slots.table, bus->allocator, 8, aws_hash_ptr, aws_ptr_eq, NULL, s_bus_destroy_listener_list)) {
- goto error;
- }
-
- return;
-
-error:
- aws_mem_release(bus->allocator, impl);
-}
-
-/*
- * AWS_BUS_ASYNC implementation
- */
-struct bus_async_impl {
- struct bus_vtable vtable;
- struct {
- /* Map of address -> list of listeners */
- struct aws_hash_table table;
- } slots;
-
- /* Queue of bus_messages to deliver */
- struct {
- struct aws_mutex mutex;
- /* backing memory for the message free list */
- void *buffer;
- void *buffer_end; /* 1 past the end of buffer */
- /* message free list */
- struct aws_linked_list free; /* struct bus_message */
- /* message delivery queue */
- struct aws_linked_list msgs; /* struct bus_message */
- /* list of pending adds/removes of listeners */
- struct aws_linked_list subs; /* struct pending_listener */
- } queue;
-
- /* dispatch thread */
- struct {
- struct aws_thread thread;
- struct aws_condition_variable notify;
- bool running;
- struct aws_atomic_var started;
- struct aws_atomic_var exited;
- } dispatch;
-
- bool reliable;
-};
-
-/* represents a message in the queue on impls that queue */
-struct bus_message {
- struct aws_linked_list_node list_node;
- uint64_t address;
- void *payload;
-
- void (*destructor)(void *);
-};
-
-struct pending_listener {
- struct aws_linked_list_node list_node;
- uint64_t address;
- aws_bus_listener_fn *listener;
- void *user_data;
- uint32_t add : 1;
- uint32_t remove : 1;
-};
-
-static void s_bus_message_clean_up(struct bus_message *msg) {
- if (msg->destructor) {
- msg->destructor(msg->payload);
- }
- msg->destructor = NULL;
- msg->payload = NULL;
-}
-
-/* Assumes the caller holds the lock */
-static void s_bus_async_free_message(struct aws_bus *bus, struct bus_message *msg) {
- struct bus_async_impl *impl = bus->impl;
- s_bus_message_clean_up(msg);
- if ((void *)msg >= impl->queue.buffer && (void *)msg < impl->queue.buffer_end) {
- AWS_ZERO_STRUCT(*msg);
- aws_linked_list_push_back(&impl->queue.free, &msg->list_node);
- return;
- }
- aws_mem_release(bus->allocator, msg);
-}
-
-/* Assumes the caller holds the lock */
-struct bus_message *s_bus_async_alloc_message(struct aws_bus *bus) {
- struct bus_async_impl *impl = bus->impl;
-
- /* try the free list first */
- if (!aws_linked_list_empty(&impl->queue.free)) {
- struct aws_linked_list_node *msg_node = aws_linked_list_pop_back(&impl->queue.free);
- struct bus_message *msg = AWS_CONTAINER_OF(msg_node, struct bus_message, list_node);
- return msg;
- }
-
- /* unreliable will re-use the oldest message */
- if (!impl->reliable) {
- struct aws_linked_list_node *msg_node = aws_linked_list_pop_front(&impl->queue.msgs);
- struct bus_message *msg = AWS_CONTAINER_OF(msg_node, struct bus_message, list_node);
- s_bus_async_free_message(bus, msg);
- return s_bus_async_alloc_message(bus);
- }
-
- return aws_mem_calloc(bus->allocator, 1, sizeof(struct bus_message));
-}
-
-/*
- * resolve all adds and removes of listeners, in FIFO order
- * NOTE: expects mutex to be held by caller
- */
-static void s_bus_apply_listeners(struct aws_bus *bus, struct aws_linked_list *pending_subs) {
- struct bus_async_impl *impl = bus->impl;
- while (!aws_linked_list_empty(pending_subs)) {
- struct aws_linked_list_node *node = aws_linked_list_pop_front(pending_subs);
- struct pending_listener *listener = AWS_CONTAINER_OF(node, struct pending_listener, list_node);
- if (listener->add) {
- s_bus_subscribe(bus, listener->address, &impl->slots.table, listener->listener, listener->user_data);
- } else if (listener->remove) {
- s_bus_unsubscribe(bus, listener->address, &impl->slots.table, listener->listener, listener->user_data);
- }
- aws_mem_release(bus->allocator, listener);
- }
-}
-
-static void s_bus_async_deliver_messages(struct aws_bus *bus, struct aws_linked_list *pending_msgs) {
- struct bus_async_impl *impl = bus->impl;
- struct aws_linked_list_node *msg_node = aws_linked_list_begin(pending_msgs);
- for (; msg_node != aws_linked_list_end(pending_msgs); msg_node = aws_linked_list_next(msg_node)) {
- struct bus_message *msg = AWS_CONTAINER_OF(msg_node, struct bus_message, list_node);
- s_bus_deliver_msg(bus, msg->address, &impl->slots.table, msg->payload);
- s_bus_message_clean_up(msg);
- }
-
- /* push all pending messages back on the free list */
- aws_mutex_lock(&impl->queue.mutex);
- {
- while (!aws_linked_list_empty(pending_msgs)) {
- msg_node = aws_linked_list_pop_front(pending_msgs);
- struct bus_message *msg = AWS_CONTAINER_OF(msg_node, struct bus_message, list_node);
- s_bus_async_free_message(bus, msg);
- }
- }
- aws_mutex_unlock(&impl->queue.mutex);
-}
-
-static void s_bus_async_clean_up(struct aws_bus *bus) {
- struct bus_async_impl *impl = bus->impl;
-
- /* shut down delivery thread, clean up dispatch */
- AWS_LOGF_TRACE(AWS_LS_COMMON_BUS, "bus: %p clean_up: starting final drain", (void *)bus);
- aws_mutex_lock(&impl->queue.mutex);
- impl->dispatch.running = false;
- aws_mutex_unlock(&impl->queue.mutex);
- aws_condition_variable_notify_one(&impl->dispatch.notify);
- /* Spin wait for the final drain and dispatch thread to complete */
- while (!aws_atomic_load_int(&impl->dispatch.exited)) {
- aws_thread_current_sleep(1000 * 1000); /* 1 microsecond */
- }
- AWS_LOGF_TRACE(AWS_LS_COMMON_BUS, "bus: %p clean_up: finished final drain", (void *)bus);
- aws_thread_join(&impl->dispatch.thread);
- aws_thread_clean_up(&impl->dispatch.thread);
- aws_condition_variable_clean_up(&impl->dispatch.notify);
-
- /* should be impossible for subs or msgs to remain after final drain */
- AWS_FATAL_ASSERT(aws_linked_list_empty(&impl->queue.msgs));
- AWS_FATAL_ASSERT(aws_linked_list_empty(&impl->queue.subs));
-
- /* this frees everything that the free/msgs lists point to */
- if (impl->queue.buffer) {
- aws_mem_release(bus->allocator, impl->queue.buffer);
- }
-
- aws_mutex_clean_up(&impl->queue.mutex);
-
- aws_hash_table_clean_up(&impl->slots.table);
- aws_mem_release(bus->allocator, impl);
-}
-
-static bool s_bus_async_should_wake_up(void *user_data) {
- struct bus_async_impl *impl = user_data;
- return !impl->dispatch.running || !aws_linked_list_empty(&impl->queue.subs) ||
- !aws_linked_list_empty(&impl->queue.msgs);
-}
-
-static bool s_bus_async_is_running(struct bus_async_impl *impl) {
- aws_mutex_lock(&impl->queue.mutex);
- bool running = impl->dispatch.running;
- aws_mutex_unlock(&impl->queue.mutex);
- return running;
-}
-
-/* Async bus delivery thread loop */
-static void s_bus_async_deliver(void *user_data) {
- struct aws_bus *bus = user_data;
- struct bus_async_impl *impl = bus->impl;
-
- aws_atomic_store_int(&impl->dispatch.started, 1);
- AWS_LOGF_DEBUG(AWS_LS_COMMON_BUS, "bus %p: delivery thread loop started", (void *)bus);
-
- /* once shutdown has been triggered, need to drain one more time to ensure all queues are empty */
- int pending_drains = 1;
- do {
- struct aws_linked_list pending_msgs;
- aws_linked_list_init(&pending_msgs);
-
- struct aws_linked_list pending_subs;
- aws_linked_list_init(&pending_subs);
-
- aws_mutex_lock(&impl->queue.mutex);
- {
- aws_condition_variable_wait_pred(
- &impl->dispatch.notify, &impl->queue.mutex, s_bus_async_should_wake_up, impl);
-
- /* copy out any queued subs/unsubs */
- aws_linked_list_swap_contents(&impl->queue.subs, &pending_subs);
- /* copy out any queued messages */
- aws_linked_list_swap_contents(&impl->queue.msgs, &pending_msgs);
- }
- aws_mutex_unlock(&impl->queue.mutex);
-
- /* first resolve subs/unsubs */
- if (!aws_linked_list_empty(&pending_subs)) {
- s_bus_apply_listeners(bus, &pending_subs);
- }
-
- /* Then deliver queued messages */
- if (!aws_linked_list_empty(&pending_msgs)) {
- s_bus_async_deliver_messages(bus, &pending_msgs);
- }
- } while (s_bus_async_is_running(impl) || pending_drains--);
-
- /* record that the dispatch thread is done */
- aws_atomic_store_int(&impl->dispatch.exited, 1);
-}
-
-int s_bus_async_send(struct aws_bus *bus, uint64_t address, void *payload, void (*destructor)(void *)) {
- struct bus_async_impl *impl = bus->impl;
-
- aws_mutex_lock(&impl->queue.mutex);
- {
- if (!impl->dispatch.running) {
- AWS_LOGF_WARN(
- AWS_LS_COMMON_BUS, "bus %p: message sent after clean_up: address: %" PRIu64 "", (void *)bus, address);
- aws_mutex_unlock(&impl->queue.mutex);
- return aws_raise_error(AWS_ERROR_INVALID_STATE);
- }
-
- struct bus_message *msg = s_bus_async_alloc_message(bus);
- msg->address = address;
- msg->payload = payload;
- msg->destructor = destructor;
-
- /* push the message onto the delivery queue */
- aws_linked_list_push_back(&impl->queue.msgs, &msg->list_node);
- }
- aws_mutex_unlock(&impl->queue.mutex);
-
- /* notify the delivery thread to wake up */
- aws_condition_variable_notify_one(&impl->dispatch.notify);
-
- return AWS_OP_SUCCESS;
-}
-
-int s_bus_async_subscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *listener, void *user_data) {
- struct bus_async_impl *impl = bus->impl;
-
- if (address == AWS_BUS_ADDRESS_CLOSE) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_BUS, "Cannot subscribe to AWS_BUS_ADDRESS_CLOSE");
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
-
- aws_mutex_lock(&impl->queue.mutex);
- {
- if (!impl->dispatch.running) {
- AWS_LOGF_WARN(
- AWS_LS_COMMON_BUS,
- "bus %p: subscribe requested after clean_up: address: %" PRIu64 "",
- (void *)bus,
- address);
- aws_mutex_unlock(&impl->queue.mutex);
- return aws_raise_error(AWS_ERROR_INVALID_STATE);
- }
-
- struct pending_listener *sub = aws_mem_calloc(bus->allocator, 1, sizeof(struct pending_listener));
- sub->address = address;
- sub->listener = listener;
- sub->user_data = user_data;
- sub->add = true;
- aws_linked_list_push_back(&impl->queue.subs, &sub->list_node);
- }
- aws_mutex_unlock(&impl->queue.mutex);
-
- /* notify the delivery thread to wake up */
- aws_condition_variable_notify_one(&impl->dispatch.notify);
- return AWS_OP_SUCCESS;
-}
-
-void s_bus_async_unsubscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *listener, void *user_data) {
- struct bus_async_impl *impl = bus->impl;
-
- if (address == AWS_BUS_ADDRESS_CLOSE) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_BUS, "Cannot unsubscribe from AWS_BUS_ADDRESS_CLOSE");
- return;
- }
-
- aws_mutex_lock(&impl->queue.mutex);
- {
- if (!impl->dispatch.running) {
- AWS_LOGF_WARN(
- AWS_LS_COMMON_BUS,
- "bus %p: unsubscribe requested after clean_up: address: %" PRIu64 "",
- (void *)bus,
- address);
- aws_mutex_unlock(&impl->queue.mutex);
- return;
- }
-
- struct pending_listener *unsub = aws_mem_calloc(bus->allocator, 1, sizeof(struct pending_listener));
- unsub->address = address;
- unsub->listener = listener;
- unsub->user_data = user_data;
- unsub->remove = true;
- aws_linked_list_push_back(&impl->queue.subs, &unsub->list_node);
- }
- aws_mutex_unlock(&impl->queue.mutex);
-
- /* notify the delivery thread to wake up */
- aws_condition_variable_notify_one(&impl->dispatch.notify);
-}
-
-static struct bus_vtable bus_async_vtable = {
- .clean_up = s_bus_async_clean_up,
- .send = s_bus_async_send,
- .subscribe = s_bus_async_subscribe,
- .unsubscribe = s_bus_async_unsubscribe,
-};
-
-static void s_bus_async_init(struct aws_bus *bus, const struct aws_bus_options *options) {
- struct bus_async_impl *impl = bus->impl = aws_mem_calloc(bus->allocator, 1, sizeof(struct bus_async_impl));
- impl->vtable = bus_async_vtable;
- impl->reliable = (options->policy == AWS_BUS_ASYNC_RELIABLE);
-
- /* init msg queue */
- if (aws_mutex_init(&impl->queue.mutex)) {
- AWS_LOGF_ERROR(
- AWS_LS_COMMON_BUS,
- "bus %p: Unable to initialize queue synchronization: %s",
- (void *)bus,
- aws_error_name(aws_last_error()));
- goto error;
- }
- aws_linked_list_init(&impl->queue.msgs);
- aws_linked_list_init(&impl->queue.free);
- aws_linked_list_init(&impl->queue.subs);
-
- /* push as many bus_messages as we can into the free list from the buffer */
- if (options->buffer_size) {
- impl->queue.buffer = aws_mem_calloc(bus->allocator, 1, options->buffer_size);
- impl->queue.buffer_end = ((uint8_t *)impl->queue.buffer) + options->buffer_size;
- const int msg_count = (int)(options->buffer_size / sizeof(struct bus_message));
- for (int msg_idx = 0; msg_idx < msg_count; ++msg_idx) {
- struct bus_message *msg = (void *)&((char *)impl->queue.buffer)[msg_idx * sizeof(struct bus_message)];
- aws_linked_list_push_back(&impl->queue.free, &msg->list_node);
- }
- }
-
- /* init subscription table */
- if (aws_hash_table_init(
- &impl->slots.table, bus->allocator, 8, aws_hash_ptr, aws_ptr_eq, NULL, s_bus_destroy_listener_list)) {
- AWS_LOGF_ERROR(
- AWS_LS_COMMON_BUS,
- "bus %p: Unable to initialize bus addressing table: %s",
- (void *)bus,
- aws_error_name(aws_last_error()));
- goto error;
- }
-
- /* Setup dispatch thread */
- if (aws_condition_variable_init(&impl->dispatch.notify)) {
- AWS_LOGF_ERROR(
- AWS_LS_COMMON_BUS,
- "bus %p: Unable to initialize async notify: %s",
- (void *)bus,
- aws_error_name(aws_last_error()));
- goto error;
- }
-
- if (aws_thread_init(&impl->dispatch.thread, bus->allocator)) {
- AWS_LOGF_ERROR(
- AWS_LS_COMMON_BUS,
- "bus %p: Unable to initialize background thread: %s",
- (void *)bus,
- aws_error_name(aws_last_error()));
- goto error;
- }
-
- impl->dispatch.running = true;
- aws_atomic_init_int(&impl->dispatch.started, 0);
- aws_atomic_init_int(&impl->dispatch.exited, 0);
- if (aws_thread_launch(&impl->dispatch.thread, s_bus_async_deliver, bus, aws_default_thread_options())) {
- AWS_LOGF_ERROR(
- AWS_LS_COMMON_BUS,
- "bus %p: Unable to launch delivery thread: %s",
- (void *)bus,
- aws_error_name(aws_last_error()));
- goto error;
- }
-
- /* wait for dispatch thread to start before returning control */
- AWS_LOGF_TRACE(AWS_LS_COMMON_BUS, "bus %p: Waiting for delivery thread to start", (void *)bus);
- while (!aws_atomic_load_int(&impl->dispatch.started)) {
- aws_thread_current_sleep(1000 * 1000);
- }
- AWS_LOGF_TRACE(AWS_LS_COMMON_BUS, "bus %p: Delivery thread started", (void *)bus);
-
- return;
-
-error:
- aws_thread_clean_up(&impl->dispatch.thread);
- aws_condition_variable_clean_up(&impl->dispatch.notify);
- aws_hash_table_clean_up(&impl->slots.table);
- aws_mem_release(bus->allocator, &impl->queue.buffer);
- aws_mutex_clean_up(&impl->queue.mutex);
- aws_mem_release(bus->allocator, impl);
- bus->impl = NULL;
-}
-
-/*
- * Public API
- */
-struct aws_bus *aws_bus_new(struct aws_allocator *allocator, const struct aws_bus_options *options) {
- struct aws_bus *bus = aws_mem_calloc(allocator, 1, sizeof(struct aws_bus));
- bus->allocator = allocator;
-
- switch (options->policy) {
- case AWS_BUS_ASYNC_RELIABLE:
- case AWS_BUS_ASYNC_UNRELIABLE:
- s_bus_async_init(bus, options);
- break;
- case AWS_BUS_SYNC_RELIABLE:
- s_bus_sync_init(bus, options);
- break;
- }
-
- if (!bus->impl) {
- aws_mem_release(allocator, bus);
- return NULL;
- }
-
- return bus;
-}
-
-void aws_bus_destroy(struct aws_bus *bus) {
- struct bus_vtable *vtable = bus->impl;
- vtable->clean_up(bus);
- aws_mem_release(bus->allocator, bus);
-}
-
-int aws_bus_subscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *listener, void *user_data) {
- struct bus_vtable *vtable = bus->impl;
- return vtable->subscribe(bus, address, listener, user_data);
-}
-
-void aws_bus_unsubscribe(struct aws_bus *bus, uint64_t address, aws_bus_listener_fn *listener, void *user_data) {
- struct bus_vtable *vtable = bus->impl;
- vtable->unsubscribe(bus, address, listener, user_data);
-}
-
-int aws_bus_send(struct aws_bus *bus, uint64_t address, void *payload, void (*destructor)(void *)) {
- struct bus_vtable *vtable = bus->impl;
- return vtable->send(bus, address, payload, destructor);
-}
-
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
diff --git a/contrib/restricted/aws/aws-c-common/source/byte_buf.c b/contrib/restricted/aws/aws-c-common/source/byte_buf.c
index f52aa16b455..b815b6bfb74 100644
--- a/contrib/restricted/aws/aws-c-common/source/byte_buf.c
+++ b/contrib/restricted/aws/aws-c-common/source/byte_buf.c
@@ -1631,7 +1631,7 @@ int aws_byte_buf_append_and_update(struct aws_byte_buf *to, struct aws_byte_curs
return AWS_OP_ERR;
}
- from_and_update->ptr = to->buffer + (to->len - from_and_update->len);
+ from_and_update->ptr = to->buffer == NULL ? NULL : to->buffer + (to->len - from_and_update->len);
return AWS_OP_SUCCESS;
}
diff --git a/contrib/restricted/aws/aws-c-common/source/command_line_parser.c b/contrib/restricted/aws/aws-c-common/source/command_line_parser.c
index bf2db81e0a0..0699e7fbbdf 100644
--- a/contrib/restricted/aws/aws-c-common/source/command_line_parser.c
+++ b/contrib/restricted/aws/aws-c-common/source/command_line_parser.c
@@ -54,13 +54,11 @@ static const struct aws_cli_option *s_find_option_from_c_str(
const struct aws_cli_option *option = &longopts[index];
while (option->name || option->val != 0) {
- if (option->name) {
- if (option->name && !strcmp(search_for, option->name)) {
- if (longindex) {
- *longindex = index;
- }
- return option;
+ if (option->name && !strcmp(search_for, option->name)) {
+ if (longindex) {
+ *longindex = index;
}
+ return option;
}
option = &longopts[++index];
diff --git a/contrib/restricted/aws/aws-c-common/source/common.c b/contrib/restricted/aws/aws-c-common/source/common.c
index a845e22acfc..062d23228d5 100644
--- a/contrib/restricted/aws/aws-c-common/source/common.c
+++ b/contrib/restricted/aws/aws-c-common/source/common.c
@@ -256,6 +256,12 @@ static struct aws_error_info errors[] = {
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_PLATFORM_NOT_SUPPORTED,
"Feature not supported on this platform"),
+ AWS_DEFINE_ERROR_INFO_COMMON(
+ AWS_ERROR_INVALID_UTF8,
+ "Invalid UTF-8"),
+ AWS_DEFINE_ERROR_INFO_COMMON(
+ AWS_ERROR_GET_HOME_DIRECTORY_FAILED,
+ "Failed to get home directory"),
};
/* clang-format on */
@@ -304,7 +310,7 @@ void aws_common_library_init(struct aws_allocator *allocator) {
/* libnuma defines set_mempolicy() as a WEAK symbol. Loading into the global symbol table overwrites symbols and
assumptions due to the way loaders and dlload are often implemented and those symbols are defined by things
like libpthread.so on some unix distros. Sorry about the memory usage here, but it's our only safe choice.
- Also, please don't do numa configurations if memory is your economic bottlneck. */
+ Also, please don't do numa configurations if memory is your economic bottleneck. */
g_libnuma_handle = dlopen("libnuma.so", RTLD_LOCAL);
/* turns out so versioning is really inconsistent these days */
diff --git a/contrib/restricted/aws/aws-c-common/source/date_time.c b/contrib/restricted/aws/aws-c-common/source/date_time.c
index 77ec6ae0c17..cee4a90d88b 100644
--- a/contrib/restricted/aws/aws-c-common/source/date_time.c
+++ b/contrib/restricted/aws/aws-c-common/source/date_time.c
@@ -61,7 +61,7 @@ static void s_check_init_str_to_int(void) {
}
}
-/* Get the 0-11 monthy number from a string representing Month. Case insensitive and will stop on abbreviation*/
+/* Get the 0-11 monthly number from a string representing Month. Case insensitive and will stop on abbreviation*/
static int get_month_number_from_str(const char *time_string, size_t start_index, size_t stop_index) {
s_check_init_str_to_int();
diff --git a/contrib/restricted/aws/aws-c-common/source/encoding.c b/contrib/restricted/aws/aws-c-common/source/encoding.c
index 038a7d74e9d..9ca5ca4fbaa 100644
--- a/contrib/restricted/aws/aws-c-common/source/encoding.c
+++ b/contrib/restricted/aws/aws-c-common/source/encoding.c
@@ -38,7 +38,7 @@ static inline bool aws_common_private_has_avx2(void) {
static const uint8_t *HEX_CHARS = (const uint8_t *)"0123456789abcdef";
-static const uint8_t BASE64_SENTIANAL_VALUE = 0xff;
+static const uint8_t BASE64_SENTINEL_VALUE = 0xff;
static const uint8_t BASE64_ENCODING_TABLE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* in this table, 0xDD is an invalid decoded value, if you have to do byte counting for any reason, there's 16 bytes
@@ -337,10 +337,10 @@ int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, stru
return AWS_OP_SUCCESS;
}
-static inline int s_base64_get_decoded_value(unsigned char to_decode, uint8_t *value, int8_t allow_sentinal) {
+static inline int s_base64_get_decoded_value(unsigned char to_decode, uint8_t *value, int8_t allow_sentinel) {
uint8_t decode_value = BASE64_DECODING_TABLE[(size_t)to_decode];
- if (decode_value != 0xDD && (decode_value != BASE64_SENTIANAL_VALUE || allow_sentinal)) {
+ if (decode_value != 0xDD && (decode_value != BASE64_SENTINEL_VALUE || allow_sentinel)) {
*value = decode_value;
return AWS_OP_SUCCESS;
}
@@ -401,9 +401,9 @@ int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, stru
output->buffer[buffer_index++] = (uint8_t)((value1 << 2) | ((value2 >> 4) & 0x03));
- if (value3 != BASE64_SENTIANAL_VALUE) {
+ if (value3 != BASE64_SENTINEL_VALUE) {
output->buffer[buffer_index++] = (uint8_t)(((value2 << 4) & 0xF0) | ((value3 >> 2) & 0x0F));
- if (value4 != BASE64_SENTIANAL_VALUE) {
+ if (value4 != BASE64_SENTINEL_VALUE) {
output->buffer[buffer_index] = (uint8_t)((value3 & 0x03) << 6 | value4);
}
}
@@ -412,7 +412,7 @@ int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, stru
return AWS_OP_SUCCESS;
}
-struct aws_utf8_validator {
+struct aws_utf8_decoder {
struct aws_allocator *alloc;
/* Value of current codepoint, updated as we read each byte */
uint32_t codepoint;
@@ -421,54 +421,66 @@ struct aws_utf8_validator {
uint32_t min;
/* Number of bytes remaining the current codepoint */
uint8_t remaining;
+ /* Custom callback */
+ int (*on_codepoint)(uint32_t codepoint, void *user_data);
+ /* user_data for on_codepoint */
+ void *user_data;
};
-struct aws_utf8_validator *aws_utf8_validator_new(struct aws_allocator *allocator) {
- struct aws_utf8_validator *validator = aws_mem_calloc(allocator, 1, sizeof(struct aws_utf8_validator));
- validator->alloc = allocator;
- return validator;
+struct aws_utf8_decoder *aws_utf8_decoder_new(
+ struct aws_allocator *allocator,
+ const struct aws_utf8_decoder_options *options) {
+
+ struct aws_utf8_decoder *decoder = aws_mem_calloc(allocator, 1, sizeof(struct aws_utf8_decoder));
+ decoder->alloc = allocator;
+ if (options) {
+ decoder->on_codepoint = options->on_codepoint;
+ decoder->user_data = options->user_data;
+ }
+ return decoder;
}
-void aws_utf8_validator_destroy(struct aws_utf8_validator *validator) {
- if (validator) {
- aws_mem_release(validator->alloc, validator);
+void aws_utf8_decoder_destroy(struct aws_utf8_decoder *decoder) {
+ if (decoder) {
+ aws_mem_release(decoder->alloc, decoder);
}
}
-void aws_utf8_validator_reset(struct aws_utf8_validator *validator) {
- validator->codepoint = 0;
- validator->min = 0;
- validator->remaining = 0;
+void aws_utf8_decoder_reset(struct aws_utf8_decoder *decoder) {
+ decoder->codepoint = 0;
+ decoder->min = 0;
+ decoder->remaining = 0;
}
/* Why yes, this could be optimized. */
-int aws_utf8_validator_update(struct aws_utf8_validator *validator, struct aws_byte_cursor bytes) {
+int aws_utf8_decoder_update(struct aws_utf8_decoder *decoder, struct aws_byte_cursor bytes) {
+
/* We're respecting RFC-3629, which uses 1 to 4 byte sequences (never 5 or 6) */
for (size_t i = 0; i < bytes.len; ++i) {
uint8_t byte = bytes.ptr[i];
- if (validator->remaining == 0) {
+ if (decoder->remaining == 0) {
/* Check first byte of the codepoint to determine how many more bytes remain */
if ((byte & 0x80) == 0x00) {
/* 1 byte codepoints start with 0xxxxxxx */
- validator->remaining = 0;
- validator->codepoint = byte;
- validator->min = 0;
+ decoder->remaining = 0;
+ decoder->codepoint = byte;
+ decoder->min = 0;
} else if ((byte & 0xE0) == 0xC0) {
/* 2 byte codepoints start with 110xxxxx */
- validator->remaining = 1;
- validator->codepoint = byte & 0x1F;
- validator->min = 0x80;
+ decoder->remaining = 1;
+ decoder->codepoint = byte & 0x1F;
+ decoder->min = 0x80;
} else if ((byte & 0xF0) == 0xE0) {
/* 3 byte codepoints start with 1110xxxx */
- validator->remaining = 2;
- validator->codepoint = byte & 0x0F;
- validator->min = 0x800;
+ decoder->remaining = 2;
+ decoder->codepoint = byte & 0x0F;
+ decoder->min = 0x800;
} else if ((byte & 0xF8) == 0xF0) {
/* 4 byte codepoints start with 11110xxx */
- validator->remaining = 3;
- validator->codepoint = byte & 0x07;
- validator->min = 0x10000;
+ decoder->remaining = 3;
+ decoder->codepoint = byte & 0x07;
+ decoder->min = 0x10000;
} else {
return aws_raise_error(AWS_ERROR_INVALID_UTF8);
}
@@ -481,45 +493,58 @@ int aws_utf8_validator_update(struct aws_utf8_validator *validator, struct aws_b
/* Insert the 6 newly decoded bits:
* shifting left anything we've already decoded, and insert the new bits to the right */
- validator->codepoint = (validator->codepoint << 6) | (byte & 0x3F);
+ decoder->codepoint = (decoder->codepoint << 6) | (byte & 0x3F);
/* If we've decoded the whole codepoint, check it for validity
* (don't need to do these particular checks on 1 byte codepoints) */
- if (--validator->remaining == 0) {
+ if (--decoder->remaining == 0) {
/* Check that it's not "overlong" (encoded using more bytes than necessary) */
- if (validator->codepoint < validator->min) {
+ if (decoder->codepoint < decoder->min) {
return aws_raise_error(AWS_ERROR_INVALID_UTF8);
}
/* UTF-8 prohibits encoding character numbers between U+D800 and U+DFFF,
* which are reserved for use with the UTF-16 encoding form (as
* surrogate pairs) and do not directly represent characters */
- if (validator->codepoint >= 0xD800 && validator->codepoint <= 0xDFFF) {
+ if (decoder->codepoint >= 0xD800 && decoder->codepoint <= 0xDFFF) {
return aws_raise_error(AWS_ERROR_INVALID_UTF8);
}
}
}
+
+ /* Invoke user's on_codepoint callback */
+ if (decoder->on_codepoint && decoder->remaining == 0) {
+ if (decoder->on_codepoint(decoder->codepoint, decoder->user_data)) {
+ return AWS_OP_ERR;
+ }
+ }
}
return AWS_OP_SUCCESS;
}
-int aws_utf8_validator_finalize(struct aws_utf8_validator *validator) {
- bool valid = validator->remaining == 0;
- aws_utf8_validator_reset(validator);
+int aws_utf8_decoder_finalize(struct aws_utf8_decoder *decoder) {
+ bool valid = decoder->remaining == 0;
+ aws_utf8_decoder_reset(decoder);
if (AWS_LIKELY(valid)) {
return AWS_OP_SUCCESS;
}
return aws_raise_error(AWS_ERROR_INVALID_UTF8);
}
-bool aws_text_is_valid_utf8(struct aws_byte_cursor bytes) {
- struct aws_utf8_validator validator = {.remaining = 0};
- if (aws_utf8_validator_update(&validator, bytes)) {
- return false;
+int aws_decode_utf8(struct aws_byte_cursor bytes, const struct aws_utf8_decoder_options *options) {
+ struct aws_utf8_decoder decoder = {
+ .on_codepoint = options ? options->on_codepoint : NULL,
+ .user_data = options ? options->user_data : NULL,
+ };
+
+ if (aws_utf8_decoder_update(&decoder, bytes)) {
+ return AWS_OP_ERR;
}
- if (validator.remaining != 0) {
- return false;
+
+ if (aws_utf8_decoder_finalize(&decoder)) {
+ return AWS_OP_ERR;
}
- return true;
+
+ return AWS_OP_SUCCESS;
}
diff --git a/contrib/restricted/aws/aws-c-common/source/error.c b/contrib/restricted/aws/aws-c-common/source/error.c
index bdd4dfcd675..ad3cec86931 100644
--- a/contrib/restricted/aws/aws-c-common/source/error.c
+++ b/contrib/restricted/aws/aws-c-common/source/error.c
@@ -145,8 +145,20 @@ void aws_register_error_info(const struct aws_error_info_list *error_info) {
}
#if DEBUG_BUILD
+ /* Assert that first error has the right value */
+ const int expected_first_code = slot_index << AWS_ERROR_ENUM_STRIDE_BITS;
+ if (error_info->error_list[0].error_code != expected_first_code) {
+ fprintf(
+ stderr,
+ "Missing info: First error in list should be %d, not %d (%s)\n",
+ expected_first_code,
+ error_info->error_list[0].error_code,
+ error_info->error_list[0].literal_name);
+ AWS_FATAL_ASSERT(0);
+ }
+
/* Assert that error info entries are in the right order. */
- for (int i = 1; i < error_info->count; ++i) {
+ for (int i = 0; i < error_info->count; ++i) {
const int expected_code = min_range + i;
const struct aws_error_info *info = &error_info->error_list[i];
if (info->error_code != expected_code) {
@@ -193,13 +205,17 @@ int aws_translate_and_raise_io_error(int error_no) {
case EISDIR:
case ENAMETOOLONG:
case ENOENT:
+ case ENOTDIR:
return aws_raise_error(AWS_ERROR_FILE_INVALID_PATH);
+ case EMFILE:
case ENFILE:
return aws_raise_error(AWS_ERROR_MAX_FDS_EXCEEDED);
case ENOMEM:
return aws_raise_error(AWS_ERROR_OOM);
case ENOSPC:
return aws_raise_error(AWS_ERROR_NO_SPACE);
+ case ENOTEMPTY:
+ return aws_raise_error(AWS_ERROR_DIRECTORY_NOT_EMPTY);
default:
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
}
diff --git a/contrib/restricted/aws/aws-c-common/source/external/cJSON.c b/contrib/restricted/aws/aws-c-common/source/external/cJSON.c
index 8dd79bf1ecd..d6e49d9a894 100644
--- a/contrib/restricted/aws/aws-c-common/source/external/cJSON.c
+++ b/contrib/restricted/aws/aws-c-common/source/external/cJSON.c
@@ -89,12 +89,6 @@ typedef struct {
const unsigned char *json;
size_t position;
} error;
-static error global_error = { NULL, 0 };
-
-CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
-{
- return (const char*) (global_error.json + global_error.position);
-}
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
{
@@ -1094,10 +1088,6 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
cJSON *item = NULL;
- /* reset error position */
- global_error.json = NULL;
- global_error.position = 0;
-
if (value == NULL || 0 == buffer_length)
{
goto fail;
@@ -1162,7 +1152,6 @@ fail:
*return_parse_end = (const char*)local_error.json + local_error.position;
}
- global_error = local_error;
}
return NULL;
diff --git a/contrib/restricted/aws/aws-c-common/source/file.c b/contrib/restricted/aws/aws-c-common/source/file.c
index 95a80b2ca53..5f490003a03 100644
--- a/contrib/restricted/aws/aws-c-common/source/file.c
+++ b/contrib/restricted/aws/aws-c-common/source/file.c
@@ -13,7 +13,14 @@
FILE *aws_fopen(const char *file_path, const char *mode) {
if (!file_path || strlen(file_path) == 0) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to open file %s", file_path);
+ AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to open file. path is empty");
+ aws_raise_error(AWS_ERROR_FILE_INVALID_PATH);
+ return NULL;
+ }
+
+ if (!mode || strlen(mode) == 0) {
+ AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to open file. mode is empty");
+ aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
return NULL;
}
@@ -34,9 +41,10 @@ int aws_byte_buf_init_from_file(struct aws_byte_buf *out_buf, struct aws_allocat
if (fp) {
if (fseek(fp, 0L, SEEK_END)) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to seek file %s with errno %d", filename, errno);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
+ AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to seek file %s with errno %d", filename, errno_value);
fclose(fp);
- return aws_translate_and_raise_io_error(errno);
+ return aws_translate_and_raise_io_error(errno_value);
}
size_t allocation_size = (size_t)ftell(fp) + 1;
@@ -52,16 +60,18 @@ int aws_byte_buf_init_from_file(struct aws_byte_buf *out_buf, struct aws_allocat
out_buf->buffer[out_buf->len] = 0;
if (fseek(fp, 0L, SEEK_SET)) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to seek file %s with errno %d", filename, errno);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
+ AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to seek file %s with errno %d", filename, errno_value);
aws_byte_buf_clean_up(out_buf);
fclose(fp);
- return aws_translate_and_raise_io_error(errno);
+ return aws_translate_and_raise_io_error(errno_value);
}
size_t read = fread(out_buf->buffer, 1, out_buf->len, fp);
+ int errno_cpy = errno; /* Always cache errno before potential side-effect */
fclose(fp);
if (read < out_buf->len) {
- AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to read file %s with errno %d", filename, errno);
+ AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to read file %s with errno %d", filename, errno_cpy);
aws_secure_zero(out_buf->buffer, out_buf->len);
aws_byte_buf_clean_up(out_buf);
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
@@ -70,12 +80,7 @@ int aws_byte_buf_init_from_file(struct aws_byte_buf *out_buf, struct aws_allocat
return AWS_OP_SUCCESS;
}
- AWS_LOGF_ERROR(AWS_LS_COMMON_IO, "static: Failed to open file %s with errno %d", filename, errno);
-
- if (errno == 0) {
- return aws_raise_error(AWS_ERROR_FILE_INVALID_PATH);
- }
- return aws_translate_and_raise_io_error(errno);
+ return AWS_OP_ERR;
}
bool aws_is_any_directory_separator(char value) {
diff --git a/contrib/restricted/aws/aws-c-common/source/json.c b/contrib/restricted/aws/aws-c-common/source/json.c
index 387f41f1837..0131ea116b5 100644
--- a/contrib/restricted/aws/aws-c-common/source/json.c
+++ b/contrib/restricted/aws/aws-c-common/source/json.c
@@ -15,7 +15,7 @@ static struct aws_allocator *s_aws_json_module_allocator = NULL;
static bool s_aws_json_module_initialized = false;
struct aws_json_value *aws_json_value_new_string(struct aws_allocator *allocator, struct aws_byte_cursor string) {
- struct aws_string *tmp = aws_string_new_from_cursor((struct aws_allocator *)allocator, &string);
+ struct aws_string *tmp = aws_string_new_from_cursor(allocator, &string);
void *ret_val = cJSON_CreateString(aws_string_c_str(tmp));
aws_string_destroy_secure(tmp);
return ret_val;
@@ -47,7 +47,7 @@ struct aws_json_value *aws_json_value_new_object(struct aws_allocator *allocator
}
int aws_json_value_get_string(const struct aws_json_value *value, struct aws_byte_cursor *output) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (!cJSON_IsString(cjson)) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
@@ -56,7 +56,7 @@ int aws_json_value_get_string(const struct aws_json_value *value, struct aws_byt
}
int aws_json_value_get_number(const struct aws_json_value *value, double *output) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (!cJSON_IsNumber(cjson)) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
@@ -65,7 +65,7 @@ int aws_json_value_get_number(const struct aws_json_value *value, double *output
}
int aws_json_value_get_boolean(const struct aws_json_value *value, bool *output) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (!cJSON_IsBool(cjson)) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
@@ -109,7 +109,7 @@ struct aws_json_value *aws_json_value_get_from_object(const struct aws_json_valu
void *return_value = NULL;
struct aws_string *tmp = aws_string_new_from_cursor(s_aws_json_module_allocator, &key);
- struct cJSON *cjson = (struct cJSON *)object;
+ const struct cJSON *cjson = (const struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
@@ -130,7 +130,7 @@ bool aws_json_value_has_key(const struct aws_json_value *object, struct aws_byte
struct aws_string *tmp = aws_string_new_from_cursor(s_aws_json_module_allocator, &key);
bool result = false;
- struct cJSON *cjson = (struct cJSON *)object;
+ const struct cJSON *cjson = (const struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
goto done;
}
@@ -172,7 +172,7 @@ int aws_json_const_iterate_object(
void *user_data) {
int result = AWS_OP_ERR;
- struct cJSON *cjson = (struct cJSON *)object;
+ const struct cJSON *cjson = (const struct cJSON *)object;
if (!cJSON_IsObject(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
@@ -182,7 +182,7 @@ int aws_json_const_iterate_object(
cJSON_ArrayForEach(key, cjson) {
bool should_continue = true;
struct aws_byte_cursor key_cur = aws_byte_cursor_from_c_str(key->string);
- if (on_member(&key_cur, (struct aws_json_value *)key, &should_continue, user_data)) {
+ if (on_member(&key_cur, (const struct aws_json_value *)key, &should_continue, user_data)) {
goto done;
}
@@ -214,8 +214,7 @@ int aws_json_value_add_array_element(struct aws_json_value *array, const struct
}
struct aws_json_value *aws_json_get_array_element(const struct aws_json_value *array, size_t index) {
-
- struct cJSON *cjson = (struct cJSON *)array;
+ const struct cJSON *cjson = (const struct cJSON *)array;
if (!cJSON_IsArray(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
return NULL;
@@ -230,7 +229,7 @@ struct aws_json_value *aws_json_get_array_element(const struct aws_json_value *a
}
size_t aws_json_get_array_size(const struct aws_json_value *array) {
- struct cJSON *cjson = (struct cJSON *)array;
+ const struct cJSON *cjson = (const struct cJSON *)array;
if (!cJSON_IsArray(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
return 0;
@@ -259,7 +258,7 @@ int aws_json_const_iterate_array(
void *user_data) {
int result = AWS_OP_ERR;
- struct cJSON *cjson = (struct cJSON *)array;
+ const struct cJSON *cjson = (const struct cJSON *)array;
if (!cJSON_IsArray(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
goto done;
@@ -269,7 +268,7 @@ int aws_json_const_iterate_array(
const cJSON *value = NULL;
cJSON_ArrayForEach(value, cjson) {
bool should_continue = true;
- if (on_value(idx, (struct aws_json_value *)value, &should_continue, user_data)) {
+ if (on_value(idx, (const struct aws_json_value *)value, &should_continue, user_data)) {
goto done;
}
@@ -286,13 +285,13 @@ done:
}
bool aws_json_value_compare(const struct aws_json_value *a, const struct aws_json_value *b, bool is_case_sensitive) {
- struct cJSON *cjson_a = (struct cJSON *)a;
- struct cJSON *cjson_b = (struct cJSON *)b;
+ const struct cJSON *cjson_a = (const struct cJSON *)a;
+ const struct cJSON *cjson_b = (const struct cJSON *)b;
return cJSON_Compare(cjson_a, cjson_b, is_case_sensitive);
}
struct aws_json_value *aws_json_value_duplicate(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
return NULL;
@@ -307,7 +306,7 @@ struct aws_json_value *aws_json_value_duplicate(const struct aws_json_value *val
}
bool aws_json_value_is_string(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return false;
}
@@ -315,7 +314,7 @@ bool aws_json_value_is_string(const struct aws_json_value *value) {
}
bool aws_json_value_is_number(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return false;
}
@@ -323,7 +322,7 @@ bool aws_json_value_is_number(const struct aws_json_value *value) {
}
bool aws_json_value_is_array(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return false;
}
@@ -331,7 +330,7 @@ bool aws_json_value_is_array(const struct aws_json_value *value) {
}
bool aws_json_value_is_boolean(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return false;
}
@@ -339,7 +338,7 @@ bool aws_json_value_is_boolean(const struct aws_json_value *value) {
}
bool aws_json_value_is_null(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return false;
}
@@ -347,7 +346,7 @@ bool aws_json_value_is_null(const struct aws_json_value *value) {
}
bool aws_json_value_is_object(const struct aws_json_value *value) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return false;
}
@@ -391,7 +390,7 @@ void aws_json_value_destroy(struct aws_json_value *value) {
}
int aws_byte_buf_append_json_string(const struct aws_json_value *value, struct aws_byte_buf *output) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
@@ -409,7 +408,7 @@ int aws_byte_buf_append_json_string(const struct aws_json_value *value, struct a
}
int aws_byte_buf_append_json_string_formatted(const struct aws_json_value *value, struct aws_byte_buf *output) {
- struct cJSON *cjson = (struct cJSON *)value;
+ const struct cJSON *cjson = (const struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
@@ -427,7 +426,7 @@ int aws_byte_buf_append_json_string_formatted(const struct aws_json_value *value
}
struct aws_json_value *aws_json_value_new_from_string(struct aws_allocator *allocator, struct aws_byte_cursor string) {
- struct aws_string *tmp = aws_string_new_from_cursor((struct aws_allocator *)allocator, &string);
+ struct aws_string *tmp = aws_string_new_from_cursor(allocator, &string);
struct cJSON *cjson = cJSON_Parse(aws_string_c_str(tmp));
aws_string_destroy_secure(tmp);
return (void *)cjson;
diff --git a/contrib/restricted/aws/aws-c-common/source/log_formatter.c b/contrib/restricted/aws/aws-c-common/source/log_formatter.c
index 513a7f87b45..d4be0c0c6d2 100644
--- a/contrib/restricted/aws/aws-c-common/source/log_formatter.c
+++ b/contrib/restricted/aws/aws-c-common/source/log_formatter.c
@@ -16,7 +16,7 @@
* Default formatter implementation
*/
-#if _MSC_VER
+#ifdef _MSC_VER
# pragma warning(disable : 4204) /* non-constant aggregate initializer */
#endif
diff --git a/contrib/restricted/aws/aws-c-common/source/log_writer.c b/contrib/restricted/aws/aws-c-common/source/log_writer.c
index 6eea2fc3c5e..5f5bc4f6fd5 100644
--- a/contrib/restricted/aws/aws-c-common/source/log_writer.c
+++ b/contrib/restricted/aws/aws-c-common/source/log_writer.c
@@ -27,7 +27,8 @@ static int s_aws_file_writer_write(struct aws_log_writer *writer, const struct a
size_t length = output->len;
if (fwrite(output->bytes, 1, length, impl->log_file) < length) {
- return aws_translate_and_raise_io_error(errno);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
+ return aws_translate_and_raise_io_error(errno_value);
}
return AWS_OP_SUCCESS;
@@ -76,7 +77,7 @@ static int s_aws_file_writer_init_internal(
impl->log_file = aws_fopen(file_name_to_open, "a+");
if (impl->log_file == NULL) {
aws_mem_release(allocator, impl);
- return aws_translate_and_raise_io_error(errno);
+ return AWS_OP_ERR;
}
impl->close_file_on_cleanup = true;
} else {
diff --git a/contrib/restricted/aws/aws-c-common/source/logging.c b/contrib/restricted/aws/aws-c-common/source/logging.c
index f9a6c5a2e65..fdc29576d82 100644
--- a/contrib/restricted/aws/aws-c-common/source/logging.c
+++ b/contrib/restricted/aws/aws-c-common/source/logging.c
@@ -15,7 +15,7 @@
#include <errno.h>
#include <stdarg.h>
-#if _MSC_VER
+#ifdef _MSC_VER
# pragma warning(disable : 4204) /* non-constant aggregate initializer */
#endif
@@ -468,7 +468,7 @@ static int s_noalloc_stderr_logger_log(
va_list format_args;
va_start(format_args, format);
-#if _MSC_VER
+#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4221) /* allow struct member to reference format_buffer */
#endif
@@ -484,7 +484,7 @@ static int s_noalloc_stderr_logger_log(
.amount_written = 0,
};
-#if _MSC_VER
+#ifdef _MSC_VER
# pragma warning(pop) /* disallow struct member to reference local value */
#endif
@@ -502,7 +502,8 @@ static int s_noalloc_stderr_logger_log(
int write_result = AWS_OP_SUCCESS;
if (fwrite(format_buffer, 1, format_data.amount_written, impl->file) < format_data.amount_written) {
- aws_translate_and_raise_io_error(errno);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
+ aws_translate_and_raise_io_error(errno_value);
write_result = AWS_OP_ERR;
}
@@ -561,6 +562,10 @@ int aws_logger_init_noalloc(
} else { /* _MSC_VER */
if (options->filename != NULL) {
impl->file = aws_fopen(options->filename, "w");
+ if (!impl->file) {
+ aws_mem_release(allocator, impl);
+ return AWS_OP_ERR;
+ }
impl->should_close = true;
} else {
impl->file = stderr;
diff --git a/contrib/restricted/aws/aws-c-common/source/memtrace.c b/contrib/restricted/aws/aws-c-common/source/memtrace.c
index 7362e07a30f..651fd93612a 100644
--- a/contrib/restricted/aws/aws-c-common/source/memtrace.c
+++ b/contrib/restricted/aws/aws-c-common/source/memtrace.c
@@ -5,19 +5,19 @@
#include <aws/common/atomics.h>
#include <aws/common/byte_buf.h>
+#include <aws/common/clock.h>
#include <aws/common/hash_table.h>
#include <aws/common/logging.h>
#include <aws/common/mutex.h>
#include <aws/common/priority_queue.h>
#include <aws/common/string.h>
#include <aws/common/system_info.h>
-#include <aws/common/time.h>
/* describes a single live allocation.
* allocated by aws_default_allocator() */
struct alloc_info {
size_t size;
- time_t time;
+ uint64_t time;
uint64_t stack; /* hash of stack frame pointers */
};
@@ -43,8 +43,8 @@ struct stack_trace {
#endif
/* Tracking structure, used as the allocator impl.
- * This structure, and all its bookkeeping datastructures, are created with the aws_default_allocator().
- * This is not customizeable because it's too expensive for every little allocation to store
+ * This structure, and all its bookkeeping data structures, are created with the aws_default_allocator().
+ * This is not customizable because it's too expensive for every little allocation to store
* a pointer back to its original allocator. */
struct alloc_tracer {
struct aws_allocator *traced_allocator; /* underlying allocator */
@@ -110,7 +110,7 @@ static void s_alloc_tracer_init(
if (frames_per_stack > 128) {
frames_per_stack = 128;
}
- tracer->frames_per_stack = (frames_per_stack) ? frames_per_stack : 8;
+ tracer->frames_per_stack = frames_per_stack ? frames_per_stack : 8;
AWS_FATAL_ASSERT(
AWS_OP_SUCCESS ==
aws_hash_table_init(
@@ -128,7 +128,7 @@ static void s_alloc_tracer_track(struct alloc_tracer *tracer, void *ptr, size_t
struct alloc_info *alloc = aws_mem_calloc(aws_default_allocator(), 1, sizeof(struct alloc_info));
AWS_FATAL_ASSERT(alloc);
alloc->size = size;
- alloc->time = time(NULL);
+ aws_high_res_clock_get_ticks(&alloc->time);
if (tracer->level == AWS_MEMTRACE_STACKS) {
/* capture stack frames, skip 2 for this function and the allocation vtable function */
@@ -300,14 +300,14 @@ void aws_mem_tracer_dump(struct aws_allocator *trace_allocator) {
size_t num_allocs = aws_hash_table_get_entry_count(&tracer->allocs);
AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "################################################################################\n");
+ AWS_LS_COMMON_MEMTRACE, "################################################################################");
AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "# BEGIN MEMTRACE DUMP #\n");
+ AWS_LS_COMMON_MEMTRACE, "# BEGIN MEMTRACE DUMP #");
AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "################################################################################\n");
+ AWS_LS_COMMON_MEMTRACE, "################################################################################");
AWS_LOGF_TRACE(
AWS_LS_COMMON_MEMTRACE,
- "tracer: %zu bytes still allocated in %zu allocations\n",
+ "tracer: %zu bytes still allocated in %zu allocations",
aws_atomic_load_int(&tracer->allocated),
num_allocs);
@@ -333,21 +333,24 @@ void aws_mem_tracer_dump(struct aws_allocator *trace_allocator) {
&allocs, aws_default_allocator(), num_allocs, sizeof(struct alloc_info *), s_alloc_compare));
aws_hash_table_foreach(&tracer->allocs, s_insert_allocs, &allocs);
/* dump allocs by time */
- AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "################################################################################\n");
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "Leaks in order of allocation:\n");
- AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "################################################################################\n");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "Leaks in order of allocation:");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
while (aws_priority_queue_size(&allocs)) {
struct alloc_info *alloc = NULL;
aws_priority_queue_pop(&allocs, &alloc);
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "ALLOC %zu bytes\n", alloc->size);
if (alloc->stack) {
struct aws_hash_element *item = NULL;
AWS_FATAL_ASSERT(
AWS_OP_SUCCESS == aws_hash_table_find(&stack_info, (void *)(uintptr_t)alloc->stack, &item));
struct stack_metadata *stack = item->value;
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, " stacktrace:\n%s\n", (const char *)aws_string_bytes(stack->trace));
+ AWS_LOGF_TRACE(
+ AWS_LS_COMMON_MEMTRACE,
+ "ALLOC %zu bytes, stacktrace:\n%s\n",
+ alloc->size,
+ aws_string_c_str(stack->trace));
+ } else {
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "ALLOC %zu bytes", alloc->size);
}
}
@@ -365,18 +368,18 @@ void aws_mem_tracer_dump(struct aws_allocator *trace_allocator) {
sizeof(struct stack_metadata *),
s_stack_info_compare_size));
aws_hash_table_foreach(&stack_info, s_insert_stacks, &stacks_by_size);
- AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE,
- "################################################################################\n");
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "Stacks by bytes leaked:\n");
- AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE,
- "################################################################################\n");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "Stacks by bytes leaked:");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
while (aws_priority_queue_size(&stacks_by_size) > 0) {
struct stack_metadata *stack = NULL;
aws_priority_queue_pop(&stacks_by_size, &stack);
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "%zu bytes in %zu allocations:\n", stack->size, stack->count);
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "%s\n", (const char *)aws_string_bytes(stack->trace));
+ AWS_LOGF_TRACE(
+ AWS_LS_COMMON_MEMTRACE,
+ "%zu bytes in %zu allocations:\n%s\n",
+ stack->size,
+ stack->count,
+ aws_string_c_str(stack->trace));
}
aws_priority_queue_clean_up(&stacks_by_size);
@@ -389,30 +392,30 @@ void aws_mem_tracer_dump(struct aws_allocator *trace_allocator) {
num_stacks,
sizeof(struct stack_metadata *),
s_stack_info_compare_count));
- AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE,
- "################################################################################\n");
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "Stacks by number of leaks:\n");
- AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE,
- "################################################################################\n");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "Stacks by number of leaks:");
+ AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
aws_hash_table_foreach(&stack_info, s_insert_stacks, &stacks_by_count);
while (aws_priority_queue_size(&stacks_by_count) > 0) {
struct stack_metadata *stack = NULL;
aws_priority_queue_pop(&stacks_by_count, &stack);
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "%zu allocations leaking %zu bytes:\n", stack->count, stack->size);
- AWS_LOGF_TRACE(AWS_LS_COMMON_MEMTRACE, "%s\n", (const char *)aws_string_bytes(stack->trace));
+ AWS_LOGF_TRACE(
+ AWS_LS_COMMON_MEMTRACE,
+ "%zu allocations leaking %zu bytes:\n%s\n",
+ stack->count,
+ stack->size,
+ aws_string_c_str(stack->trace));
}
aws_priority_queue_clean_up(&stacks_by_count);
aws_hash_table_clean_up(&stack_info);
}
AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "################################################################################\n");
+ AWS_LS_COMMON_MEMTRACE, "################################################################################");
AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "# END MEMTRACE DUMP #\n");
+ AWS_LS_COMMON_MEMTRACE, "# END MEMTRACE DUMP #");
AWS_LOGF_TRACE(
- AWS_LS_COMMON_MEMTRACE, "################################################################################\n");
+ AWS_LS_COMMON_MEMTRACE, "################################################################################");
aws_mutex_unlock(&tracer->mutex);
}
@@ -460,7 +463,7 @@ struct aws_allocator *aws_mem_tracer_new(
enum aws_mem_trace_level level,
size_t frames_per_stack) {
- /* deprecated customizeable bookkeeping allocator */
+ /* deprecated customizable bookkeeping allocator */
(void)deprecated;
struct alloc_tracer *tracer = NULL;
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/file.c b/contrib/restricted/aws/aws-c-common/source/posix/file.c
index 7c26ade8c36..e8b39c509c3 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/file.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/file.c
@@ -5,47 +5,39 @@
#include <aws/common/environment.h>
#include <aws/common/file.h>
+#include <aws/common/logging.h>
#include <aws/common/string.h>
#include <dirent.h>
#include <errno.h>
+#include <pwd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
FILE *aws_fopen_safe(const struct aws_string *file_path, const struct aws_string *mode) {
- return fopen(aws_string_c_str(file_path), aws_string_c_str(mode));
-}
-
-static int s_parse_and_raise_error(int errno_cpy) {
- if (errno_cpy == 0) {
- return AWS_OP_SUCCESS;
- }
-
- if (errno_cpy == ENOENT || errno_cpy == ENOTDIR) {
- return aws_raise_error(AWS_ERROR_FILE_INVALID_PATH);
- }
-
- if (errno_cpy == EMFILE || errno_cpy == ENFILE) {
- return aws_raise_error(AWS_ERROR_MAX_FDS_EXCEEDED);
- }
-
- if (errno_cpy == EACCES) {
- return aws_raise_error(AWS_ERROR_NO_PERMISSION);
+ FILE *f = fopen(aws_string_c_str(file_path), aws_string_c_str(mode));
+ if (!f) {
+ int errno_cpy = errno; /* Always cache errno before potential side-effect */
+ aws_translate_and_raise_io_error(errno_cpy);
+ AWS_LOGF_ERROR(
+ AWS_LS_COMMON_IO,
+ "static: Failed to open file. path:'%s' mode:'%s' errno:%d aws-error:%d(%s)",
+ aws_string_c_str(file_path),
+ aws_string_c_str(mode),
+ errno_cpy,
+ aws_last_error(),
+ aws_error_name(aws_last_error()));
}
-
- if (errno_cpy == ENOTEMPTY) {
- return aws_raise_error(AWS_ERROR_DIRECTORY_NOT_EMPTY);
- }
-
- return aws_raise_error(AWS_ERROR_UNKNOWN);
+ return f;
}
int aws_directory_create(const struct aws_string *dir_path) {
int mkdir_ret = mkdir(aws_string_c_str(dir_path), S_IRWXU | S_IRWXG | S_IRWXO);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
/** nobody cares if it already existed. */
- if (mkdir_ret != 0 && errno != EEXIST) {
- return s_parse_and_raise_error(errno);
+ if (mkdir_ret != 0 && errno_value != EEXIST) {
+ return aws_translate_and_raise_io_error(errno_value);
}
return AWS_OP_SUCCESS;
@@ -101,24 +93,27 @@ int aws_directory_delete(const struct aws_string *dir_path, bool recursive) {
}
int error_code = rmdir(aws_string_c_str(dir_path));
+ int errno_value = errno; /* Always cache errno before potential side-effect */
- return error_code == 0 ? AWS_OP_SUCCESS : s_parse_and_raise_error(errno);
+ return error_code == 0 ? AWS_OP_SUCCESS : aws_translate_and_raise_io_error(errno_value);
}
int aws_directory_or_file_move(const struct aws_string *from, const struct aws_string *to) {
int error_code = rename(aws_string_c_str(from), aws_string_c_str(to));
+ int errno_value = errno; /* Always cache errno before potential side-effect */
- return error_code == 0 ? AWS_OP_SUCCESS : s_parse_and_raise_error(errno);
+ return error_code == 0 ? AWS_OP_SUCCESS : aws_translate_and_raise_io_error(errno_value);
}
int aws_file_delete(const struct aws_string *file_path) {
int error_code = unlink(aws_string_c_str(file_path));
+ int errno_value = errno; /* Always cache errno before potential side-effect */
- if (!error_code || errno == ENOENT) {
+ if (!error_code || errno_value == ENOENT) {
return AWS_OP_SUCCESS;
}
- return s_parse_and_raise_error(errno);
+ return aws_translate_and_raise_io_error(errno_value);
}
int aws_directory_traverse(
@@ -128,9 +123,10 @@ int aws_directory_traverse(
aws_on_directory_entry *on_entry,
void *user_data) {
DIR *dir = opendir(aws_string_c_str(path));
+ int errno_value = errno; /* Always cache errno before potential side-effect */
if (!dir) {
- return s_parse_and_raise_error(errno);
+ return aws_translate_and_raise_io_error(errno_value);
}
struct aws_byte_cursor current_path = aws_byte_cursor_from_string(path);
@@ -227,13 +223,39 @@ AWS_STATIC_STRING_FROM_LITERAL(s_home_env_var, "HOME");
struct aws_string *aws_get_home_directory(struct aws_allocator *allocator) {
- /* ToDo: check getpwuid_r if environment check fails */
- struct aws_string *home_env_var_value = NULL;
- if (aws_get_environment_value(allocator, s_home_env_var, &home_env_var_value) == 0 && home_env_var_value != NULL) {
- return home_env_var_value;
+ /* First, check "HOME" environment variable.
+ * If it's set, then return it, even if it's an empty string. */
+ struct aws_string *home_value = NULL;
+ aws_get_environment_value(allocator, s_home_env_var, &home_value);
+ if (home_value != NULL) {
+ return home_value;
+ }
+
+ /* Next, check getpwuid_r().
+ * We need to allocate a tmp buffer to store the result strings,
+ * and the max possible size for this thing can be pretty big,
+ * so start with a reasonable allocation, and if that's not enough try something bigger. */
+ uid_t uid = getuid(); /* cannot fail */
+ struct passwd pwd;
+ struct passwd *result = NULL;
+ char *buf = NULL;
+ int status = ERANGE;
+ for (size_t bufsize = 1024; bufsize <= 16384 && status == ERANGE; bufsize *= 2) {
+ if (buf) {
+ aws_mem_release(allocator, buf);
+ }
+ buf = aws_mem_acquire(allocator, bufsize);
+ status = getpwuid_r(uid, &pwd, buf, bufsize, &result);
+ }
+
+ if (status == 0 && result != NULL && result->pw_dir != NULL) {
+ home_value = aws_string_new_from_c_str(allocator, result->pw_dir);
+ } else {
+ aws_raise_error(AWS_ERROR_GET_HOME_DIRECTORY_FAILED);
}
- return NULL;
+ aws_mem_release(allocator, buf);
+ return home_value;
}
bool aws_path_exists(const struct aws_string *path) {
@@ -251,10 +273,11 @@ int aws_fseek(FILE *file, int64_t offset, int whence) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
int result = fseek(file, offset, whence);
-#endif /* AWS_HAVE_POSIX_LFS */
+#endif /* AWS_HAVE_POSIX_LFS */
+ int errno_value = errno; /* Always cache errno before potential side-effect */
if (result != 0) {
- return aws_translate_and_raise_io_error(errno);
+ return aws_translate_and_raise_io_error(errno_value);
}
return AWS_OP_SUCCESS;
@@ -270,7 +293,8 @@ int aws_file_get_length(FILE *file, int64_t *length) {
}
if (fstat(fd, &file_stats)) {
- return aws_translate_and_raise_io_error(errno);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
+ return aws_translate_and_raise_io_error(errno_value);
}
*length = file_stats.st_size;
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/thread.c b/contrib/restricted/aws/aws-c-common/source/posix/thread.c
index d17d859c3b1..57d48aa9c70 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/thread.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/thread.c
@@ -23,9 +23,11 @@
#include <time.h>
#include <unistd.h>
-#if defined(__FreeBSD__) || defined(__NETBSD__)
+#if defined(__FreeBSD__) || defined(__NetBSD__)
# include <pthread_np.h>
typedef cpuset_t cpu_set_t;
+#elif defined(__OpenBSD__)
+# include <pthread_np.h>
#endif
#if !defined(AWS_AFFINITY_METHOD)
@@ -128,6 +130,8 @@ static void s_set_thread_name(pthread_t thread_id, const char *name) {
pthread_setname_np(name);
#elif defined(AWS_PTHREAD_SETNAME_TAKES_2ARGS)
pthread_setname_np(thread_id, name);
+#elif defined(AWS_PTHREAD_SET_NAME_TAKES_2ARGS)
+ pthread_set_name_np(thread_id, name);
#elif defined(AWS_PTHREAD_SETNAME_TAKES_3ARGS)
pthread_setname_np(thread_id, name, NULL);
#else
@@ -165,8 +169,9 @@ static void *thread_fn(void *arg) {
* and makes sure the numa node of the cpu we launched this thread on is where memory gets allocated. However,
* we don't want to fail the application if this fails, so make the call, and ignore the result. */
long resp = g_set_mempolicy_ptr(AWS_MPOL_PREFERRED_ALIAS, NULL, 0);
+ int errno_value = errno; /* Always cache errno before potential side-effect */
if (resp) {
- AWS_LOGF_WARN(AWS_LS_COMMON_THREAD, "call to set_mempolicy() failed with errno %d", errno);
+ AWS_LOGF_WARN(AWS_LS_COMMON_THREAD, "call to set_mempolicy() failed with errno %d", errno_value);
}
}
wrapper.func(wrapper.arg);
@@ -274,7 +279,7 @@ int aws_thread_launch(
/* AFAIK you can't set thread affinity on apple platforms, and it doesn't really matter since all memory
* NUMA or not is setup in interleave mode.
- * Thread afinity is also not supported on Android systems, and honestly, if you're running android on a NUMA
+ * Thread affinity is also not supported on Android systems, and honestly, if you're running android on a NUMA
* configuration, you've got bigger problems. */
#if AWS_AFFINITY_METHOD == AWS_AFFINITY_METHOD_PTHREAD_ATTR
if (options->cpu_id >= 0) {
@@ -460,3 +465,32 @@ int aws_thread_current_at_exit(aws_thread_atexit_fn *callback, void *user_data)
tl_wrapper->atexit = cb;
return AWS_OP_SUCCESS;
}
+
+int aws_thread_current_name(struct aws_allocator *allocator, struct aws_string **out_name) {
+ return aws_thread_name(allocator, aws_thread_current_thread_id(), out_name);
+}
+
+#define THREAD_NAME_BUFFER_SIZE 256
+int aws_thread_name(struct aws_allocator *allocator, aws_thread_id_t thread_id, struct aws_string **out_name) {
+ *out_name = NULL;
+#if defined(AWS_PTHREAD_GETNAME_TAKES_2ARGS) || defined(AWS_PTHREAD_GETNAME_TAKES_3ARGS) || \
+ defined(AWS_PTHREAD_GET_NAME_TAKES_2_ARGS)
+ char name[THREAD_NAME_BUFFER_SIZE] = {0};
+# ifdef AWS_PTHREAD_GETNAME_TAKES_3ARGS
+ if (pthread_getname_np(thread_id, name, THREAD_NAME_BUFFER_SIZE)) {
+# elif AWS_PTHREAD_GETNAME_TAKES_2ARGS
+ if (pthread_getname_np(thread_id, name)) {
+# elif AWS_PTHREAD_GET_NAME_TAKES_2ARGS
+ if (pthread_get_name_np(thread_id, name)) {
+# endif
+
+ return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
+ }
+
+ *out_name = aws_string_new_from_c_str(allocator, name);
+ return AWS_OP_SUCCESS;
+#else
+
+ return aws_raise_error(AWS_ERROR_PLATFORM_NOT_SUPPORTED);
+#endif
+}
diff --git a/contrib/restricted/aws/aws-c-common/source/priority_queue.c b/contrib/restricted/aws/aws-c-common/source/priority_queue.c
index f7d0f54e2d6..86a91feb3ae 100644
--- a/contrib/restricted/aws/aws-c-common/source/priority_queue.c
+++ b/contrib/restricted/aws/aws-c-common/source/priority_queue.c
@@ -59,7 +59,8 @@ static bool s_sift_down(struct aws_priority_queue *queue, size_t root) {
size_t left = LEFT_OF(root);
size_t right = RIGHT_OF(root);
size_t first = root;
- void *first_item = NULL, *other_item = NULL;
+ void *first_item = NULL;
+ void *other_item = NULL;
aws_array_list_get_at_ptr(&queue->container, &first_item, root);
aws_array_list_get_at_ptr(&queue->container, &other_item, left);
@@ -100,7 +101,8 @@ static bool s_sift_up(struct aws_priority_queue *queue, size_t index) {
bool did_move = false;
- void *parent_item = NULL, *child_item = NULL;
+ void *parent_item = NULL;
+ void *child_item = NULL;
size_t parent = PARENT_OF(index);
while (index) {
/*
@@ -216,8 +218,8 @@ bool aws_priority_queue_backpointers_valid(const struct aws_priority_queue *cons
/* Internal container validity */
bool backpointer_list_is_valid =
- ((aws_array_list_is_valid(&queue->backpointers) && (queue->backpointers.current_size != 0) &&
- (queue->backpointers.data != NULL)));
+ (aws_array_list_is_valid(&queue->backpointers) && (queue->backpointers.current_size != 0) &&
+ (queue->backpointers.data != NULL));
/* Backpointer struct should either be zero or should be
* initialized to be at most as long as the container, and having
diff --git a/contrib/restricted/aws/aws-c-common/source/uri.c b/contrib/restricted/aws/aws-c-common/source/uri.c
index 05596414200..1fafc9492e6 100644
--- a/contrib/restricted/aws/aws-c-common/source/uri.c
+++ b/contrib/restricted/aws/aws-c-common/source/uri.c
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <string.h>
-#if _MSC_VER
+#ifdef _MSC_VER
# pragma warning(disable : 4221) /* aggregate initializer using local variable addresses */
# pragma warning(disable : 4204) /* non-constant aggregate initializer */
#endif
@@ -264,7 +264,7 @@ int aws_uri_query_string_params(const struct aws_uri *uri, struct aws_array_list
}
static void s_parse_scheme(struct uri_parser *parser, struct aws_byte_cursor *str) {
- uint8_t *location_of_colon = memchr(str->ptr, ':', str->len);
+ const uint8_t *location_of_colon = memchr(str->ptr, ':', str->len);
if (!location_of_colon) {
parser->state = ON_AUTHORITY;
@@ -292,8 +292,8 @@ static void s_parse_scheme(struct uri_parser *parser, struct aws_byte_cursor *st
}
static void s_parse_authority(struct uri_parser *parser, struct aws_byte_cursor *str) {
- uint8_t *location_of_slash = memchr(str->ptr, '/', str->len);
- uint8_t *location_of_qmark = memchr(str->ptr, '?', str->len);
+ const uint8_t *location_of_slash = memchr(str->ptr, '/', str->len);
+ const uint8_t *location_of_qmark = memchr(str->ptr, '?', str->len);
if (!location_of_slash && !location_of_qmark && str->len) {
parser->uri->authority.ptr = str->ptr;
@@ -309,7 +309,7 @@ static void s_parse_authority(struct uri_parser *parser, struct aws_byte_cursor
aws_raise_error(AWS_ERROR_MALFORMED_INPUT_STRING);
return;
} else {
- uint8_t *end = str->ptr + str->len;
+ const uint8_t *end = str->ptr + str->len;
if (location_of_slash) {
parser->state = ON_PATH;
end = location_of_slash;
@@ -325,7 +325,7 @@ static void s_parse_authority(struct uri_parser *parser, struct aws_byte_cursor
if (authority_parse_csr.len) {
/* RFC-3986 section 3.2: authority = [ userinfo "@" ] host [ ":" port ] */
- uint8_t *userinfo_delim = memchr(authority_parse_csr.ptr, '@', authority_parse_csr.len);
+ const uint8_t *userinfo_delim = memchr(authority_parse_csr.ptr, '@', authority_parse_csr.len);
if (userinfo_delim) {
parser->uri->userinfo =
@@ -351,7 +351,7 @@ static void s_parse_authority(struct uri_parser *parser, struct aws_byte_cursor
/* RFC-3986 section 3.2: host identified by IPv6 literal address is
* enclosed within square brackets. We must ignore any colons within
* IPv6 literals and only search for port delimiter after closing bracket.*/
- uint8_t *port_search_start = authority_parse_csr.ptr;
+ const uint8_t *port_search_start = authority_parse_csr.ptr;
size_t port_search_len = authority_parse_csr.len;
if (authority_parse_csr.len > 0 && authority_parse_csr.ptr[0] == '[') {
port_search_start = memchr(authority_parse_csr.ptr, ']', authority_parse_csr.len);
@@ -363,7 +363,7 @@ static void s_parse_authority(struct uri_parser *parser, struct aws_byte_cursor
port_search_len = authority_parse_csr.len - (port_search_start - authority_parse_csr.ptr);
}
- uint8_t *port_delim = memchr(port_search_start, ':', port_search_len);
+ const uint8_t *port_delim = memchr(port_search_start, ':', port_search_len);
if (!port_delim) {
parser->uri->port = 0;
@@ -407,7 +407,7 @@ static void s_parse_authority(struct uri_parser *parser, struct aws_byte_cursor
static void s_parse_path(struct uri_parser *parser, struct aws_byte_cursor *str) {
parser->uri->path_and_query = *str;
- uint8_t *location_of_q_mark = memchr(str->ptr, '?', str->len);
+ const uint8_t *location_of_q_mark = memchr(str->ptr, '?', str->len);
if (!location_of_q_mark) {
parser->uri->path.ptr = str->ptr;
@@ -540,8 +540,8 @@ static int s_encode_cursor_to_buffer(
struct aws_byte_buf *buffer,
const struct aws_byte_cursor *cursor,
unchecked_append_canonicalized_character_fn *append_canonicalized_character) {
- uint8_t *current_ptr = cursor->ptr;
- uint8_t *end_ptr = cursor->ptr + cursor->len;
+ const uint8_t *current_ptr = cursor->ptr;
+ const uint8_t *end_ptr = cursor->ptr + cursor->len;
/*
* reserve room up front for the worst possible case: everything gets % encoded
diff --git a/contrib/restricted/aws/aws-c-common/source/xml_parser.c b/contrib/restricted/aws/aws-c-common/source/xml_parser.c
index 692324ac9a2..ac238cdfaf3 100644
--- a/contrib/restricted/aws/aws-c-common/source/xml_parser.c
+++ b/contrib/restricted/aws/aws-c-common/source/xml_parser.c
@@ -151,13 +151,13 @@ int aws_xml_parser_parse(
/* burn everything that precedes the actual xml nodes. */
while (parser->doc.len) {
- uint8_t *start = memchr(parser->doc.ptr, '<', parser->doc.len);
+ const uint8_t *start = memchr(parser->doc.ptr, '<', parser->doc.len);
if (!start) {
AWS_LOGF_ERROR(AWS_LS_COMMON_XML_PARSER, "XML document is invalid.");
return aws_raise_error(AWS_ERROR_MALFORMED_INPUT_STRING);
}
- uint8_t *location = memchr(parser->doc.ptr, '>', parser->doc.len);
+ const uint8_t *location = memchr(parser->doc.ptr, '>', parser->doc.len);
if (!location) {
AWS_LOGF_ERROR(AWS_LS_COMMON_XML_PARSER, "XML document is invalid.");
@@ -312,14 +312,14 @@ int aws_xml_node_traverse(
/* look for the next node at the current level. do this until we encounter the parent node's
* closing tag. */
while (!parser->stop_parsing && !parser->error) {
- uint8_t *next_location = memchr(parser->doc.ptr, '<', parser->doc.len);
+ const uint8_t *next_location = memchr(parser->doc.ptr, '<', parser->doc.len);
if (!next_location) {
AWS_LOGF_ERROR(AWS_LS_COMMON_XML_PARSER, "XML document is invalid.");
return aws_raise_error(AWS_ERROR_MALFORMED_INPUT_STRING);
}
- uint8_t *end_location = memchr(parser->doc.ptr, '>', parser->doc.len);
+ const uint8_t *end_location = memchr(parser->doc.ptr, '>', parser->doc.len);
if (!end_location) {
AWS_LOGF_ERROR(AWS_LS_COMMON_XML_PARSER, "XML document is invalid.");
@@ -409,14 +409,14 @@ int aws_xml_node_get_attribute(
int s_node_next_sibling(struct aws_xml_parser *parser) {
AWS_PRECONDITION(parser);
- uint8_t *next_location = memchr(parser->doc.ptr, '<', parser->doc.len);
+ const uint8_t *next_location = memchr(parser->doc.ptr, '<', parser->doc.len);
if (!next_location) {
return parser->error;
}
aws_byte_cursor_advance(&parser->doc, next_location - parser->doc.ptr);
- uint8_t *end_location = memchr(parser->doc.ptr, '>', parser->doc.len);
+ const uint8_t *end_location = memchr(parser->doc.ptr, '>', parser->doc.len);
if (!end_location) {
AWS_LOGF_ERROR(AWS_LS_COMMON_XML_PARSER, "XML document is invalid.");
diff --git a/contrib/restricted/aws/aws-c-common/ya.make b/contrib/restricted/aws/aws-c-common/ya.make
index afc4b7af5b2..85a2c01545d 100644
--- a/contrib/restricted/aws/aws-c-common/ya.make
+++ b/contrib/restricted/aws/aws-c-common/ya.make
@@ -1,4 +1,4 @@
-# Generated by devtools/yamaker from nixpkgs 22.11.
+# Generated by devtools/yamaker from nixpkgs 23.05.
LIBRARY()
@@ -11,9 +11,9 @@ LICENSE(
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
-VERSION(0.8.6)
+VERSION(0.8.15)
-ORIGINAL_SOURCE(https://github.com/awslabs/aws-c-common/archive/v0.8.6.tar.gz)
+ORIGINAL_SOURCE(https://github.com/awslabs/aws-c-common/archive/v0.8.15.tar.gz)
ADDINCL(
GLOBAL contrib/restricted/aws/aws-c-common/generated/include
@@ -26,6 +26,7 @@ NO_RUNTIME()
CFLAGS(
-DAWS_COMMON_USE_IMPORT_EXPORT
+ -DAWS_PTHREAD_GETNAME_TAKES_3ARGS
-DAWS_PTHREAD_SETNAME_TAKES_2ARGS
-DCJSON_HIDE_SYMBOLS
-DHAVE_SYSCONF
@@ -62,7 +63,6 @@ SRCS(
source/allocator_sba.c
source/array_list.c
source/assert.c
- source/bus.c
source/byte_buf.c
source/cache.c
source/codegen.c