File tree 7 files changed +73
-3
lines changed
7 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -859,6 +859,10 @@ if (MSVC)
859
859
${CMAKE_CURRENT_SOURCE_DIR} /msvc /unicorn/qapi-types.c
860
860
${CMAKE_CURRENT_SOURCE_DIR} /msvc /unicorn/qapi-visit.c
861
861
)
862
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
863
+ enable_language (ASM_MASM)
864
+ set (UNICORN_SRCS ${UNICORN_SRCS} qemu/util/setjmp-wrapper-win32 .asm)
865
+ endif ()
862
866
else ()
863
867
set (UNICORN_SRCS
864
868
${UNICORN_SRCS_COMMON}
Original file line number Diff line number Diff line change 53
53
</PropertyGroup >
54
54
<Import Project =" $(VCTargetsPath)\Microsoft.Cpp.props" />
55
55
<ImportGroup Label =" ExtensionSettings" >
56
+ <Import Project =" $(VCTargetsPath)\BuildCustomizations\masm.props" />
56
57
</ImportGroup >
57
58
<ImportGroup Label =" PropertySheets" Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
58
59
<Import Project =" $(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition =" exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label =" LocalAppDataPlatform" />
@@ -357,7 +358,16 @@ copy "$(SolutionDir)..\include\unicorn\*.h" "$(SolutionDir)distro\include\unicor
357
358
<ClInclude Include =" ..\qapi-types.h" />
358
359
<ClInclude Include =" ..\qapi-visit.h" />
359
360
</ItemGroup >
361
+ <ItemGroup >
362
+ <MASM Include =" ..\..\..\qemu\util\setjmp-wrapper-win32.asm" >
363
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >true</ExcludedFromBuild >
364
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >true</ExcludedFromBuild >
365
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >false</ExcludedFromBuild >
366
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >false</ExcludedFromBuild >
367
+ </MASM >
368
+ </ItemGroup >
360
369
<Import Project =" $(VCTargetsPath)\Microsoft.Cpp.targets" />
361
370
<ImportGroup Label =" ExtensionTargets" >
371
+ <Import Project =" $(VCTargetsPath)\BuildCustomizations\masm.targets" />
362
372
</ImportGroup >
363
- </Project >
373
+ </Project >
Original file line number Diff line number Diff line change 499
499
<ClInclude Include =" ..\..\..\include\unicorn\unicorn.h" />
500
500
<ClInclude Include =" ..\..\..\include\unicorn\x86.h" />
501
501
</ItemGroup >
502
+ <ItemGroup >
503
+ <MASM Include =" ..\..\..\qemu\util\setjmp-wrapper-win32.asm" />
504
+ </ItemGroup >
502
505
</Project >
Original file line number Diff line number Diff line change 169
169
<ClInclude Include =" ..\qapi-types.h" />
170
170
<ClInclude Include =" ..\qapi-visit.h" />
171
171
</ItemGroup >
172
+ <ItemGroup >
173
+ <MASM Include =" ..\..\..\qemu\util\setjmp-wrapper-win32.asm" >
174
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >true</ExcludedFromBuild >
175
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Release|Win32'" >true</ExcludedFromBuild >
176
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >false</ExcludedFromBuild >
177
+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Release|x64'" >false</ExcludedFromBuild >
178
+ </MASM >
179
+ </ItemGroup >
172
180
<PropertyGroup Label =" Globals" >
173
181
<ProjectGuid >{B6EFD6D7-C2D4-4FBB-B363-2E08CE09CC96}</ProjectGuid >
174
182
<Keyword >Win32Proj</Keyword >
204
212
</PropertyGroup >
205
213
<Import Project =" $(VCTargetsPath)\Microsoft.Cpp.props" />
206
214
<ImportGroup Label =" ExtensionSettings" >
215
+ <Import Project =" $(VCTargetsPath)\BuildCustomizations\masm.props" />
207
216
</ImportGroup >
208
217
<ImportGroup Label =" PropertySheets" Condition =" '$(Configuration)|$(Platform)'=='Debug|Win32'" >
209
218
<Import Project =" $(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition =" exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label =" LocalAppDataPlatform" />
@@ -363,5 +372,6 @@ copy "$(SolutionDir)..\include\unicorn\*.h" "$(SolutionDir)distro\include\unicor
363
372
</ItemDefinitionGroup >
364
373
<Import Project =" $(VCTargetsPath)\Microsoft.Cpp.targets" />
365
374
<ImportGroup Label =" ExtensionTargets" >
375
+ <Import Project =" $(VCTargetsPath)\BuildCustomizations\masm.targets" />
366
376
</ImportGroup >
367
- </Project >
377
+ </Project >
Original file line number Diff line number Diff line change 498
498
<Filter >qemu</Filter >
499
499
</ClInclude >
500
500
</ItemGroup >
501
+ <ItemGroup >
502
+ <MASM Include =" ..\..\..\qemu\util\setjmp-wrapper-win32.asm" />
503
+ </ItemGroup >
501
504
</Project >
Original file line number Diff line number Diff line change 56
56
# define EWOULDBLOCK WSAEWOULDBLOCK
57
57
#endif
58
58
59
- #if defined(_WIN64 ) && !defined( _MSC_VER )
59
+ #if defined(_WIN64 )
60
60
/* On w64, setjmp is implemented by _setjmp which needs a second parameter.
61
61
* If this parameter is NULL, longjump does no stack unwinding.
62
62
* That is what we need for QEMU. Passing the value of register rsp (default)
63
63
* lets longjmp try a stack unwinding which will crash with generated code. */
64
+
65
+ #if defined(_MSC_VER ) // MSVC
66
+
67
+ // See qemu/include/utils/setjmp-wrapper-win32.asm for details.
68
+ extern int _setjmp_wrapper (jmp_buf );
69
+
70
+ # undef setjmp
71
+ # define setjmp (env ) _setjmp_wrapper(env)
72
+
73
+ #else // MinGW
74
+
75
+ // Original QEMU patch.
64
76
# undef setjmp
65
77
# define setjmp (env ) _setjmp(env, NULL)
78
+ #endif
79
+
66
80
#endif
67
81
/* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
68
82
* "longjmp and don't touch the signal masks". Since we know that the
Original file line number Diff line number Diff line change
1
+ EXTERN _setjmp: proc
2
+ PUBLIC _setjmp_wrapper
3
+
4
+ _TEXT SEGMENT
5
+
6
+ _setjmp_wrapper PROC
7
+
8
+ ; Why do we need this wrapper?
9
+ ; Short answer: Windows default implementation of setjmp/longjmp is incompatible with generated code.
10
+ ; A longer answer: https://blog.lazym.io/2020/09/21/Unicorn-Devblog-setjmp-longjmp-on-Windows/.
11
+
12
+ ; From qemu os-win32 comments:
13
+ ; > On w64, setjmp is implemented by _setjmp which needs a second parameter.
14
+ ; > If this parameter is NULL, longjump does no stack unwinding.
15
+ ; > That is what we need for QEMU. Passing the value of register rsp (default)
16
+ ; > lets longjmp try a stack unwinding which will crash with generated code.
17
+ ; It's true indeed, but MSVC doesn't has a setjmp signature which receives two arguements.
18
+ ; Therefore, we add a wrapper to keep the second argument zero.
19
+ xor rdx , rdx
20
+ jmp _setjmp
21
+
22
+ _setjmp_wrapper ENDP
23
+
24
+ _TEXT ENDS
25
+
26
+ END
You can’t perform that action at this time.
0 commit comments