mirror of
https://github.com/SysRay/psOff_public.git
synced 2024-10-07 03:43:54 +00:00
move runtime| exception handler
This commit is contained in:
parent
ce69cfa241
commit
1f4503fbd5
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)
|
||||
include(ExternalProject)
|
||||
|
||||
set(PSOFF_LIB_VERSION v.0.0)
|
||||
set(PSOFF_RENDER_VERSION v.0.5-nightly_27.04.24 )
|
||||
set(PSOFF_RENDER_VERSION v.0.5-nightly_27.04.24)
|
||||
|
||||
set(ProjectName psOff_${CMAKE_BUILD_TYPE})
|
||||
project(${ProjectName} VERSION 0.0.1)
|
||||
@ -103,6 +103,7 @@ add_subdirectory(modules)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(utility)
|
||||
add_subdirectory(tools/gamereport)
|
||||
add_subdirectory(tools/runtime)
|
||||
|
||||
# #- Projects
|
||||
|
||||
|
@ -320,7 +320,9 @@ EXPORT SYSV_ABI void _sceKernelRtldSetApplicationHeapAPI(void* api[]) {
|
||||
|
||||
EXPORT SYSV_ABI void sceKernelDebugRaiseException(int reason, int id) {
|
||||
LOG_USE_MODULE(libkernel);
|
||||
LOG_CRIT(L"Exception: reason:0x%x id:0x%x", reason, id);
|
||||
|
||||
auto const retAddr = (uint64_t)_ReturnAddress();
|
||||
LOG_CRIT(L"Exception: reason:0x%x id:0x%x @0x%08llx", reason, id, retAddr);
|
||||
}
|
||||
|
||||
EXPORT SYSV_ABI int __NID(__elf_phdr_match_addr)(SceKernelModuleInfoEx* m, uint64_t dtor_vaddr) {
|
||||
|
5
tools/runtime/CMakeLists.txt
Normal file
5
tools/runtime/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
add_library(runtime OBJECT
|
||||
util/exceptionHandler.cpp
|
||||
)
|
56
tools/runtime/util/exceptionHandler.cpp
Normal file
56
tools/runtime/util/exceptionHandler.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include "exceptionHandler.h"
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <mutex>
|
||||
#include <windows.h>
|
||||
|
||||
LOG_DEFINE_MODULE(ExceptionHandler);
|
||||
|
||||
namespace {
|
||||
enum class AccessViolationType { Unknown, Read, Write, Execute };
|
||||
|
||||
LONG WINAPI DefaultExceptionHandler(PEXCEPTION_POINTERS exception) {
|
||||
LOG_USE_MODULE(ExceptionHandler);
|
||||
|
||||
PEXCEPTION_RECORD exceptionRecord = exception->ExceptionRecord;
|
||||
|
||||
auto exceptionAddr = (uint64_t)(exceptionRecord->ExceptionAddress);
|
||||
auto violationAddr = exceptionRecord->ExceptionInformation[1];
|
||||
|
||||
AccessViolationType violationType;
|
||||
switch (exceptionRecord->ExceptionInformation[0]) {
|
||||
case 0: violationType = AccessViolationType::Read; break;
|
||||
case 1: violationType = AccessViolationType::Write; break;
|
||||
case 8: violationType = AccessViolationType::Execute; break;
|
||||
default: LOG_CRIT(L"unknown exception at 0x%08llx", exceptionAddr); break;
|
||||
}
|
||||
|
||||
LOG_CRIT(L"Access violation: %S at addr:0x%08llx info:0x%08llx", magic_enum::enum_name(violationType).data(), exceptionAddr, violationAddr);
|
||||
//(violationVaddr == accessRuntimeLinker().getAddrInvalidMemory() ? L"(Unpatched object)" : L""));
|
||||
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
std::once_flag INSTALL_FLAG;
|
||||
} // namespace
|
||||
|
||||
namespace ExceptionHandler {
|
||||
|
||||
std::unique_ptr<uint8_t[]> install(uint64_t imageAddr, uint64_t imageSize) {
|
||||
auto funcTableData = std::make_unique<uint8_t[]>(sizeof(RUNTIME_FUNCTION));
|
||||
|
||||
auto functionTable = (RUNTIME_FUNCTION*)funcTableData.get();
|
||||
|
||||
functionTable->BeginAddress = 0;
|
||||
functionTable->EndAddress = imageSize;
|
||||
functionTable->UnwindData = 0;
|
||||
|
||||
RtlAddFunctionTable(functionTable, 1, imageAddr);
|
||||
|
||||
std::call_once(INSTALL_FLAG, [] { AddVectoredExceptionHandler(1, DefaultExceptionHandler); });
|
||||
|
||||
return funcTableData;
|
||||
}
|
||||
} // namespace ExceptionHandler
|
8
tools/runtime/util/exceptionHandler.h
Normal file
8
tools/runtime/util/exceptionHandler.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace ExceptionHandler {
|
||||
|
||||
std::unique_ptr<uint8_t[]> install(uint64_t imageAddr, uint64_t imageSize);
|
||||
} // namespace ExceptionHandler
|
Loading…
Reference in New Issue
Block a user