unicorn-engine / unicorn

Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)
http://www.unicorn-engine.org
GNU General Public License v2.0
7.33k stars 1.31k forks source link

Compatibility with MSVC's /CETCOMPACT + on Windows 11 with CET (Control-flow Enforcement Technology) enabled #1889

Open hzqst opened 8 months ago

hzqst commented 8 months ago

Requirements to repro the issue

Windows 11 with CET (Control-flow Enforcement Technology) enabled

Visual Studio 2022

Description

Though this might be a won-fix or low-priority issue, I wrote this just in case someone else get into this and waste their life on debugging.

This issue occurs only when you get your .exe linked with linker flag /CETCOMPACT which was introduced in Visual Studio 2022, and you are running your .exe on Windows 11 with Control-flow Enforcement Technology enabled.

You will get a STATUS_STACK_BUFFEROVERRUN exception at the last instruction of `helper**_***_mmu_x86_64`

.text:00000001402F0C29                 mov     r14, [rsp+88h+arg_10]
.text:00000001402F0C31                 add     rsp, 50h
.text:00000001402F0C35                 pop     r15
.text:00000001402F0C37                 pop     r13
.text:00000001402F0C39                 pop     r12
.text:00000001402F0C3B                 pop     rdi
.text:00000001402F0C3C                 pop     rsi
.text:00000001402F0C3D                 pop     rbp
.text:00000001402F0C3E                 pop     rbx
.text:00000001402F0C3F                 retn                                     <------ exception here
.text:00000001402F0C3F helper_le_stw_mmu_x86_64 endp

1

The actual return address seems to be some generated code from tcg.

2

Version

1.0.0 ~ 1.0.3, and 2.0.0 (others are not tested)