diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d8bbd29e..a6a51a683 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_MARMASM) + else() + enable_language(C CXX ASM_MASM) + endif() else() enable_language(C CXX ASM) endif() @@ -18,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 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