Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复Windows arm64无法编译的问题 #366

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}")
Expand Down
10 changes: 8 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions src/co/context/context_arm64.asm
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion src/co/hook_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/log/StackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down