From 62d37d227de14a1422de6fc08d9846ec0109163d Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sun, 19 May 2024 12:07:50 +0200 Subject: [PATCH] Remove Security system as it is useless --- CHANGELOG.md | 1 + include/renderd7/Security.hpp | 69 ----------------------------------- include/renderd7/font.hpp | 4 +- include/renderd7/renderd7.hpp | 1 - rd7tf/source/main.cpp | 2 +- source/Hardware.cpp | 13 +++---- source/Security.cpp | 69 ----------------------------------- source/internal_db.cpp | 2 +- source/renderd7.cpp | 38 ++++++++++--------- 9 files changed, 32 insertions(+), 167 deletions(-) delete mode 100644 include/renderd7/Security.hpp delete mode 100644 source/Security.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index cdcfe79..6d145ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Add LinearAllocator (for std) - Fix Crash in FilsSystem - Implement basic Theme System +- Remove 0.9.4 Security ## 0.9.4 - Implement new Security System To prevent from crashes - Implement Functiontrace for better Timing Tests diff --git a/include/renderd7/Security.hpp b/include/renderd7/Security.hpp deleted file mode 100644 index cbf2fc9..0000000 --- a/include/renderd7/Security.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * This file is part of RenderD7 - * Copyright (C) 2021-2024 NPI-D7, tobid7 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once -#include <3ds.h> - -namespace RenderD7 { -namespace Init { -void Security(); -} - -class Security { - public: - /// @brief Security Levels - enum Level { - NONE, ///< Do Completly Nothing (excludes FrameEnd Security) - FULL, ///< Display Every Reports even Success - ERRORS, ///< Display Only Errors - WARNINGS, ///< Display Errors and Warnings - LOG, ///< Log Every Error with Detailed Information - }; - - Security(); - ~Security(); - /// @brief Set the Security Level - /// @param level Level to use - void SetLevel(Level level); - /// @brief Get Current Security Level - /// @return Security Level - Level GetLevel(); - /// @brief Call a Function at Program Crash/Exit - /// @param exit_func Function to Call - void SafeExit(void (*exit_func)()); - /// @brief SaveInit a Function and define a Exit Func - /// @param init_func Init Function - /// @param exit_func Exit Function - void SafeInit(void (*init_func)(), void (*exit_func)()); - /// @brief SaveInit a Function and define a Exit Func - /// @param init_func Init Function - /// @param exit_func Exit Function - void SafeInit(Result (*init_func)(), void (*exit_func)()); - /// @brief SaveInit a Function and define a Exit Func - /// @param init_func Init Function - /// @param exit_func Exit Function - void SafeInit(void (*init_func)(), Result (*exit_func)()); - /// @brief SaveInit a Function and define a Exit Func - /// @param init_func Init Function - /// @param exit_func Exit Function - void SafeInit(Result (*init_func)(), Result (*exit_func)()); -}; -} // namespace RenderD7 - -/// @brief RenderD7 Security Object -extern RenderD7::Security *rd7_security; diff --git a/include/renderd7/font.hpp b/include/renderd7/font.hpp index f17dcef..c6616d8 100644 --- a/include/renderd7/font.hpp +++ b/include/renderd7/font.hpp @@ -31,8 +31,8 @@ class Font { Font(const std::string& path) { Load(path); }; ~Font() { Unload(); } using Ref = std::shared_ptr; - template - inline static Ref New(args &&...a) { + template + inline static Ref New(args&&... a) { return std::make_shared(std::forward(a)...); } void Load(const std::string& path) { diff --git a/include/renderd7/renderd7.hpp b/include/renderd7/renderd7.hpp index 23e9727..17a6190 100644 --- a/include/renderd7/renderd7.hpp +++ b/include/renderd7/renderd7.hpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/rd7tf/source/main.cpp b/rd7tf/source/main.cpp index aa5f437..27c0543 100644 --- a/rd7tf/source/main.cpp +++ b/rd7tf/source/main.cpp @@ -29,7 +29,7 @@ int main() { auto fnt = RD7::Font::New("romfs:/roboto_bold.bcfnt"); RD7::TextFont(fnt); // IdbServer(); - //RD7::Init::NdspFirm(); + // RD7::Init::NdspFirm(); RD7::Scene::Load(std::make_unique()); RD7::Ftrace::End("app", "app_init"); while (RD7::MainLoop()) { diff --git a/source/Hardware.cpp b/source/Hardware.cpp index 4a39067..b4011c0 100644 --- a/source/Hardware.cpp +++ b/source/Hardware.cpp @@ -17,21 +17,20 @@ */ #include -#include +#include // Os Specific includes #include <3ds.h> -// RenderD7 Security -extern bool isndspinit; - void RenderD7::Hardware::Initialisize() { - rd7_security->SafeInit(mcuHwcInit, &mcuHwcExit); - rd7_security->SafeInit(ptmuInit, &ptmuExit); + mcuHwcInit(); + atexit(mcuHwcExit); + ptmuInit(); + atexit(ptmuExit); } bool RenderD7::Hardware::IsHeadphones() { - if (isndspinit) { + if (rd7i_is_ndsp) { bool inserted; DSP_GetHeadphoneStatus(&inserted); return inserted; diff --git a/source/Security.cpp b/source/Security.cpp deleted file mode 100644 index 305dd7b..0000000 --- a/source/Security.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * This file is part of RenderD7 - * Copyright (C) 2021-2024 NPI-D7, tobid7 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include <3ds.h> -#include -#include - -#include -#include - -RenderD7::Security *rd7_security; - -bool *running_addr = NULL; -RenderD7::Security::Level rd7i_slvl = RenderD7::Security::Level::NONE; - -RenderD7::Security::Level RenderD7::Security::GetLevel() { return rd7i_slvl; } - -void RenderD7::Security::SetLevel(RenderD7::Security::Level level) { - rd7i_slvl = level; -} - -namespace RenderD7 { -Security::Security() { running_addr = &rd7i_running; } - -Security::~Security() { *running_addr = false; } -void Security::SafeExit(void (*exit_func)()) { atexit(exit_func); } - -void Security::SafeInit(void (*init_func)(), void (*exit_func)()) { - init_func(); - atexit(exit_func); -} - -void Security::SafeInit(Result (*init_func)(), void (*exit_func)()) { - init_func(); - atexit(exit_func); -} - -void Security::SafeInit(void (*init_func)(), Result (*exit_func)()) { - init_func(); - atexit(reinterpret_cast(exit_func)); -} - -void Security::SafeInit(Result (*init_func)(), Result (*exit_func)()) { - init_func(); - atexit(reinterpret_cast(exit_func)); -} -} // namespace RenderD7 -namespace RenderD7 { -namespace Init { -void Security() { - rd7_security = new RenderD7::Security(); // Load and Init the Security System -} -} // namespace Init -} // namespace RenderD7 \ No newline at end of file diff --git a/source/internal_db.cpp b/source/internal_db.cpp index 3d1e60e..61a5fe5 100644 --- a/source/internal_db.cpp +++ b/source/internal_db.cpp @@ -230,7 +230,7 @@ void ServerThread(RenderD7::Parameter param) { return; } rd7i_idb_running = true; - rd7_security->SafeExit(KillIdbServer); + atexit(KillIdbServer); tcp_server server("0.0.0.0", 4727); int cmd = 0; while (true && !rd7i_idb_fp) { diff --git a/source/renderd7.cpp b/source/renderd7.cpp index 5fbb0eb..aacbe2a 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -36,6 +36,7 @@ static void RD7i_ExitHook() { C2D_TextBufDelete(rd7i_text_buffer); C2D_TextBufDelete(rd7i_d2_dimbuf); + romfsExit(); } std::vector string_to_lines(std::string input_str) { @@ -231,7 +232,8 @@ bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x, } void RenderD7::Init::NdspFirm() { if (access("sdmc:/3ds/dspfirm.cdc", F_OK) != -1) { - rd7_security->SafeInit(ndspInit, ndspExit); + ndspInit(); + atexit(ndspExit); rd7i_is_ndsp = true; } else { RenderD7::PushMessage(RenderD7::Message( @@ -336,24 +338,26 @@ Result RenderD7::Init::Main(std::string app_name) { rd7i_app_name = app_name; /// The only func that can be executed before Security RenderD7::Ftrace::Beg("rd7-core", f2s(RenderD7::Init::Main)); - RenderD7::Init::Security(); - rd7_security->SafeInit(gfxInitDefault, gfxExit); + gfxInitDefault(); + atexit(gfxExit); // Speedup osSetSpeedupEnable(true); // consoleInit(GFX_TOP, NULL); - rd7_security->SafeInit(cfguInit, cfguExit); + cfguInit(); + atexit(cfguExit); CFGU_SecureInfoGetRegion(&rd7i_system_region); CFGU_GetSystemModel(&rd7i_console_model); - rd7_security->SafeInit(aptInit, aptExit); - rd7_security->SafeInit(romfsInit, romfsExit); + aptInit(); + atexit(aptExit); + romfsInit(); C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - rd7_security->SafeExit(C3D_Fini); + atexit(C3D_Fini); C2D_Init((size_t)rd7_max_objects); - rd7_security->SafeExit(C2D_Fini); - rd7_security->SafeExit(RD7i_ExitHook); + atexit(C2D_Fini); + atexit(RD7i_ExitHook); C2D_Prepare(); Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT); @@ -372,7 +376,7 @@ Result RenderD7::Init::Main(std::string app_name) { rd7i_init_input(); rd7i_init_theme(); UI7::Init(); - rd7_security->SafeExit(UI7::Deinit); + atexit(UI7::Deinit); RenderD7::Ftrace::End("rd7-core", f2s(RenderD7::Init::Main)); rd7i_running = true; return 0; @@ -380,17 +384,17 @@ Result RenderD7::Init::Main(std::string app_name) { Result RenderD7::Init::Minimal(std::string app_name) { rd7i_app_name = app_name; - RenderD7::Init::Security(); - rd7_security->SafeInit(gfxInitDefault, gfxExit); - rd7_security->SafeInit(romfsInit, romfsExit); + gfxInitDefault(); + atexit(gfxExit); + romfsInit(); osSetSpeedupEnable(true); C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - rd7_security->SafeExit(C3D_Fini); + atexit(C3D_Fini); C2D_Init((size_t)rd7_max_objects); - rd7_security->SafeExit(C2D_Fini); - rd7_security->SafeExit(RD7i_ExitHook); + atexit(C2D_Fini); + atexit(RD7i_ExitHook); C2D_Prepare(); Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT); @@ -410,7 +414,7 @@ Result RenderD7::Init::Minimal(std::string app_name) { rd7i_init_input(); rd7i_init_theme(); UI7::Init(); - rd7_security->SafeExit(UI7::Deinit); + atexit(UI7::Deinit); rd7i_running = true; return 0; }