aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common/source/posix
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/restricted/aws/aws-c-common/source/posix
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
downloadydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz
Restoring authorship annotation for <orivej@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.c46
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c48
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/device_random.c12
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/environment.c12
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/mutex.c26
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/process.c106
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c6
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/system_info.c442
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/thread.c300
-rw-r--r--contrib/restricted/aws/aws-c-common/source/posix/time.c6
10 files changed, 502 insertions, 502 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..2e2b43f266 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/clock.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/clock.c
@@ -1,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/clock.h>
@@ -35,9 +35,9 @@ static int s_legacy_get_time(uint64_t *timestamp) {
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);
+ 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;
}
@@ -45,13 +45,13 @@ static int s_legacy_get_time(uint64_t *timestamp) {
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;
+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) {
- aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL);
+ aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL);
int ret_val = 0;
if (s_gettime_fn) {
@@ -62,9 +62,9 @@ int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
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;
+ 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;
}
@@ -72,7 +72,7 @@ int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
}
int aws_sys_clock_get_ticks(uint64_t *timestamp) {
- aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL);
+ aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL);
int ret_val = 0;
if (s_gettime_fn) {
@@ -82,9 +82,9 @@ int aws_sys_clock_get_ticks(uint64_t *timestamp) {
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;
+ 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);
@@ -112,9 +112,9 @@ int aws_high_res_clock_get_ticks(uint64_t *timestamp) {
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;
+ 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;
}
@@ -127,10 +127,10 @@ int aws_sys_clock_get_ticks(uint64_t *timestamp) {
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;
-
+ 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__) */
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..b45fc7382d 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,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/condition_variable.h>
@@ -22,30 +22,30 @@ static int process_error_code(int err) {
}
int aws_condition_variable_init(struct aws_condition_variable *condition_variable) {
- AWS_PRECONDITION(condition_variable);
-
+ AWS_PRECONDITION(condition_variable);
+
if (pthread_cond_init(&condition_variable->condition_handle, NULL)) {
- AWS_ZERO_STRUCT(*condition_variable);
+ AWS_ZERO_STRUCT(*condition_variable);
return aws_raise_error(AWS_ERROR_COND_VARIABLE_INIT_FAILED);
}
- condition_variable->initialized = true;
+ condition_variable->initialized = true;
return AWS_OP_SUCCESS;
}
void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable) {
- AWS_PRECONDITION(condition_variable);
-
- if (condition_variable->initialized) {
- pthread_cond_destroy(&condition_variable->condition_handle);
- }
-
- AWS_ZERO_STRUCT(*condition_variable);
+ AWS_PRECONDITION(condition_variable);
+
+ if (condition_variable->initialized) {
+ pthread_cond_destroy(&condition_variable->condition_handle);
+ }
+
+ AWS_ZERO_STRUCT(*condition_variable);
}
int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable) {
- AWS_PRECONDITION(condition_variable && condition_variable->initialized);
-
+ AWS_PRECONDITION(condition_variable && condition_variable->initialized);
+
int err_code = pthread_cond_signal(&condition_variable->condition_handle);
if (err_code) {
@@ -56,8 +56,8 @@ int aws_condition_variable_notify_one(struct aws_condition_variable *condition_v
}
int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable) {
- AWS_PRECONDITION(condition_variable && condition_variable->initialized);
-
+ AWS_PRECONDITION(condition_variable && condition_variable->initialized);
+
int err_code = pthread_cond_broadcast(&condition_variable->condition_handle);
if (err_code) {
@@ -68,9 +68,9 @@ int aws_condition_variable_notify_all(struct aws_condition_variable *condition_v
}
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);
-
+ 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) {
@@ -85,9 +85,9 @@ int aws_condition_variable_wait_for(
struct aws_mutex *mutex,
int64_t time_to_wait) {
- AWS_PRECONDITION(condition_variable && condition_variable->initialized);
- AWS_PRECONDITION(mutex && mutex->initialized);
-
+ 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;
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..e60edc7e20 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,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/device_random.h>
@@ -18,8 +18,8 @@ static aws_thread_once s_rand_init = AWS_THREAD_ONCE_STATIC_INIT;
#else
# define OPEN_FLAGS (O_RDONLY)
#endif
-static void s_init_rand(void *user_data) {
- (void)user_data;
+static void s_init_rand(void *user_data) {
+ (void)user_data;
s_rand_fd = open("/dev/urandom", OPEN_FLAGS);
if (s_rand_fd == -1) {
@@ -37,7 +37,7 @@ static void s_init_rand(void *user_data) {
static int s_fallback_device_random_buffer(struct aws_byte_buf *output) {
- aws_thread_call_once(&s_rand_init, s_init_rand, NULL);
+ aws_thread_call_once(&s_rand_init, s_init_rand, NULL);
size_t diff = output->capacity - output->len;
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..2fd670eaf6 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/environment.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/environment.c
@@ -1,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/environment.h>
@@ -13,7 +13,7 @@ int aws_get_environment_value(
const struct aws_string *variable_name,
struct aws_string **value_out) {
- const char *value = getenv(aws_string_c_str(variable_name));
+ const char *value = getenv(aws_string_c_str(variable_name));
if (value == NULL) {
*value_out = NULL;
return AWS_OP_SUCCESS;
@@ -29,7 +29,7 @@ int aws_get_environment_value(
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) {
+ if (setenv(aws_string_c_str(variable_name), aws_string_c_str(value), 1) != 0) {
return aws_raise_error(AWS_ERROR_ENVIRONMENT_SET);
}
@@ -37,7 +37,7 @@ int aws_set_environment_value(const struct aws_string *variable_name, const stru
}
int aws_unset_environment_value(const struct aws_string *variable_name) {
- if (unsetenv(aws_string_c_str(variable_name)) != 0) {
+ if (unsetenv(aws_string_c_str(variable_name)) != 0) {
return aws_raise_error(AWS_ERROR_ENVIRONMENT_UNSET);
}
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..bc3a94af28 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/mutex.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/mutex.c
@@ -1,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/mutex.h>
@@ -9,15 +9,15 @@
#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);
+ AWS_PRECONDITION(mutex);
+ if (mutex->initialized) {
+ pthread_mutex_destroy(&mutex->mutex_handle);
+ }
+ AWS_ZERO_STRUCT(*mutex);
}
int aws_mutex_init(struct aws_mutex *mutex) {
- AWS_PRECONDITION(mutex);
+ AWS_PRECONDITION(mutex);
pthread_mutexattr_t attr;
int err_code = pthread_mutexattr_init(&attr);
int return_code = AWS_OP_SUCCESS;
@@ -33,21 +33,21 @@ int aws_mutex_init(struct aws_mutex *mutex) {
return_code = aws_private_convert_and_raise_error_code(err_code);
}
- mutex->initialized = (return_code == AWS_OP_SUCCESS);
+ mutex->initialized = (return_code == AWS_OP_SUCCESS);
return return_code;
}
int aws_mutex_lock(struct aws_mutex *mutex) {
- AWS_PRECONDITION(mutex && mutex->initialized);
+ 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) {
- AWS_PRECONDITION(mutex && mutex->initialized);
+ 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) {
- AWS_PRECONDITION(mutex && mutex->initialized);
+ AWS_PRECONDITION(mutex && mutex->initialized);
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/process.c b/contrib/restricted/aws/aws-c-common/source/posix/process.c
index fb808faeb6..217ccb7d32 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/process.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/process.c
@@ -1,53 +1,53 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/process.h>
-
-#include <sys/resource.h>
-#include <sys/time.h>
-#include <unistd.h>
-
-int aws_get_pid(void) {
- return (int)getpid();
-}
-
-size_t aws_get_soft_limit_io_handles(void) {
- struct rlimit rlimit;
- AWS_ZERO_STRUCT(rlimit);
-
- AWS_FATAL_ASSERT(
- !getrlimit(RLIMIT_NOFILE, &rlimit) &&
- "getrlimit() should never fail for RLIMIT_NOFILE regardless of user permissions");
- return rlimit.rlim_cur;
-}
-
-size_t aws_get_hard_limit_io_handles(void) {
- struct rlimit rlimit;
- AWS_ZERO_STRUCT(rlimit);
-
- AWS_FATAL_ASSERT(
- !getrlimit(RLIMIT_NOFILE, &rlimit) &&
- "getrlimit() should never fail for RLIMIT_NOFILE regardless of user permissions");
- return rlimit.rlim_max;
-}
-
-int aws_set_soft_limit_io_handles(size_t max_handles) {
- size_t hard_limit = aws_get_hard_limit_io_handles();
-
- if (max_handles > hard_limit) {
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
-
- struct rlimit rlimit = {
- .rlim_cur = max_handles,
- .rlim_max = hard_limit,
- };
-
- if (setrlimit(RLIMIT_NOFILE, &rlimit)) {
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
-
- return AWS_OP_SUCCESS;
-}
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/common/process.h>
+
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+int aws_get_pid(void) {
+ return (int)getpid();
+}
+
+size_t aws_get_soft_limit_io_handles(void) {
+ struct rlimit rlimit;
+ AWS_ZERO_STRUCT(rlimit);
+
+ AWS_FATAL_ASSERT(
+ !getrlimit(RLIMIT_NOFILE, &rlimit) &&
+ "getrlimit() should never fail for RLIMIT_NOFILE regardless of user permissions");
+ return rlimit.rlim_cur;
+}
+
+size_t aws_get_hard_limit_io_handles(void) {
+ struct rlimit rlimit;
+ AWS_ZERO_STRUCT(rlimit);
+
+ AWS_FATAL_ASSERT(
+ !getrlimit(RLIMIT_NOFILE, &rlimit) &&
+ "getrlimit() should never fail for RLIMIT_NOFILE regardless of user permissions");
+ return rlimit.rlim_max;
+}
+
+int aws_set_soft_limit_io_handles(size_t max_handles) {
+ size_t hard_limit = aws_get_hard_limit_io_handles();
+
+ if (max_handles > hard_limit) {
+ return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
+
+ struct rlimit rlimit = {
+ .rlim_cur = max_handles,
+ .rlim_max = hard_limit,
+ };
+
+ if (setrlimit(RLIMIT_NOFILE, &rlimit)) {
+ return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
+
+ return AWS_OP_SUCCESS;
+}
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..e814ea8ebf 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,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/atomics.h>
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..26faefc35e 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,14 +1,14 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * 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/byte_buf.h>
-#include <aws/common/logging.h>
-#include <aws/common/platform.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
@@ -22,13 +22,13 @@ size_t aws_system_info_processor_count(void) {
return (size_t)nprocs;
}
- AWS_FATAL_POSTCONDITION(nprocs >= 0);
+ AWS_FATAL_POSTCONDITION(nprocs >= 0);
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);
+ AWS_FATAL_PRECONDITION(AWS_NUM_CPU_CORES > 0);
return AWS_NUM_CPU_CORES;
# else
return 1;
@@ -36,42 +36,42 @@ size_t aws_system_info_processor_count(void) {
}
#endif
-#include <ctype.h>
-#include <fcntl.h>
-
-bool aws_is_debugger_present(void) {
- /* Open the status file */
- const int status_fd = open("/proc/self/status", O_RDONLY);
- if (status_fd == -1) {
- return false;
- }
-
- /* Read its contents */
- char buf[4096];
- const ssize_t num_read = read(status_fd, buf, sizeof(buf) - 1);
- close(status_fd);
- if (num_read <= 0) {
- return false;
- }
- buf[num_read] = '\0';
-
- /* Search for the TracerPid field, which will indicate the debugger process */
- const char tracerPidString[] = "TracerPid:";
- const char *tracer_pid = strstr(buf, tracerPidString);
- if (!tracer_pid) {
- return false;
- }
-
- /* If it's not 0, then there's a debugger */
- for (const char *cur = tracer_pid + sizeof(tracerPidString) - 1; cur <= buf + num_read; ++cur) {
- if (!aws_isspace(*cur)) {
- return aws_isdigit(*cur) && *cur != '0';
- }
- }
-
- return false;
-}
-
+#include <ctype.h>
+#include <fcntl.h>
+
+bool aws_is_debugger_present(void) {
+ /* Open the status file */
+ const int status_fd = open("/proc/self/status", O_RDONLY);
+ if (status_fd == -1) {
+ return false;
+ }
+
+ /* Read its contents */
+ char buf[4096];
+ const ssize_t num_read = read(status_fd, buf, sizeof(buf) - 1);
+ close(status_fd);
+ if (num_read <= 0) {
+ return false;
+ }
+ buf[num_read] = '\0';
+
+ /* Search for the TracerPid field, which will indicate the debugger process */
+ const char tracerPidString[] = "TracerPid:";
+ const char *tracer_pid = strstr(buf, tracerPidString);
+ if (!tracer_pid) {
+ return false;
+ }
+
+ /* If it's not 0, then there's a debugger */
+ for (const char *cur = tracer_pid + sizeof(tracerPidString) - 1; cur <= buf + num_read; ++cur) {
+ if (!aws_isspace(*cur)) {
+ return aws_isdigit(*cur) && *cur != '0';
+ }
+ }
+
+ return false;
+}
+
#include <signal.h>
#ifndef __has_builtin
@@ -80,13 +80,13 @@ bool aws_is_debugger_present(void) {
void aws_debug_break(void) {
#ifdef DEBUG_BUILD
- if (aws_is_debugger_present()) {
+ if (aws_is_debugger_present()) {
# if __has_builtin(__builtin_debugtrap)
- __builtin_debugtrap();
+ __builtin_debugtrap();
# else
- raise(SIGTRAP);
+ raise(SIGTRAP);
# endif
- }
+ }
#endif /* DEBUG_BUILD */
}
@@ -103,22 +103,22 @@ struct aws_stack_frame_info {
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 */
-char *s_whitelist_chars(char *path) {
- char *cur = path;
- while (*cur) {
- bool whitelisted = aws_isalnum(*cur) || aws_isspace(*cur) || *cur == '/' || *cur == '_' || *cur == '.' ||
- (cur > path && *cur == '-');
- if (!whitelisted) {
- *cur = '_';
- }
- ++cur;
- }
- return path;
-}
-
+/* 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 */
+char *s_whitelist_chars(char *path) {
+ char *cur = path;
+ while (*cur) {
+ bool whitelisted = aws_isalnum(*cur) || aws_isspace(*cur) || *cur == '/' || *cur == '_' || *cur == '.' ||
+ (cur > path && *cur == '-');
+ if (!whitelisted) {
+ *cur = '_';
+ }
+ ++cur;
+ }
+ return path;
+}
+
# if defined(__APPLE__)
# include <ctype.h>
# include <dlfcn.h>
@@ -141,16 +141,16 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *
const char *current_exe = s_get_executable_path();
/* parse exe/shared lib */
const char *exe_start = strstr(symbol, " ");
- while (aws_isspace(*exe_start)) {
+ 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));
}
- s_whitelist_chars(frame->exe);
+ s_whitelist_chars(frame->exe);
/* parse addr */
const char *addr_start = strstr(exe_end, "0x");
@@ -160,11 +160,11 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *
/* 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;
- }
+ /* 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 */
@@ -180,9 +180,9 @@ void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
}
# 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>]
+ /* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
* or: <exe-or-shared-lib> [0x<addr>]
- * or: [0x<addr>]
+ * or: [0x<addr>]
*/
(void)addr;
const char *open_paren = strstr(symbol, "(");
@@ -190,45 +190,45 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *
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, "[");
+ exe_end = strstr(symbol, "[");
if (!exe_end) {
return AWS_OP_ERR;
}
- /* if exe_end == symbol, there's no exe */
- if (exe_end != symbol) {
- exe_end -= 1;
- }
+ /* if exe_end == symbol, there's no exe */
+ if (exe_end != symbol) {
+ exe_end -= 1;
+ }
}
ptrdiff_t exe_len = exe_end - symbol;
- if (exe_len > 0) {
- strncpy(frame->exe, symbol, exe_len);
+ if (exe_len > 0) {
+ strncpy(frame->exe, symbol, exe_len);
}
- s_whitelist_chars(frame->exe);
+ 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 */
- /* there might be (<function>+<addr>) or just (<function>) */
- const char *function_start = open_paren + 1;
- const char *plus = strstr(function_start, "+");
- const char *function_end = (plus) ? plus : close_paren;
- if (function_end > function_start) {
- function_len = function_end - function_start;
- strncpy(frame->function, function_start, function_len);
- } else if (plus) {
- 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;
- char *addr_end = strstr(addr_start, "]");
- if (!addr_end) {
- return AWS_OP_ERR;
- }
- strncpy(frame->addr, addr_start, addr_end - addr_start);
+ /* there might be (<function>+<addr>) or just (<function>) */
+ const char *function_start = open_paren + 1;
+ const char *plus = strstr(function_start, "+");
+ const char *function_end = (plus) ? plus : close_paren;
+ if (function_end > function_start) {
+ function_len = function_end - function_start;
+ strncpy(frame->function, function_start, function_len);
+ } else if (plus) {
+ 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;
+ char *addr_end = strstr(addr_start, "]");
+ if (!addr_end) {
+ return AWS_OP_ERR;
+ }
+ strncpy(frame->addr, addr_start, addr_end - addr_start);
+ }
return AWS_OP_SUCCESS;
}
@@ -237,63 +237,63 @@ void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) {
}
# endif
-size_t aws_backtrace(void **stack_frames, size_t num_frames) {
- return backtrace(stack_frames, (int)aws_min_size(num_frames, INT_MAX));
-}
-
-char **aws_backtrace_symbols(void *const *stack_frames, size_t stack_depth) {
- return backtrace_symbols(stack_frames, (int)aws_min_size(stack_depth, INT_MAX));
-}
-
-char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) {
- char **symbols = aws_backtrace_symbols(stack_frames, stack_depth);
- AWS_FATAL_ASSERT(symbols);
- struct aws_byte_buf lines;
- aws_byte_buf_init(&lines, aws_default_allocator(), stack_depth * 256);
-
- /* insert pointers for each stack entry */
- memset(lines.buffer, 0, stack_depth * sizeof(void *));
- lines.len += stack_depth * sizeof(void *);
-
- /* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
- * or: <exe-or-shared-lib> [0x<addr>]
- * start at 1 to skip the current frame (this function) */
- for (size_t frame_idx = 0; 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:
- /* record the pointer to where the symbol will be */
- *((char **)&lines.buffer[frame_idx * sizeof(void *)]) = (char *)lines.buffer + lines.len;
- struct aws_byte_cursor line_cursor = aws_byte_cursor_from_c_str(symbol);
- line_cursor.len += 1; /* strings must be null terminated, make sure we copy the null */
- aws_byte_buf_append_dynamic(&lines, &line_cursor);
- }
- free(symbols);
- return (char **)lines.buffer; /* caller is responsible for freeing */
-}
-
+size_t aws_backtrace(void **stack_frames, size_t num_frames) {
+ return backtrace(stack_frames, (int)aws_min_size(num_frames, INT_MAX));
+}
+
+char **aws_backtrace_symbols(void *const *stack_frames, size_t stack_depth) {
+ return backtrace_symbols(stack_frames, (int)aws_min_size(stack_depth, INT_MAX));
+}
+
+char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) {
+ char **symbols = aws_backtrace_symbols(stack_frames, stack_depth);
+ AWS_FATAL_ASSERT(symbols);
+ struct aws_byte_buf lines;
+ aws_byte_buf_init(&lines, aws_default_allocator(), stack_depth * 256);
+
+ /* insert pointers for each stack entry */
+ memset(lines.buffer, 0, stack_depth * sizeof(void *));
+ lines.len += stack_depth * sizeof(void *);
+
+ /* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
+ * or: <exe-or-shared-lib> [0x<addr>]
+ * start at 1 to skip the current frame (this function) */
+ for (size_t frame_idx = 0; 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:
+ /* record the pointer to where the symbol will be */
+ *((char **)&lines.buffer[frame_idx * sizeof(void *)]) = (char *)lines.buffer + lines.len;
+ struct aws_byte_cursor line_cursor = aws_byte_cursor_from_c_str(symbol);
+ line_cursor.len += 1; /* strings must be null terminated, make sure we copy the null */
+ aws_byte_buf_append_dynamic(&lines, &line_cursor);
+ }
+ free(symbols);
+ 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) {
@@ -304,21 +304,21 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) {
}
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);
+ 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;
}
- fprintf(fp, "################################################################################\n");
- fprintf(fp, "Resolved stacktrace:\n");
- fprintf(fp, "################################################################################\n");
- /* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>]
+ 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: [0x<addr>]
+ * or: [0x<addr>]
* start at 1 to skip the current frame (this function) */
- for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) {
+ 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];
@@ -346,64 +346,64 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) {
parse_failed:
fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : "");
}
-
- fprintf(fp, "################################################################################\n");
- fprintf(fp, "Raw stacktrace:\n");
- fprintf(fp, "################################################################################\n");
- for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) {
- const char *symbol = symbols[frame_idx];
- fprintf(fp, "%s\n", symbol);
- }
- fflush(fp);
-
+
+ fprintf(fp, "################################################################################\n");
+ fprintf(fp, "Raw stacktrace:\n");
+ fprintf(fp, "################################################################################\n");
+ for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) {
+ const char *symbol = symbols[frame_idx];
+ fprintf(fp, "%s\n", symbol);
+ }
+ fflush(fp);
+
free(symbols);
}
#else
void aws_backtrace_print(FILE *fp, void *call_site_data) {
- (void)call_site_data;
+ (void)call_site_data;
fprintf(fp, "No call stack information available\n");
}
-
-size_t aws_backtrace(void **stack_frames, size_t size) {
- (void)stack_frames;
- (void)size;
- return 0;
-}
-
-char **aws_backtrace_symbols(void *const *stack_frames, size_t stack_depth) {
- (void)stack_frames;
- (void)stack_depth;
- return NULL;
-}
-
-char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) {
- (void)stack_frames;
- (void)stack_depth;
- return NULL;
-}
+
+size_t aws_backtrace(void **stack_frames, size_t size) {
+ (void)stack_frames;
+ (void)size;
+ return 0;
+}
+
+char **aws_backtrace_symbols(void *const *stack_frames, size_t stack_depth) {
+ (void)stack_frames;
+ (void)stack_depth;
+ return NULL;
+}
+
+char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) {
+ (void)stack_frames;
+ (void)stack_depth;
+ return NULL;
+}
#endif /* AWS_HAVE_EXECINFO */
-
-void aws_backtrace_log() {
- void *stack_frames[1024];
- size_t num_frames = aws_backtrace(stack_frames, 1024);
- if (!num_frames) {
- return;
- }
- char **symbols = aws_backtrace_addr2line(stack_frames, num_frames);
- for (size_t line = 0; line < num_frames; ++line) {
- const char *symbol = symbols[line];
- AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "%s", symbol);
- }
- free(symbols);
-}
-
-#if defined(AWS_OS_APPLE)
-enum aws_platform_os aws_get_platform_build_os(void) {
- return AWS_PLATFORM_OS_MAC;
-}
-#else
-enum aws_platform_os aws_get_platform_build_os(void) {
- return AWS_PLATFORM_OS_UNIX;
-}
-#endif /* AWS_OS_APPLE */
+
+void aws_backtrace_log() {
+ void *stack_frames[1024];
+ size_t num_frames = aws_backtrace(stack_frames, 1024);
+ if (!num_frames) {
+ return;
+ }
+ char **symbols = aws_backtrace_addr2line(stack_frames, num_frames);
+ for (size_t line = 0; line < num_frames; ++line) {
+ const char *symbol = symbols[line];
+ AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "%s", symbol);
+ }
+ free(symbols);
+}
+
+#if defined(AWS_OS_APPLE)
+enum aws_platform_os aws_get_platform_build_os(void) {
+ return AWS_PLATFORM_OS_MAC;
+}
+#else
+enum aws_platform_os aws_get_platform_build_os(void) {
+ return AWS_PLATFORM_OS_UNIX;
+}
+#endif /* AWS_OS_APPLE */
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..a2d4834b54 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/thread.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/thread.c
@@ -1,94 +1,94 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
-#if !defined(__MACH__)
-# define _GNU_SOURCE
-#endif
+#if !defined(__MACH__)
+# define _GNU_SOURCE
+#endif
#include <aws/common/clock.h>
-#include <aws/common/logging.h>
-#include <aws/common/private/dlloads.h>
-#include <aws/common/thread.h>
+#include <aws/common/logging.h>
+#include <aws/common/private/dlloads.h>
+#include <aws/common/thread.h>
-#include <dlfcn.h>
+#include <dlfcn.h>
#include <errno.h>
-#include <inttypes.h>
+#include <inttypes.h>
#include <limits.h>
-#include <sched.h>
+#include <sched.h>
#include <time.h>
-#include <unistd.h>
-
-#if defined(__FreeBSD__) || defined(__NETBSD__)
-# include <pthread_np.h>
-typedef cpuset_t cpu_set_t;
-#endif
+#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. */
- .stack_size = 0,
- .cpu_id = -1,
-};
-
-struct thread_atexit_callback {
- aws_thread_atexit_fn *callback;
- void *user_data;
- struct thread_atexit_callback *next;
-};
-
+ .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_atexit_callback *atexit;
- void (*call_once)(void *);
- void *once_arg;
- struct aws_thread *thread;
- bool membind;
+ 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 AWS_THREAD_LOCAL struct thread_wrapper *tl_wrapper = NULL;
+
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) {
- AWS_LOGF_INFO(
- AWS_LS_COMMON_THREAD,
- "id=%p: a cpu affinity was specified when launching this thread and set_mempolicy() is available on this "
- "system. Setting the memory policy to MPOL_PREFERRED",
- (void *)tl_wrapper->thread);
- /* if a user set a cpu id in their thread options, we're going to make sure the numa policy honors that
- * 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);
- if (resp) {
- AWS_LOGF_WARN(
- AWS_LS_COMMON_THREAD,
- "id=%p: call to set_mempolicy() failed with errno %d",
- (void *)wrapper.thread,
- errno);
- }
- }
- wrapper.func(wrapper.arg);
-
- struct thread_atexit_callback *exit_callback_data = wrapper.atexit;
- aws_mem_release(allocator, arg);
-
- while (exit_callback_data) {
- aws_thread_atexit_fn *exit_callback = exit_callback_data->callback;
- void *exit_callback_user_data = exit_callback_data->user_data;
- struct thread_atexit_callback *next_exit_callback_data = exit_callback_data->next;
-
- aws_mem_release(allocator, exit_callback_data);
-
- exit_callback(exit_callback_user_data);
- exit_callback_data = next_exit_callback_data;
- }
- tl_wrapper = NULL;
-
+ struct aws_allocator *allocator = wrapper.allocator;
+ tl_wrapper = &wrapper;
+ if (wrapper.membind && g_set_mempolicy_ptr) {
+ AWS_LOGF_INFO(
+ AWS_LS_COMMON_THREAD,
+ "id=%p: a cpu affinity was specified when launching this thread and set_mempolicy() is available on this "
+ "system. Setting the memory policy to MPOL_PREFERRED",
+ (void *)tl_wrapper->thread);
+ /* if a user set a cpu id in their thread options, we're going to make sure the numa policy honors that
+ * 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);
+ if (resp) {
+ AWS_LOGF_WARN(
+ AWS_LS_COMMON_THREAD,
+ "id=%p: call to set_mempolicy() failed with errno %d",
+ (void *)wrapper.thread,
+ errno);
+ }
+ }
+ wrapper.func(wrapper.arg);
+
+ struct thread_atexit_callback *exit_callback_data = wrapper.atexit;
+ aws_mem_release(allocator, arg);
+
+ while (exit_callback_data) {
+ aws_thread_atexit_fn *exit_callback = exit_callback_data->callback;
+ void *exit_callback_user_data = exit_callback_data->user_data;
+ struct thread_atexit_callback *next_exit_callback_data = exit_callback_data->next;
+
+ aws_mem_release(allocator, exit_callback_data);
+
+ exit_callback(exit_callback_user_data);
+ exit_callback_data = next_exit_callback_data;
+ }
+ tl_wrapper = NULL;
+
return NULL;
}
@@ -102,28 +102,28 @@ void aws_thread_clean_up(struct aws_thread *thread) {
}
}
-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;
- if (!tl_wrapper) {
- tl_wrapper = &temp_wrapper;
- }
-
- tl_wrapper->call_once = call_once;
- tl_wrapper->once_arg = user_data;
- pthread_once(flag, s_call_once);
-
- if (tl_wrapper == &temp_wrapper) {
- tl_wrapper = NULL;
- }
+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;
+ if (!tl_wrapper) {
+ tl_wrapper = &temp_wrapper;
+ }
+
+ tl_wrapper->call_once = call_once;
+ tl_wrapper->once_arg = user_data;
+ pthread_once(flag, s_call_once);
+
+ if (tl_wrapper == &temp_wrapper) {
+ tl_wrapper = NULL;
+ }
+}
+
int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator) {
- *thread = (struct aws_thread){.allocator = allocator, .detach_state = AWS_THREAD_NOT_CREATED};
+ *thread = (struct aws_thread){.allocator = allocator, .detach_state = AWS_THREAD_NOT_CREATED};
return AWS_OP_SUCCESS;
}
@@ -155,50 +155,50 @@ int aws_thread_launch(
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.
- * Thread afinity is also not supported on Android systems, and honestly, if you're running android on a NUMA
- * configuration, you've got bigger problems. */
-#if !defined(__MACH__) && !defined(__ANDROID__) && !defined(_musl_)
- if (options->cpu_id >= 0) {
- AWS_LOGF_INFO(
- AWS_LS_COMMON_THREAD,
- "id=%p: cpu affinity of cpu_id %d was specified, attempting to honor the value.",
- (void *)thread,
- options->cpu_id);
-
- cpu_set_t cpuset;
- CPU_ZERO(&cpuset);
- CPU_SET((uint32_t)options->cpu_id, &cpuset);
-
- attr_return = pthread_attr_setaffinity_np(attributes_ptr, sizeof(cpuset), &cpuset);
-
- if (attr_return) {
- AWS_LOGF_ERROR(
- AWS_LS_COMMON_THREAD,
- "id=%p: pthread_attr_setaffinity_np() failed with %d.",
- (void *)thread,
- errno);
- goto cleanup;
- }
- }
-#endif /* !defined(__MACH__) && !defined(__ANDROID__) */
+
+/* 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
+ * configuration, you've got bigger problems. */
+#if !defined(__MACH__) && !defined(__ANDROID__) && !defined(_musl_)
+ if (options->cpu_id >= 0) {
+ AWS_LOGF_INFO(
+ AWS_LS_COMMON_THREAD,
+ "id=%p: cpu affinity of cpu_id %d was specified, attempting to honor the value.",
+ (void *)thread,
+ options->cpu_id);
+
+ cpu_set_t cpuset;
+ CPU_ZERO(&cpuset);
+ CPU_SET((uint32_t)options->cpu_id, &cpuset);
+
+ attr_return = pthread_attr_setaffinity_np(attributes_ptr, sizeof(cpuset), &cpuset);
+
+ if (attr_return) {
+ AWS_LOGF_ERROR(
+ AWS_LS_COMMON_THREAD,
+ "id=%p: pthread_attr_setaffinity_np() failed with %d.",
+ (void *)thread,
+ errno);
+ goto cleanup;
+ }
+ }
+#endif /* !defined(__MACH__) && !defined(__ANDROID__) */
}
struct thread_wrapper *wrapper =
- (struct thread_wrapper *)aws_mem_calloc(thread->allocator, 1, sizeof(struct thread_wrapper));
+ (struct thread_wrapper *)aws_mem_calloc(thread->allocator, 1, sizeof(struct thread_wrapper));
if (!wrapper) {
allocation_failed = 1;
goto cleanup;
}
- if (options && options->cpu_id >= 0) {
- wrapper->membind = true;
- }
-
- wrapper->thread = thread;
+ if (options && options->cpu_id >= 0) {
+ wrapper->membind = true;
+ }
+
+ wrapper->thread = thread;
wrapper->allocator = thread->allocator;
wrapper->func = func;
wrapper->arg = arg;
@@ -234,8 +234,8 @@ cleanup:
return AWS_OP_SUCCESS;
}
-aws_thread_id_t aws_thread_get_id(struct aws_thread *thread) {
- return thread->thread_id;
+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) {
@@ -264,14 +264,14 @@ int aws_thread_join(struct aws_thread *thread) {
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;
+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);
@@ -284,19 +284,19 @@ void aws_thread_current_sleep(uint64_t nanos) {
nanosleep(&tm, &output);
}
-
-int aws_thread_current_at_exit(aws_thread_atexit_fn *callback, void *user_data) {
- if (!tl_wrapper) {
- return aws_raise_error(AWS_ERROR_THREAD_NOT_JOINABLE);
- }
-
- struct thread_atexit_callback *cb = aws_mem_calloc(tl_wrapper->allocator, 1, sizeof(struct thread_atexit_callback));
- if (!cb) {
- return AWS_OP_ERR;
- }
- cb->callback = callback;
- cb->user_data = user_data;
- cb->next = tl_wrapper->atexit;
- tl_wrapper->atexit = cb;
- return AWS_OP_SUCCESS;
-}
+
+int aws_thread_current_at_exit(aws_thread_atexit_fn *callback, void *user_data) {
+ if (!tl_wrapper) {
+ return aws_raise_error(AWS_ERROR_THREAD_NOT_JOINABLE);
+ }
+
+ struct thread_atexit_callback *cb = aws_mem_calloc(tl_wrapper->allocator, 1, sizeof(struct thread_atexit_callback));
+ if (!cb) {
+ return AWS_OP_ERR;
+ }
+ cb->callback = callback;
+ cb->user_data = user_data;
+ cb->next = tl_wrapper->atexit;
+ tl_wrapper->atexit = cb;
+ return AWS_OP_SUCCESS;
+}
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..6ce3bf2e2b 100644
--- a/contrib/restricted/aws/aws-c-common/source/posix/time.c
+++ b/contrib/restricted/aws/aws-c-common/source/posix/time.c
@@ -1,6 +1,6 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/time.h>