add Linux support

This commit is contained in:
InoriRus
2022-10-03 15:33:23 +10:00
parent e427645422
commit 37b020e9ba
69 changed files with 2716 additions and 971 deletions
+3 -2
View File
@@ -3,8 +3,9 @@
#include "Kyty/Core/Common.h"
#if (KYTY_COMPILER == KYTY_COMPILER_CLANG || KYTY_COMPILER == KYTY_COMPILER_MINGW) && KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS && \
KYTY_BITNESS == 64 && KYTY_ENDIAN == KYTY_ENDIAN_LITTLE && KYTY_ABI == KYTY_ABI_X86_64 && KYTY_PROJECT == KYTY_PROJECT_EMULATOR
#if (KYTY_COMPILER == KYTY_COMPILER_CLANG || KYTY_COMPILER == KYTY_COMPILER_MINGW || KYTY_COMPILER == KYTY_COMPILER_GCC) && \
(KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS || KYTY_PLATFORM == KYTY_PLATFORM_LINUX) && KYTY_BITNESS == 64 && \
KYTY_ENDIAN == KYTY_ENDIAN_LITTLE && KYTY_ABI == KYTY_ABI_X86_64 && KYTY_PROJECT == KYTY_PROJECT_EMULATOR
#define KYTY_EMU_ENABLED
#endif
@@ -136,14 +136,14 @@ inline long double VaArg_long_double(VaList* l)
return VaArg_overflow_arg_area<long double, 16, 16>(l);
}
inline wint_t VaArg_wint_t(VaList* l)
/*inline wint_t VaArg_wint_t(VaList* l)
{
if (l->gp_offset <= 40)
{
return VaArg_reg_save_area_gp<wint_t, 8>(l);
}
return VaArg_overflow_arg_area<wint_t, 1, 8>(l);
}
}*/
inline VaCharX16 VaArg_char_x16(VaList* l)
{
@@ -12,6 +12,10 @@
#ifdef KYTY_EMU_ENABLED
namespace Kyty::Core::VirtualMemory {
class ExceptionHandler;
} // namespace Kyty::Core::VirtualMemory
namespace Kyty::Loader {
class Elf64;
@@ -19,10 +23,6 @@ struct Elf64_Sym;
struct Elf64_Rela;
class RuntimeLinker;
namespace VirtualMemory {
class ExceptionHandler;
} // namespace VirtualMemory
using module_func_t = int (*)(size_t args, const void* argp);
struct ModuleId
@@ -103,23 +103,23 @@ struct DynamicInfo
struct Program
{
int32_t unique_id = -1;
RuntimeLinker* rt = nullptr;
String file_name;
Elf64* elf = nullptr;
VirtualMemory::ExceptionHandler* exception_handler = nullptr;
DynamicInfo* dynamic_info = nullptr;
uint64_t base_vaddr = 0;
uint64_t base_size = 0;
uint64_t base_size_aligned = 0;
SymbolDatabase* export_symbols = nullptr;
SymbolDatabase* import_symbols = nullptr;
ThreadLocalStorage tls;
bool fail_if_global_not_resolved = true;
bool dbg_print_reloc = false;
uint64_t proc_param_vaddr = 0;
uint64_t custom_call_plt_vaddr = 0;
uint32_t custom_call_plt_num = 0;
int32_t unique_id = -1;
RuntimeLinker* rt = nullptr;
String file_name;
Elf64* elf = nullptr;
Core::VirtualMemory::ExceptionHandler* exception_handler = nullptr;
DynamicInfo* dynamic_info = nullptr;
uint64_t base_vaddr = 0;
uint64_t base_size = 0;
uint64_t base_size_aligned = 0;
SymbolDatabase* export_symbols = nullptr;
SymbolDatabase* import_symbols = nullptr;
ThreadLocalStorage tls;
bool fail_if_global_not_resolved = true;
bool dbg_print_reloc = false;
uint64_t proc_param_vaddr = 0;
uint64_t custom_call_plt_vaddr = 0;
uint32_t custom_call_plt_num = 0;
};
class RuntimeLinker
@@ -1,117 +0,0 @@
#ifndef EMULATOR_INCLUDE_EMULATOR_LOADER_VIRTUALMEMORY_H_
#define EMULATOR_INCLUDE_EMULATOR_LOADER_VIRTUALMEMORY_H_
#include "Kyty/Core/Common.h"
#include "Kyty/Core/String.h"
#include "Emulator/Common.h"
#ifdef KYTY_EMU_ENABLED
namespace Kyty::Loader {
enum class ProcessorArchitecture
{
Unknown,
Amd64, // x64 (AMD or Intel)
};
struct SystemInfo
{
uint32_t PageSize;
uint64_t MinimumApplicationAddress;
uint64_t MaximumApplicationAddress;
uint32_t ActiveProcessorMask;
uint32_t NumberOfProcessors;
ProcessorArchitecture ProcessorArchitecture;
uint32_t AllocationGranularity;
uint16_t ProcessorLevel;
uint16_t ProcessorRevision;
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::Loader
#endif // KYTY_EMU_ENABLED
#endif /* EMULATOR_INCLUDE_EMULATOR_LOADER_VIRTUALMEMORY_H_ */