|
| 1 | +From f07b3895767beda7b19751042f9595a3891c6c3b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Qwinci <32550582+Qwinci@users.noreply.github.com> |
| 3 | +Date: Fri, 16 Feb 2024 00:25:36 +0200 |
| 4 | +Subject: [PATCH] Add managarm support |
| 5 | + |
| 6 | +--- |
| 7 | + dlls/ntdll/unix/signal_x86_64.c | 39 +++++++++++++++++++++++++++++++++ |
| 8 | + dlls/ntdll/unix/system.c | 4 ++-- |
| 9 | + 2 files changed, 41 insertions(+), 2 deletions(-) |
| 10 | + |
| 11 | +diff --git a/dlls/ntdll/unix/signal_x86_64.c b/dlls/ntdll/unix/signal_x86_64.c |
| 12 | +index ab54490..1e10a9b 100644 |
| 13 | +--- a/dlls/ntdll/unix/signal_x86_64.c |
| 14 | ++++ b/dlls/ntdll/unix/signal_x86_64.c |
| 15 | +@@ -75,6 +75,11 @@ |
| 16 | + #include "unix_private.h" |
| 17 | + #include "wine/debug.h" |
| 18 | + |
| 19 | ++#ifdef __managarm__ |
| 20 | ++#include <hel.h> |
| 21 | ++#include <hel-syscalls.h> |
| 22 | ++#endif |
| 23 | ++ |
| 24 | + WINE_DEFAULT_DEBUG_CHANNEL(unwind); |
| 25 | + WINE_DECLARE_DEBUG_CHANNEL(seh); |
| 26 | + |
| 27 | +@@ -292,6 +297,38 @@ static inline XMM_SAVE_AREA32 *FPU_sig( const ucontext_t *context ) |
| 28 | + |
| 29 | + #define XState_sig(context) NULL |
| 30 | + |
| 31 | ++#elif defined(__managarm__) |
| 32 | ++ |
| 33 | ++#ifndef FP_XSTATE_MAGIC1 |
| 34 | ++#define FP_XSTATE_MAGIC1 0x46505853 |
| 35 | ++#endif |
| 36 | ++ |
| 37 | ++#define RAX_sig(context) ((context)->uc_mcontext.gregs[REG_RAX]) |
| 38 | ++#define RBX_sig(context) ((context)->uc_mcontext.gregs[REG_RBX]) |
| 39 | ++#define RCX_sig(context) ((context)->uc_mcontext.gregs[REG_RCX]) |
| 40 | ++#define RDX_sig(context) ((context)->uc_mcontext.gregs[REG_RDX]) |
| 41 | ++#define RSI_sig(context) ((context)->uc_mcontext.gregs[REG_RSI]) |
| 42 | ++#define RDI_sig(context) ((context)->uc_mcontext.gregs[REG_RDI]) |
| 43 | ++#define RBP_sig(context) ((context)->uc_mcontext.gregs[REG_RBP]) |
| 44 | ++#define R8_sig(context) ((context)->uc_mcontext.gregs[REG_R8]) |
| 45 | ++#define R9_sig(context) ((context)->uc_mcontext.gregs[REG_R9]) |
| 46 | ++#define R10_sig(context) ((context)->uc_mcontext.gregs[REG_R10]) |
| 47 | ++#define R11_sig(context) ((context)->uc_mcontext.gregs[REG_R11]) |
| 48 | ++#define R12_sig(context) ((context)->uc_mcontext.gregs[REG_R12]) |
| 49 | ++#define R13_sig(context) ((context)->uc_mcontext.gregs[REG_R13]) |
| 50 | ++#define R14_sig(context) ((context)->uc_mcontext.gregs[REG_R14]) |
| 51 | ++#define R15_sig(context) ((context)->uc_mcontext.gregs[REG_R15]) |
| 52 | ++#define CS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 0)) |
| 53 | ++#define GS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 1)) |
| 54 | ++#define FS_sig(context) (*((WORD *)&(context)->uc_mcontext.gregs[REG_CSGSFS] + 2)) |
| 55 | ++#define RSP_sig(context) ((context)->uc_mcontext.gregs[REG_RSP]) |
| 56 | ++#define RIP_sig(context) ((context)->uc_mcontext.gregs[REG_RIP]) |
| 57 | ++#define EFL_sig(context) ((context)->uc_mcontext.gregs[REG_EFL]) |
| 58 | ++#define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO]) |
| 59 | ++#define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR]) |
| 60 | ++#define FPU_sig(context) ((XMM_SAVE_AREA32 *)((context)->uc_mcontext.fpregs)) |
| 61 | ++#define XState_sig(fpu) (((unsigned int *)fpu->Reserved4)[12] == FP_XSTATE_MAGIC1 ? (XSTATE *)(fpu + 1) : NULL) |
| 62 | ++ |
| 63 | + #else |
| 64 | + #error You must define the signal context functions for your platform |
| 65 | + #endif |
| 66 | +@@ -2496,6 +2533,8 @@ void call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB |
| 67 | + thread's gsbase. Have each thread record its gsbase pointer into its |
| 68 | + TEB so alloc_tls_slot() can find it. */ |
| 69 | + teb->Instrumentation[0] = thread_data->pthread_teb; |
| 70 | ++#elif defined(__managarm__) |
| 71 | ++ helWriteGsBase(teb); |
| 72 | + #else |
| 73 | + # error Please define setting %gs for your architecture |
| 74 | + #endif |
| 75 | +diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c |
| 76 | +index 879a589..24228ac 100644 |
| 77 | +--- a/dlls/ntdll/unix/system.c |
| 78 | ++++ b/dlls/ntdll/unix/system.c |
| 79 | +@@ -1369,7 +1369,7 @@ static NTSTATUS create_cpuset_info(SYSTEM_CPU_SET_INFORMATION *info) |
| 80 | + return STATUS_SUCCESS; |
| 81 | + } |
| 82 | + |
| 83 | +-#if defined(linux) || defined(__APPLE__) |
| 84 | ++#if defined(linux) || defined(__APPLE__) || defined(__managarm__) |
| 85 | + |
| 86 | + static void copy_smbios_string( char **buffer, const char *s, size_t len ) |
| 87 | + { |
| 88 | +@@ -1561,7 +1561,7 @@ static NTSTATUS create_smbios_tables( SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, U |
| 89 | + |
| 90 | + #endif |
| 91 | + |
| 92 | +-#ifdef linux |
| 93 | ++#if defined(linux) || defined(__managarm__) |
| 94 | + |
| 95 | + static size_t get_smbios_string( const char *path, char *str, size_t size ) |
| 96 | + { |
| 97 | +-- |
| 98 | +2.43.1 |
| 99 | + |
0 commit comments