aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common/source/posix
diff options
context:
space:
mode:
authorunril <unril@yandex-team.ru>2022-02-10 16:46:05 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:05 +0300
commit11ae9eca250d0188b7962459cbc6706719e7dca9 (patch)
tree4b7d6755091980d33210de19b2eb35a401a761ea /contrib/restricted/aws/aws-c-common/source/posix
parent9c914f41ba5e9f9365f404e892197553ac23809e (diff)
downloadydb-11ae9eca250d0188b7962459cbc6706719e7dca9.tar.gz
Restoring authorship annotation for <unril@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source/posix')
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/clock.c226
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c174
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/device_random.c102
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/environment.c78
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/mutex.c80
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c92
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/system_info.c376
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/thread.c308
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/time.c152
9 files changed, 794 insertions, 794 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/clock.c b/contrib/restricted/aws/aws-c-common/source/posix/clock.c
index 90e213ea7c..a74515f5fe 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/clock.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/clock.c
@@ -1,136 +1,136 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/clock.h>
-
-#include <time.h>
-
-static const uint64_t NS_PER_SEC = 1000000000;
-
-#if defined(CLOCK_MONOTONIC_RAW)
-# define HIGH_RES_CLOCK CLOCK_MONOTONIC_RAW
-#else
-# define HIGH_RES_CLOCK CLOCK_MONOTONIC
-#endif
-
-/* This entire compilation branch has two goals. First, prior to OSX Sierra, clock_gettime does not exist on OSX, so we
- * already need to branch on that. Second, even if we compile on a newer OSX, which we will always do for bindings (e.g.
- * python, dotnet, java etc...), we have to worry about the same lib being loaded on an older version, and thus, we'd
- * get linker errors at runtime. To avoid this, we do a dynamic load
- * to keep the function out of linker tables and only use the symbol if the current running process has access to the
- * function. */
-#if defined(__MACH__)
-# include <AvailabilityMacros.h>
-# include <aws/common/thread.h>
-# include <dlfcn.h>
-# include <sys/time.h>
-
-static int s_legacy_get_time(uint64_t *timestamp) {
- struct timeval tv;
- int ret_val = gettimeofday(&tv, NULL);
-
- if (ret_val) {
- return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
- }
-
+ */
+
+#include <aws/common/clock.h>
+
+#include <time.h>
+
+static const uint64_t NS_PER_SEC = 1000000000;
+
+#if defined(CLOCK_MONOTONIC_RAW)
+# define HIGH_RES_CLOCK CLOCK_MONOTONIC_RAW
+#else
+# define HIGH_RES_CLOCK CLOCK_MONOTONIC
+#endif
+
+/* This entire compilation branch has two goals. First, prior to OSX Sierra, clock_gettime does not exist on OSX, so we
+ * already need to branch on that. Second, even if we compile on a newer OSX, which we will always do for bindings (e.g.
+ * python, dotnet, java etc...), we have to worry about the same lib being loaded on an older version, and thus, we'd
+ * get linker errors at runtime. To avoid this, we do a dynamic load
+ * to keep the function out of linker tables and only use the symbol if the current running process has access to the
+ * function. */
+#if defined(__MACH__)
+# include <AvailabilityMacros.h>
+# include <aws/common/thread.h>
+# include <dlfcn.h>
+# include <sys/time.h>
+
+static int s_legacy_get_time(uint64_t *timestamp) {
+ struct timeval tv;
+ int ret_val = gettimeofday(&tv, NULL);
+
+ if (ret_val) {
+ return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
+ }
+
uint64_t secs = (uint64_t)tv.tv_sec;
uint64_t u_secs = (uint64_t)tv.tv_usec;
*timestamp = (secs * NS_PER_SEC) + (u_secs * 1000);
- return AWS_OP_SUCCESS;
-}
-
-# if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
-static aws_thread_once s_thread_once_flag = AWS_THREAD_ONCE_STATIC_INIT;
-static int (*s_gettime_fn)(clockid_t __clock_id, struct timespec *__tp) = NULL;
-
+ return AWS_OP_SUCCESS;
+}
+
+# if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
+static aws_thread_once s_thread_once_flag = AWS_THREAD_ONCE_STATIC_INIT;
+static int (*s_gettime_fn)(clockid_t __clock_id, struct timespec *__tp) = NULL;
+
static void s_do_osx_loads(void *user_data) {
(void)user_data;
- s_gettime_fn = (int (*)(clockid_t __clock_id, struct timespec * __tp)) dlsym(RTLD_DEFAULT, "clock_gettime");
-}
-
-int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
+ s_gettime_fn = (int (*)(clockid_t __clock_id, struct timespec * __tp)) dlsym(RTLD_DEFAULT, "clock_gettime");
+}
+
+int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL);
- int ret_val = 0;
-
- if (s_gettime_fn) {
- struct timespec ts;
- ret_val = s_gettime_fn(HIGH_RES_CLOCK, &ts);
-
- if (ret_val) {
- return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
- }
-
+ int ret_val = 0;
+
+ if (s_gettime_fn) {
+ struct timespec ts;
+ ret_val = s_gettime_fn(HIGH_RES_CLOCK, &ts);
+
+ if (ret_val) {
+ return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
+ }
+
uint64_t secs = (uint64_t)ts.tv_sec;
uint64_t n_secs = (uint64_t)ts.tv_nsec;
*timestamp = (secs * NS_PER_SEC) + n_secs;
- return AWS_OP_SUCCESS;
- }
-
- return s_legacy_get_time(timestamp);
-}
-
-int aws_sys_clock_get_ticks(uint64_t *timestamp) {
+ return AWS_OP_SUCCESS;
+ }
+
+ return s_legacy_get_time(timestamp);
+}
+
+int aws_sys_clock_get_ticks(uint64_t *timestamp) {
aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL);
- int ret_val = 0;
-
- if (s_gettime_fn) {
- struct timespec ts;
- ret_val = s_gettime_fn(CLOCK_REALTIME, &ts);
- if (ret_val) {
- return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
- }
-
+ int ret_val = 0;
+
+ if (s_gettime_fn) {
+ struct timespec ts;
+ ret_val = s_gettime_fn(CLOCK_REALTIME, &ts);
+ if (ret_val) {
+ return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
+ }
+
uint64_t secs = (uint64_t)ts.tv_sec;
uint64_t n_secs = (uint64_t)ts.tv_nsec;
*timestamp = (secs * NS_PER_SEC) + n_secs;
- return AWS_OP_SUCCESS;
- }
- return s_legacy_get_time(timestamp);
-}
-# else
-int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
- return s_legacy_get_time(timestamp);
-}
-
-int aws_sys_clock_get_ticks(uint64_t *timestamp) {
- return s_legacy_get_time(timestamp);
-}
-
-# endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 */
-/* Everywhere else, just link clock_gettime in directly */
-#else
-int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
- int ret_val = 0;
-
- struct timespec ts;
-
- ret_val = clock_gettime(HIGH_RES_CLOCK, &ts);
-
- if (ret_val) {
- return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
- }
-
+ return AWS_OP_SUCCESS;
+ }
+ return s_legacy_get_time(timestamp);
+}
+# else
+int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
+ return s_legacy_get_time(timestamp);
+}
+
+int aws_sys_clock_get_ticks(uint64_t *timestamp) {
+ return s_legacy_get_time(timestamp);
+}
+
+# endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 */
+/* Everywhere else, just link clock_gettime in directly */
+#else
+int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
+ int ret_val = 0;
+
+ struct timespec ts;
+
+ ret_val = clock_gettime(HIGH_RES_CLOCK, &ts);
+
+ if (ret_val) {
+ return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
+ }
+
uint64_t secs = (uint64_t)ts.tv_sec;
uint64_t n_secs = (uint64_t)ts.tv_nsec;
*timestamp = (secs * NS_PER_SEC) + n_secs;
- return AWS_OP_SUCCESS;
-}
-
-int aws_sys_clock_get_ticks(uint64_t *timestamp) {
- int ret_val = 0;
-
- struct timespec ts;
- ret_val = clock_gettime(CLOCK_REALTIME, &ts);
- if (ret_val) {
- return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
- }
-
+ return AWS_OP_SUCCESS;
+}
+
+int aws_sys_clock_get_ticks(uint64_t *timestamp) {
+ int ret_val = 0;
+
+ struct timespec ts;
+ ret_val = clock_gettime(CLOCK_REALTIME, &ts);
+ if (ret_val) {
+ return aws_raise_error(AWS_ERROR_CLOCK_FAILURE);
+ }
+
uint64_t secs = (uint64_t)ts.tv_sec;
uint64_t n_secs = (uint64_t)ts.tv_nsec;
*timestamp = (secs * NS_PER_SEC) + n_secs;
- return AWS_OP_SUCCESS;
-}
-#endif /* defined(__MACH__) */
+ return AWS_OP_SUCCESS;
+}
+#endif /* defined(__MACH__) */
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c b/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c
index ca321c6bfa..b4914e919b 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c
@@ -1,39 +1,39 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/condition_variable.h>
-
-#include <aws/common/clock.h>
-#include <aws/common/mutex.h>
-
-#include <errno.h>
-
-static int process_error_code(int err) {
- switch (err) {
- case ENOMEM:
- return aws_raise_error(AWS_ERROR_OOM);
- case ETIMEDOUT:
- return aws_raise_error(AWS_ERROR_COND_VARIABLE_TIMED_OUT);
- default:
- return aws_raise_error(AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN);
- }
-}
-
-int aws_condition_variable_init(struct aws_condition_variable *condition_variable) {
+ */
+
+#include <aws/common/condition_variable.h>
+
+#include <aws/common/clock.h>
+#include <aws/common/mutex.h>
+
+#include <errno.h>
+
+static int process_error_code(int err) {
+ switch (err) {
+ case ENOMEM:
+ return aws_raise_error(AWS_ERROR_OOM);
+ case ETIMEDOUT:
+ return aws_raise_error(AWS_ERROR_COND_VARIABLE_TIMED_OUT);
+ default:
+ return aws_raise_error(AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN);
+ }
+}
+
+int aws_condition_variable_init(struct aws_condition_variable *condition_variable) {
AWS_PRECONDITION(condition_variable);
- if (pthread_cond_init(&condition_variable->condition_handle, NULL)) {
+ if (pthread_cond_init(&condition_variable->condition_handle, NULL)) {
AWS_ZERO_STRUCT(*condition_variable);
- return aws_raise_error(AWS_ERROR_COND_VARIABLE_INIT_FAILED);
- }
-
+ return aws_raise_error(AWS_ERROR_COND_VARIABLE_INIT_FAILED);
+ }
+
condition_variable->initialized = true;
- return AWS_OP_SUCCESS;
-}
-
-void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable) {
+ return AWS_OP_SUCCESS;
+}
+
+void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable) {
AWS_PRECONDITION(condition_variable);
if (condition_variable->initialized) {
@@ -41,71 +41,71 @@ void aws_condition_variable_clean_up(struct aws_condition_variable *condition_va
}
AWS_ZERO_STRUCT(*condition_variable);
-}
-
-int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable) {
+}
+
+int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable) {
AWS_PRECONDITION(condition_variable && condition_variable->initialized);
- int err_code = pthread_cond_signal(&condition_variable->condition_handle);
-
- if (err_code) {
- return process_error_code(err_code);
- }
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable) {
+ int err_code = pthread_cond_signal(&condition_variable->condition_handle);
+
+ if (err_code) {
+ return process_error_code(err_code);
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable) {
AWS_PRECONDITION(condition_variable && condition_variable->initialized);
- int err_code = pthread_cond_broadcast(&condition_variable->condition_handle);
-
- if (err_code) {
- return process_error_code(err_code);
- }
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex) {
+ int err_code = pthread_cond_broadcast(&condition_variable->condition_handle);
+
+ if (err_code) {
+ return process_error_code(err_code);
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex) {
AWS_PRECONDITION(condition_variable && condition_variable->initialized);
AWS_PRECONDITION(mutex && mutex->initialized);
- int err_code = pthread_cond_wait(&condition_variable->condition_handle, &mutex->mutex_handle);
-
- if (err_code) {
- return process_error_code(err_code);
- }
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_condition_variable_wait_for(
- struct aws_condition_variable *condition_variable,
- struct aws_mutex *mutex,
- int64_t time_to_wait) {
-
+ int err_code = pthread_cond_wait(&condition_variable->condition_handle, &mutex->mutex_handle);
+
+ if (err_code) {
+ return process_error_code(err_code);
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_condition_variable_wait_for(
+ struct aws_condition_variable *condition_variable,
+ struct aws_mutex *mutex,
+ int64_t time_to_wait) {
+
AWS_PRECONDITION(condition_variable && condition_variable->initialized);
AWS_PRECONDITION(mutex && mutex->initialized);
- uint64_t current_sys_time = 0;
- if (aws_sys_clock_get_ticks(&current_sys_time)) {
- return AWS_OP_ERR;
- }
-
- time_to_wait += current_sys_time;
-
- struct timespec ts;
- uint64_t remainder = 0;
- ts.tv_sec =
- (time_t)aws_timestamp_convert((uint64_t)time_to_wait, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &remainder);
- ts.tv_nsec = (long)remainder;
-
- int err_code = pthread_cond_timedwait(&condition_variable->condition_handle, &mutex->mutex_handle, &ts);
-
- if (err_code) {
- return process_error_code(err_code);
- }
-
- return AWS_OP_SUCCESS;
-}
+ uint64_t current_sys_time = 0;
+ if (aws_sys_clock_get_ticks(&current_sys_time)) {
+ return AWS_OP_ERR;
+ }
+
+ time_to_wait += current_sys_time;
+
+ struct timespec ts;
+ uint64_t remainder = 0;
+ ts.tv_sec =
+ (time_t)aws_timestamp_convert((uint64_t)time_to_wait, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &remainder);
+ ts.tv_nsec = (long)remainder;
+
+ int err_code = pthread_cond_timedwait(&condition_variable->condition_handle, &mutex->mutex_handle, &ts);
+
+ if (err_code) {
+ return process_error_code(err_code);
+ }
+
+ return AWS_OP_SUCCESS;
+}
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/device_random.c b/contrib/restricted/aws/aws-c-common/source/posix/device_random.c
index f446002231..995bb79aaf 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/device_random.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/device_random.c
@@ -1,57 +1,57 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-#include <aws/common/device_random.h>
-
-#include <aws/common/byte_buf.h>
-#include <aws/common/thread.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-
-static int s_rand_fd = -1;
-static aws_thread_once s_rand_init = AWS_THREAD_ONCE_STATIC_INIT;
-
-#ifdef O_CLOEXEC
-# define OPEN_FLAGS (O_RDONLY | O_CLOEXEC)
-#else
-# define OPEN_FLAGS (O_RDONLY)
-#endif
+ */
+#include <aws/common/device_random.h>
+
+#include <aws/common/byte_buf.h>
+#include <aws/common/thread.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+static int s_rand_fd = -1;
+static aws_thread_once s_rand_init = AWS_THREAD_ONCE_STATIC_INIT;
+
+#ifdef O_CLOEXEC
+# define OPEN_FLAGS (O_RDONLY | O_CLOEXEC)
+#else
+# define OPEN_FLAGS (O_RDONLY)
+#endif
static void s_init_rand(void *user_data) {
(void)user_data;
- s_rand_fd = open("/dev/urandom", OPEN_FLAGS);
-
- if (s_rand_fd == -1) {
- s_rand_fd = open("/dev/urandom", O_RDONLY);
-
- if (s_rand_fd == -1) {
- abort();
- }
- }
-
- if (-1 == fcntl(s_rand_fd, F_SETFD, FD_CLOEXEC)) {
- abort();
- }
-}
-
-static int s_fallback_device_random_buffer(struct aws_byte_buf *output) {
-
+ s_rand_fd = open("/dev/urandom", OPEN_FLAGS);
+
+ if (s_rand_fd == -1) {
+ s_rand_fd = open("/dev/urandom", O_RDONLY);
+
+ if (s_rand_fd == -1) {
+ abort();
+ }
+ }
+
+ if (-1 == fcntl(s_rand_fd, F_SETFD, FD_CLOEXEC)) {
+ abort();
+ }
+}
+
+static int s_fallback_device_random_buffer(struct aws_byte_buf *output) {
+
aws_thread_call_once(&s_rand_init, s_init_rand, NULL);
-
- size_t diff = output->capacity - output->len;
-
- ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, diff);
-
- if (amount_read != diff) {
- return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED);
- }
-
- output->len += diff;
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_device_random_buffer(struct aws_byte_buf *output) {
- return s_fallback_device_random_buffer(output);
-}
+
+ size_t diff = output->capacity - output->len;
+
+ ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, diff);
+
+ if (amount_read != diff) {
+ return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED);
+ }
+
+ output->len += diff;
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_device_random_buffer(struct aws_byte_buf *output) {
+ return s_fallback_device_random_buffer(output);
+}
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/environment.c b/contrib/restricted/aws/aws-c-common/source/posix/environment.c
index f4b69caea2..5bc7679d6e 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/environment.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/environment.c
@@ -1,45 +1,45 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/environment.h>
-
-#include <aws/common/string.h>
-#include <stdlib.h>
-
-int aws_get_environment_value(
- struct aws_allocator *allocator,
- const struct aws_string *variable_name,
- struct aws_string **value_out) {
-
+ */
+
+#include <aws/common/environment.h>
+
+#include <aws/common/string.h>
+#include <stdlib.h>
+
+int aws_get_environment_value(
+ struct aws_allocator *allocator,
+ const struct aws_string *variable_name,
+ struct aws_string **value_out) {
+
const char *value = getenv(aws_string_c_str(variable_name));
- if (value == NULL) {
- *value_out = NULL;
- return AWS_OP_SUCCESS;
- }
-
- *value_out = aws_string_new_from_c_str(allocator, value);
- if (*value_out == NULL) {
- return aws_raise_error(AWS_ERROR_ENVIRONMENT_GET);
- }
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value) {
-
+ if (value == NULL) {
+ *value_out = NULL;
+ return AWS_OP_SUCCESS;
+ }
+
+ *value_out = aws_string_new_from_c_str(allocator, value);
+ if (*value_out == NULL) {
+ return aws_raise_error(AWS_ERROR_ENVIRONMENT_GET);
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value) {
+
if (setenv(aws_string_c_str(variable_name), aws_string_c_str(value), 1) != 0) {
- return aws_raise_error(AWS_ERROR_ENVIRONMENT_SET);
- }
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_unset_environment_value(const struct aws_string *variable_name) {
+ return aws_raise_error(AWS_ERROR_ENVIRONMENT_SET);
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_unset_environment_value(const struct aws_string *variable_name) {
if (unsetenv(aws_string_c_str(variable_name)) != 0) {
- return aws_raise_error(AWS_ERROR_ENVIRONMENT_UNSET);
- }
-
- return AWS_OP_SUCCESS;
-}
+ return aws_raise_error(AWS_ERROR_ENVIRONMENT_UNSET);
+ }
+
+ return AWS_OP_SUCCESS;
+}
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/mutex.c b/contrib/restricted/aws/aws-c-common/source/posix/mutex.c
index 2cbf2db66c..adca71d8ff 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/mutex.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/mutex.c
@@ -1,53 +1,53 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/mutex.h>
-#include <aws/common/posix/common.inl>
-
-#include <errno.h>
-
-void aws_mutex_clean_up(struct aws_mutex *mutex) {
+ */
+
+#include <aws/common/mutex.h>
+#include <aws/common/posix/common.inl>
+
+#include <errno.h>
+
+void aws_mutex_clean_up(struct aws_mutex *mutex) {
AWS_PRECONDITION(mutex);
if (mutex->initialized) {
pthread_mutex_destroy(&mutex->mutex_handle);
}
AWS_ZERO_STRUCT(*mutex);
-}
-
-int aws_mutex_init(struct aws_mutex *mutex) {
+}
+
+int aws_mutex_init(struct aws_mutex *mutex) {
AWS_PRECONDITION(mutex);
- pthread_mutexattr_t attr;
- int err_code = pthread_mutexattr_init(&attr);
- int return_code = AWS_OP_SUCCESS;
-
- if (!err_code) {
- if ((err_code = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL)) ||
- (err_code = pthread_mutex_init(&mutex->mutex_handle, &attr))) {
-
- return_code = aws_private_convert_and_raise_error_code(err_code);
- }
- pthread_mutexattr_destroy(&attr);
- } else {
- return_code = aws_private_convert_and_raise_error_code(err_code);
- }
-
+ pthread_mutexattr_t attr;
+ int err_code = pthread_mutexattr_init(&attr);
+ int return_code = AWS_OP_SUCCESS;
+
+ if (!err_code) {
+ if ((err_code = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL)) ||
+ (err_code = pthread_mutex_init(&mutex->mutex_handle, &attr))) {
+
+ return_code = aws_private_convert_and_raise_error_code(err_code);
+ }
+ pthread_mutexattr_destroy(&attr);
+ } else {
+ return_code = aws_private_convert_and_raise_error_code(err_code);
+ }
+
mutex->initialized = (return_code == AWS_OP_SUCCESS);
- return return_code;
-}
-
-int aws_mutex_lock(struct aws_mutex *mutex) {
+ return return_code;
+}
+
+int aws_mutex_lock(struct aws_mutex *mutex) {
AWS_PRECONDITION(mutex && mutex->initialized);
- return aws_private_convert_and_raise_error_code(pthread_mutex_lock(&mutex->mutex_handle));
-}
-
-int aws_mutex_try_lock(struct aws_mutex *mutex) {
+ return aws_private_convert_and_raise_error_code(pthread_mutex_lock(&mutex->mutex_handle));
+}
+
+int aws_mutex_try_lock(struct aws_mutex *mutex) {
AWS_PRECONDITION(mutex && mutex->initialized);
- return aws_private_convert_and_raise_error_code(pthread_mutex_trylock(&mutex->mutex_handle));
-}
-
-int aws_mutex_unlock(struct aws_mutex *mutex) {
+ return aws_private_convert_and_raise_error_code(pthread_mutex_trylock(&mutex->mutex_handle));
+}
+
+int aws_mutex_unlock(struct aws_mutex *mutex) {
AWS_PRECONDITION(mutex && mutex->initialized);
- return aws_private_convert_and_raise_error_code(pthread_mutex_unlock(&mutex->mutex_handle));
-}
+ return aws_private_convert_and_raise_error_code(pthread_mutex_unlock(&mutex->mutex_handle));
+}
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c b/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c
index 824477d6cf..94ebe1fbf2 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c
@@ -1,49 +1,49 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/atomics.h>
-#include <aws/common/rw_lock.h>
-
-#include <aws/common/posix/common.inl>
-
-int aws_rw_lock_init(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_init(&lock->lock_handle, NULL));
-}
-
-void aws_rw_lock_clean_up(struct aws_rw_lock *lock) {
-
- pthread_rwlock_destroy(&lock->lock_handle);
-}
-
-int aws_rw_lock_rlock(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_rdlock(&lock->lock_handle));
-}
-
-int aws_rw_lock_wlock(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_wrlock(&lock->lock_handle));
-}
-
-int aws_rw_lock_try_rlock(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_tryrdlock(&lock->lock_handle));
-}
-
-int aws_rw_lock_try_wlock(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_trywrlock(&lock->lock_handle));
-}
-
-int aws_rw_lock_runlock(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle));
-}
-
-int aws_rw_lock_wunlock(struct aws_rw_lock *lock) {
-
- return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle));
-}
+ */
+
+#include <aws/common/atomics.h>
+#include <aws/common/rw_lock.h>
+
+#include <aws/common/posix/common.inl>
+
+int aws_rw_lock_init(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_init(&lock->lock_handle, NULL));
+}
+
+void aws_rw_lock_clean_up(struct aws_rw_lock *lock) {
+
+ pthread_rwlock_destroy(&lock->lock_handle);
+}
+
+int aws_rw_lock_rlock(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_rdlock(&lock->lock_handle));
+}
+
+int aws_rw_lock_wlock(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_wrlock(&lock->lock_handle));
+}
+
+int aws_rw_lock_try_rlock(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_tryrdlock(&lock->lock_handle));
+}
+
+int aws_rw_lock_try_wlock(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_trywrlock(&lock->lock_handle));
+}
+
+int aws_rw_lock_runlock(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle));
+}
+
+int aws_rw_lock_wunlock(struct aws_rw_lock *lock) {
+
+ return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle));
+}
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/system_info.c b/contrib/restricted/aws/aws-c-common/source/posix/system_info.c
index 1311be4096..5fae2812ad 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/system_info.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/system_info.c
@@ -1,41 +1,41 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/system_info.h>
-
+ */
+
+#include <aws/common/system_info.h>
+
#include <aws/common/byte_buf.h>
#include <aws/common/logging.h>
#include <aws/common/platform.h>
-#if defined(__FreeBSD__) || defined(__NetBSD__)
-# define __BSD_VISIBLE 1
-#endif
-
-#include <unistd.h>
-
-#if defined(HAVE_SYSCONF)
-size_t aws_system_info_processor_count(void) {
- long nprocs = sysconf(_SC_NPROCESSORS_ONLN);
- if (AWS_LIKELY(nprocs >= 0)) {
- return (size_t)nprocs;
- }
-
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+# define __BSD_VISIBLE 1
+#endif
+
+#include <unistd.h>
+
+#if defined(HAVE_SYSCONF)
+size_t aws_system_info_processor_count(void) {
+ long nprocs = sysconf(_SC_NPROCESSORS_ONLN);
+ if (AWS_LIKELY(nprocs >= 0)) {
+ return (size_t)nprocs;
+ }
+
AWS_FATAL_POSTCONDITION(nprocs >= 0);
- return 0;
-}
-#else
-size_t aws_system_info_processor_count(void) {
-# if defined(AWS_NUM_CPU_CORES)
+ return 0;
+}
+#else
+size_t aws_system_info_processor_count(void) {
+# if defined(AWS_NUM_CPU_CORES)
AWS_FATAL_PRECONDITION(AWS_NUM_CPU_CORES > 0);
- return AWS_NUM_CPU_CORES;
-# else
- return 1;
-# endif
-}
-#endif
-
+ return AWS_NUM_CPU_CORES;
+# else
+ return 1;
+# endif
+}
+#endif
+
#include <ctype.h>
#include <fcntl.h>
@@ -72,37 +72,37 @@ bool aws_is_debugger_present(void) {
return false;
}
-#include <signal.h>
-
-#ifndef __has_builtin
-# define __has_builtin(x) 0
-#endif
-
-void aws_debug_break(void) {
-#ifdef DEBUG_BUILD
+#include <signal.h>
+
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
+
+void aws_debug_break(void) {
+#ifdef DEBUG_BUILD
if (aws_is_debugger_present()) {
-# if __has_builtin(__builtin_debugtrap)
+# if __has_builtin(__builtin_debugtrap)
__builtin_debugtrap();
-# else
+# else
raise(SIGTRAP);
-# endif
+# endif
}
-#endif /* DEBUG_BUILD */
-}
-
-#if defined(AWS_HAVE_EXECINFO)
-# include <execinfo.h>
-# include <limits.h>
-
-# define AWS_BACKTRACE_DEPTH 128
-
-struct aws_stack_frame_info {
- char exe[PATH_MAX];
- char addr[32];
- char base[32]; /* base addr for dylib/exe */
- char function[128];
-};
-
+#endif /* DEBUG_BUILD */
+}
+
+#if defined(AWS_HAVE_EXECINFO)
+# include <execinfo.h>
+# include <limits.h>
+
+# define AWS_BACKTRACE_DEPTH 128
+
+struct aws_stack_frame_info {
+ char exe[PATH_MAX];
+ char addr[32];
+ char base[32]; /* base addr for dylib/exe */
+ char function[128];
+};
+
/* Ensure only safe characters in a path buffer in case someone tries to
rename the exe and trigger shell execution via the sub commands used to
resolve symbols */
@@ -119,95 +119,95 @@ char *s_whitelist_chars(char *path) {
return path;
}
-# if defined(__APPLE__)
-# include <ctype.h>
-# include <dlfcn.h>
-# include <mach-o/dyld.h>
-static char s_exe_path[PATH_MAX];
-const char *s_get_executable_path() {
- static const char *s_exe = NULL;
- if (AWS_LIKELY(s_exe)) {
- return s_exe;
- }
- uint32_t len = sizeof(s_exe_path);
- if (!_NSGetExecutablePath(s_exe_path, &len)) {
- s_exe = s_exe_path;
- }
- return s_exe;
-}
-int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) {
- /* symbols look like: <frame_idx> <exe-or-shared-lib> <addr> <function> + <offset>
- */
- const char *current_exe = s_get_executable_path();
- /* parse exe/shared lib */
- const char *exe_start = strstr(symbol, " ");
+# if defined(__APPLE__)
+# include <ctype.h>
+# include <dlfcn.h>
+# include <mach-o/dyld.h>
+static char s_exe_path[PATH_MAX];
+const char *s_get_executable_path() {
+ static const char *s_exe = NULL;
+ if (AWS_LIKELY(s_exe)) {
+ return s_exe;
+ }
+ uint32_t len = sizeof(s_exe_path);
+ if (!_NSGetExecutablePath(s_exe_path, &len)) {
+ s_exe = s_exe_path;
+ }
+ return s_exe;
+}
+int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) {
+ /* symbols look like: <frame_idx> <exe-or-shared-lib> <addr> <function> + <offset>
+ */
+ const char *current_exe = s_get_executable_path();
+ /* parse exe/shared lib */
+ const char *exe_start = strstr(symbol, " ");
while (aws_isspace(*exe_start)) {
- ++exe_start;
- }
- const char *exe_end = strstr(exe_start, " ");
- strncpy(frame->exe, exe_start, exe_end - exe_start);
- /* executables get basename'd, so restore the path */
- if (strstr(current_exe, frame->exe)) {
- strncpy(frame->exe, current_exe, strlen(current_exe));
+ ++exe_start;
}
+ const char *exe_end = strstr(exe_start, " ");
+ strncpy(frame->exe, exe_start, exe_end - exe_start);
+ /* executables get basename'd, so restore the path */
+ if (strstr(current_exe, frame->exe)) {
+ strncpy(frame->exe, current_exe, strlen(current_exe));
+ }
s_whitelist_chars(frame->exe);
-
- /* parse addr */
- const char *addr_start = strstr(exe_end, "0x");
- const char *addr_end = strstr(addr_start, " ");
- strncpy(frame->addr, addr_start, addr_end - addr_start);
-
- /* parse function */
- const char *function_start = strstr(addr_end, " ") + 1;
- const char *function_end = strstr(function_start, " ");
+
+ /* parse addr */
+ const char *addr_start = strstr(exe_end, "0x");
+ const char *addr_end = strstr(addr_start, " ");
+ strncpy(frame->addr, addr_start, addr_end - addr_start);
+
+ /* parse function */
+ const char *function_start = strstr(addr_end, " ") + 1;
+ const char *function_end = strstr(function_start, " ");
/* truncate function name if needed */
size_t function_len = function_end - function_start;
if (function_len >= (sizeof(frame->function) - 1)) {
function_len = sizeof(frame->function) - 1;
}
- strncpy(frame->function, function_start, function_end - function_start);
-
- /* find base addr for library/exe */
- Dl_info addr_info;
- dladdr(addr, &addr_info);
- snprintf(frame->base, sizeof(frame->base), "0x%p", addr_info.dli_fbase);
-
- return AWS_OP_SUCCESS;
-}
-
-void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
- snprintf(cmd, len, "atos -o %s -l %s %s", frame->exe, frame->base, frame->addr);
-}
-# else
-int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) {
+ strncpy(frame->function, function_start, function_end - function_start);
+
+ /* find base addr for library/exe */
+ Dl_info addr_info;
+ dladdr(addr, &addr_info);
+ snprintf(frame->base, sizeof(frame->base), "0x%p", addr_info.dli_fbase);
+
+ return AWS_OP_SUCCESS;
+}
+
+void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
+ snprintf(cmd, len, "atos -o %s -l %s %s", frame->exe, frame->base, frame->addr);
+}
+# else
+int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) {
/* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
- * or: <exe-or-shared-lib> [0x<addr>]
+ * or: <exe-or-shared-lib> [0x<addr>]
* or: [0x<addr>]
- */
- (void)addr;
- const char *open_paren = strstr(symbol, "(");
- const char *close_paren = strstr(symbol, ")");
- const char *exe_end = open_paren;
- /* there may not be a function in parens, or parens at all */
- if (open_paren == NULL || close_paren == NULL) {
+ */
+ (void)addr;
+ const char *open_paren = strstr(symbol, "(");
+ const char *close_paren = strstr(symbol, ")");
+ const char *exe_end = open_paren;
+ /* there may not be a function in parens, or parens at all */
+ if (open_paren == NULL || close_paren == NULL) {
exe_end = strstr(symbol, "[");
- if (!exe_end) {
- return AWS_OP_ERR;
- }
+ if (!exe_end) {
+ return AWS_OP_ERR;
+ }
/* if exe_end == symbol, there's no exe */
if (exe_end != symbol) {
exe_end -= 1;
}
- }
-
- ptrdiff_t exe_len = exe_end - symbol;
+ }
+
+ ptrdiff_t exe_len = exe_end - symbol;
if (exe_len > 0) {
strncpy(frame->exe, symbol, exe_len);
- }
+ }
s_whitelist_chars(frame->exe);
-
- long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0;
- if (function_len > 0) { /* dynamic symbol was found */
+
+ long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0;
+ if (function_len > 0) { /* dynamic symbol was found */
/* there might be (<function>+<addr>) or just (<function>) */
const char *function_start = open_paren + 1;
const char *plus = strstr(function_start, "+");
@@ -219,7 +219,7 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *
long addr_len = close_paren - plus - 1;
strncpy(frame->addr, plus + 1, addr_len);
}
- }
+ }
if (frame->addr[0] == 0) {
/* use the address in []'s, since it's all we have */
const char *addr_start = strstr(exe_end, "[") + 1;
@@ -229,14 +229,14 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *
}
strncpy(frame->addr, addr_start, addr_end - addr_start);
}
-
- return AWS_OP_SUCCESS;
-}
-void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
- snprintf(cmd, len, "addr2line -afips -e %s %s", frame->exe, frame->addr);
-}
-# endif
-
+
+ return AWS_OP_SUCCESS;
+}
+void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
+ snprintf(cmd, len, "addr2line -afips -e %s %s", frame->exe, frame->addr);
+}
+# endif
+
size_t aws_backtrace(void **stack_frames, size_t num_frames) {
return backtrace(stack_frames, (int)aws_min_size(num_frames, INT_MAX));
}
@@ -294,58 +294,58 @@ char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) {
return (char **)lines.buffer; /* caller is responsible for freeing */
}
-void aws_backtrace_print(FILE *fp, void *call_site_data) {
- siginfo_t *siginfo = call_site_data;
- if (siginfo) {
- fprintf(fp, "Signal received: %d, errno: %d\n", siginfo->si_signo, siginfo->si_errno);
- if (siginfo->si_signo == SIGSEGV) {
- fprintf(fp, " SIGSEGV @ 0x%p\n", siginfo->si_addr);
- }
- }
-
- void *stack_frames[AWS_BACKTRACE_DEPTH];
+void aws_backtrace_print(FILE *fp, void *call_site_data) {
+ siginfo_t *siginfo = call_site_data;
+ if (siginfo) {
+ fprintf(fp, "Signal received: %d, errno: %d\n", siginfo->si_signo, siginfo->si_errno);
+ if (siginfo->si_signo == SIGSEGV) {
+ fprintf(fp, " SIGSEGV @ 0x%p\n", siginfo->si_addr);
+ }
+ }
+
+ void *stack_frames[AWS_BACKTRACE_DEPTH];
size_t stack_depth = aws_backtrace(stack_frames, AWS_BACKTRACE_DEPTH);
char **symbols = aws_backtrace_symbols(stack_frames, stack_depth);
- if (symbols == NULL) {
- fprintf(fp, "Unable to decode backtrace via backtrace_symbols\n");
- return;
- }
-
+ if (symbols == NULL) {
+ fprintf(fp, "Unable to decode backtrace via backtrace_symbols\n");
+ return;
+ }
+
fprintf(fp, "################################################################################\n");
fprintf(fp, "Resolved stacktrace:\n");
fprintf(fp, "################################################################################\n");
/* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
- * or: <exe-or-shared-lib> [0x<addr>]
+ * or: <exe-or-shared-lib> [0x<addr>]
* or: [0x<addr>]
- * start at 1 to skip the current frame (this function) */
+ * start at 1 to skip the current frame (this function) */
for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) {
- struct aws_stack_frame_info frame;
- AWS_ZERO_STRUCT(frame);
- const char *symbol = symbols[frame_idx];
- if (s_parse_symbol(symbol, stack_frames[frame_idx], &frame)) {
- goto parse_failed;
- }
-
- /* TODO: Emulate libunwind */
- char cmd[sizeof(struct aws_stack_frame_info)] = {0};
- s_resolve_cmd(cmd, sizeof(cmd), &frame);
- FILE *out = popen(cmd, "r");
- if (!out) {
- goto parse_failed;
- }
- char output[1024];
- if (fgets(output, sizeof(output), out)) {
- /* if addr2line or atos don't know what to do with an address, they just echo it */
- /* if there are spaces in the output, then they resolved something */
- if (strstr(output, " ")) {
- symbol = output;
- }
- }
- pclose(out);
-
- parse_failed:
- fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : "");
- }
+ struct aws_stack_frame_info frame;
+ AWS_ZERO_STRUCT(frame);
+ const char *symbol = symbols[frame_idx];
+ if (s_parse_symbol(symbol, stack_frames[frame_idx], &frame)) {
+ goto parse_failed;
+ }
+
+ /* TODO: Emulate libunwind */
+ char cmd[sizeof(struct aws_stack_frame_info)] = {0};
+ s_resolve_cmd(cmd, sizeof(cmd), &frame);
+ FILE *out = popen(cmd, "r");
+ if (!out) {
+ goto parse_failed;
+ }
+ char output[1024];
+ if (fgets(output, sizeof(output), out)) {
+ /* if addr2line or atos don't know what to do with an address, they just echo it */
+ /* if there are spaces in the output, then they resolved something */
+ if (strstr(output, " ")) {
+ symbol = output;
+ }
+ }
+ pclose(out);
+
+ parse_failed:
+ fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : "");
+ }
fprintf(fp, "################################################################################\n");
fprintf(fp, "Raw stacktrace:\n");
@@ -356,14 +356,14 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) {
}
fflush(fp);
- free(symbols);
-}
-
-#else
-void aws_backtrace_print(FILE *fp, void *call_site_data) {
+ free(symbols);
+}
+
+#else
+void aws_backtrace_print(FILE *fp, void *call_site_data) {
(void)call_site_data;
- fprintf(fp, "No call stack information available\n");
-}
+ fprintf(fp, "No call stack information available\n");
+}
size_t aws_backtrace(void **stack_frames, size_t size) {
(void)stack_frames;
@@ -382,7 +382,7 @@ char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) {
(void)stack_depth;
return NULL;
}
-#endif /* AWS_HAVE_EXECINFO */
+#endif /* AWS_HAVE_EXECINFO */
void aws_backtrace_log() {
void *stack_frames[1024];
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 064d16882f..1ae2660f1a 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/thread.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/thread.c
@@ -1,57 +1,57 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-
+ */
+
#if !defined(__MACH__)
# define _GNU_SOURCE
#endif
-
-#include <aws/common/clock.h>
+
+#include <aws/common/clock.h>
#include <aws/common/logging.h>
#include <aws/common/private/dlloads.h>
#include <aws/common/thread.h>
-
+
#include <dlfcn.h>
-#include <errno.h>
+#include <errno.h>
#include <inttypes.h>
-#include <limits.h>
+#include <limits.h>
#include <sched.h>
-#include <time.h>
+#include <time.h>
#include <unistd.h>
-
+
#if defined(__FreeBSD__) || defined(__NETBSD__)
# include <pthread_np.h>
typedef cpuset_t cpu_set_t;
#endif
-static struct aws_thread_options s_default_options = {
- /* this will make sure platform default stack size is used. */
+static struct aws_thread_options s_default_options = {
+ /* this will make sure platform default stack size is used. */
.stack_size = 0,
.cpu_id = -1,
};
-
+
struct thread_atexit_callback {
aws_thread_atexit_fn *callback;
void *user_data;
struct thread_atexit_callback *next;
};
-struct thread_wrapper {
- struct aws_allocator *allocator;
- void (*func)(void *arg);
- void *arg;
+struct thread_wrapper {
+ struct aws_allocator *allocator;
+ void (*func)(void *arg);
+ void *arg;
struct thread_atexit_callback *atexit;
void (*call_once)(void *);
void *once_arg;
struct aws_thread *thread;
bool membind;
-};
-
+};
+
static AWS_THREAD_LOCAL struct thread_wrapper *tl_wrapper = NULL;
-static void *thread_fn(void *arg) {
- struct thread_wrapper wrapper = *(struct thread_wrapper *)arg;
+static void *thread_fn(void *arg) {
+ struct thread_wrapper wrapper = *(struct thread_wrapper *)arg;
struct aws_allocator *allocator = wrapper.allocator;
tl_wrapper = &wrapper;
if (wrapper.membind && g_set_mempolicy_ptr) {
@@ -73,7 +73,7 @@ static void *thread_fn(void *arg) {
}
}
wrapper.func(wrapper.arg);
-
+
struct thread_atexit_callback *exit_callback_data = wrapper.atexit;
aws_mem_release(allocator, arg);
@@ -89,23 +89,23 @@ static void *thread_fn(void *arg) {
}
tl_wrapper = NULL;
- return NULL;
-}
-
-const struct aws_thread_options *aws_default_thread_options(void) {
- return &s_default_options;
-}
-
-void aws_thread_clean_up(struct aws_thread *thread) {
- if (thread->detach_state == AWS_THREAD_JOINABLE) {
- pthread_detach(thread->thread_id);
- }
-}
-
+ return NULL;
+}
+
+const struct aws_thread_options *aws_default_thread_options(void) {
+ return &s_default_options;
+}
+
+void aws_thread_clean_up(struct aws_thread *thread) {
+ if (thread->detach_state == AWS_THREAD_JOINABLE) {
+ pthread_detach(thread->thread_id);
+ }
+}
+
static void s_call_once(void) {
tl_wrapper->call_once(tl_wrapper->once_arg);
-}
-
+}
+
void aws_thread_call_once(aws_thread_once *flag, void (*call_once)(void *), void *user_data) {
// If this is a non-aws_thread, then gin up a temp thread wrapper
struct thread_wrapper temp_wrapper;
@@ -122,39 +122,39 @@ void aws_thread_call_once(aws_thread_once *flag, void (*call_once)(void *), void
}
}
-int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator) {
+int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator) {
*thread = (struct aws_thread){.allocator = allocator, .detach_state = AWS_THREAD_NOT_CREATED};
-
- return AWS_OP_SUCCESS;
-}
-
-int aws_thread_launch(
- struct aws_thread *thread,
- void (*func)(void *arg),
- void *arg,
- const struct aws_thread_options *options) {
-
- pthread_attr_t attributes;
- pthread_attr_t *attributes_ptr = NULL;
- int attr_return = 0;
- int allocation_failed = 0;
-
- if (options) {
- attr_return = pthread_attr_init(&attributes);
-
- if (attr_return) {
- goto cleanup;
- }
-
- attributes_ptr = &attributes;
-
- if (options->stack_size > PTHREAD_STACK_MIN) {
- attr_return = pthread_attr_setstacksize(attributes_ptr, options->stack_size);
-
- if (attr_return) {
- goto cleanup;
- }
- }
+
+ return AWS_OP_SUCCESS;
+}
+
+int aws_thread_launch(
+ struct aws_thread *thread,
+ void (*func)(void *arg),
+ void *arg,
+ const struct aws_thread_options *options) {
+
+ pthread_attr_t attributes;
+ pthread_attr_t *attributes_ptr = NULL;
+ int attr_return = 0;
+ int allocation_failed = 0;
+
+ if (options) {
+ attr_return = pthread_attr_init(&attributes);
+
+ if (attr_return) {
+ goto cleanup;
+ }
+
+ attributes_ptr = &attributes;
+
+ if (options->stack_size > PTHREAD_STACK_MIN) {
+ attr_return = pthread_attr_setstacksize(attributes_ptr, options->stack_size);
+
+ if (attr_return) {
+ goto cleanup;
+ }
+ }
/* 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.
@@ -184,106 +184,106 @@ int aws_thread_launch(
}
}
#endif /* !defined(__MACH__) && !defined(__ANDROID__) */
- }
-
- struct thread_wrapper *wrapper =
+ }
+
+ struct thread_wrapper *wrapper =
(struct thread_wrapper *)aws_mem_calloc(thread->allocator, 1, sizeof(struct thread_wrapper));
-
- if (!wrapper) {
- allocation_failed = 1;
- goto cleanup;
- }
-
+
+ if (!wrapper) {
+ allocation_failed = 1;
+ goto cleanup;
+ }
+
if (options && options->cpu_id >= 0) {
wrapper->membind = true;
}
wrapper->thread = thread;
- wrapper->allocator = thread->allocator;
- wrapper->func = func;
- wrapper->arg = arg;
- attr_return = pthread_create(&thread->thread_id, attributes_ptr, thread_fn, (void *)wrapper);
-
- if (attr_return) {
- goto cleanup;
- }
-
- thread->detach_state = AWS_THREAD_JOINABLE;
-
-cleanup:
- if (attributes_ptr) {
- pthread_attr_destroy(attributes_ptr);
- }
-
- if (attr_return == EINVAL) {
- return aws_raise_error(AWS_ERROR_THREAD_INVALID_SETTINGS);
- }
-
- if (attr_return == EAGAIN) {
- return aws_raise_error(AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE);
- }
-
- if (attr_return == EPERM) {
- return aws_raise_error(AWS_ERROR_THREAD_NO_PERMISSIONS);
- }
-
- if (allocation_failed || attr_return == ENOMEM) {
- return aws_raise_error(AWS_ERROR_OOM);
- }
-
- return AWS_OP_SUCCESS;
-}
-
+ wrapper->allocator = thread->allocator;
+ wrapper->func = func;
+ wrapper->arg = arg;
+ attr_return = pthread_create(&thread->thread_id, attributes_ptr, thread_fn, (void *)wrapper);
+
+ if (attr_return) {
+ goto cleanup;
+ }
+
+ thread->detach_state = AWS_THREAD_JOINABLE;
+
+cleanup:
+ if (attributes_ptr) {
+ pthread_attr_destroy(attributes_ptr);
+ }
+
+ if (attr_return == EINVAL) {
+ return aws_raise_error(AWS_ERROR_THREAD_INVALID_SETTINGS);
+ }
+
+ if (attr_return == EAGAIN) {
+ return aws_raise_error(AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE);
+ }
+
+ if (attr_return == EPERM) {
+ return aws_raise_error(AWS_ERROR_THREAD_NO_PERMISSIONS);
+ }
+
+ if (allocation_failed || attr_return == ENOMEM) {
+ return aws_raise_error(AWS_ERROR_OOM);
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
aws_thread_id_t aws_thread_get_id(struct aws_thread *thread) {
return thread->thread_id;
-}
-
-enum aws_thread_detach_state aws_thread_get_detach_state(struct aws_thread *thread) {
- return thread->detach_state;
-}
-
-int aws_thread_join(struct aws_thread *thread) {
- if (thread->detach_state == AWS_THREAD_JOINABLE) {
- int err_no = pthread_join(thread->thread_id, 0);
-
- if (err_no) {
- if (err_no == EINVAL) {
- return aws_raise_error(AWS_ERROR_THREAD_NOT_JOINABLE);
- }
- if (err_no == ESRCH) {
- return aws_raise_error(AWS_ERROR_THREAD_NO_SUCH_THREAD_ID);
- }
- if (err_no == EDEADLK) {
- return aws_raise_error(AWS_ERROR_THREAD_DEADLOCK_DETECTED);
- }
- }
-
- thread->detach_state = AWS_THREAD_JOIN_COMPLETED;
- }
-
- return AWS_OP_SUCCESS;
-}
-
+}
+
+enum aws_thread_detach_state aws_thread_get_detach_state(struct aws_thread *thread) {
+ return thread->detach_state;
+}
+
+int aws_thread_join(struct aws_thread *thread) {
+ if (thread->detach_state == AWS_THREAD_JOINABLE) {
+ int err_no = pthread_join(thread->thread_id, 0);
+
+ if (err_no) {
+ if (err_no == EINVAL) {
+ return aws_raise_error(AWS_ERROR_THREAD_NOT_JOINABLE);
+ }
+ if (err_no == ESRCH) {
+ return aws_raise_error(AWS_ERROR_THREAD_NO_SUCH_THREAD_ID);
+ }
+ if (err_no == EDEADLK) {
+ return aws_raise_error(AWS_ERROR_THREAD_DEADLOCK_DETECTED);
+ }
+ }
+
+ thread->detach_state = AWS_THREAD_JOIN_COMPLETED;
+ }
+
+ return AWS_OP_SUCCESS;
+}
+
aws_thread_id_t aws_thread_current_thread_id(void) {
return pthread_self();
-}
-
+}
+
bool aws_thread_thread_id_equal(aws_thread_id_t t1, aws_thread_id_t t2) {
return pthread_equal(t1, t2) != 0;
}
-void aws_thread_current_sleep(uint64_t nanos) {
- uint64_t nano = 0;
- time_t seconds = (time_t)aws_timestamp_convert(nanos, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &nano);
-
- struct timespec tm = {
- .tv_sec = seconds,
- .tv_nsec = (long)nano,
- };
- struct timespec output;
-
- nanosleep(&tm, &output);
-}
+void aws_thread_current_sleep(uint64_t nanos) {
+ uint64_t nano = 0;
+ time_t seconds = (time_t)aws_timestamp_convert(nanos, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &nano);
+
+ struct timespec tm = {
+ .tv_sec = seconds,
+ .tv_nsec = (long)nano,
+ };
+ struct timespec output;
+
+ nanosleep(&tm, &output);
+}
int aws_thread_current_at_exit(aws_thread_atexit_fn *callback, void *user_data) {
if (!tl_wrapper) {
diff --git a/contrib/restricted/aws/aws-c-common/source/posix/time.c b/contrib/restricted/aws/aws-c-common/source/posix/time.c
index dd49d6b0b6..73d35945c9 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/time.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/time.c
@@ -1,79 +1,79 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
- */
-#include <aws/common/time.h>
-
-#if defined(__ANDROID__) && !defined(__LP64__)
-/*
- * This branch brought to you by the kind folks at google chromium. It's been modified a bit, but
- * gotta give credit where it's due.... I'm not a lawyer so I'm just gonna drop their copyright
- * notification here to avoid all of that.
- */
-
-/*
- * Copyright 2014 The Chromium Authors. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- * From src/base/os_compat_android.cc:
- */
-# include <time64.h>
-
-static const time_t s_time_max = ~(1L << ((sizeof(time_t) * __CHAR_BIT__ - 1)));
-static const time_t s_time_min = (1L << ((sizeof(time_t)) * __CHAR_BIT__ - 1));
-
-/* 32-bit Android has only timegm64() and not timegm(). */
-time_t aws_timegm(struct tm *const t) {
-
- time64_t result = timegm64(t);
- if (result < s_time_min || result > s_time_max) {
- return -1;
- }
- return (time_t)result;
-}
-
-#else
-
-# ifndef __APPLE__
-/* glibc.... you disappoint me.. */
-extern time_t timegm(struct tm *);
-# endif
-
-time_t aws_timegm(struct tm *const t) {
- return timegm(t);
-}
-
-#endif /* defined(__ANDROID__) && !defined(__LP64__) */
-
-void aws_localtime(time_t time, struct tm *t) {
- localtime_r(&time, t);
-}
-
-void aws_gmtime(time_t time, struct tm *t) {
- gmtime_r(&time, t);
-}
+ */
+#include <aws/common/time.h>
+
+#if defined(__ANDROID__) && !defined(__LP64__)
+/*
+ * This branch brought to you by the kind folks at google chromium. It's been modified a bit, but
+ * gotta give credit where it's due.... I'm not a lawyer so I'm just gonna drop their copyright
+ * notification here to avoid all of that.
+ */
+
+/*
+ * Copyright 2014 The Chromium Authors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ * From src/base/os_compat_android.cc:
+ */
+# include <time64.h>
+
+static const time_t s_time_max = ~(1L << ((sizeof(time_t) * __CHAR_BIT__ - 1)));
+static const time_t s_time_min = (1L << ((sizeof(time_t)) * __CHAR_BIT__ - 1));
+
+/* 32-bit Android has only timegm64() and not timegm(). */
+time_t aws_timegm(struct tm *const t) {
+
+ time64_t result = timegm64(t);
+ if (result < s_time_min || result > s_time_max) {
+ return -1;
+ }
+ return (time_t)result;
+}
+
+#else
+
+# ifndef __APPLE__
+/* glibc.... you disappoint me.. */
+extern time_t timegm(struct tm *);
+# endif
+
+time_t aws_timegm(struct tm *const t) {
+ return timegm(t);
+}
+
+#endif /* defined(__ANDROID__) && !defined(__LP64__) */
+
+void aws_localtime(time_t time, struct tm *t) {
+ localtime_r(&time, t);
+}
+
+void aws_gmtime(time_t time, struct tm *t) {
+ gmtime_r(&time, t);
+}