From 27ecdcac0f5b7bc8fdb0ca317d009db903c1b808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=B0=E9=98=85=E9=83=A8=E8=90=BD?= <43716063+Baiyuetribe@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:07:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DWindows=20arm64=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=BC=96=E8=AF=91=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 6 +++++- src/co/hook_win.cc | 4 +++- src/log/StackWalker.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d8bbd29e..c27571f62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,11 @@ endif() project(coost VERSION 3.0.0) if(MSVC) - enable_language(C CXX ASM_MASM) + if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") + enable_language(C CXX ASM) + else() + enable_language(C CXX ASM_MASM) + endif() else() enable_language(C CXX ASM) endif() diff --git a/src/co/hook_win.cc b/src/co/hook_win.cc index 2fd28f31a..4f0c20d7d 100644 --- a/src/co/hook_win.cc +++ b/src/co/hook_win.cc @@ -1359,7 +1359,9 @@ WSASendMsg_fp_t get_WSASendMsg_fp() { } // extern "C" namespace co { - +#if !defined(PCHAR) +#define PCHAR const char * +#endif inline void detour_attach(PVOID* ppbReal, PVOID pbMine, PCHAR psz) { LONG l = DetourAttach(ppbReal, pbMine); CHECK_EQ(l, 0) << "detour attach failed: " << psz; diff --git a/src/log/StackWalker.cpp b/src/log/StackWalker.cpp index c331e0b64..e3ab0b9d3 100644 --- a/src/log/StackWalker.cpp +++ b/src/log/StackWalker.cpp @@ -999,6 +999,14 @@ BOOL StackWalker::ShowCallstack(HANDLE hThread, s.AddrBStore.Mode = AddrModeFlat; s.AddrStack.Offset = c.IntSp; s.AddrStack.Mode = AddrModeFlat; +#elif _M_ARM64 + imageType = IMAGE_FILE_MACHINE_ARM64; + s.AddrPC.Offset = c.Pc; + s.AddrPC.Mode = AddrModeFlat; + s.AddrFrame.Offset = c.Fp; + s.AddrFrame.Mode = AddrModeFlat; + s.AddrStack.Offset = c.Sp; + s.AddrStack.Mode = AddrModeFlat; #else #error "Platform not supported!" #endif From ae8c326497545f979914ce6cdbe06e02b93ece92 Mon Sep 17 00:00:00 2001 From: mac_arm64_win11 <2894049053@qq.com> Date: Tue, 10 Sep 2024 16:43:57 +0800 Subject: [PATCH 2/2] add arm64.asm --- CMakeLists.txt | 6 ++-- src/CMakeLists.txt | 10 +++++-- src/co/context/context_arm64.asm | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/co/context/context_arm64.asm diff --git a/CMakeLists.txt b/CMakeLists.txt index c27571f62..a6a51a683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(coost VERSION 3.0.0) if(MSVC) if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") - enable_language(C CXX ASM) + enable_language(C CXX ASM_MARMASM) else() enable_language(C CXX ASM_MASM) endif() @@ -22,7 +22,9 @@ include(GNUInstallDirs) include(CMakePackageConfigHelpers) if(MSVC) - add_compile_options(/fp:fast /EHsc) + if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") + add_compile_options(/fp:fast /EHsc) # arm64上使用armasm64.exe时,不支持/fp:fast + endif() add_link_options(/SAFESEH:NO) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b1c6a6cf..f2592e1da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,9 +5,15 @@ if(MSVC) if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(ASM_FILES co/context/context_x86.asm) else() - set(ASM_FILES co/context/context_x64.asm) + if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") + set(ASM_FILES co/context/context_arm64.asm) + else() + set(ASM_FILES co/context/context_x64.asm) + endif() + endif() + if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") + set_property(SOURCE ${ASM_FILES} PROPERTY LANGUAGE ASM_MASM) endif() - set_property(SOURCE ${ASM_FILES} PROPERTY LANGUAGE ASM_MASM) else() set(ASM_FILES co/context/context.S) endif() diff --git a/src/co/context/context_arm64.asm b/src/co/context/context_arm64.asm new file mode 100644 index 000000000..ceccf9bc3 --- /dev/null +++ b/src/co/context/context_arm64.asm @@ -0,0 +1,47 @@ +TB_CONTEXT_SJLJ_BYTES EQU 0 + + AREA |.text|, CODE, READONLY + + EXPORT tb_context_make +tb_context_make PROC + add x0, x0, x1 + and x0, x0, #~15 + sub x0, x0, #112 + str x2, [x0, #96] + adr x1, __end + str x1, [x0, #88] + ret + +__end + mov x0, #0 + ; Instead of calling ExitProcess, we'll just return + ret + + ENDP + + EXPORT tb_context_jump +tb_context_jump PROC + sub sp, sp, #112 + stp x19, x20, [sp, #0] + stp x21, x22, [sp, #16] + stp x23, x24, [sp, #32] + stp x25, x26, [sp, #48] + stp x27, x28, [sp, #64] + stp x29, x30, [sp, #80] + str x30, [sp, #96] + mov x9, sp + mov sp, x0 + ldp x19, x20, [sp, #0] + ldp x21, x22, [sp, #16] + ldp x23, x24, [sp, #32] + ldp x25, x26, [sp, #48] + ldp x27, x28, [sp, #64] + ldp x29, x30, [sp, #80] + ldr x4, [sp, #96] + add sp, sp, #112 + mov x0, x9 + br x4 + + ENDP + + END \ No newline at end of file