Skip to content

Commit

Permalink
Add XRPL_ASSERT and XRPL_UNREACHABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Jun 14, 2024
1 parent 27d18be commit 77b867e
Show file tree
Hide file tree
Showing 298 changed files with 2,013 additions and 1,646 deletions.
4 changes: 3 additions & 1 deletion Builds/CMake/RippledCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ else ()
endif ()

if (voidstar)
if (NOT is_linux)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "Antithesis instrumentation requires Debug build type, aborting...")
elseif (NOT is_linux)
message(FATAL_ERROR "Antithesis instrumentation requires Linux, aborting...")
elseif (NOT (is_clang AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0))
message(FATAL_ERROR "Antithesis instrumentation requires Clang version 16 or later, aborting...")
Expand Down
1 change: 1 addition & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ install (
src/ripple/basics/comparators.h
src/ripple/basics/contract.h
src/ripple/basics/hardened_hash.h
src/ripple/basics/instrumentation.h
src/ripple/basics/join.h
src/ripple/basics/make_SSLContext.h
src/ripple/basics/mulDiv.h
Expand Down
5 changes: 4 additions & 1 deletion Builds/levelization/results/loops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ Loop: ripple.app ripple.rpc
Loop: ripple.app ripple.shamap
ripple.app > ripple.shamap

Loop: ripple.basics ripple.beast
ripple.basics > ripple.beast

Loop: ripple.basics ripple.core
ripple.core > ripple.basics

Loop: ripple.basics ripple.json
ripple.json ~= ripple.basics
ripple.json > ripple.basics

Loop: ripple.basics ripple.protocol
ripple.protocol > ripple.basics
Expand Down
1 change: 0 additions & 1 deletion Builds/levelization/results/ordering.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ripple.app > ripple.json
ripple.app > ripple.protocol
ripple.app > ripple.resource
ripple.app > test.unit_test
ripple.basics > ripple.beast
ripple.conditions > ripple.basics
ripple.conditions > ripple.protocol
ripple.consensus > ripple.basics
Expand Down
102 changes: 66 additions & 36 deletions external/antithesis-sdk/antithesis_instrumentation.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,87 @@
#pragma once

/*
This header file enables code coverage instrumentation. It is distributed with the Antithesis C++ SDK.
This header file enables code coverage instrumentation. It is distributed with
the Antithesis C++ SDK.
This header file can be used in both C and C++ programs. (The rest of the SDK works only for C++ programs.)
This header file can be used in both C and C++ programs. (The rest of the SDK
works only for C++ programs.)
You should include it in a single .cpp or .c file.
The instructions (such as required compiler flags) and usage guidance are found at https://antithesis.com/docs/using_antithesis/sdk/cpp_sdk.html.
The instructions (such as required compiler flags) and usage guidance are found
at https://antithesis.com/docs/using_antithesis/sdk/cpp_sdk.html.
*/

#include <unistd.h>
#include <string.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifndef __cplusplus
#include <stdbool.h>
#include <stddef.h>
#endif

// If the libvoidstar(determ) library is present,
// If the libvoidstar(determ) library is present,
// pass thru trace_pc_guard related callbacks to it
typedef void (*trace_pc_guard_init_fn)(uint32_t *start, uint32_t *stop);
typedef void (*trace_pc_guard_fn)(uint32_t *guard, uint64_t edge);
typedef void (*trace_pc_guard_init_fn)(uint32_t* start, uint32_t* stop);
typedef void (*trace_pc_guard_fn)(uint32_t* guard, uint64_t edge);

static trace_pc_guard_init_fn trace_pc_guard_init = NULL;
static trace_pc_guard_fn trace_pc_guard = NULL;
static bool did_check_libvoidstar = false;
static bool has_libvoidstar = false;

static __attribute__((no_sanitize("coverage"))) void debug_message_out(const char *msg) {
(void)printf("%s\n", msg);
return;
static __attribute__((no_sanitize("coverage"))) void
debug_message_out(const char* msg)
{
(void)printf("%s\n", msg);
return;
}

extern
#ifdef __cplusplus
"C"
#endif
__attribute__((no_sanitize("coverage"))) void antithesis_load_libvoidstar() {
__attribute__((no_sanitize("coverage"))) void
antithesis_load_libvoidstar()
{
#ifdef __cplusplus
constexpr
#endif
const char* LIB_PATH = "/usr/lib/libvoidstar.so";
const char* LIB_PATH = "/usr/lib/libvoidstar.so";

if (did_check_libvoidstar) {
return;
if (did_check_libvoidstar)
{
return;
}
debug_message_out("TRYING TO LOAD libvoidstar");
did_check_libvoidstar = true;
void* shared_lib = dlopen(LIB_PATH, RTLD_NOW);
if (!shared_lib) {
if (!shared_lib)
{
debug_message_out("Can not load the Antithesis native library");
return;
}

void* trace_pc_guard_init_sym = dlsym(shared_lib, "__sanitizer_cov_trace_pc_guard_init");
if (!trace_pc_guard_init_sym) {
debug_message_out("Can not forward calls to libvoidstar for __sanitizer_cov_trace_pc_guard_init");
void* trace_pc_guard_init_sym =
dlsym(shared_lib, "__sanitizer_cov_trace_pc_guard_init");
if (!trace_pc_guard_init_sym)
{
debug_message_out(
"Can not forward calls to libvoidstar for "
"__sanitizer_cov_trace_pc_guard_init");
return;
}

void* trace_pc_guard_sym = dlsym(shared_lib, "__sanitizer_cov_trace_pc_guard_internal");
if (!trace_pc_guard_sym) {
debug_message_out("Can not forward calls to libvoidstar for __sanitizer_cov_trace_pc_guard");
void* trace_pc_guard_sym =
dlsym(shared_lib, "__sanitizer_cov_trace_pc_guard_internal");
if (!trace_pc_guard_sym)
{
debug_message_out(
"Can not forward calls to libvoidstar for "
"__sanitizer_cov_trace_pc_guard");
return;
}

Expand All @@ -74,38 +91,51 @@ __attribute__((no_sanitize("coverage"))) void antithesis_load_libvoidstar() {
debug_message_out("LOADED libvoidstar");
}

// The following symbols are indeed reserved identifiers, since we're implementing functions defined
// in the compiler runtime. Not clear how to get Clang on board with that besides narrowly suppressing
// the warning in this case. The sample code on the CoverageSanitizer documentation page fails this
// The following symbols are indeed reserved identifiers, since we're
// implementing functions defined in the compiler runtime. Not clear how to get
// Clang on board with that besides narrowly suppressing the warning in this
// case. The sample code on the CoverageSanitizer documentation page fails this
// warning!
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-identifier"
extern
extern
#ifdef __cplusplus
"C"
#endif
void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) {
debug_message_out("SDK forwarding to libvoidstar for __sanitizer_cov_trace_pc_guard_init()");
if (!did_check_libvoidstar) {
void
__sanitizer_cov_trace_pc_guard_init(uint32_t* start, uint32_t* stop)
{
debug_message_out(
"SDK forwarding to libvoidstar for "
"__sanitizer_cov_trace_pc_guard_init()");
if (!did_check_libvoidstar)
{
antithesis_load_libvoidstar();
}
if (has_libvoidstar) {
if (has_libvoidstar)
{
trace_pc_guard_init(start, stop);
}
return;
}

extern
extern
#ifdef __cplusplus
"C"
#endif
void __sanitizer_cov_trace_pc_guard( uint32_t *guard ) {
if (has_libvoidstar) {
void
__sanitizer_cov_trace_pc_guard(uint32_t* guard)
{
if (has_libvoidstar)
{
uint64_t edge = (uint64_t)(__builtin_return_address(0));
trace_pc_guard(guard, edge);
} else {
if (guard) {
*guard = 0;
}
else
{
if (guard)
{
*guard = 0;
}
}
return;
Expand Down
Loading

0 comments on commit 77b867e

Please sign in to comment.