mirror of https://github.com/InoriRus/Kyty.git
add macos support
This commit is contained in:
parent
cbad2533e4
commit
c6701e2f0d
Binary file not shown.
|
@ -6,9 +6,6 @@ if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
|
|||
set(LINUX TRUE)
|
||||
endif()
|
||||
|
||||
if (NOT ((WIN32 AND (MINGW OR MSVC)) OR LINUX))
|
||||
message(FATAL_ERROR "only mingw and msvc supported (or linux)")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSDBG_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxDbg.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSDbg.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsDbg.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxDbg.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSDbg.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSDBG_H_ */
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSFILEIO_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxFileIO.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSFileIO.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsFileIO.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxFileIO.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSFileIO.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSFILEIO_H_ */
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSHEAP_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxHeap.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSHeap.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsHeap.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxHeap.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSHeap.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSHEAP_H_ */
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSSTDIO_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdio.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSStdio.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdio.h" // IWYU pragma: export
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdio.h" //
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSStdio.h" //
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdio.h" //
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSTDIO_H_ */
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSSTDLIB_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdlib.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSStdlib.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdlib.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdlib.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSStdlib.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSTDLIB_H_ */
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSSYNC_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxSync.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSSync.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsSync.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxSync.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSSync.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSYNC_H_ */
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSTIMER_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxTimer.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSTimer.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsTimer.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxTimer.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSTimer.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSTIMER_H_ */
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
#define INCLUDE_KYTY_SYS_SYSVIRTUAL_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxVirtual.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/MacOS/SysMacOSVirtual.h" // IWYU pragma: export
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include "Kyty/Sys/Windows/SysWindowsVirtual.h" // IWYU pragma: export
|
||||
#elif __linux__
|
||||
#include "Kyty/Sys/Linux/SysLinuxVirtual.h" // IWYU pragma: export
|
||||
#elif __APPLE__
|
||||
#include "Kyty/Sys/MacOS/SysMacOSVirtual.h" // IWYU pragma: export
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSVIRTUAL_H_ */
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Sys/SysTimer.h"
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
namespace Kyty {
|
||||
|
||||
using KYTY_HANDLE = void*;
|
||||
|
@ -120,4 +120,6 @@ void sys_file_remove_readonly(const String& name);
|
|||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_WIN32_INCLUDE_KYTY_SYSFILEIO_H_ */
|
||||
|
|
|
@ -7,122 +7,124 @@
|
|||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
struct SysTimeStruct
|
||||
{
|
||||
uint16_t Year; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Month; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Day; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Hour; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Minute; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Second; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Milliseconds; // NOLINT(readability-identifier-naming)
|
||||
bool is_invalid; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Year; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Month; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Day; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Hour; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Minute; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Second; // NOLINT(readability-identifier-naming)
|
||||
uint16_t Milliseconds; // NOLINT(readability-identifier-naming)
|
||||
bool is_invalid; // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
|
||||
struct SysFileTimeStruct
|
||||
{
|
||||
FILETIME time;
|
||||
bool is_invalid;
|
||||
FILETIME time;
|
||||
bool is_invalid;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_file_to_system_time_utc(const SysFileTimeStruct& f, SysTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
SYSTEMTIME s;
|
||||
|
||||
if (f.is_invalid || (FileTimeToSystemTime(&f.time, &s) == 0))
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
if (f.is_invalid || (FileTimeToSystemTime(&f.time, &s) == 0))
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_time_t_to_system(time_t t, SysTimeStruct& s)
|
||||
{
|
||||
SysFileTimeStruct ft {};
|
||||
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
|
||||
ft.time.dwLowDateTime = static_cast<DWORD>(ll);
|
||||
ft.time.dwHighDateTime = static_cast<DWORD>(static_cast<uint64_t>(ll) >> 32u);
|
||||
ft.is_invalid = false;
|
||||
sys_file_to_system_time_utc(ft, s);
|
||||
SysFileTimeStruct ft {};
|
||||
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
|
||||
ft.time.dwLowDateTime = static_cast<DWORD>(ll);
|
||||
ft.time.dwHighDateTime = static_cast<DWORD>(static_cast<uint64_t>(ll) >> 32u);
|
||||
ft.is_invalid = false;
|
||||
sys_file_to_system_time_utc(ft, s);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_system_to_file_time_utc(const SysTimeStruct& f, SysFileTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
SYSTEMTIME s;
|
||||
|
||||
s.wYear = f.Year;
|
||||
s.wMonth = f.Month;
|
||||
s.wDay = f.Day;
|
||||
s.wHour = f.Hour;
|
||||
s.wMinute = f.Minute;
|
||||
s.wSecond = f.Second;
|
||||
s.wMilliseconds = f.Milliseconds;
|
||||
s.wYear = f.Year;
|
||||
s.wMonth = f.Month;
|
||||
s.wDay = f.Day;
|
||||
s.wHour = f.Hour;
|
||||
s.wMinute = f.Minute;
|
||||
s.wSecond = f.Second;
|
||||
s.wMilliseconds = f.Milliseconds;
|
||||
|
||||
t.is_invalid = (f.is_invalid || (SystemTimeToFileTime(&s, &t.time) == 0));
|
||||
t.is_invalid = (f.is_invalid || (SystemTimeToFileTime(&s, &t.time) == 0));
|
||||
}
|
||||
|
||||
// Retrieves the current local date and time
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_get_system_time(SysTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
GetLocalTime(&s);
|
||||
SYSTEMTIME s;
|
||||
GetLocalTime(&s);
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
}
|
||||
|
||||
// Retrieves the current system date and time in Coordinated Universal Time (UTC).
|
||||
// NOLINTNEXTLINE(google-runtime-references)
|
||||
inline void sys_get_system_time_utc(SysTimeStruct& t)
|
||||
{
|
||||
SYSTEMTIME s;
|
||||
GetSystemTime(&s);
|
||||
SYSTEMTIME s;
|
||||
GetSystemTime(&s);
|
||||
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
t.is_invalid = false;
|
||||
t.Year = s.wYear;
|
||||
t.Month = s.wMonth;
|
||||
t.Day = s.wDay;
|
||||
t.Hour = s.wHour;
|
||||
t.Minute = s.wMinute;
|
||||
t.Second = (s.wSecond == 60 ? 59 : s.wSecond);
|
||||
t.Milliseconds = s.wMilliseconds;
|
||||
}
|
||||
|
||||
inline void sys_query_performance_frequency(uint64_t* freq)
|
||||
{
|
||||
LARGE_INTEGER f;
|
||||
QueryPerformanceFrequency(&f);
|
||||
*freq = f.QuadPart;
|
||||
LARGE_INTEGER f;
|
||||
QueryPerformanceFrequency(&f);
|
||||
*freq = f.QuadPart;
|
||||
}
|
||||
|
||||
inline void sys_query_performance_counter(uint64_t* counter)
|
||||
{
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
*counter = c.QuadPart;
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
*counter = c.QuadPart;
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
@ -130,3 +132,5 @@ inline void sys_query_performance_counter(uint64_t* counter)
|
|||
#endif
|
||||
|
||||
#endif /* SYS_WIN32_INCLUDE_KYTY_SYSTIMER_H_ */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,13 +47,6 @@ endif()
|
|||
|
||||
add_dependencies(launcher KytyGitVersion)
|
||||
|
||||
if(NOT LINUX)
|
||||
find_program(QT_WINDEPLOYQT NAMES windeployqt PATHS "${Qt5_DIR}/../../../bin")
|
||||
if(NOT QT_WINDEPLOYQT)
|
||||
message(FATAL_ERROR "Could not find windeployqt")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(launcher_name "launcher")
|
||||
|
||||
set_target_properties(launcher PROPERTIES OUTPUT_NAME ${launcher_name})
|
||||
|
|
|
@ -1188,7 +1188,7 @@ bool ZipReader::GetFileStat(int file_index, ZipFileStat* o)
|
|||
o->m_file_index = s.m_file_index;
|
||||
|
||||
SysTimeStruct at = {0};
|
||||
sys_time_t_to_system(s.m_time, at);
|
||||
sys_time_t_to_system(s.m_time, at);
|
||||
o->m_time = DateTime(Date(at.Year, at.Month, at.Day), Time(at.Hour, at.Minute, at.Second, at.Milliseconds));
|
||||
|
||||
o->m_crc32 = s.m_crc32;
|
||||
|
|
|
@ -17,11 +17,25 @@
|
|||
#include "Kyty/Core/DbgAssert.h"
|
||||
#include "Kyty/Sys/SysDbg.h"
|
||||
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#include <psapi.h> // IWYU pragma: keep
|
||||
#ifdef _WIN64
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#include <psapi.h> // IWYU pragma: keep
|
||||
#else
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#include <psapi.h> // IWYU pragma: keep
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
|
||||
|
||||
#if KYTY_COMPILER == KYTY_COMPILER_MSVC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
#include <psapi.h> // IWYU pragma: keep
|
||||
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
|
@ -35,10 +49,9 @@ static thread_local sys_dbg_stack_info_t g_stack = {0};
|
|||
|
||||
struct FrameS
|
||||
{
|
||||
struct FrameS* next;
|
||||
void* ret_addr;
|
||||
struct FrameS* next;
|
||||
void* ret_addr;
|
||||
};
|
||||
|
||||
constexpr DWORD READABLE =
|
||||
(static_cast<DWORD>(PAGE_EXECUTE_READ) | static_cast<DWORD>(PAGE_EXECUTE_READWRITE) | static_cast<DWORD>(PAGE_EXECUTE_WRITECOPY) |
|
||||
static_cast<DWORD>(PAGE_READONLY) | static_cast<DWORD>(PAGE_READWRITE) | static_cast<DWORD>(PAGE_WRITECOPY));
|
||||
|
@ -48,94 +61,94 @@ exception_filter_func_t g_exception_filter_func = nullptr;
|
|||
|
||||
bool sys_mem_read_allowed(void* ptr)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
|
||||
size_t s = VirtualQuery(ptr, &mbi, sizeof(mbi));
|
||||
size_t s = VirtualQuery(ptr, &mbi, sizeof(mbi));
|
||||
|
||||
if (s == 0)
|
||||
{
|
||||
EXIT_IF(s == 0);
|
||||
}
|
||||
if (s == 0)
|
||||
{
|
||||
EXIT_IF(s == 0);
|
||||
}
|
||||
|
||||
return ((mbi.Protect & PROTECTED) == 0u) && ((mbi.State & static_cast<DWORD>(MEM_COMMIT)) != 0u) &&
|
||||
((mbi.AllocationProtect & READABLE) != 0u);
|
||||
return ((mbi.Protect & PROTECTED) == 0u) && ((mbi.State & static_cast<DWORD>(MEM_COMMIT)) != 0u) &&
|
||||
((mbi.AllocationProtect & READABLE) != 0u);
|
||||
}
|
||||
|
||||
// LONG WINAPI
|
||||
// VectoredHandlerSkip(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
||||
//{
|
||||
// PCONTEXT Context;
|
||||
// PCONTEXT Context;
|
||||
//
|
||||
// g_need_break = true;
|
||||
// g_need_break = true;
|
||||
//
|
||||
// Context = ExceptionInfo->ContextRecord;
|
||||
// Context = ExceptionInfo->ContextRecord;
|
||||
//#ifdef _AMD64_
|
||||
// Context->Rip++;
|
||||
// Context->Rip++;
|
||||
//#else
|
||||
// Context->Eip++;
|
||||
// Context->Eip++;
|
||||
//#endif
|
||||
// return EXCEPTION_CONTINUE_EXECUTION;
|
||||
// return EXCEPTION_CONTINUE_EXECUTION;
|
||||
//}
|
||||
|
||||
#if KYTY_BITNESS == 32
|
||||
static void stackwalk(void* ebp, void** stack, int* depth, uintptr_t stack_addr, size_t stack_size)
|
||||
{
|
||||
frame_t* frame = (frame_t*)ebp;
|
||||
frame_t* frame = (frame_t*)ebp;
|
||||
|
||||
int d = *depth;
|
||||
int d = *depth;
|
||||
|
||||
int i;
|
||||
int i;
|
||||
|
||||
// printf("1\n");
|
||||
for (i = 0; i < KYTY_FRAME_SKIP; i++)
|
||||
{
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (!sys_mem_read_allowed(&frame->next)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
// printf("1\n");
|
||||
for (i = 0; i < KYTY_FRAME_SKIP; i++)
|
||||
{
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (!sys_mem_read_allowed(&frame->next)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
|
||||
frame = frame->next;
|
||||
}
|
||||
// printf("2\n");
|
||||
for (i = 0; i < d; i++)
|
||||
{
|
||||
//#ifdef _MSC_VER
|
||||
// __try
|
||||
// {
|
||||
//#endif
|
||||
// FILE *f = fopen("_sw", "wt");
|
||||
// printf("%d, %08x\n", i, (uint32_t)frame);
|
||||
// fflush(stdout);
|
||||
// fclose(f);
|
||||
// printf("%d, %08x, %08x, %08x\n", i, (uint32_t)frame,
|
||||
// (uint32_t)frame->ret_addr, (uint32_t)frame->next);
|
||||
frame = frame->next;
|
||||
}
|
||||
// printf("2\n");
|
||||
for (i = 0; i < d; i++)
|
||||
{
|
||||
//#ifdef _MSC_VER
|
||||
// __try
|
||||
// {
|
||||
//#endif
|
||||
// FILE *f = fopen("_sw", "wt");
|
||||
// printf("%d, %08x\n", i, (uint32_t)frame);
|
||||
// fflush(stdout);
|
||||
// fclose(f);
|
||||
// printf("%d, %08x, %08x, %08x\n", i, (uint32_t)frame,
|
||||
// (uint32_t)frame->ret_addr, (uint32_t)frame->next);
|
||||
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (uintptr_t(frame) == 0 || frame->ret_addr == 0 ) break;
|
||||
// if (uintptr_t(frame) <= 0xffff || (uintptr_t(frame) & 0xf0000000)
|
||||
// || frame->ret_addr == 0
|
||||
// || (uintptr_t(frame->ret_addr) & 0xf0000000)
|
||||
// || (uintptr_t(frame->next) & 0xf0000000)) break;
|
||||
// if (uintptr_t(frame) == 0 || frame->ret_addr == 0 ) break;
|
||||
|
||||
// if (!sys_mem_read_allowed(&frame->next) || !sys_mem_read_allowed(&frame->ret_addr)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
// if (!sys_mem_read_allowed(&frame->next) || !sys_mem_read_allowed(&frame->ret_addr)) break;
|
||||
if (!(uintptr_t(frame) >= stack_addr && uintptr_t(frame) < stack_addr + stack_size)) break;
|
||||
|
||||
// if (g_need_break) break;
|
||||
// if (g_need_break) break;
|
||||
|
||||
stack[i] = frame->ret_addr;
|
||||
stack[i] = frame->ret_addr;
|
||||
|
||||
frame = frame->next;
|
||||
//#ifdef _MSC_VER
|
||||
// } __except(EXCEPTION_EXECUTE_HANDLER)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
// printf("3\n");
|
||||
frame = frame->next;
|
||||
//#ifdef _MSC_VER
|
||||
// } __except(EXCEPTION_EXECUTE_HANDLER)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
// printf("3\n");
|
||||
|
||||
*depth = i;
|
||||
*depth = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -143,159 +156,161 @@ static void stackwalk(void* ebp, void** stack, int* depth, uintptr_t stack_addr,
|
|||
void sys_stack_walk(void** stack, int* depth)
|
||||
{
|
||||
#if KYTY_COMPILER == KYTY_COMPILER_MSVC
|
||||
void* ebp = (size_t*)_AddressOfReturnAddress() - 1;
|
||||
void* ebp = (size_t*)_AddressOfReturnAddress() - 1;
|
||||
#else
|
||||
void* ebp = __builtin_frame_address(0);
|
||||
void* ebp = __builtin_frame_address(0);
|
||||
#endif
|
||||
|
||||
// g_need_break = false;
|
||||
// g_need_break = false;
|
||||
|
||||
//#ifndef _MSC_VER
|
||||
// PVOID p = AddVectoredExceptionHandler(1000, VectoredHandlerSkip);
|
||||
// if (!g_stack_addr) g_stack_addr = (uintptr_t)&depth;
|
||||
///#endif
|
||||
//#ifndef _MSC_VER
|
||||
// PVOID p = AddVectoredExceptionHandler(1000, VectoredHandlerSkip);
|
||||
// if (!g_stack_addr) g_stack_addr = (uintptr_t)&depth;
|
||||
///#endif
|
||||
|
||||
if (g_stack.total_size == 0)
|
||||
{
|
||||
sys_stack_usage(g_stack);
|
||||
}
|
||||
if (g_stack.total_size == 0)
|
||||
{
|
||||
sys_stack_usage(g_stack);
|
||||
}
|
||||
|
||||
stackwalk(ebp, stack, depth, g_stack.addr, g_stack.total_size);
|
||||
stackwalk(ebp, stack, depth, g_stack.addr, g_stack.total_size);
|
||||
|
||||
//#ifndef _MSC_VER
|
||||
// RemoveVectoredExceptionHandler(p);
|
||||
//#endif
|
||||
//#ifndef _MSC_VER
|
||||
// RemoveVectoredExceptionHandler(p);
|
||||
//#endif
|
||||
}
|
||||
#else
|
||||
//#include <unwind.h>
|
||||
// struct unwind_info_t
|
||||
//{
|
||||
// void **stack;
|
||||
// int depth;
|
||||
// int max_depth;
|
||||
// void **stack;
|
||||
// int depth;
|
||||
// int max_depth;
|
||||
//};
|
||||
//_Unwind_Reason_Code trace_fcn(_Unwind_Context *ctx, void *d)
|
||||
//{
|
||||
// unwind_info_t *info = (unwind_info_t*)d;
|
||||
// unwind_info_t *info = (unwind_info_t*)d;
|
||||
// //printf("\t#%d: program counter at %08x\n", *depth, _Unwind_GetIP(ctx));
|
||||
// //(*depth)++;
|
||||
// if (info->depth < info->max_depth)
|
||||
// {
|
||||
// void *ptr = (void*)_Unwind_GetIP(ctx);
|
||||
// info->stack[info->depth] = ptr;
|
||||
// info->depth++;
|
||||
// }
|
||||
// if (info->depth < info->max_depth)
|
||||
// {
|
||||
// void *ptr = (void*)_Unwind_GetIP(ctx);
|
||||
// info->stack[info->depth] = ptr;
|
||||
// info->depth++;
|
||||
// }
|
||||
// return _URC_NO_REASON;
|
||||
//}
|
||||
int WalkStack(int z_stack_depth, void** z_stack_trace)
|
||||
{
|
||||
CONTEXT context;
|
||||
// KNONVOLATILE_CONTEXT_POINTERS NvContext;
|
||||
PRUNTIME_FUNCTION runtime_function = nullptr;
|
||||
PVOID handler_data = nullptr;
|
||||
ULONG64 establisher_frame = 0;
|
||||
ULONG64 image_base = 0;
|
||||
CONTEXT context;
|
||||
// KNONVOLATILE_CONTEXT_POINTERS NvContext;
|
||||
PRUNTIME_FUNCTION runtime_function = nullptr;
|
||||
PVOID handler_data = nullptr;
|
||||
ULONG64 establisher_frame = 0;
|
||||
ULONG64 image_base = 0;
|
||||
|
||||
RtlCaptureContext(&context);
|
||||
RtlCaptureContext(&context);
|
||||
|
||||
int frame = 0;
|
||||
int frame = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (frame >= z_stack_depth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
if (frame >= z_stack_depth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
z_stack_trace[frame] = reinterpret_cast<void*>(context.Rip);
|
||||
z_stack_trace[frame] = reinterpret_cast<void*>(context.Rip);
|
||||
|
||||
frame++;
|
||||
frame++;
|
||||
|
||||
runtime_function = RtlLookupFunctionEntry(context.Rip, &image_base, nullptr);
|
||||
runtime_function = RtlLookupFunctionEntry(context.Rip, &image_base, nullptr);
|
||||
|
||||
if (runtime_function == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (runtime_function == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// RtlZeroMemory(&NvContext, sizeof(KNONVOLATILE_CONTEXT_POINTERS));
|
||||
RtlVirtualUnwind(0, image_base, context.Rip, runtime_function, &context, &handler_data, &establisher_frame, nullptr /*&NvContext*/);
|
||||
// RtlZeroMemory(&NvContext, sizeof(KNONVOLATILE_CONTEXT_POINTERS));
|
||||
RtlVirtualUnwind(0, image_base, context.Rip, runtime_function, &context, &handler_data, &establisher_frame, nullptr /*&NvContext*/);
|
||||
|
||||
if (context.Rip == 0u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (context.Rip == 0u)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return frame;
|
||||
return frame;
|
||||
}
|
||||
|
||||
void sys_stack_walk(void** stack, int* depth)
|
||||
{
|
||||
// USHORT n = CaptureStackBackTrace(KYTY_FRAME_SKIP, *depth, stack, 0);
|
||||
int n = WalkStack(*depth, stack);
|
||||
*depth = n;
|
||||
// unwind_info_t info = {stack, 0, *depth};
|
||||
// _Unwind_Backtrace(&trace_fcn, &info);
|
||||
// *depth = info.depth;
|
||||
// USHORT n = CaptureStackBackTrace(KYTY_FRAME_SKIP, *depth, stack, 0);
|
||||
int n = WalkStack(*depth, stack);
|
||||
*depth = n;
|
||||
// unwind_info_t info = {stack, 0, *depth};
|
||||
// _Unwind_Backtrace(&trace_fcn, &info);
|
||||
// *depth = info.depth;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sys_stack_usage_print(sys_dbg_stack_info_t& stack)
|
||||
{
|
||||
printf("stack: (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ")\n",
|
||||
static_cast<uint64_t>(stack.reserved_addr), static_cast<uint64_t>(stack.reserved_size), static_cast<uint64_t>(stack.guard_addr),
|
||||
static_cast<uint64_t>(stack.guard_size), static_cast<uint64_t>(stack.commited_addr), static_cast<uint64_t>(stack.commited_size));
|
||||
printf("stack: (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ") + (0x%" PRIx64 ", %" PRIu64 ")\n",
|
||||
static_cast<uint64_t>(stack.reserved_addr), static_cast<uint64_t>(stack.reserved_size), static_cast<uint64_t>(stack.guard_addr),
|
||||
static_cast<uint64_t>(stack.guard_size), static_cast<uint64_t>(stack.commited_addr), static_cast<uint64_t>(stack.commited_size));
|
||||
}
|
||||
|
||||
void sys_stack_usage(sys_dbg_stack_info_t& s)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi {};
|
||||
[[maybe_unused]] size_t ss = VirtualQuery(&mbi, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
PVOID reserved = mbi.AllocationBase;
|
||||
ss = VirtualQuery(reserved, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
size_t reserved_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(reserved) + reserved_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* guard_page = mbi.BaseAddress;
|
||||
size_t guard_page_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(guard_page) + guard_page_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* commited = mbi.BaseAddress;
|
||||
size_t commited_size = mbi.RegionSize;
|
||||
s.reserved_addr = reinterpret_cast<uintptr_t>(reserved);
|
||||
s.reserved_size = reserved_size;
|
||||
s.guard_addr = reinterpret_cast<uintptr_t>(guard_page);
|
||||
s.guard_size = guard_page_size;
|
||||
s.commited_addr = reinterpret_cast<uintptr_t>(commited);
|
||||
s.commited_size = commited_size;
|
||||
MEMORY_BASIC_INFORMATION mbi {};
|
||||
[[maybe_unused]] size_t ss = VirtualQuery(&mbi, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
PVOID reserved = mbi.AllocationBase;
|
||||
ss = VirtualQuery(reserved, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
size_t reserved_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(reserved) + reserved_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* guard_page = mbi.BaseAddress;
|
||||
size_t guard_page_size = mbi.RegionSize;
|
||||
ss = VirtualQuery(static_cast<char*>(guard_page) + guard_page_size, &mbi, sizeof(mbi));
|
||||
EXIT_IF(ss == 0);
|
||||
void* commited = mbi.BaseAddress;
|
||||
size_t commited_size = mbi.RegionSize;
|
||||
s.reserved_addr = reinterpret_cast<uintptr_t>(reserved);
|
||||
s.reserved_size = reserved_size;
|
||||
s.guard_addr = reinterpret_cast<uintptr_t>(guard_page);
|
||||
s.guard_size = guard_page_size;
|
||||
s.commited_addr = reinterpret_cast<uintptr_t>(commited);
|
||||
s.commited_size = commited_size;
|
||||
|
||||
s.addr = s.reserved_addr;
|
||||
s.total_size = s.reserved_size + s.guard_size + s.commited_size;
|
||||
s.addr = s.reserved_addr;
|
||||
s.total_size = s.reserved_size + s.guard_size + s.commited_size;
|
||||
}
|
||||
|
||||
void sys_get_code_info(uintptr_t* addr, size_t* size)
|
||||
{
|
||||
MODULEINFO info {};
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &info, sizeof(MODULEINFO));
|
||||
*addr = reinterpret_cast<uintptr_t>(info.lpBaseOfDll);
|
||||
*size = static_cast<size_t>(info.SizeOfImage);
|
||||
MODULEINFO info {};
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &info, sizeof(MODULEINFO));
|
||||
*addr = reinterpret_cast<uintptr_t>(info.lpBaseOfDll);
|
||||
*size = static_cast<size_t>(info.SizeOfImage);
|
||||
}
|
||||
|
||||
static LONG WINAPI ExceptionFilter(PEXCEPTION_POINTERS exception)
|
||||
{
|
||||
g_exception_filter_func(exception->ExceptionRecord->ExceptionAddress);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
g_exception_filter_func(exception->ExceptionRecord->ExceptionAddress);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
void sys_set_exception_filter(exception_filter_func_t func)
|
||||
{
|
||||
g_exception_filter_func = func;
|
||||
SetUnhandledExceptionFilter(ExceptionFilter);
|
||||
g_exception_filter_func = func;
|
||||
SetUnhandledExceptionFilter(ExceptionFilter);
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -12,8 +12,13 @@
|
|||
#include "Kyty/Sys/SysFileIO.h"
|
||||
#include "Kyty/Sys/SysTimer.h"
|
||||
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#ifdef _WIN64
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#else
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#endif
|
||||
// IWYU pragma: no_include <fileapi.h>
|
||||
// IWYU pragma: no_include <handleapi.h>
|
||||
// IWYU pragma: no_include <minwinbase.h>
|
||||
|
@ -641,3 +646,4 @@ void sys_file_remove_readonly(const String& name)
|
|||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -10,8 +10,13 @@
|
|||
#include "Kyty/Sys/SysVirtual.h"
|
||||
|
||||
#include "cpuinfo.h"
|
||||
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#ifdef _WIN64
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#else
|
||||
#include <windows.h> // IWYU pragma: keep
|
||||
#endif
|
||||
|
||||
// IWYU pragma: no_include <basetsd.h>
|
||||
// IWYU pragma: no_include <errhandlingapi.h>
|
||||
|
@ -257,3 +262,5 @@ bool sys_virtual_patch_replace(uint64_t vaddr, uint64_t value)
|
|||
} // namespace Kyty::Core
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue