Skip to content

Commit

Permalink
Improve compiler compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Oct 13, 2024
1 parent 43578c3 commit 1f9a892
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions riscvm/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion riscvm/cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RISCVM_CUSTOM_SYSCALLS = false
[target.riscvm]
type = "executable"
sources = ["main.cpp", "riscvm.cpp"]
headers = ["riscvm.h", "opcodes.h", "shuffled_opcodes.h", "trace.h"]
headers = ["riscvm.h", "opcodes.h", "shuffled_opcodes.h", "trace.h", "riscvm-code.h"]
compile-features = ["cxx_std_17"]
RISCVM_DIRECT_DISPATCH.compile-definitions = ["DIRECT_DISPATCH"]
RISCVM_CODE_ENCRYPTION.compile-definitions = ["CODE_ENCRYPTION"]
Expand Down
18 changes: 10 additions & 8 deletions riscvm/riscvm-code.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#include <stdint.h>

#ifdef _WIN32
#pragma section(".vmcode", read, write)
__declspec(align(4096)) uint8_t g_code[0x10000];
#pragma section(".vmstack", read, write)
__declspec(align(4096)) uint8_t g_stack[0x10000];
#if defined(__GNUC__) || defined(__clang__)
#define RISCVM_SECTION(name, decl) decl __attribute__((section(name), aligned(0x1000)))
#elif defined(_MSC_VER)
#define RISCVM_SECTION(name, decl) __pragma(section, name, read, write) __declspec(align(0x1000)) decl
#else
uint8_t g_code[0x10000] __attribute__((aligned(0x1000)));
uint8_t g_stack[0x10000] __attribute__((aligned(0x1000)));
#endif // _WIN32
#warning Unsupported compiler
#define RISCVM_SECTION(name, decl) decl
#endif // __GNUC__

RISCVM_SECTION(".vmcode", static uint8_t g_code[0x10000]);
RISCVM_SECTION(".vmstack", static uint8_t g_stack[0x10000]);
10 changes: 5 additions & 5 deletions riscvm/riscvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#elif defined(__GNUC__)
#define __debugbreak() __builtin_trap()
#else
#warning Unsupported platform/compiler
#pragma message("Unsupported platform/compiler")
#include <signal.h>
#define __debugbreak() raise(SIGTRAP)
#endif // _MSC_VER
Expand All @@ -24,7 +24,7 @@
bool g_trace;

#ifdef CODE_ENCRYPTION
#warning Code encryption enabled
#pragma message("Code encryption enabled")

ALWAYS_INLINE static uint32_t tetra_twist(uint32_t input)
{
Expand Down Expand Up @@ -67,7 +67,7 @@ ALWAYS_INLINE static uint32_t riscvm_fetch(riscvm_ptr self)
}

#ifdef CUSTOM_SYSCALLS
#warning Custom syscalls enabled
#pragma message("Custom syscalls enabled")
#else
ALWAYS_INLINE static bool riscvm_handle_syscall(riscvm_ptr self, uint64_t code, uint64_t& result)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ ALWAYS_INLINE static bool riscvm_handle_syscall(riscvm_ptr self, uint64_t code,
#ifdef _WIN32
result = __readgsqword(0x60);
#else
#warning get_peb unsupported on this platform
#pragma message("get_peb unsupported on this platform")
#endif // _WIN32
break;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ ALWAYS_INLINE static __int128 riscvm_shr_int128(__int128 a, __int128 b)
}

#ifdef DIRECT_DISPATCH
#warning Direct dispatch enabled
#pragma message("Direct dispatch enabled")
#define HANDLER(op) handler_##op
#define FWHANDLER(op) static bool HANDLER(op)(riscvm_ptr self, Instruction inst)
FWHANDLER(rv64_load);
Expand Down
4 changes: 2 additions & 2 deletions riscvm/riscvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <wchar.h>

#ifdef TRACING
#warning Tracing enabled
#pragma message("Tracing enabled")

extern bool g_trace;

Expand Down Expand Up @@ -257,7 +257,7 @@ enum RegIndex
};

#ifdef OPCODE_SHUFFLING
#warning Opcode shuffling enabled
#pragma message("Opcode shuffling enabled")
#include "shuffled_opcodes.h"
#else
#include "opcodes.h"
Expand Down

0 comments on commit 1f9a892

Please sign in to comment.