From c08016dd9d18390cec5f2023b0768b63929825d9 Mon Sep 17 00:00:00 2001 From: David Rowland <drowland96@gmail.com> Date: Thu, 23 May 2024 21:58:00 +0100 Subject: [PATCH] Updated readme --- README.md | 75 ++++++++++++++++------------------ src/lib_rt_check.cpp | 11 ++++- src/lib_rt_check.h | 6 +++ tests/fail_custom_function.cpp | 16 ++++++++ tests/fail_reallocf.cpp | 11 +++++ 5 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 tests/fail_custom_function.cpp create mode 100644 tests/fail_reallocf.cpp diff --git a/README.md b/README.md index 65ff6ec..f5a971c 100644 --- a/README.md +++ b/README.md @@ -2,48 +2,43 @@ Dynamic library to catch run-time safety violations heavily inspired by [RADSan](https://github.com/realtime-sanitizer/radsan) ## Features -- [ ] Enable in scope -- [ ] Disable in scope -- [ ] Symbolicated stack-trace +- [x] Enable in scope +- [x] Disable in scope +- [x] Symbolicated stack-trace - [ ] Build-time flags for checks - [ ] Run-time options for checks -- [ ] Opt-in for own code -- [ ] linux -- [ ] macOS - -## Functions -| First Header | Second Header | -|--------------|---------------| -| - l1 | - [x] | -| - l2 | - [ ] | +- [x] Opt-in for own code +- [x] linux +- [x] macOS (malloc unsupported) +## Functions (test = ✔) - Time - - [x] sleep - - [x] nanosleep - - [x] usleep + - [x] sleep ✔ + - [x] nanosleep ✔ + - [x] usleep ✔ - Memory - - [x] malloc - - [x] calloc - - [x] realloc - - [x] free - - [ ] reallocf (macOS) - - [x] valloc - - [x] posix_memalign - - [x] mmap - - [x] munmap + - [x] malloc ✔ + - [x] calloc ✔ + - [x] realloc ✔ + - [x] free ✔ + - [x] reallocf ✔ + - [x] valloc ✔ + - [x] posix_memalign ✔ + - [x] mmap ✔ + - [x] munmap ✔ - Threads - - [ ] pthread_create - - [ ] pthread_mutex_lock - - [ ] pthread_mutex_unlock - - [ ] pthread_join - - [ ] pthread_cond_signal - - [ ] pthread_cond_broadcast - - [ ] pthread_cond_wait - - [ ] pthread_cond_timedwait - - [ ] pthread_rwlock_rdlock - - [ ] pthread_rwlock_unlock - - [ ] pthread_rwlock_wrlock - - [ ] pthread_spin_lock + - [x] pthread_create + - [x] pthread_mutex_lock ✔ + - [x] pthread_mutex_unlock ✔ + - [x] pthread_join + - [x] pthread_cond_signal + - [x] pthread_cond_broadcast + - [x] pthread_cond_wait + - [x] pthread_cond_timedwait + - [x] pthread_rwlock_rdlock ✔ + - [x] pthread_rwlock_unlock ✔ + - [x] pthread_rwlock_wrlock ✔ + - [x] pthread_spin_lock (linux) - Files - [ ] open - [ ] openat @@ -56,7 +51,7 @@ Dynamic library to catch run-time safety violations heavily inspired by [RADSan] - [ ] creat - [ ] puts - [ ] fputs - - [x] stat + - [x] stat ✔ - [ ] stat64 - [ ] fstat - [ ] fstat64 @@ -70,15 +65,15 @@ Dynamic library to catch run-time safety violations heavily inspired by [RADSan] - [ ] recvfrom - [ ] shutdown - System calls - - [x] syscall + - [x] syscall ✔ ## CI/Tests -- [ ] Failures +- Failures - [x] Throwing exceptions - [x] Large std::function - [x] Atomic 4*ptr size - [ ] Dynamic loading of a library -- [ ] Passes +- Passes - [x] Atomic double - [x] Small std::function - [x] Running on CI Linux diff --git a/src/lib_rt_check.cpp b/src/lib_rt_check.cpp index b76aafa..d7b603d 100644 --- a/src/lib_rt_check.cpp +++ b/src/lib_rt_check.cpp @@ -11,7 +11,7 @@ static bool has_initialised = false; -inline void log_function_if_realtime_context (const char* function_name) +void log_function_if_realtime_context (const char* function_name) { if (! has_initialised) return; @@ -26,6 +26,7 @@ inline void log_function_if_realtime_context (const char* function_name) std::exit (1); } + //============================================================================== // memory //============================================================================== @@ -56,6 +57,14 @@ INTERCEPTOR(void*, realloc, void *ptr, size_t new_size) return REAL(realloc)(ptr, new_size); } +INTERCEPTOR(void *, reallocf, void *ptr, size_t size) +{ + log_function_if_realtime_context (__func__); + + INTERCEPT_FUNCTION(void*, reallocf, void*, size_t); + return REAL(reallocf)(ptr, size); +} + INTERCEPTOR(void*, valloc, size_t size) { log_function_if_realtime_context (__func__); diff --git a/src/lib_rt_check.h b/src/lib_rt_check.h index 11197f1..d9a6d7d 100644 --- a/src/lib_rt_check.h +++ b/src/lib_rt_check.h @@ -90,6 +90,12 @@ struct non_realtime_context } }; + +//============================================================================== +//============================================================================== +void log_function_if_realtime_context (const char* function_name); + + //============================================================================== inline std::string demangle (std::string name) { diff --git a/tests/fail_custom_function.cpp b/tests/fail_custom_function.cpp new file mode 100644 index 0000000..484023f --- /dev/null +++ b/tests/fail_custom_function.cpp @@ -0,0 +1,16 @@ +#include <lib_rt_check.h> + +void my_func() +{ + log_function_if_realtime_context (__func__); +} + +int main() +{ + my_func(); + + realtime_context rc; + my_func(); + + return 0; +} diff --git a/tests/fail_reallocf.cpp b/tests/fail_reallocf.cpp new file mode 100644 index 0000000..6e80e5f --- /dev/null +++ b/tests/fail_reallocf.cpp @@ -0,0 +1,11 @@ +#include <lib_rt_check.h> + +int main() +{ + auto res = malloc (1024); + + realtime_context rc; + res = reallocf (res, 1024 * 4); + + return 0; +}