diff --git a/.gitignore b/.gitignore index aa724b7..6fda15c 100644 Binary files a/.gitignore and b/.gitignore differ diff --git a/app/src/main/CMakeLists.txt b/app/src/main/CMakeLists.txt index a38d339..ea1b06a 100644 --- a/app/src/main/CMakeLists.txt +++ b/app/src/main/CMakeLists.txt @@ -25,7 +25,7 @@ target_include_directories(zenith PRIVATE ${ZENITH_MISC_DIR} ${ZENITH_DIR}) target_sources(zenith PRIVATE ${ZENITH_DIR}/app.cpp - ${ZENITH_DIR}/paper_logger.cpp + ${ZENITH_DIR}/logger.cpp ${ZENITH_DIR}/eeiv/ee_engine.cpp ${ZENITH_DIR}/eeiv/cop0.cpp ${ZENITH_DIR}/eeiv/mmu_tlb.cpp diff --git a/app/src/main/cpp/jvm_comm.cpp b/app/src/main/cpp/jvm_comm.cpp index d32177a..8ec4c92 100644 --- a/app/src/main/cpp/jvm_comm.cpp +++ b/app/src/main/cpp/jvm_comm.cpp @@ -7,8 +7,8 @@ // is started by Java Runtime using System.loadLibrary("zenith") extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { auto desiredVersion{JNI_VERSION_1_6}; - // Kickstart the user readable log system also called as, PalePaper - zenith::userLog = std::make_shared(); + // 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