From 6bef528fc39ed4b74357ca131bf8b5413b25c533 Mon Sep 17 00:00:00 2001 From: Gabriel Correia Date: Fri, 29 Sep 2023 11:09:03 -0700 Subject: [PATCH] Providing an exception object and removing unnecessary assert statements --- .gitignore | Bin 225 -> 294 bytes app/src/main/CMakeLists.txt | 2 +- app/src/main/cpp/jvm_comm.cpp | 4 +-- app/src/main/cpp/zenith/app.cpp | 2 +- app/src/main/cpp/zenith/app.h | 4 +-- app/src/main/cpp/zenith/eeiv/mmu_tlb.cpp | 8 ++++-- app/src/main/cpp/zenith/impltypes.h | 9 ++++--- app/src/main/cpp/zenith/logger.cpp | 8 ++++++ .../cpp/zenith/{paper_logger.h => logger.h} | 14 +++++----- app/src/main/cpp/zenith/paper_debug.h | 16 ----------- app/src/main/cpp/zenith/paper_logger.cpp | 2 -- app/src/main/cpp/zenith/verify.h | 25 ++++++++++++++++++ 12 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 app/src/main/cpp/zenith/logger.cpp rename app/src/main/cpp/zenith/{paper_logger.h => logger.h} (50%) delete mode 100644 app/src/main/cpp/zenith/paper_debug.h delete mode 100644 app/src/main/cpp/zenith/paper_logger.cpp create mode 100644 app/src/main/cpp/zenith/verify.h diff --git a/.gitignore b/.gitignore index aa724b77071afcbd9bb398053e05adaf7ac9405a..6fda15c3d1b2ea7f0ca6b19ebe1a88c44d860bbf 100644 GIT binary patch literal 294 zcmZusI}XAy49y&=7hy>5fM8|mz=+($Di&@NIcbSFJt=f(1+x5m@7b~sh6Zl5=>!4Uk!m`qs~u0zitj}*b-4jo}Wd&)s}D5Qk> zN-q%KV$L-7>n?L@Z*5gC=XDdYuh~J&lPvcbEE#14zCflKk6(dtr8N5Y8BnpBRiaRF Qbx^6sM(JApW9)}}177=CY5)KL literal 225 zcmZXPu@1s83`F;Q3WNI(2v(L3jL1!_V&Nu{h=W-%2)RL$ zM}e#(); + // Kickstart the user readable log system also called as, GlobalLogger + zenith::userLog = std::make_shared(); zenith::deviceRes = std::make_unique(vm); diff --git a/app/src/main/cpp/zenith/app.cpp b/app/src/main/cpp/zenith/app.cpp index 45bc6d9..6fb6782 100644 --- a/app/src/main/cpp/zenith/app.cpp +++ b/app/src/main/cpp/zenith/app.cpp @@ -2,7 +2,7 @@ namespace zenith { std::unique_ptr deviceRes; - std::shared_ptr userLog; + std::shared_ptr userLog; std::unique_ptr zenithApp; CoreApplication::CoreApplication() diff --git a/app/src/main/cpp/zenith/app.h b/app/src/main/cpp/zenith/app.h index 96fe2f6..3d34693 100644 --- a/app/src/main/cpp/zenith/app.h +++ b/app/src/main/cpp/zenith/app.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace zenith { class CoreApplication { @@ -18,5 +18,5 @@ namespace zenith { extern std::unique_ptr deviceRes; extern std::unique_ptr zenithApp; - extern std::shared_ptr userLog; + extern std::shared_ptr userLog; } diff --git a/app/src/main/cpp/zenith/eeiv/mmu_tlb.cpp b/app/src/main/cpp/zenith/eeiv/mmu_tlb.cpp index 36de52f..9f6fdc9 100644 --- a/app/src/main/cpp/zenith/eeiv/mmu_tlb.cpp +++ b/app/src/main/cpp/zenith/eeiv/mmu_tlb.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include namespace zenith::eeiv { @@ -27,7 +27,11 @@ namespace zenith::eeiv { // directly to the table entries for (auto segmentPage{kUnmapStart}; segmentPage != kUnmapEnd; segmentPage += 4096) { auto kVTable{segmentPage / 4096}; - PaperRtAssert(kVTable < 1024 * 1024, ""); + + if (kVTable >= 1024 * 1024) { + throw exception::runtime_fault("Kernel TLB table is outside the specified range"); + } + kernelVTLB[kVTable] = choiceMemSrc(segmentPage & (0x20000000 - 1)); if (segmentPage < 0xa0000000) diff --git a/app/src/main/cpp/zenith/impltypes.h b/app/src/main/cpp/zenith/impltypes.h index 4b8decb..7cdd157 100644 --- a/app/src/main/cpp/zenith/impltypes.h +++ b/app/src/main/cpp/zenith/impltypes.h @@ -2,7 +2,7 @@ #include #include -#include +#include namespace zenith { using u8 = uint8_t; using u16 = uint16_t; @@ -27,10 +27,13 @@ namespace zenith { int basicFd; void operator=(int fileNativeFd) { - PaperRtAssertPersistent(fileNativeFd == invalidFileDescriptor, ""); + if (fileNativeFd == invalidFileDescriptor) { + throw exception::runtime_fault("Corrupted file descriptor being passed without checking"); + } basicFd = fileNativeFd; + fstat(basicFd, &lastStates); - PaperRtAssert((lastStates.st_mode & S_IFMT) == S_IFREG, ""); + VerifyRtAssert((lastStates.st_mode & S_IFMT) == S_IFREG); } auto operator*()-> int { return basicFd; diff --git a/app/src/main/cpp/zenith/logger.cpp b/app/src/main/cpp/zenith/logger.cpp new file mode 100644 index 0000000..76226f0 --- /dev/null +++ b/app/src/main/cpp/zenith/logger.cpp @@ -0,0 +1,8 @@ +#include + +namespace zenith { + void verifyRtCheck(bool condition, std::function func) { + [[unlikely]] if (condition) + func(); + } +} diff --git a/app/src/main/cpp/zenith/paper_logger.h b/app/src/main/cpp/zenith/logger.h similarity index 50% rename from app/src/main/cpp/zenith/paper_logger.h rename to app/src/main/cpp/zenith/logger.h index 2e27a17..20f60f0 100644 --- a/app/src/main/cpp/zenith/paper_logger.h +++ b/app/src/main/cpp/zenith/logger.h @@ -6,19 +6,19 @@ #include namespace zenith { - enum PaleLevel { - PaleInfo = ANDROID_LOG_INFO, - PaleDebug = ANDROID_LOG_DEBUG, - PaleVerbose = ANDROID_LOG_VERBOSE, - PaleError = ANDROID_LOG_ERROR, + enum LoggerLevel { + Info = ANDROID_LOG_INFO, + Debug = ANDROID_LOG_DEBUG, + Verbose = ANDROID_LOG_VERBOSE, + Error = ANDROID_LOG_ERROR, }; - class PalePaper { + class GlobalLogger { public: private: ZenFile logFile{}; // Don't allow these specific levels to be threaded or printed to the user - std::vector refuseLevels{}; + std::vector refuseLevels{}; }; } diff --git a/app/src/main/cpp/zenith/paper_debug.h b/app/src/main/cpp/zenith/paper_debug.h deleted file mode 100644 index bc0ad6a..0000000 --- a/app/src/main/cpp/zenith/paper_debug.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -#define PaperRtAssertPersistent(cond, assertMessage)\ - [[unlikely]] if (!(cond))\ - assert((cond)) - -#if defined(DEBUG) -#define PaperRtAssert(cond, assertMessage)\ - [[unlikely]] if (!(cond))\ - assert((cond)) -#else -#define PaperRtAssert(cond, assertMessage)\ - (void)(cond) -#endif diff --git a/app/src/main/cpp/zenith/paper_logger.cpp b/app/src/main/cpp/zenith/paper_logger.cpp deleted file mode 100644 index 56b04c4..0000000 --- a/app/src/main/cpp/zenith/paper_logger.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include -namespace zenith {} diff --git a/app/src/main/cpp/zenith/verify.h b/app/src/main/cpp/zenith/verify.h new file mode 100644 index 0000000..4de9a51 --- /dev/null +++ b/app/src/main/cpp/zenith/verify.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +namespace zenith { + namespace exception { + class runtime_fault : public std::runtime_error { + public: + runtime_fault(const std::string& faultMessage) : std::runtime_error(faultMessage) {} + runtime_fault(const char* faultMessage) : std::runtime_error(faultMessage) {} + }; + } + void verifyRtCheck(bool condition, std::function func); +} + +#if defined(DEBUG) +#define VerifyRtAssert(cond)\ + paperRtCheck(cond, [](){\ + assert(cond);\ + }) +#else +#define VerifyRtAssert(cond)\ + (void)(cond) +#endif