Skip to content

Commit

Permalink
Merge branch 'main' into leaked_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin authored Oct 2, 2023
2 parents 7dab3d6 + 4c0a9f5 commit 4374629
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 107 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/proof_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
run: |
# Search within 5 most recent releases for latest available package
CBMC_REL="https://api.github.com/repos/diffblue/cbmc/releases?page=1&per_page=5"
CBMC_DEB=$(curl -s $CBMC_REL | jq -r '.[].assets[].browser_download_url' | grep -e 'ubuntu-20.04' | head -n 1)
CBMC_DEB=$(curl -s $CBMC_REL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq -r '.[].assets[].browser_download_url' | grep -e 'ubuntu-20.04' | head -n 1)
CBMC_ARTIFACT_NAME=$(basename $CBMC_DEB)
curl -o $CBMC_ARTIFACT_NAME -L $CBMC_DEB
sudo dpkg -i $CBMC_ARTIFACT_NAME
Expand All @@ -81,7 +81,7 @@ jobs:
shell: bash
run: |
CBMC_VIEWER_REL="https://api.github.com/repos/model-checking/cbmc-viewer/releases/latest"
CBMC_VIEWER_VERSION=$(curl -s $CBMC_VIEWER_REL | jq -r .name | sed 's/viewer-//')
CBMC_VIEWER_VERSION=$(curl -s $CBMC_VIEWER_REL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq -r .name | sed 's/viewer-//')
pip3 install cbmc-viewer==$CBMC_VIEWER_VERSION
- name: Install CBMC viewer ${{ env.CBMC_VIEWER_VERSION }}
if: ${{ env.CBMC_VIEWER_VERSION != 'latest' }}
Expand All @@ -97,7 +97,7 @@ jobs:
run: |
# Search within 5 most recent releases for latest available package
LITANI_REL="https://api.github.com/repos/awslabs/aws-build-accumulator/releases?page=1&per_page=5"
LITANI_DEB=$(curl -s $LITANI_REL | jq -r '.[].assets[0].browser_download_url' | head -n 1)
LITANI_DEB=$(curl -s $LITANI_REL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq -r '.[].assets[0].browser_download_url' | head -n 1)
DBN_PKG_FILENAME=$(basename $LITANI_DEB)
curl -L $LITANI_DEB -o $DBN_PKG_FILENAME
sudo apt-get update
Expand All @@ -119,7 +119,7 @@ jobs:
if ${{ env.KISSAT_TAG == 'latest' }}
then
KISSAT_REL="https://api.github.com/repos/arminbiere/kissat/releases/latest"
KISSAT_TAG_NAME=$(curl -s $KISSAT_REL | jq -r '.tag_name')
KISSAT_TAG_NAME=$(curl -s $KISSAT_REL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq -r '.tag_name')
else
KISSAT_TAG_NAME=${{ env.KISSAT_TAG }}
fi
Expand All @@ -138,7 +138,7 @@ jobs:
if ${{ env.CADICAL_TAG == 'latest' }}
then
CADICAL_REL="https://api.github.com/repos/arminbiere/cadical/releases/latest"
CADICAL_TAG_NAME=$(curl -s $CADICAL_REL | jq -r '.tag_name')
CADICAL_TAG_NAME=$(curl -s $CADICAL_REL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq -r '.tag_name')
else
CADICAL_TAG_NAME=${{ env.CADICAL_TAG }}
fi
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0.

cmake_minimum_required(VERSION 3.0)
option(STATIC_CRT "Windows specific option that to specify static/dynamic run-time library" OFF)
option(ALLOW_CROSS_COMPILED_TESTS "Allow tests to be compiled via cross compile, for use with qemu" OFF)

project(aws-c-common LANGUAGES C VERSION 0.1.0)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Or on windows,
* -DENABLE_SANITIZERS=ON - Enables gcc/clang sanitizers, by default this adds -fsanitizer=address,undefined to the compile flags for projects that call aws_add_sanitizers.
* -DENABLE_FUZZ_TESTS=ON - Includes fuzz tests in the unit test suite. Off by default, because fuzz tests can take a long time. Set -DFUZZ_TESTS_MAX_TIME=N to determine how long to run each fuzz test (default 60s).
* -DCMAKE_INSTALL_PREFIX=/path/to/install - Standard way of installing to a user defined path. If specified when configuring aws-c-common, ensure the same prefix is specified when configuring other aws-c-* SDKs.
* -DSTATIC_CRT=ON - On MSVC, use /MT(d) to link MSVCRT
* -DAWS_STATIC_MSVC_RUNTIME_LIBRARY=ON - Windows-only. Turn ON to use the statically-linked MSVC runtime lib, instead of the DLL.

### API style and conventions
Every API has a specific set of styles and conventions. We'll outline them here. These conventions are followed in every
Expand Down Expand Up @@ -197,7 +197,7 @@ Example:
Not this:

typedef int(*fn_name_fn)(void *);

* If a callback may be async, then always have it be async.
Callbacks that are sometimes async and sometimes sync are hard to code around and lead to bugs
(see [this blog post](https://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/)).
Expand Down Expand Up @@ -239,7 +239,7 @@ platform, you have more liberty on this.
* When checking more than one error condition, check and log each condition separately with a unique message.

Do this:

if (options->callback == NULL) {
AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - callback is null");
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
Expand All @@ -251,7 +251,7 @@ platform, you have more liberty on this.
}

Not this:

if (options->callback == NULL || options->allocator == NULL) {
AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - something is null");
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
Expand Down
55 changes: 28 additions & 27 deletions cmake/AwsCFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ option(LEGACY_COMPILER_SUPPORT "This enables builds with compiler versions such
option(AWS_SUPPORT_WIN7 "Restricts WINAPI calls to Win7 and older (This will have implications in downstream libraries that use TLS especially)" OFF)
option(AWS_WARNINGS_ARE_ERRORS "Compiler warning is treated as an error. Try turning this off when observing errors on a new or uncommon compiler" OFF)
option(AWS_ENABLE_TRACING "Enable tracing macros" OFF)
option(AWS_STATIC_MSVC_RUNTIME_LIBRARY "Windows-only. Turn ON to use the statically-linked MSVC runtime lib, instead of the DLL" OFF)
option(STATIC_CRT "Deprecated. Use AWS_STATIC_MSVC_RUNTIME_LIBRARY instead" OFF)

# Check for Posix Large Files Support (LFS).
# On most 64bit systems, LFS is enabled by default.
Expand Down Expand Up @@ -80,21 +82,19 @@ function(aws_set_common_properties target)
list(APPEND AWS_C_FLAGS /DAWS_SUPPORT_WIN7=1)
endif()

string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE)
if(STATIC_CRT)
string(REPLACE "/MD" "/MT" _FLAGS "${CMAKE_C_FLAGS_${_CMAKE_BUILD_TYPE}}")
# Set MSVC runtime libary.
# Note: there are other ways of doing this if we bump our CMake minimum to 3.14+
# See: https://cmake.org/cmake/help/latest/policy/CMP0091.html
if (AWS_STATIC_MSVC_RUNTIME_LIBRARY OR STATIC_CRT)
list(APPEND AWS_C_FLAGS "/MT$<$<CONFIG:Debug>:d>")
else()
string(REPLACE "/MT" "/MD" _FLAGS "${CMAKE_C_FLAGS_${_CMAKE_BUILD_TYPE}}")
list(APPEND AWS_C_FLAGS "/MD$<$<CONFIG:Debug>:d>")
endif()
string(REPLACE " " ";" _FLAGS "${_FLAGS}")
list(APPEND AWS_C_FLAGS "${_FLAGS}")

else()
list(APPEND AWS_C_FLAGS -Wall -Wstrict-prototypes)

if (NOT CMAKE_BUILD_TYPE STREQUAL Release)
list(APPEND AWS_C_FLAGS -fno-omit-frame-pointer)
endif()
list(APPEND AWS_C_FLAGS $<$<NOT:$<CONFIG:Release>>:-fno-omit-frame-pointer>)

if(AWS_WARNINGS_ARE_ERRORS)
list(APPEND AWS_C_FLAGS -Werror)
Expand Down Expand Up @@ -223,25 +223,28 @@ function(aws_set_common_properties target)
list(APPEND AWS_C_DEFINES_PRIVATE -DHAVE_SYSCONF)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND AWS_C_DEFINES_PRIVATE -DDEBUG_BUILD)
else() # release build
list(APPEND AWS_C_DEFINES_PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)

if ((NOT SET_PROPERTIES_NO_LTO) AND AWS_ENABLE_LTO)
# enable except in Debug builds
set(_ENABLE_LTO_EXPR $<NOT:$<CONFIG:Debug>>)

# try to check whether compiler supports LTO/IPO
if (POLICY CMP0069)
if ((NOT SET_PROPERTIES_NO_LTO) AND AWS_ENABLE_LTO)
cmake_policy(SET CMP0069 NEW) # Enable LTO/IPO if available in the compiler
include(CheckIPOSupported OPTIONAL RESULT_VARIABLE ipo_check_exists)
if (ipo_check_exists)
check_ipo_supported(RESULT ipo_supported)
if (ipo_supported)
message(STATUS "Enabling IPO/LTO for Release builds")
set(AWS_ENABLE_LTO ON)
else()
message(STATUS "AWS_ENABLE_LTO is enabled, but cmake/compiler does not support it, disabling")
set(AWS_ENABLE_LTO OFF)
endif()
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported OPTIONAL RESULT_VARIABLE ipo_check_exists)
if (ipo_check_exists)
check_ipo_supported(RESULT ipo_supported)
if (ipo_supported)
message(STATUS "Enabling IPO/LTO for Release builds")
else()
message(STATUS "AWS_ENABLE_LTO is enabled, but cmake/compiler does not support it, disabling")
set(_ENABLE_LTO_EXPR OFF)
endif()
endif()
endif()
else()
set(_ENABLE_LTO_EXPR OFF)
endif()

if(BUILD_SHARED_LIBS)
Expand All @@ -260,7 +263,5 @@ function(aws_set_common_properties target)
target_compile_options(${target} PRIVATE ${AWS_C_FLAGS})
target_compile_definitions(${target} PRIVATE ${AWS_C_DEFINES_PRIVATE} PUBLIC ${AWS_C_DEFINES_PUBLIC})
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE C C_STANDARD 99 C_STANDARD_REQUIRED ON)
if (AWS_ENABLE_LTO)
set_target_properties(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
set_target_properties(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${_ENABLE_LTO_EXPR}>)
endfunction()
13 changes: 3 additions & 10 deletions cmake/AwsTestHarness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ define_property(GLOBAL PROPERTY AWS_TEST_CASES BRIEF_DOCS "Test Cases" FULL_DOCS
set(AWS_TEST_CASES "" CACHE INTERNAL "Test cases valid for this configuration")

# The return value for the skipped test cases. Refer to the return code defined in aws_test_harness.h:
# #define SKIP (1)
set(SKIP_RETURN_CODE_VALUE 1)
# #define SKIP (103)
set(SKIP_RETURN_CODE_VALUE 103)

# Registers a test case by name (the first argument to the AWS_TEST_CASE macro in aws_test_harness.h)
macro(add_test_case name)
Expand Down Expand Up @@ -54,13 +54,6 @@ function(generate_test_driver driver_exe_name)
target_link_libraries(${driver_exe_name} PRIVATE ${PROJECT_NAME})

set_target_properties(${driver_exe_name} PROPERTIES LINKER_LANGUAGE C C_STANDARD 99)
if (MSVC)
if(STATIC_CRT)
target_compile_options(${driver_exe_name} PRIVATE "/MT$<$<CONFIG:Debug>:d>")
else()
target_compile_options(${driver_exe_name} PRIVATE "/MD$<$<CONFIG:Debug>:d>")
endif()
endif()
target_compile_definitions(${driver_exe_name} PRIVATE AWS_UNSTABLE_TESTING_API=1)
target_include_directories(${driver_exe_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR})

Expand All @@ -80,7 +73,7 @@ function(generate_cpp_test_driver driver_exe_name)

set_target_properties(${driver_exe_name} PROPERTIES LINKER_LANGUAGE CXX)
if (MSVC)
if(STATIC_CRT)
if(AWS_STATIC_MSVC_RUNTIME_LIBRARY OR STATIC_CRT)
target_compile_options(${driver_exe_name} PRIVATE "/MT$<$<CONFIG:Debug>:d>")
else()
target_compile_options(${driver_exe_name} PRIVATE "/MD$<$<CONFIG:Debug>:d>")
Expand Down
11 changes: 11 additions & 0 deletions include/aws/common/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ void aws_register_error_info(const struct aws_error_info_list *error_info);
AWS_COMMON_API
void aws_unregister_error_info(const struct aws_error_info_list *error_info);

/**
* Convert a c library io error into an aws error, and raise it.
* If no conversion is found, fallback_aws_error_code is raised.
* Always returns AWS_OP_ERR.
*/
AWS_COMMON_API
int aws_translate_and_raise_io_error_or(int error_no, int fallback_aws_error_code);

/**
* Convert a c library io error into an aws error, and raise it.
* If no conversion is found, AWS_ERROR_SYS_CALL_FAILURE is raised.
Expand Down Expand Up @@ -202,6 +210,9 @@ enum aws_common_error {
AWS_ERROR_INVALID_UTF8,
AWS_ERROR_GET_HOME_DIRECTORY_FAILED,
AWS_ERROR_INVALID_XML,
AWS_ERROR_FILE_OPEN_FAILURE,
AWS_ERROR_FILE_READ_FAILURE,
AWS_ERROR_FILE_WRITE_FAILURE,
AWS_ERROR_END_COMMON_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_COMMON_PACKAGE_ID)
};

Expand Down
2 changes: 2 additions & 0 deletions include/aws/common/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ bool aws_path_exists(const struct aws_string *path);
* fseeko() on linux
*
* whence can either be SEEK_SET or SEEK_END
*
* Returns AWS_OP_SUCCESS, or AWS_OP_ERR (after an error has been raised).
*/
AWS_COMMON_API
int aws_fseek(FILE *file, int64_t offset, int whence);
Expand Down
5 changes: 3 additions & 2 deletions include/aws/common/hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ typedef uint64_t(aws_hash_fn)(const void *key);
* keys, but note that the same type is used for a function that compares
* two hash table values in aws_hash_table_eq.
*
* Equality functions used in a hash table must be reflexive (i.e., a == b if
* and only if b == a), and must be consistent with the hash function in use.
* Equality functions used in a hash table must be be reflexive (a == a),
* symmetric (a == b => b == a), transitive (a == b, b == c => a == c)
* and consistent (result does not change with time).
*/
typedef bool(aws_hash_callback_eq_fn)(const void *a, const void *b);

Expand Down
8 changes: 5 additions & 3 deletions include/aws/testing/aws_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ static int total_skip;

#define SUCCESS (0)
#define FAILURE (-1)
/* The skip code returned to ctest to indicate the test is skipped. Refer to cmake doc:
* https://cmake.org/cmake/help/latest/prop_test/SKIP_RETURN_CODE.html */
#define SKIP (1)
/* The exit code returned to ctest to indicate the test is skipped. Refer to cmake doc:
* https://cmake.org/cmake/help/latest/prop_test/SKIP_RETURN_CODE.html
* The value has no special meaning, it's just an arbitrary exit code reducing the chance of clashing with exit codes
* that may be returned from various tools (e.g. sanitizer). */
#define SKIP (103)

#define POSTSKIP_INTERNAL() \
do { \
Expand Down
23 changes: 16 additions & 7 deletions source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static struct aws_error_info errors[] = {
),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_SYS_CALL_FAILURE,
"System call failure"),
"System call failure."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_FILE_INVALID_PATH,
"Invalid file path."),
Expand All @@ -232,7 +232,7 @@ static struct aws_error_info errors[] = {
"User does not have permission to perform the requested action."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_STREAM_UNSEEKABLE,
"Stream does not support seek operations"),
"Stream does not support seek operations."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_C_STRING_BUFFER_NOT_NULL_TERMINATED,
"A c-string like buffer was passed but a null terminator was not found within the bounds of the buffer."),
Expand All @@ -244,7 +244,7 @@ static struct aws_error_info errors[] = {
"Attempt to divide a number by zero."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_INVALID_FILE_HANDLE,
"Invalid file handle"),
"Invalid file handle."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_OPERATION_INTERUPTED,
"The operation was interrupted."
Expand All @@ -255,16 +255,25 @@ static struct aws_error_info errors[] = {
),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_PLATFORM_NOT_SUPPORTED,
"Feature not supported on this platform"),
"Feature not supported on this platform."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_INVALID_UTF8,
"Invalid UTF-8"),
"Invalid UTF-8."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_GET_HOME_DIRECTORY_FAILED,
"Failed to get home directory"),
"Failed to get home directory."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_INVALID_XML,
"Invalid XML document"),
"Invalid XML document."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_FILE_OPEN_FAILURE,
"Failed opening file."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_FILE_READ_FAILURE,
"Failed reading from file."),
AWS_DEFINE_ERROR_INFO_COMMON(
AWS_ERROR_FILE_WRITE_FAILURE,
"Failed writing to file."),
};
/* clang-format on */

Expand Down
16 changes: 12 additions & 4 deletions source/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,19 @@ void aws_unregister_error_info(const struct aws_error_info_list *error_info) {
}

int aws_translate_and_raise_io_error(int error_no) {
return aws_translate_and_raise_io_error_or(error_no, AWS_ERROR_SYS_CALL_FAILURE);
}

int aws_translate_and_raise_io_error_or(int error_no, int fallback_aws_error_code) {
switch (error_no) {
case EINVAL:
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
case ESPIPE:
return aws_raise_error(AWS_ERROR_STREAM_UNSEEKABLE);
/* If useful fallback code provided, raise that instead of AWS_ERROR_INVALID_ARGUMENT,
* which isn't very useful when it bubbles out from deep within some complex system. */
if (fallback_aws_error_code != AWS_ERROR_SYS_CALL_FAILURE) {
return aws_raise_error(fallback_aws_error_code);
} else {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
case EPERM:
case EACCES:
return aws_raise_error(AWS_ERROR_NO_PERMISSION);
Expand All @@ -217,6 +225,6 @@ int aws_translate_and_raise_io_error(int error_no) {
case ENOTEMPTY:
return aws_raise_error(AWS_ERROR_DIRECTORY_NOT_EMPTY);
default:
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
return aws_raise_error(fallback_aws_error_code);
}
}
Loading

0 comments on commit 4374629

Please sign in to comment.