Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975// Copyright (c) Microsoft. All rights reserved.// Licensed under the MIT license. See LICENSE file in the project root for// full license information.
/* * Exercise lots of different kinds of C++ EH frames. Compile this with * every combination of opts you can to stress the C++ EH frame code in the * backend. */
#include <stdio.h>#include <malloc.h>#include <stdarg.h>#include <memory.h>
#ifndef ALIGN#define ALIGN 64#endif
#define ARG(x) &x, sizeof(x)#define ARG2(x) ARG(x), ARG(x)#define ARG5(x) ARG(x), ARG(x), ARG(x), ARG(x), ARG(x)
extern int TestFunc(int, ...);
int failures;
int one = 1;int zero = 0;
size_t global = 16;volatile bool TestFuncThrows;
struct SmallObj { int x;};
struct BigObj { char x[1024];};
int Simple(int arg) { puts(__FUNCTION__); int res = 0; SmallObj f; __try { TestFunc(1, ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int Try(int arg) { puts(__FUNCTION__); int res = 0; SmallObj f; __try { res = TestFunc(1, ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int GSCookie(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; SmallObj f; __try { TestFunc(1, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndGSCookie(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; SmallObj f; __try { res = TestFunc(1, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int Align(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { TestFunc(1, ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndAlign(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { res = TestFunc(1, ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(d), ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlign(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { TestFunc(1, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlign(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { res = TestFunc(1, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int Alloca(int arg) { puts(__FUNCTION__); int res = 0; SmallObj f; __try { TestFunc(1, _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; SmallObj f; __try { res = TestFunc(1, _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; SmallObj f; __try { TestFunc(1, ARG(buf), _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; SmallObj f; __try { res = TestFunc(1, ARG(buf), _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int AlignAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { TestFunc(1, ARG(d), _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndAlignAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { res = TestFunc(1, ARG(d), _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(d), ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlignAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { TestFunc(1, ARG(buf), ARG(d), _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlignAndAlloca(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; SmallObj f; __try { res = TestFunc(1, ARG(buf), ARG(d), _alloca(global), global, ARG(f), ARG(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(d), ARG(f), ARG(res), ARG(arg), NULL); } return res;}
/* * The BigLocals variants try to trigger EBP adjustment, and generally do in * the /O1 case for the non-aligned stacks. */
int BigLocals(int arg) { puts(__FUNCTION__); int res = 0; BigObj f1; __try { TestFunc(1, ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; BigObj f1; __try { res = TestFunc(1, ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; BigObj f1; __try { TestFunc(1, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; BigObj f1; __try { res = TestFunc(1, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int AlignAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndAlignAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlignAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlignAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int AllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; BigObj f1; __try { TestFunc(1, _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; BigObj f1; __try { res = TestFunc(1, _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; BigObj f1; __try { TestFunc(1, ARG(buf), _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; BigObj f1; __try { res = TestFunc(1, ARG(buf), _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int AlignAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(d), _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndAlignAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(d), _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlignAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(buf), ARG(d), _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlignAndAllocaAndBigLocals(int arg) { puts(__FUNCTION__); int res = 0; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(buf), ARG(d), _alloca(global), global, ARG(f1), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG5(res), ARG(arg), NULL); } return res;}
/* * The EbpAdj variants try to trigger EBP adjustment, and generally do in * the /O1 case for the non-aligned stacks. They add a non-GS-protected * buffer so the EH node is far from both sides of the local variable * allocation. Doesn't seem to add any testing over what the BigLocals cases * already do. */
int EbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; BigObj f1; __try { TestFunc(1, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; BigObj f1; __try { res = TestFunc(1, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; BigObj f1; __try { TestFunc(1, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; BigObj f1; __try { res = TestFunc(1, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int AlignAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndAlignAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlignAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlignAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int AllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; BigObj f1; __try { TestFunc(1, _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; BigObj f1; __try { res = TestFunc(1, _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; BigObj f1; __try { TestFunc(1, ARG(buf), _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; BigObj f1; __try { res = TestFunc(1, ARG(buf), _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int AlignAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(d), _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndAlignAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(d), _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int GSCookieAndAlignAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { TestFunc(1, ARG(buf), ARG(d), _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __finally { res = TestFunc(1, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
int TryAndGSCookieAndAlignAndAllocaAndEbpAdj(int arg) { puts(__FUNCTION__); int res = 0; int a[512]; char buf[16]; __declspec(align(ALIGN)) double d[4]; BigObj f1; __try { res = TestFunc(1, ARG(buf), ARG(d), _alloca(global), global, ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } __except(TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL), zero) { res = TestFunc(2, ARG(buf), ARG(d), ARG(f1), ARG2(a), ARG5(res), ARG(arg), NULL); } return res;}
__declspec(noinline) int TestFunc(int x, ...) { va_list ap; va_start(ap, x);
for (;;) { void *pbuf = va_arg(ap, void *); if (pbuf == NULL) { break; } size_t len = va_arg(ap, size_t); memset(pbuf, 0, len); }
if (TestFuncThrows) { TestFuncThrows = false; *(volatile int *)0; }
return static_cast<int>(global);}
void RunTests() { puts("Test pass 1 - no exceptions");
__try { Simple(1); Try(1); GSCookie(1); TryAndGSCookie(1); Align(1); TryAndAlign(1); GSCookieAndAlign(1); TryAndGSCookieAndAlign(1); Alloca(1); TryAndAlloca(1); GSCookieAndAlloca(1); TryAndGSCookieAndAlloca(1); AlignAndAlloca(1); TryAndAlignAndAlloca(1); GSCookieAndAlignAndAlloca(1); TryAndGSCookieAndAlignAndAlloca(1); BigLocals(1); TryAndBigLocals(1); GSCookieAndBigLocals(1); TryAndGSCookieAndBigLocals(1); AlignAndBigLocals(1); TryAndAlignAndBigLocals(1); GSCookieAndAlignAndBigLocals(1); TryAndGSCookieAndAlignAndBigLocals(1); AllocaAndBigLocals(1); TryAndAllocaAndBigLocals(1); GSCookieAndAllocaAndBigLocals(1); TryAndGSCookieAndAllocaAndBigLocals(1); AlignAndAllocaAndBigLocals(1); TryAndAlignAndAllocaAndBigLocals(1); GSCookieAndAlignAndAllocaAndBigLocals(1); TryAndGSCookieAndAlignAndAllocaAndBigLocals(1); EbpAdj(1); TryAndEbpAdj(1); GSCookieAndEbpAdj(1); TryAndGSCookieAndEbpAdj(1); AlignAndEbpAdj(1); TryAndAlignAndEbpAdj(1); GSCookieAndAlignAndEbpAdj(1); TryAndGSCookieAndAlignAndEbpAdj(1); AllocaAndEbpAdj(1); TryAndAllocaAndEbpAdj(1); GSCookieAndAllocaAndEbpAdj(1); TryAndGSCookieAndAllocaAndEbpAdj(1); AlignAndAllocaAndEbpAdj(1); TryAndAlignAndAllocaAndEbpAdj(1); GSCookieAndAlignAndAllocaAndEbpAdj(1); TryAndGSCookieAndAlignAndAllocaAndEbpAdj(1); } __except(one) { puts("ERROR - exception not expected"); ++failures; }
puts("Test pass 2 - exceptions");
for (int i = 0; i < 48; ++i) { TestFuncThrows = true; bool caught = false; __try { switch (i) { case 0: Simple(1); break; case 1: Try(1); break; case 2: GSCookie(1); break; case 3: TryAndGSCookie(1); break; case 4: Align(1); break; case 5: TryAndAlign(1); break; case 6: GSCookieAndAlign(1); break; case 7: TryAndGSCookieAndAlign(1); break; case 8: Alloca(1); break; case 9: TryAndAlloca(1); break; case 10: GSCookieAndAlloca(1); break; case 11: TryAndGSCookieAndAlloca(1); break; case 12: AlignAndAlloca(1); break; case 13: TryAndAlignAndAlloca(1); break; case 14: GSCookieAndAlignAndAlloca(1); break; case 15: TryAndGSCookieAndAlignAndAlloca(1); break; case 16: BigLocals(1); break; case 17: TryAndBigLocals(1); break; case 18: GSCookieAndBigLocals(1); break; case 19: TryAndGSCookieAndBigLocals(1); break; case 20: AlignAndBigLocals(1); break; case 21: TryAndAlignAndBigLocals(1); break; case 22: GSCookieAndAlignAndBigLocals(1); break; case 23: TryAndGSCookieAndAlignAndBigLocals(1); break; case 24: AllocaAndBigLocals(1); break; case 25: TryAndAllocaAndBigLocals(1); break; case 26: GSCookieAndAllocaAndBigLocals(1); break; case 27: TryAndGSCookieAndAllocaAndBigLocals(1); break; case 28: AlignAndAllocaAndBigLocals(1); break; case 29: TryAndAlignAndAllocaAndBigLocals(1); break; case 30: GSCookieAndAlignAndAllocaAndBigLocals(1); break; case 31: TryAndGSCookieAndAlignAndAllocaAndBigLocals(1); break; case 32: EbpAdj(1); break; case 33: TryAndEbpAdj(1); break; case 34: GSCookieAndEbpAdj(1); break; case 35: TryAndGSCookieAndEbpAdj(1); break; case 36: AlignAndEbpAdj(1); break; case 37: TryAndAlignAndEbpAdj(1); break; case 38: GSCookieAndAlignAndEbpAdj(1); break; case 39: TryAndGSCookieAndAlignAndEbpAdj(1); break; case 40: AllocaAndEbpAdj(1); break; case 41: TryAndAllocaAndEbpAdj(1); break; case 42: GSCookieAndAllocaAndEbpAdj(1); break; case 43: TryAndGSCookieAndAllocaAndEbpAdj(1); break; case 44: AlignAndAllocaAndEbpAdj(1); break; case 45: TryAndAlignAndAllocaAndEbpAdj(1); break; case 46: GSCookieAndAlignAndAllocaAndEbpAdj(1); break; case 47: TryAndGSCookieAndAlignAndAllocaAndEbpAdj(1); break; } } __except(one) { caught = true; }
if (!caught) { puts("ERROR - did not see expected exception"); ++failures; } }}
int main() { __try { RunTests(); } __except(1) { puts("ERROR - Unexpectedly caught an exception"); ++failures; }
if (failures) { printf("Test failed with %d failure%s\n", failures, failures == 1 ? "" : "s"); } else { puts("Test passed"); }
return failures;}