Skip to content

Commit d614855

Browse files
authored
Merge pull request #1552 from sakura57/dev
Various fixes and improvements for Windows emulation
2 parents 56dd77b + f390b47 commit d614855

File tree

20 files changed

+1481
-175
lines changed

20 files changed

+1481
-175
lines changed

examples/scripts/dllscollector.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ CALL :collect_dll32 wininet.dll
9494
CALL :collect_dll32 winmm.dll
9595
CALL :collect_dll32 ws2_32.dll
9696
CALL :collect_dll32 wsock32.dll
97+
CALL :collect_dll32 msvcp140.dll
98+
CALL :collect_dll32 msvcp140_1.dll
99+
CALL :collect_dll32 msvcp140_2.dll
97100

98101
CALL :collect_dll32 downlevel\api-ms-win-core-fibers-l1-1-1.dll
99102
CALL :collect_dll32 downlevel\api-ms-win-core-localization-l1-2-1.dll
@@ -131,6 +134,9 @@ CALL :collect_dll64 win32u.dll
131134
CALL :collect_dll64 winhttp.dll
132135
CALL :collect_dll64 wininet.dll
133136
CALL :collect_dll64 ws2_32.dll
137+
CALL :collect_dll64 msvcp140.dll
138+
CALL :collect_dll64 msvcp140_1.dll
139+
CALL :collect_dll64 msvcp140_2.dll
134140

135141
CALL :collect_dll64 downlevel\api-ms-win-crt-heap-l1-1-0.dll
136142
CALL :collect_dll64 downlevel\api-ms-win-crt-locale-l1-1-0.dll
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This is the default Hello World program generated by Visual Studio 2022.
2+
3+
#include <iostream>
4+
5+
int main()
6+
{
7+
std::cout << "Hello World!\n";
8+
9+
return 0;
10+
}
11+

examples/src/windows/except/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In this folder: Sources for programs intended to help test C++ features and software exceptions.
2+
3+
Compile with MSVC (Visual Studio 2022)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
4+
/*
5+
* Test simple try..catch.
6+
*/
7+
void test1()
8+
{
9+
std::cout << "y";
10+
11+
try {
12+
std::cout << "y";
13+
throw (unsigned int)0x12345678;
14+
std::cout << "n";
15+
}
16+
catch(unsigned int n) {
17+
n;
18+
std::cout << "y";
19+
}
20+
21+
std::cout << "y";
22+
}
23+
24+
/*
25+
* Test simple try..catch with throw.
26+
*/
27+
void test2()
28+
{
29+
std::cout << "y";
30+
31+
try {
32+
std::cout << "y";
33+
throw (unsigned int)0x12345679;
34+
std::cout << "n";
35+
}
36+
catch (unsigned int n) {
37+
n;
38+
if (n == 0x12345679) {
39+
std::cout << "y";
40+
}
41+
else {
42+
std::cout << "n";
43+
}
44+
}
45+
46+
std::cout << "y";
47+
}
48+
49+
/*
50+
* Test nested try..catch with throw.
51+
*/
52+
void test3()
53+
{
54+
std::cout << "y";
55+
56+
try {
57+
std::cout << "y";
58+
59+
try {
60+
std::cout << "y";
61+
throw (unsigned int)0x1234567A;
62+
std::cout << "n";
63+
}
64+
catch (unsigned int n) {
65+
n;
66+
if (n == 0x1234567A) {
67+
std::cout << "y";
68+
}
69+
else {
70+
std::cout << "n";
71+
}
72+
}
73+
74+
std::cout << "y";
75+
}
76+
catch (unsigned int n) {
77+
n;
78+
std::cout << "n";
79+
}
80+
81+
std::cout << "y";
82+
}
83+
84+
int main()
85+
{
86+
/*
87+
* For this program, all subtests successful will print:
88+
* - 14 'y'
89+
* - 0 'n'
90+
*/
91+
92+
test1();
93+
test2();
94+
test3();
95+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <windows.h>
2+
#include <cstdio>
3+
4+
LONG WINAPI CustomExceptionFilter(EXCEPTION_POINTERS* ExceptionInfo) {
5+
printf("Inside exception filter (GOOD)\n");
6+
DWORD exceptionCode = (DWORD)ExceptionInfo->ExceptionRecord->ExceptionCode;
7+
printf("Exception Code: 0x%X\n", exceptionCode);
8+
9+
if (exceptionCode == 0xE06D7363) { // code for C++ exception
10+
printf("Exception code DOES match, GOOD\n");
11+
}
12+
else {
13+
printf("Exception code DOES NOT match, BAD\n");
14+
}
15+
16+
printf("Exception Address: 0x%llx\n", (ULONGLONG)ExceptionInfo->ExceptionRecord->ExceptionAddress);
17+
18+
printf("After printing exception: (GOOD)\n");
19+
20+
return EXCEPTION_EXECUTE_HANDLER;
21+
}
22+
23+
int main() {
24+
/*
25+
* For this program, all subtests successful will print:
26+
* - 3 'GOOD'
27+
* - 0 'BAD'
28+
*
29+
* It is expected that the program terminates abnormally
30+
* with status code 0xE06D7363 (C++ exception)
31+
*/
32+
33+
// Set the custom top-level exception filter
34+
SetUnhandledExceptionFilter(CustomExceptionFilter);
35+
36+
// Throw an unhandled exception.
37+
// It should be caught by our filter.
38+
throw (unsigned int)5;
39+
40+
// We should never reach this point, because the exception
41+
// dispatcher should terminate the program after our unhandled
42+
// exception filter is called.
43+
printf("After exception filter (BAD)\n");
44+
45+
return 0;
46+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
#include <cstdio>
3+
4+
int main()
5+
{
6+
/*
7+
* For this program, all subtests successful will print:
8+
* - 1 'GOOD'
9+
* - 0 'BAD'
10+
*
11+
* It is expected that the program terminates abnormally
12+
* with status code 0xC0000409 (stack buffer overrun/security
13+
* check failure)
14+
*/
15+
16+
printf("Before throw (GOOD)\n");
17+
18+
throw (unsigned int)5;
19+
20+
printf("After throw (BAD)\n");
21+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <iostream>
2+
3+
struct TestStruct {
4+
float q;
5+
};
6+
7+
class TestClass {
8+
public:
9+
int x, y;
10+
virtual ~TestClass() {
11+
std::cout << "TestClass destructor, GOOD" << std::endl;
12+
};
13+
void yyy() {
14+
std::cout << "REALLY GOOD" << std::endl;
15+
}
16+
};
17+
18+
class Something {
19+
public:
20+
char z;
21+
virtual ~Something() {
22+
std::cout << "Something destructor, GOOD" << std::endl;
23+
};
24+
virtual void zzz() {
25+
std::cout << "BAD" << std::endl;
26+
};
27+
};
28+
29+
class TestClass2 : public TestClass, public Something {
30+
public:
31+
int z;
32+
virtual ~TestClass2() {
33+
std::cout << "TestClass2 destructor, GOOD" << std::endl;
34+
};
35+
virtual void zzz() {
36+
std::cout << "GOOD" << std::endl;
37+
};
38+
};
39+
40+
int main()
41+
{
42+
/*
43+
* For this program, all subtests successful will print:
44+
* - 12 'GOOD'
45+
* - 0 'BAD'
46+
*/
47+
48+
int x = 5;
49+
TestClass p;
50+
TestStruct s;
51+
52+
std::cout << typeid(x).name() << std::endl;
53+
if (strcmp(typeid(x).name(), "int") == 0) {
54+
std::cout << "typeid(x) is int, GOOD" << std::endl;
55+
}
56+
else {
57+
std::cout << "typeid(x) is NOT int, BAD" << std::endl;
58+
}
59+
60+
std::cout << typeid(p).name() << std::endl;
61+
if (strcmp(typeid(p).name(), "class TestClass") == 0) {
62+
std::cout << "typeid(p) is \"class TestClass\", GOOD" << std::endl;
63+
}
64+
else {
65+
std::cout << "typeid(p) is NOT \"class TestClass\", BAD" << std::endl;
66+
}
67+
68+
std::cout << typeid(s).name() << std::endl;
69+
if (strcmp(typeid(s).name(), "struct TestStruct") == 0) {
70+
std::cout << "typeid(s) is \"struct TestStruct\", GOOD" << std::endl;
71+
}
72+
else {
73+
std::cout << "typeid(s) is NOT \"struct TestStruct\", BAD" << std::endl;
74+
}
75+
76+
std::cout << "Reached virtual methods and dynamic_cast test. GOOD" << std::endl;
77+
78+
TestClass2* kz = new TestClass2;
79+
80+
Something* ks = static_cast<Something*>(kz);
81+
82+
ks->zzz();
83+
84+
TestClass* pk = dynamic_cast<TestClass*>(ks);
85+
86+
pk->yyy();
87+
88+
std::cout << "Reached virtual destructor test. GOOD" << std::endl;
89+
90+
delete pk;
91+
92+
std::cout << "Finished all tests. GOOD" << std::endl;
93+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <windows.h>
2+
#include <cstdio>
3+
4+
void test1() {
5+
__try {
6+
printf("Inside __try block. (GOOD)\n");
7+
8+
RaiseException(
9+
0xE0000001,
10+
0,
11+
0,
12+
nullptr
13+
);
14+
15+
printf("After RaiseException. (BAD)\n");
16+
}
17+
__except (EXCEPTION_EXECUTE_HANDLER) {
18+
printf("In __except block. (GOOD)\n");
19+
20+
unsigned long excepCode = GetExceptionCode();
21+
22+
printf("Exception code=0x%x\n", excepCode);
23+
24+
if (excepCode == 0xE0000001) {
25+
printf("Exception code IS same, GOOD\n");
26+
}
27+
else {
28+
printf("Exception code DOES NOT MATCH, BAD\n");
29+
}
30+
}
31+
32+
printf("After __except block. (GOOD)\n");
33+
}
34+
35+
int main() {
36+
/*
37+
* For this program, all subtests successful will print:
38+
* - 4 'GOOD'
39+
* - 0 'BAD'
40+
*/
41+
42+
test1();
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)