mirror of
https://github.com/InoriRus/Kyty.git
synced 2026-08-28 05:06:40 +00:00
add Linux support
This commit is contained in:
@@ -29,11 +29,7 @@ bool dbg_is_debugger_present();
|
||||
|
||||
} // namespace Kyty::Core
|
||||
|
||||
//#if KYTY_COMPILER == KYTY_COMPILER_MINGW
|
||||
//#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
//#endif
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS || KYTY_PLATFORM == KYTY_PLATFORM_LINUX
|
||||
#define ASSERT_HALT() \
|
||||
(Kyty::Core::dbg_is_debugger_present() ? (::fflush(nullptr), *(reinterpret_cast<volatile int*>(1)) = 0) \
|
||||
: (Kyty::Core::dbg_exit(321), 1))
|
||||
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
virtual ~CondVar();
|
||||
|
||||
void Wait(Mutex* mutex);
|
||||
void WaitFor(Mutex* mutex, uint32_t micros);
|
||||
bool WaitFor(Mutex* mutex, uint32_t micros);
|
||||
void Signal();
|
||||
void SignalAll();
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#ifndef INCLUDE_KYTY_CORE_VIRTUALMEMORY_H_
|
||||
#define INCLUDE_KYTY_CORE_VIRTUALMEMORY_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
||||
struct SystemInfo
|
||||
{
|
||||
String ProcessorName;
|
||||
};
|
||||
|
||||
SystemInfo GetSystemInfo();
|
||||
|
||||
namespace VirtualMemory {
|
||||
|
||||
class ExceptionHandlerPrivate;
|
||||
|
||||
class ExceptionHandler
|
||||
{
|
||||
public:
|
||||
enum class ExceptionType
|
||||
{
|
||||
Unknown,
|
||||
AccessViolation
|
||||
};
|
||||
|
||||
enum class AccessViolationType
|
||||
{
|
||||
Unknown,
|
||||
Read,
|
||||
Write,
|
||||
Execute
|
||||
};
|
||||
|
||||
struct ExceptionInfo
|
||||
{
|
||||
ExceptionType type = ExceptionType::Unknown;
|
||||
AccessViolationType access_violation_type = AccessViolationType::Unknown;
|
||||
uint64_t access_violation_vaddr = 0;
|
||||
uint64_t exception_address = 0;
|
||||
uint64_t rbp = 0;
|
||||
uint32_t exception_win_code = 0;
|
||||
};
|
||||
|
||||
using handler_func_t = void (*)(const ExceptionInfo*);
|
||||
|
||||
ExceptionHandler();
|
||||
virtual ~ExceptionHandler();
|
||||
|
||||
KYTY_CLASS_NO_COPY(ExceptionHandler);
|
||||
|
||||
static uint64_t GetSize();
|
||||
|
||||
bool Install(uint64_t base_address, uint64_t handler_addr, uint64_t image_size, handler_func_t func);
|
||||
bool Uninstall();
|
||||
|
||||
static bool InstallVectored(handler_func_t func);
|
||||
|
||||
private:
|
||||
ExceptionHandlerPrivate* m_p = nullptr;
|
||||
};
|
||||
|
||||
enum class Mode : uint32_t
|
||||
{
|
||||
NoAccess = 0,
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
ReadWrite = Read | Write,
|
||||
Execute = 4,
|
||||
ExecuteRead = Execute | Read,
|
||||
ExecuteWrite = Execute | Write,
|
||||
ExecuteReadWrite = Execute | Read | Write,
|
||||
};
|
||||
|
||||
inline bool IsExecute(Mode mode)
|
||||
{
|
||||
return (mode == Mode::Execute || mode == Mode::ExecuteRead || mode == Mode::ExecuteWrite || mode == Mode::ExecuteReadWrite);
|
||||
}
|
||||
|
||||
void Init();
|
||||
|
||||
uint64_t Alloc(uint64_t address, uint64_t size, Mode mode);
|
||||
uint64_t AllocAligned(uint64_t address, uint64_t size, Mode mode, uint64_t alignment);
|
||||
bool AllocFixed(uint64_t address, uint64_t size, Mode mode);
|
||||
bool Free(uint64_t address);
|
||||
bool Protect(uint64_t address, uint64_t size, Mode mode, Mode* old_mode = nullptr);
|
||||
bool FlushInstructionCache(uint64_t address, uint64_t size);
|
||||
bool PatchReplace(uint64_t vaddr, uint64_t value);
|
||||
|
||||
} // namespace VirtualMemory
|
||||
|
||||
} // namespace Kyty::Core
|
||||
|
||||
#endif /* INCLUDE_KYTY_CORE_VIRTUALMEMORY_H_ */
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_dbg_stack_info_t
|
||||
{
|
||||
uintptr_t code_addr;
|
||||
+16
-10
@@ -8,25 +8,28 @@
|
||||
#else
|
||||
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Sys/SysLinuxTimer.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxTimer.h"
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
enum sys_file_type_t
|
||||
{
|
||||
SYS_FILE_ERROR,
|
||||
SYS_FILE_MEMORY_STAT,
|
||||
SYS_FILE_FILE,
|
||||
SYS_FILE_MEMORY_DYN
|
||||
SYS_FILE_ERROR, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_MEMORY_STAT, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_FILE, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_MEMORY_DYN // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
enum sys_file_cache_type_t
|
||||
{
|
||||
SYS_FILE_CACHE_AUTO = 0,
|
||||
SYS_FILE_CACHE_RANDOM_ACCESS = 1,
|
||||
SYS_FILE_CACHE_SEQUENTIAL_SCAN = 2
|
||||
SYS_FILE_CACHE_AUTO = 0, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_CACHE_RANDOM_ACCESS = 1, // NOLINT(readability-identifier-naming)
|
||||
SYS_FILE_CACHE_SEQUENTIAL_SCAN = 2 // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_file_mem_buf_t
|
||||
{
|
||||
uint8_t* base;
|
||||
@@ -34,6 +37,7 @@ struct sys_file_mem_buf_t
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_file_t
|
||||
{
|
||||
sys_file_type_t type;
|
||||
@@ -44,6 +48,7 @@ struct sys_file_t
|
||||
};
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_file_find_t
|
||||
{
|
||||
String path_with_name;
|
||||
@@ -52,14 +57,15 @@ struct sys_file_find_t
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sys_dir_entry_t
|
||||
{
|
||||
String name;
|
||||
bool is_file;
|
||||
};
|
||||
|
||||
void sys_file_read(void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_read = 0);
|
||||
void sys_file_write(const void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_written = 0);
|
||||
void sys_file_read(void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_read = nullptr);
|
||||
void sys_file_write(const void* data, uint32_t size, sys_file_t& f, uint32_t* bytes_written = nullptr);
|
||||
void sys_file_read_r(void* data, uint32_t size, sys_file_t& f);
|
||||
void sys_file_write_r(const void* data, uint32_t size, sys_file_t& f);
|
||||
sys_file_t* sys_file_create(const String& file_name);
|
||||
@@ -0,0 +1,104 @@
|
||||
#ifndef SYS_LINUX_INCLUDE_KYTY_SYSHEAP_H_
|
||||
#define SYS_LINUX_INCLUDE_KYTY_SYSHEAP_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_LINUX"
|
||||
#else
|
||||
|
||||
#include "Kyty/Sys/Linux/SysLinuxSync.h"
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
using sys_heap_id_t = SysCS*;
|
||||
|
||||
inline sys_heap_id_t sys_heap_create()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline sys_heap_id_t sys_heap_deafult()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline void* sys_heap_alloc(sys_heap_id_t /*heap_id*/, size_t size)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = malloc(size);
|
||||
|
||||
EXIT_IF(m == nullptr);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void* sys_heap_realloc(sys_heap_id_t /*heap_id*/, void* p, size_t size)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = p != nullptr ? realloc(p, size) : malloc(size);
|
||||
|
||||
if (m == nullptr)
|
||||
{
|
||||
EXIT_IF(m == nullptr);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void sys_heap_free(sys_heap_id_t /*heap_id*/, void* p)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
free(p);
|
||||
}
|
||||
|
||||
inline sys_heap_id_t sys_heap_create_s()
|
||||
{
|
||||
auto* cs = new SysCS;
|
||||
cs->Init();
|
||||
return cs;
|
||||
}
|
||||
|
||||
inline void* sys_heap_alloc_s(sys_heap_id_t heap_id, size_t size)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = malloc(size);
|
||||
|
||||
heap_id->Leave();
|
||||
|
||||
EXIT_IF(m == nullptr);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void* sys_heap_realloc_s(sys_heap_id_t heap_id, void* p, size_t size)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
void* m = p != nullptr ? realloc(p, size) : malloc(size);
|
||||
|
||||
heap_id->Leave();
|
||||
|
||||
EXIT_IF(m == nullptr);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void sys_heap_free_s(sys_heap_id_t heap_id, void* p)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,hicpp-no-malloc)
|
||||
free(p);
|
||||
|
||||
heap_id->Leave();
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_LINUX_INCLUDE_KYTY_SYSHEAP_H_ */
|
||||
+4
-4
@@ -8,22 +8,22 @@
|
||||
#else
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <cstdarg>
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
inline uint32_t sys_vscprintf(const char* format, va_list argptr)
|
||||
{
|
||||
int len;
|
||||
va_list argcopy;
|
||||
va_copy(argcopy, argptr);
|
||||
len = vsnprintf(0, 0, format, argcopy);
|
||||
int len = vsnprintf(nullptr, 0, format, argcopy);
|
||||
va_end(argcopy);
|
||||
return len < 0 ? 0 : len;
|
||||
}
|
||||
|
||||
inline uint32_t sys_vsnprintf(char* Dest, size_t Count, const char* Format, va_list Args)
|
||||
inline uint32_t sys_vsnprintf(char* dest, size_t count, const char* format, va_list args)
|
||||
{
|
||||
int len = vsnprintf(Dest, Count + 1, Format, Args);
|
||||
int len = vsnprintf(dest, count + 1, format, args);
|
||||
return len < 0 ? 0 : len;
|
||||
}
|
||||
|
||||
+3
-3
@@ -21,12 +21,12 @@ inline double sys_strtod(const char* nptr, char** endptr)
|
||||
|
||||
inline int32_t sys_strtoi32(const char* nptr, char** endptr, int base)
|
||||
{
|
||||
long r = strtol(nptr, endptr, base);
|
||||
if (r >= static_cast<long>(INT32_MAX))
|
||||
int64_t r = strtol(nptr, endptr, base);
|
||||
if (r >= static_cast<int64_t>(INT32_MAX))
|
||||
{
|
||||
return INT32_MAX;
|
||||
}
|
||||
if (r <= static_cast<long>(INT32_MIN))
|
||||
if (r <= static_cast<int64_t>(INT32_MIN))
|
||||
{
|
||||
return INT32_MIN;
|
||||
}
|
||||
+22
-20
@@ -15,64 +15,66 @@ namespace Kyty {
|
||||
class SysCS
|
||||
{
|
||||
public:
|
||||
SysCS() { check_ptr = 0; }
|
||||
SysCS() = default;
|
||||
|
||||
void Init()
|
||||
{
|
||||
EXIT_IF(check_ptr != 0);
|
||||
EXIT_IF(m_check_ptr != nullptr);
|
||||
|
||||
check_ptr = this;
|
||||
m_check_ptr = this;
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_t attr {};
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
pthread_mutex_init(&m, &attr);
|
||||
pthread_mutex_init(&m_mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
void Delete()
|
||||
{
|
||||
EXIT_IF(check_ptr != this);
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
check_ptr = 0;
|
||||
pthread_mutex_destroy(&m);
|
||||
m_check_ptr = nullptr;
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
}
|
||||
|
||||
~SysCS() { EXIT_IF(check_ptr != 0); }
|
||||
~SysCS() { EXIT_IF(m_check_ptr != nullptr); }
|
||||
|
||||
void Enter()
|
||||
{
|
||||
EXIT_IF(check_ptr != this);
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
pthread_mutex_lock(&m);
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
}
|
||||
|
||||
bool TryEnter()
|
||||
{
|
||||
EXIT_IF(check_ptr != this);
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
return pthread_mutex_trylock(&m) == 0;
|
||||
return pthread_mutex_trylock(&m_mutex) == 0;
|
||||
}
|
||||
|
||||
void Leave()
|
||||
{
|
||||
EXIT_IF(check_ptr != this);
|
||||
EXIT_IF(m_check_ptr != this);
|
||||
|
||||
pthread_mutex_unlock(&m);
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
KYTY_CLASS_NO_COPY(SysCS);
|
||||
|
||||
private:
|
||||
SysCS* check_ptr;
|
||||
pthread_mutex_t m;
|
||||
SysCS* m_check_ptr = nullptr;
|
||||
pthread_mutex_t m_mutex {};
|
||||
};
|
||||
|
||||
inline void sys_sleep(uint32_t ms)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct timespec ts
|
||||
{
|
||||
};
|
||||
ts.tv_sec = ms / 1000;
|
||||
ts.tv_nsec = (ms % 1000) * 1000000;
|
||||
nanosleep(&ts, 0);
|
||||
ts.tv_nsec = static_cast<int64_t>(ms % 1000) * 1000000;
|
||||
nanosleep(&ts, nullptr);
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
+22
-18
@@ -31,9 +31,11 @@ struct SysFileTimeStruct
|
||||
|
||||
inline void sys_file_to_system_time_utc(const SysFileTimeStruct& f, SysTimeStruct& t)
|
||||
{
|
||||
struct tm i;
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
if (f.is_invalid || !gmtime_r(&f.time, &i))
|
||||
if (f.is_invalid || gmtime_r(&f.time, &i) == nullptr)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
@@ -51,7 +53,7 @@ inline void sys_file_to_system_time_utc(const SysFileTimeStruct& f, SysTimeStruc
|
||||
|
||||
inline void sys_time_t_to_system(time_t t, SysTimeStruct& s)
|
||||
{
|
||||
SysFileTimeStruct ft;
|
||||
SysFileTimeStruct ft {};
|
||||
ft.time = t;
|
||||
ft.is_invalid = false;
|
||||
sys_file_to_system_time_utc(ft, s);
|
||||
@@ -66,7 +68,9 @@ inline time_t sys_timegm(struct tm* tm)
|
||||
|
||||
inline void sys_system_to_file_time_utc(const SysTimeStruct& f, SysFileTimeStruct& t)
|
||||
{
|
||||
struct tm i;
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
i.tm_year = f.Year - 1900;
|
||||
i.tm_mon = f.Month - 1;
|
||||
@@ -75,22 +79,18 @@ inline void sys_system_to_file_time_utc(const SysTimeStruct& f, SysFileTimeStruc
|
||||
i.tm_min = f.Minute;
|
||||
i.tm_sec = f.Second;
|
||||
|
||||
if (f.is_invalid || (t.time = sys_timegm(&i)) == (time_t)-1)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
} else
|
||||
{
|
||||
t.is_invalid = false;
|
||||
}
|
||||
t.is_invalid = (f.is_invalid || (t.time = sys_timegm(&i)) == static_cast<time_t>(-1));
|
||||
}
|
||||
|
||||
// Retrieves the current local date and time
|
||||
inline void sys_get_system_time(SysTimeStruct& t)
|
||||
{
|
||||
time_t st;
|
||||
struct tm i;
|
||||
time_t st {};
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
if (time(&st) == (time_t)-1 || !localtime_r(&st, &i))
|
||||
if (time(&st) == static_cast<time_t>(-1) || localtime_r(&st, &i) == nullptr)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
@@ -109,10 +109,12 @@ inline void sys_get_system_time(SysTimeStruct& t)
|
||||
// Retrieves the current system date and time in Coordinated Universal Time (UTC).
|
||||
inline void sys_get_system_time_utc(SysTimeStruct& t)
|
||||
{
|
||||
time_t st;
|
||||
struct tm i;
|
||||
time_t st {};
|
||||
struct tm i
|
||||
{
|
||||
};
|
||||
|
||||
if (time(&st) == (time_t)-1 || !gmtime_r(&st, &i))
|
||||
if (time(&st) == static_cast<time_t>(-1) || gmtime_r(&st, &i) == nullptr)
|
||||
{
|
||||
t.is_invalid = true;
|
||||
return;
|
||||
@@ -135,7 +137,9 @@ inline void sys_query_performance_frequency(uint64_t* freq)
|
||||
|
||||
inline void sys_query_performance_counter(uint64_t* counter)
|
||||
{
|
||||
struct timespec now;
|
||||
struct timespec now
|
||||
{
|
||||
};
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
*counter = now.tv_sec * 1000000000LL + now.tv_nsec;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef INCLUDE_KYTY_SYS_LINUX_SYSLINUXVIRTUAL_H_
|
||||
#define INCLUDE_KYTY_SYS_LINUX_SYSLINUXVIRTUAL_H_
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_LINUX"
|
||||
#else
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Core/VirtualMemory.h"
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
||||
void sys_get_system_info(SystemInfo* info);
|
||||
|
||||
void sys_virtual_init();
|
||||
|
||||
uint64_t sys_virtual_alloc(uint64_t address, uint64_t size, VirtualMemory::Mode mode);
|
||||
uint64_t sys_virtual_alloc_aligned(uint64_t address, uint64_t size, VirtualMemory::Mode mode, uint64_t alignment);
|
||||
bool sys_virtual_alloc_fixed(uint64_t address, uint64_t size, VirtualMemory::Mode mode);
|
||||
bool sys_virtual_free(uint64_t address);
|
||||
bool sys_virtual_protect(uint64_t address, uint64_t size, VirtualMemory::Mode mode, VirtualMemory::Mode* old_mode = nullptr);
|
||||
bool sys_virtual_flush_instruction_cache(uint64_t address, uint64_t size);
|
||||
bool sys_virtual_patch_replace(uint64_t vaddr, uint64_t value);
|
||||
|
||||
} // namespace Kyty::Core
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_LINUX_SYSLINUXVIRTUAL_H_ */
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSDBG_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxDbg.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsDbg.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxDbg.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsDbg.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSDBG_H_ */
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSFILEIO_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxFileIO.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsFileIO.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxFileIO.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsFileIO.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSFILEIO_H_ */
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSHEAP_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxHeap.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsHeap.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxHeap.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsHeap.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSHEAP_H_ */
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
#ifndef SYS_LINUX_INCLUDE_KYTY_SYSHEAP_H_
|
||||
#define SYS_LINUX_INCLUDE_KYTY_SYSHEAP_H_
|
||||
|
||||
// IWYU pragma: private
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_LINUX
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_LINUX"
|
||||
#else
|
||||
|
||||
#include "Kyty/Sys/SysLinuxSync.h"
|
||||
|
||||
namespace Kyty {
|
||||
|
||||
typedef SysCS* sys_heap_id_t;
|
||||
|
||||
inline sys_heap_id_t sys_heap_create()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline sys_heap_id_t sys_heap_deafult()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void* sys_heap_alloc(sys_heap_id_t heap_id, size_t size)
|
||||
{
|
||||
void* m = malloc(size);
|
||||
|
||||
EXIT_IF(m == 0);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void* sys_heap_realloc(sys_heap_id_t heap_id, void* p, size_t size)
|
||||
{
|
||||
void* m = p ? realloc(p, size) : malloc(size);
|
||||
|
||||
if (m == 0)
|
||||
{
|
||||
EXIT_IF(m == 0);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void sys_heap_free(sys_heap_id_t heap_id, void* p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
inline sys_heap_id_t sys_heap_create_s()
|
||||
{
|
||||
SysCS* cs = new SysCS;
|
||||
cs->Init();
|
||||
return cs;
|
||||
}
|
||||
|
||||
inline void* sys_heap_alloc_s(sys_heap_id_t heap_id, size_t size)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
void* m = malloc(size);
|
||||
|
||||
heap_id->Leave();
|
||||
|
||||
EXIT_IF(m == 0);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void* sys_heap_realloc_s(sys_heap_id_t heap_id, void* p, size_t size)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
void* m = p ? realloc(p, size) : malloc(size);
|
||||
|
||||
heap_id->Leave();
|
||||
|
||||
EXIT_IF(m == 0);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void sys_heap_free_s(sys_heap_id_t heap_id, void* p)
|
||||
{
|
||||
heap_id->Enter();
|
||||
|
||||
free(p);
|
||||
|
||||
heap_id->Leave();
|
||||
}
|
||||
|
||||
} // namespace Kyty
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* SYS_LINUX_INCLUDE_KYTY_SYSHEAP_H_ */
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSSTDIO_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxStdio.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsStdio.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdio.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdio.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSTDIO_H_ */
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSSTDLIB_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxStdlib.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsStdlib.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxStdlib.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsStdlib.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSTDLIB_H_ */
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSSYNC_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxSync.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsSync.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxSync.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsSync.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSSYNC_H_ */
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define INCLUDE_KYTY_SYS_SYSTIMER_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
|
||||
#include "Kyty/Sys/SysLinuxTimer.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/SysWindowsTimer.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Linux/SysLinuxTimer.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsTimer.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSTIMER_H_ */
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef INCLUDE_KYTY_SYS_SYSVIRTUAL_H_
|
||||
#define INCLUDE_KYTY_SYS_SYSVIRTUAL_H_
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Sys/Linux/SysLinuxVirtual.h" // IWYU pragma: export
|
||||
#include "Kyty/Sys/Windows/SysWindowsVirtual.h" // IWYU pragma: export
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_SYSVIRTUAL_H_ */
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef INCLUDE_KYTY_SYS_WINDOWS_SYSWINDOWSVIRTUAL_H_
|
||||
#define INCLUDE_KYTY_SYS_WINDOWS_SYSWINDOWSVIRTUAL_H_
|
||||
|
||||
#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS
|
||||
//#error "KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS"
|
||||
#else
|
||||
|
||||
#include "Kyty/Core/Common.h"
|
||||
#include "Kyty/Core/String.h"
|
||||
#include "Kyty/Core/VirtualMemory.h"
|
||||
|
||||
namespace Kyty::Core {
|
||||
|
||||
void sys_get_system_info(SystemInfo* info);
|
||||
|
||||
void sys_virtual_init();
|
||||
|
||||
uint64_t sys_virtual_alloc(uint64_t address, uint64_t size, VirtualMemory::Mode mode);
|
||||
uint64_t sys_virtual_alloc_aligned(uint64_t address, uint64_t size, VirtualMemory::Mode mode, uint64_t alignment);
|
||||
bool sys_virtual_alloc_fixed(uint64_t address, uint64_t size, VirtualMemory::Mode mode);
|
||||
bool sys_virtual_free(uint64_t address);
|
||||
bool sys_virtual_protect(uint64_t address, uint64_t size, VirtualMemory::Mode mode, VirtualMemory::Mode* old_mode = nullptr);
|
||||
bool sys_virtual_flush_instruction_cache(uint64_t address, uint64_t size);
|
||||
bool sys_virtual_patch_replace(uint64_t vaddr, uint64_t value);
|
||||
|
||||
} // namespace Kyty::Core
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* INCLUDE_KYTY_SYS_WINDOWS_SYSWINDOWSVIRTUAL_H_ */
|
||||
Reference in New Issue
Block a user