Providing an exception object and removing unnecessary assert statements

This commit is contained in:
Gabriel Correia 2023-09-29 11:09:03 -07:00
parent 55123258b4
commit 6bef528fc3
12 changed files with 58 additions and 36 deletions

BIN
.gitignore vendored

Binary file not shown.

View File

@ -25,7 +25,7 @@ target_include_directories(zenith PRIVATE ${ZENITH_MISC_DIR} ${ZENITH_DIR})
target_sources(zenith PRIVATE target_sources(zenith PRIVATE
${ZENITH_DIR}/app.cpp ${ZENITH_DIR}/app.cpp
${ZENITH_DIR}/paper_logger.cpp ${ZENITH_DIR}/logger.cpp
${ZENITH_DIR}/eeiv/ee_engine.cpp ${ZENITH_DIR}/eeiv/ee_engine.cpp
${ZENITH_DIR}/eeiv/cop0.cpp ${ZENITH_DIR}/eeiv/cop0.cpp
${ZENITH_DIR}/eeiv/mmu_tlb.cpp ${ZENITH_DIR}/eeiv/mmu_tlb.cpp

View File

@ -7,8 +7,8 @@
// is started by Java Runtime using System.loadLibrary("zenith") // is started by Java Runtime using System.loadLibrary("zenith")
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
auto desiredVersion{JNI_VERSION_1_6}; auto desiredVersion{JNI_VERSION_1_6};
// Kickstart the user readable log system also called as, PalePaper // Kickstart the user readable log system also called as, GlobalLogger
zenith::userLog = std::make_shared<zenith::PalePaper>(); zenith::userLog = std::make_shared<zenith::GlobalLogger>();
zenith::deviceRes = std::make_unique<zenith::java::JvmManager>(vm); zenith::deviceRes = std::make_unique<zenith::java::JvmManager>(vm);

View File

@ -2,7 +2,7 @@
namespace zenith { namespace zenith {
std::unique_ptr<java::JvmManager> deviceRes; std::unique_ptr<java::JvmManager> deviceRes;
std::shared_ptr<PalePaper> userLog; std::shared_ptr<GlobalLogger> userLog;
std::unique_ptr<CoreApplication> zenithApp; std::unique_ptr<CoreApplication> zenithApp;
CoreApplication::CoreApplication() CoreApplication::CoreApplication()

View File

@ -4,7 +4,7 @@
#include <console/virtual_devices.h> #include <console/virtual_devices.h>
#include <java/device_handler.h> #include <java/device_handler.h>
#include <paper_logger.h> #include <logger.h>
namespace zenith { namespace zenith {
class CoreApplication { class CoreApplication {
@ -18,5 +18,5 @@ namespace zenith {
extern std::unique_ptr<java::JvmManager> deviceRes; extern std::unique_ptr<java::JvmManager> deviceRes;
extern std::unique_ptr<CoreApplication> zenithApp; extern std::unique_ptr<CoreApplication> zenithApp;
extern std::shared_ptr<PalePaper> userLog; extern std::shared_ptr<GlobalLogger> userLog;
} }

View File

@ -1,5 +1,5 @@
#include <cstring> #include <cstring>
#include <paper_debug.h> #include <verify.h>
#include <eeiv/mmu_tlb.h> #include <eeiv/mmu_tlb.h>
namespace zenith::eeiv { namespace zenith::eeiv {
@ -27,7 +27,11 @@ namespace zenith::eeiv {
// directly to the table entries // directly to the table entries
for (auto segmentPage{kUnmapStart}; segmentPage != kUnmapEnd; segmentPage += 4096) { for (auto segmentPage{kUnmapStart}; segmentPage != kUnmapEnd; segmentPage += 4096) {
auto kVTable{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)); kernelVTLB[kVTable] = choiceMemSrc(segmentPage & (0x20000000 - 1));
if (segmentPage < 0xa0000000) if (segmentPage < 0xa0000000)

View File

@ -2,7 +2,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <paper_debug.h> #include <verify.h>
namespace zenith { namespace zenith {
using u8 = uint8_t; using u8 = uint8_t;
using u16 = uint16_t; using u16 = uint16_t;
@ -27,10 +27,13 @@ namespace zenith {
int basicFd; int basicFd;
void operator=(int fileNativeFd) { void operator=(int fileNativeFd) {
PaperRtAssertPersistent(fileNativeFd == invalidFileDescriptor, ""); if (fileNativeFd == invalidFileDescriptor) {
throw exception::runtime_fault("Corrupted file descriptor being passed without checking");
}
basicFd = fileNativeFd; basicFd = fileNativeFd;
fstat(basicFd, &lastStates); fstat(basicFd, &lastStates);
PaperRtAssert((lastStates.st_mode & S_IFMT) == S_IFREG, ""); VerifyRtAssert((lastStates.st_mode & S_IFMT) == S_IFREG);
} }
auto operator*()-> int { auto operator*()-> int {
return basicFd; return basicFd;

View File

@ -0,0 +1,8 @@
#include <logger.h>
namespace zenith {
void verifyRtCheck(bool condition, std::function<void()> func) {
[[unlikely]] if (condition)
func();
}
}

View File

@ -6,19 +6,19 @@
#include <impltypes.h> #include <impltypes.h>
namespace zenith { namespace zenith {
enum PaleLevel { enum LoggerLevel {
PaleInfo = ANDROID_LOG_INFO, Info = ANDROID_LOG_INFO,
PaleDebug = ANDROID_LOG_DEBUG, Debug = ANDROID_LOG_DEBUG,
PaleVerbose = ANDROID_LOG_VERBOSE, Verbose = ANDROID_LOG_VERBOSE,
PaleError = ANDROID_LOG_ERROR, Error = ANDROID_LOG_ERROR,
}; };
class PalePaper { class GlobalLogger {
public: public:
private: private:
ZenFile logFile{}; ZenFile logFile{};
// Don't allow these specific levels to be threaded or printed to the user // Don't allow these specific levels to be threaded or printed to the user
std::vector<PaleLevel> refuseLevels{}; std::vector<LoggerLevel> refuseLevels{};
}; };
} }

View File

@ -1,16 +0,0 @@
#pragma once
#include <cassert>
#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

View File

@ -1,2 +0,0 @@
#include <paper_logger.h>
namespace zenith {}

View File

@ -0,0 +1,25 @@
#pragma once
#include <cassert>
#include <functional>
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<void()> func);
}
#if defined(DEBUG)
#define VerifyRtAssert(cond)\
paperRtCheck(cond, [](){\
assert(cond);\
})
#else
#define VerifyRtAssert(cond)\
(void)(cond)
#endif