sample.c.txt 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full
  3. // license information.
  4. /*
  5. * COMMAND LINE: -Ox -Gz -YX -UPROTOTYPES_REQUIRED
  6. */
  7. #pragma warning(disable : 4532)
  8. #pragma warning(disable : 4702)
  9. #if defined(_WIN32)
  10. #if defined(_M_SH)
  11. #define WIN_CE
  12. #endif
  13. #if defined(_M_AMD64)
  14. #define NEST_IN_FINALLY /* allow when __try nested in __finally OK */
  15. #endif
  16. #define NTSTATUS LONG
  17. #define EXCEPTION_NESTED_CALL 0x10
  18. #define RtlRaiseStatus(x) RaiseException((x), 0, 0, NULL)
  19. #define RtlRaiseException(x) \
  20. RaiseException((x)->ExceptionCode, (x)->ExceptionFlags, \
  21. (x)->NumberParameters, (x)->ExceptionInformation)
  22. #define IN
  23. #define OUT
  24. #if !(defined(_M_IA64) || defined(_M_ALPHA) || defined(_M_PPC) || \
  25. defined(_M_AMD64) || defined(_M_ARM) || defined(_M_ARM64))
  26. #define i386 1
  27. #endif
  28. #define try __try
  29. #define except __except
  30. #define finally __finally
  31. #define leave __leave
  32. #endif
  33. #define WIN32_LEAN_AND_MEAN
  34. #include "stdio.h"
  35. #if defined(_M_IA64) || defined(_M_ALPHA) || defined(_M_PPC) || \
  36. defined(_M_AMD64) || defined(_M_ARM) || defined(_M_ARM64)
  37. #include "setjmpex.h"
  38. #else
  39. #include "setjmp.h"
  40. #endif
  41. #include "float.h"
  42. #include "windows.h"
  43. #include "math.h"
  44. #if !defined(STATUS_SUCCESS)
  45. #define STATUS_SUCCESS 0
  46. #endif
  47. #if !defined(STATUS_UNSUCCESSFUL)
  48. #define STATUS_UNSUCCESSFUL ((NTSTATUS)0xC0000001L)
  49. #endif
  50. //
  51. // Define switch constants.
  52. //
  53. #define BLUE 0
  54. #define RED 1
  55. //
  56. // Define function prototypes.
  57. //
  58. VOID addtwo(IN LONG First, IN LONG Second, IN PLONG Place);
  59. VOID bar1(IN NTSTATUS Status, IN PLONG Counter);
  60. VOID bar2(IN PLONG BlackHole, IN PLONG BadAddress, IN PLONG Counter);
  61. VOID dojump(IN jmp_buf JumpBuffer, IN PLONG Counter);
  62. LONG Echo(IN LONG Value);
  63. #if !defined(WIN_CE) // return through finally not allowed on WinCE
  64. VOID eret(IN NTSTATUS Status, IN PLONG Counter);
  65. #endif
  66. VOID except1(IN PLONG Counter);
  67. ULONG
  68. except2(IN PEXCEPTION_POINTERS ExceptionPointers, IN PLONG Counter);
  69. ULONG
  70. except3(IN PEXCEPTION_POINTERS ExceptionPointers, IN PLONG Counter);
  71. VOID foo1(IN NTSTATUS Status);
  72. VOID foo2(IN PLONG BlackHole, IN PLONG BadAddress);
  73. #if !defined(WIN_CE) // return from finally not allowed on WinCE
  74. VOID fret(IN PLONG Counter);
  75. #endif
  76. BOOLEAN
  77. Tkm(VOID);
  78. VOID Test61Part2(IN OUT PULONG Counter);
  79. double SquareDouble(IN double op);
  80. DECLSPEC_NOINLINE
  81. ULONG
  82. PgFilter(VOID)
  83. {
  84. printf("filter entered...");
  85. return EXCEPTION_EXECUTE_HANDLER;
  86. }
  87. #pragma warning(push)
  88. #pragma warning(disable : 4532)
  89. VOID PgTest69(IN PLONG State, IN PLONG Fault)
  90. {
  91. try {
  92. try {
  93. *Fault += 1;
  94. }
  95. finally {
  96. if (AbnormalTermination()) {
  97. if (*State == 1) {
  98. *State += 1;
  99. } else {
  100. *Fault += 1;
  101. }
  102. }
  103. }
  104. }
  105. except(((*State += 1) == 1) ? PgFilter() : EXCEPTION_CONTINUE_SEARCH) {
  106. if (*State != 2) {
  107. *Fault += 1;
  108. }
  109. }
  110. return;
  111. }
  112. VOID PgTest70(IN PLONG State, IN PLONG Fault)
  113. {
  114. try {
  115. try {
  116. *Fault += 1;
  117. }
  118. finally {
  119. if (AbnormalTermination()) {
  120. if (*State == 2) {
  121. PgFilter();
  122. return;
  123. } else {
  124. *Fault += 1;
  125. }
  126. }
  127. }
  128. }
  129. except(((*State += 2) == 2) ? EXCEPTION_EXECUTE_HANDLER
  130. : EXCEPTION_CONTINUE_SEARCH) {
  131. *Fault += 1;
  132. }
  133. return;
  134. }
  135. VOID PgTest71(IN PLONG State, IN PLONG Fault)
  136. {
  137. try {
  138. try {
  139. try {
  140. *Fault += 1;
  141. }
  142. finally {
  143. if (AbnormalTermination()) {
  144. if (*State == 3) {
  145. *State += 3;
  146. return;
  147. } else {
  148. *Fault += 1;
  149. }
  150. }
  151. }
  152. }
  153. finally {
  154. if (AbnormalTermination()) {
  155. if (*State == 6) {
  156. *State += 3;
  157. } else {
  158. *Fault += 1;
  159. }
  160. }
  161. }
  162. }
  163. except(((*State += 3) == 3) ? PgFilter() : EXCEPTION_CONTINUE_SEARCH) {
  164. *Fault += 1;
  165. }
  166. return;
  167. }
  168. VOID PgTest72(IN PLONG State, IN PLONG Fault)
  169. {
  170. try {
  171. try {
  172. try {
  173. *Fault += 1;
  174. }
  175. finally {
  176. if (AbnormalTermination()) {
  177. if (*State == 4) {
  178. *State += 4;
  179. return;
  180. } else {
  181. *Fault += 1;
  182. }
  183. }
  184. }
  185. }
  186. finally {
  187. if (AbnormalTermination()) {
  188. if (*State == 8) {
  189. *State += 4;
  190. PgFilter();
  191. } else {
  192. *Fault += 1;
  193. }
  194. }
  195. }
  196. }
  197. except(((*State += 4) == 4) ? EXCEPTION_EXECUTE_HANDLER
  198. : EXCEPTION_CONTINUE_SEARCH) {
  199. *Fault += 1;
  200. }
  201. return;
  202. }
  203. VOID PgTest73(IN PLONG State, IN PLONG Fault)
  204. {
  205. try {
  206. try {
  207. try {
  208. *Fault += 1;
  209. }
  210. finally {
  211. if (AbnormalTermination()) {
  212. if (*State == 5) {
  213. *State += 5;
  214. } else {
  215. *Fault += 1;
  216. }
  217. }
  218. }
  219. }
  220. finally {
  221. if (AbnormalTermination()) {
  222. if (*State == 10) {
  223. *State += 5;
  224. return;
  225. } else {
  226. *Fault += 1;
  227. }
  228. }
  229. }
  230. }
  231. except(((*State += 5) == 5) ? PgFilter() : EXCEPTION_CONTINUE_SEARCH) {
  232. *Fault += 1;
  233. }
  234. return;
  235. }
  236. VOID PgTest74(IN PLONG State, IN PLONG Fault)
  237. {
  238. try {
  239. try {
  240. try {
  241. *Fault += 1;
  242. }
  243. finally {
  244. if (AbnormalTermination()) {
  245. if (*State == 6) {
  246. *State += 6;
  247. } else {
  248. *Fault += 1;
  249. }
  250. }
  251. }
  252. }
  253. finally {
  254. if (AbnormalTermination()) {
  255. if (*State == 12) {
  256. *State += 6;
  257. PgFilter();
  258. return;
  259. } else {
  260. *Fault += 1;
  261. }
  262. }
  263. }
  264. }
  265. except(((*State += 6) == 6) ? EXCEPTION_EXECUTE_HANDLER
  266. : EXCEPTION_CONTINUE_SEARCH) {
  267. *Fault += 1;
  268. }
  269. return;
  270. }
  271. VOID PgTest75(IN PLONG State, IN PLONG Fault)
  272. {
  273. try {
  274. try {
  275. try {
  276. try {
  277. *Fault += 1;
  278. }
  279. finally {
  280. if (AbnormalTermination()) {
  281. if (*State == 7) {
  282. *State += 7;
  283. *Fault += 1;
  284. } else {
  285. *State += 10;
  286. }
  287. }
  288. }
  289. }
  290. except(((*State += 7) == 7) ? EXCEPTION_EXECUTE_HANDLER
  291. : EXCEPTION_CONTINUE_SEARCH) {
  292. *Fault += 1;
  293. }
  294. }
  295. finally {
  296. if (AbnormalTermination()) {
  297. if (*State == 28) {
  298. *State += 7;
  299. return;
  300. } else {
  301. *Fault += 1;
  302. }
  303. }
  304. }
  305. }
  306. except(((*State += 7) == 28) ? PgFilter() : EXCEPTION_CONTINUE_SEARCH) {
  307. *Fault += 1;
  308. }
  309. return;
  310. }
  311. VOID PgTest76(IN PLONG State, IN PLONG Fault)
  312. {
  313. try {
  314. try {
  315. try {
  316. try {
  317. *Fault += 1;
  318. }
  319. finally {
  320. if (AbnormalTermination()) {
  321. if (*State == 8) {
  322. *State += 8;
  323. *Fault += 1;
  324. } else {
  325. *State += 10;
  326. }
  327. }
  328. }
  329. }
  330. except(((*State += 8) == 8) ? EXCEPTION_EXECUTE_HANDLER
  331. : EXCEPTION_CONTINUE_SEARCH) {
  332. *Fault += 1;
  333. }
  334. }
  335. finally {
  336. if (AbnormalTermination()) {
  337. if (*State == 32) {
  338. *State += 8;
  339. PgFilter();
  340. return;
  341. } else {
  342. *Fault += 1;
  343. }
  344. }
  345. }
  346. }
  347. except(((*State += 8) == 32) ? EXCEPTION_EXECUTE_HANDLER
  348. : EXCEPTION_CONTINUE_SEARCH) {
  349. *Fault += 1;
  350. }
  351. return;
  352. }
  353. VOID PgTest77(IN PLONG State, IN PLONG Fault)
  354. {
  355. try {
  356. try {
  357. try {
  358. try {
  359. *Fault += 1;
  360. }
  361. finally {
  362. if (AbnormalTermination()) {
  363. if (*State == 9) {
  364. *State += 9;
  365. *Fault += 1;
  366. } else {
  367. *State += 10;
  368. }
  369. }
  370. }
  371. }
  372. except(((*State += 9) == 9) ? PgFilter() : EXCEPTION_CONTINUE_SEARCH) {
  373. *Fault += 1;
  374. }
  375. }
  376. finally {
  377. if (AbnormalTermination()) {
  378. if (*State == 36) {
  379. *State += 9;
  380. return;
  381. } else {
  382. *Fault += 1;
  383. }
  384. }
  385. }
  386. }
  387. except(((*State += 9) == 36) ? EXCEPTION_EXECUTE_HANDLER
  388. : EXCEPTION_CONTINUE_SEARCH) {
  389. *Fault += 1;
  390. }
  391. return;
  392. }
  393. VOID PgTest78(IN PLONG State, IN PLONG Fault)
  394. {
  395. try {
  396. try {
  397. try {
  398. try {
  399. *Fault += 1;
  400. }
  401. finally {
  402. if (AbnormalTermination()) {
  403. if (*State == 10) {
  404. *State += 10;
  405. PgFilter();
  406. *Fault += 1;
  407. } else {
  408. *State += 10;
  409. }
  410. }
  411. }
  412. }
  413. except(((*State += 10) == 10) ? EXCEPTION_EXECUTE_HANDLER
  414. : EXCEPTION_CONTINUE_SEARCH) {
  415. *Fault += 1;
  416. }
  417. }
  418. finally {
  419. if (AbnormalTermination()) {
  420. if (*State == 40) {
  421. *State += 10;
  422. return;
  423. } else {
  424. *Fault += 1;
  425. }
  426. }
  427. }
  428. }
  429. except(((*State += 10) == 40) ? EXCEPTION_EXECUTE_HANDLER
  430. : EXCEPTION_CONTINUE_SEARCH) {
  431. *Fault += 1;
  432. }
  433. return;
  434. }
  435. #pragma warning(pop)
  436. VOID Test79(PLONG Counter, PLONG Fault)
  437. {
  438. try {
  439. try {
  440. try {
  441. *Fault += 1;
  442. }
  443. finally {
  444. printf("finally 1...");
  445. *Fault += 1;
  446. }
  447. }
  448. finally { printf("finally 2..."); }
  449. }
  450. except(*Counter += 1, printf("filter 1..."), EXCEPTION_CONTINUE_SEARCH) {}
  451. return;
  452. }
  453. ULONG G;
  454. ULONG
  455. Test80(VOID)
  456. {
  457. G = 1;
  458. try {
  459. while (G) {
  460. try {
  461. if (G == 10) {
  462. return 1;
  463. }
  464. if (G == 1) {
  465. continue;
  466. }
  467. }
  468. finally { G = 0; }
  469. }
  470. }
  471. finally { G = 10; }
  472. return 0;
  473. }
  474. void Test81(int *pCounter) {
  475. volatile char *AvPtr = NULL;
  476. __try {
  477. __try { *AvPtr = '\0'; }
  478. __except(EXCEPTION_EXECUTE_HANDLER) { __leave; }
  479. }
  480. __finally {
  481. printf("in finally ");
  482. *pCounter += 1;
  483. }
  484. return;
  485. }
  486. DECLSPEC_NOINLINE
  487. VOID Test82Foo(VOID)
  488. {
  489. *(volatile int *)0 = 0;
  490. }
  491. VOID Test82(__inout PLONG Counter)
  492. {
  493. int retval = 1;
  494. __try {
  495. __try { Test82Foo(); }
  496. __finally {
  497. switch (*Counter) {
  498. case 0:
  499. printf("something failed!\n");
  500. retval = 6;
  501. break;
  502. case 1:
  503. retval = 0;
  504. break;
  505. case 2:
  506. printf("how did you get here?\n");
  507. retval = 2;
  508. break;
  509. case 3:
  510. printf("what?!?\n");
  511. retval = 3;
  512. break;
  513. case 4:
  514. printf("not correct\n");
  515. retval = 4;
  516. break;
  517. case 5:
  518. printf("error!\n");
  519. retval = 5;
  520. break;
  521. }
  522. }
  523. }
  524. __except(1){}
  525. *Counter = retval;
  526. return;
  527. }
  528. LONG Test83(VOID)
  529. {
  530. G = 1;
  531. try {
  532. try {
  533. while (G) {
  534. try {
  535. if (G == 10) {
  536. return 1;
  537. }
  538. if (G == 1) {
  539. continue;
  540. }
  541. }
  542. finally { G = 0; }
  543. }
  544. }
  545. except(EXCEPTION_EXECUTE_HANDLER) { leave; }
  546. }
  547. finally { G = 10; }
  548. return 0;
  549. }
  550. DECLSPEC_NOINLINE
  551. VOID Test84(_Inout_ PLONG Counter)
  552. {
  553. volatile int *Fault = 0;
  554. try {
  555. try {
  556. *Fault += 1;
  557. }
  558. except(EXCEPTION_EXECUTE_HANDLER) {
  559. try {
  560. return;
  561. }
  562. finally { *Counter += 1; }
  563. }
  564. }
  565. finally {
  566. if (AbnormalTermination()) {
  567. *Counter += 1;
  568. }
  569. }
  570. return;
  571. }
  572. DECLSPEC_NOINLINE
  573. LONG Test85(_Inout_ PLONG Counter)
  574. {
  575. volatile int *Fault = 0;
  576. G = 1;
  577. try {
  578. try {
  579. try {
  580. while (G) {
  581. try {
  582. try {
  583. if (G == 10) {
  584. return 1;
  585. }
  586. try {
  587. *Counter += 1;
  588. }
  589. except(EXCEPTION_EXECUTE_HANDLER) {}
  590. if (G == 1) {
  591. continue;
  592. }
  593. }
  594. finally {
  595. G = 0;
  596. *Counter += 1;
  597. *Fault += 1;
  598. }
  599. }
  600. except(EXCEPTION_EXECUTE_HANDLER) {
  601. *Counter += 1;
  602. leave;
  603. }
  604. }
  605. }
  606. finally {
  607. G = 10;
  608. *Counter += 1;
  609. *Fault += 1;
  610. }
  611. }
  612. except(EXCEPTION_EXECUTE_HANDLER) { *Counter += 1; }
  613. *Counter += 1;
  614. }
  615. finally { *Counter += 1; }
  616. return 1;
  617. }
  618. DECLSPEC_NOINLINE
  619. VOID Test86(_Inout_ PLONG Counter)
  620. {
  621. volatile int *Fault = 0;
  622. try {
  623. try {
  624. try {
  625. try {
  626. try {
  627. try {
  628. *Fault += 1;
  629. }
  630. except(printf("Filter1 %d..", *Counter),
  631. EXCEPTION_EXECUTE_HANDLER) {
  632. try {
  633. printf("Handler1 %d..", *Counter);
  634. return;
  635. }
  636. finally {
  637. printf("Finally1 %d..", *Counter);
  638. *Counter += 1;
  639. }
  640. }
  641. }
  642. finally {
  643. printf("Finally2 %d..", *Counter);
  644. *Counter += 1;
  645. }
  646. }
  647. except(EXCEPTION_EXECUTE_HANDLER) { leave; }
  648. }
  649. finally { *Counter += 1; }
  650. }
  651. except(EXCEPTION_EXECUTE_HANDLER) { leave; }
  652. }
  653. finally { *Counter += 1; }
  654. return;
  655. }
  656. VOID Test87(_Inout_ PLONG Counter)
  657. /*++
  658. Routine Description:
  659. This function verifies the behavior of nested exception dispatching.
  660. Arguments:
  661. Counter - Supplies a pointer to the state counter.
  662. Return Value:
  663. None.
  664. --*/
  665. {
  666. volatile int *Fault = 0;
  667. //
  668. // N.B. Disabled on x86 due to failing test case with handling of returns
  669. // in nested termination handlers on x86.
  670. //
  671. // Disabled on ARM due to failing test case with handling of abutting
  672. // termination handlers within an except handler.
  673. //
  674. // Disabled on AMD64 due to failing test case with handling of
  675. // abutting termination handlers within an except handler when a
  676. // non-local goto is involved.
  677. //
  678. #if !defined(_X86_)
  679. try {
  680. try {
  681. try {
  682. try {
  683. try {
  684. *Fault += 1;
  685. try {
  686. }
  687. finally {
  688. if (AbnormalTermination()) {
  689. *Fault += 1;
  690. }
  691. }
  692. }
  693. finally {
  694. if (AbnormalTermination()) {
  695. if ((*Counter += 13) == 26) {
  696. return;
  697. } else {
  698. *Fault += 1;
  699. }
  700. }
  701. }
  702. }
  703. finally {
  704. if (AbnormalTermination()) {
  705. *Counter += 13;
  706. *Fault += 1;
  707. }
  708. }
  709. }
  710. except(((*Counter += 13) == 13) ? EXCEPTION_EXECUTE_HANDLER
  711. : EXCEPTION_CONTINUE_SEARCH) {
  712. *Fault += 1;
  713. }
  714. }
  715. except(((*Counter += 13) == 65) ? EXCEPTION_EXECUTE_HANDLER
  716. : EXCEPTION_CONTINUE_SEARCH) {
  717. try {
  718. *Counter += 13;
  719. return;
  720. }
  721. finally {
  722. if (AbnormalTermination()) {
  723. *Counter += 13;
  724. goto Finish;
  725. }
  726. }
  727. }
  728. }
  729. finally {
  730. if (AbnormalTermination()) {
  731. if ((*Counter += 13) == 104) {
  732. goto Finish;
  733. }
  734. }
  735. }
  736. Finish:
  737. #else
  738. *Counter = 104;
  739. #endif
  740. return;
  741. }
  742. VOID Test88(_Inout_ PLONG Counter)
  743. {
  744. volatile int *Fault = 0;
  745. try {
  746. try {
  747. try {
  748. try {
  749. try {
  750. try {
  751. try {
  752. try {
  753. *Fault += 1;
  754. }
  755. except(((*Counter += 1) == 1) ? *Fault
  756. : EXCEPTION_CONTINUE_SEARCH) {}
  757. }
  758. except(*Counter += 1, EXCEPTION_EXECUTE_HANDLER) { *Fault += 2; }
  759. }
  760. except(*Counter += 1, EXCEPTION_CONTINUE_SEARCH) { leave; }
  761. }
  762. except(*Counter += 1, EXCEPTION_CONTINUE_SEARCH) { leave; }
  763. }
  764. except(EXCEPTION_EXECUTE_HANDLER) {}
  765. }
  766. except(EXCEPTION_EXECUTE_HANDLER) {}
  767. }
  768. except(EXCEPTION_EXECUTE_HANDLER) { leave; }
  769. }
  770. finally { *Counter += 1; }
  771. }
  772. int main(int argc, char *argv[])
  773. {
  774. PLONG BadAddress;
  775. PCHAR BadByte;
  776. PLONG BlackHole;
  777. ULONG Index1;
  778. ULONG Index2 = RED;
  779. jmp_buf JumpBuffer;
  780. LONG Counter;
  781. EXCEPTION_RECORD ExceptionRecord;
  782. double doubleresult;
  783. //
  784. // Announce start of exception test.
  785. //
  786. printf("Start of exception test\n");
  787. //
  788. // Initialize exception record.
  789. //
  790. ExceptionRecord.ExceptionCode = STATUS_INTEGER_OVERFLOW;
  791. ExceptionRecord.ExceptionFlags = 0;
  792. ExceptionRecord.ExceptionRecord = NULL;
  793. ExceptionRecord.NumberParameters = 0;
  794. //
  795. // Initialize pointers.
  796. //
  797. BadAddress = (PLONG)NULL;
  798. BadByte = (PCHAR)NULL;
  799. BadByte += 1;
  800. BlackHole = &Counter;
  801. //
  802. // Simply try statement with a finally clause that is entered sequentially.
  803. //
  804. printf(" test1...");
  805. Counter = 0;
  806. try {
  807. Counter += 1;
  808. }
  809. finally {
  810. if (abnormal_termination() == FALSE) {
  811. Counter += 1;
  812. }
  813. }
  814. if (Counter != 2) {
  815. printf("failed, count = %d\n", Counter);
  816. } else {
  817. printf("succeeded\n");
  818. }
  819. //
  820. // Simple try statement with an exception clause that is never executed
  821. // because there is no exception raised in the try clause.
  822. //
  823. printf(" test2...");
  824. Counter = 0;
  825. try {
  826. Counter += 1;
  827. }
  828. except(Counter) { Counter += 1; }
  829. if (Counter != 1) {
  830. printf("failed, count = %d\n", Counter);
  831. } else {
  832. printf("succeeded\n");
  833. }
  834. //
  835. // Simple try statement with an exception handler that is never executed
  836. // because the exception expression continues execution.
  837. //
  838. printf(" test3...");
  839. Counter = 0;
  840. try {
  841. Counter -= 1;
  842. RtlRaiseException(&ExceptionRecord);
  843. }
  844. except(Counter) { Counter -= 1; }
  845. if (Counter != -1) {
  846. printf("failed, count = %d\n", Counter);
  847. } else {
  848. printf("succeeded\n");
  849. }
  850. //
  851. // Simple try statement with an exception clause that is always executed.
  852. //
  853. printf(" test4...");
  854. Counter = 0;
  855. try {
  856. Counter += 1;
  857. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  858. }
  859. except(Counter) { Counter += 1; }
  860. if (Counter != 2) {
  861. printf("failed, count = %d\n", Counter);
  862. } else {
  863. printf("succeeded\n");
  864. }
  865. //
  866. // Simple try statement with an exception clause that is always executed.
  867. //
  868. printf(" test5...");
  869. Counter = 0;
  870. try {
  871. Counter += 1;
  872. *BlackHole += *BadAddress;
  873. }
  874. except(Counter) { Counter += 1; }
  875. if (Counter != 2) {
  876. printf("failed, count = %d\n", Counter);
  877. } else {
  878. printf("succeeded\n");
  879. }
  880. //
  881. // Simply try statement with a finally clause that is entered as the
  882. // result of an exception.
  883. //
  884. printf(" test6...");
  885. Counter = 0;
  886. try {
  887. try {
  888. Counter += 1;
  889. RtlRaiseException(&ExceptionRecord);
  890. }
  891. finally {
  892. if (abnormal_termination() != FALSE) {
  893. Counter += 1;
  894. }
  895. }
  896. }
  897. except(Counter) {
  898. if (Counter == 2) {
  899. Counter += 1;
  900. }
  901. }
  902. if (Counter != 3) {
  903. printf("failed, count = %d\n", Counter);
  904. } else {
  905. printf("succeeded\n");
  906. }
  907. //
  908. // Simply try statement with a finally clause that is entered as the
  909. // result of an exception.
  910. //
  911. printf(" test7...");
  912. Counter = 0;
  913. try {
  914. try {
  915. Counter += 1;
  916. *BlackHole += *BadAddress;
  917. }
  918. finally {
  919. if (abnormal_termination() != FALSE) {
  920. Counter += 1;
  921. }
  922. }
  923. }
  924. except(Counter) {
  925. if (Counter == 2) {
  926. Counter += 1;
  927. }
  928. }
  929. if (Counter != 3) {
  930. printf("failed, count = %d\n", Counter);
  931. } else {
  932. printf("succeeded\n");
  933. }
  934. //
  935. // Simple try that calls a function which raises an exception.
  936. //
  937. printf(" test8...");
  938. Counter = 0;
  939. try {
  940. Counter += 1;
  941. foo1(STATUS_ACCESS_VIOLATION);
  942. }
  943. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  944. ? EXCEPTION_EXECUTE_HANDLER
  945. : EXCEPTION_CONTINUE_SEARCH) {
  946. Counter += 1;
  947. }
  948. if (Counter != 2) {
  949. printf("failed, count = %d\n", Counter);
  950. } else {
  951. printf("succeeded\n");
  952. }
  953. //
  954. // Simple try that calls a function which raises an exception.
  955. //
  956. printf(" test9...");
  957. Counter = 0;
  958. try {
  959. Counter += 1;
  960. foo2(BlackHole, BadAddress);
  961. }
  962. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  963. ? EXCEPTION_EXECUTE_HANDLER
  964. : EXCEPTION_CONTINUE_SEARCH) {
  965. Counter += 1;
  966. }
  967. if (Counter != 2) {
  968. printf("failed, count = %d\n", Counter);
  969. } else {
  970. printf("succeeded\n");
  971. }
  972. //
  973. // Simple try that calls a function which calls a function that
  974. // raises an exception. The first function has a finally clause
  975. // that must be executed for this test to work.
  976. //
  977. printf(" test10...");
  978. Counter = 0;
  979. try {
  980. bar1(STATUS_ACCESS_VIOLATION, &Counter);
  981. }
  982. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  983. ? EXCEPTION_EXECUTE_HANDLER
  984. : EXCEPTION_CONTINUE_SEARCH) {
  985. Counter -= 1;
  986. }
  987. if (Counter != 98) {
  988. printf("failed, count = %d\n", Counter);
  989. } else {
  990. printf("succeeded\n");
  991. }
  992. //
  993. // Simple try that calls a function which calls a function that
  994. // raises an exception. The first function has a finally clause
  995. // that must be executed for this test to work.
  996. //
  997. printf(" test11...");
  998. Counter = 0;
  999. try {
  1000. bar2(BlackHole, BadAddress, &Counter);
  1001. }
  1002. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  1003. ? EXCEPTION_EXECUTE_HANDLER
  1004. : EXCEPTION_CONTINUE_SEARCH) {
  1005. Counter -= 1;
  1006. }
  1007. if (Counter != 98) {
  1008. printf("failed, count = %d\n", Counter);
  1009. } else {
  1010. printf("succeeded\n");
  1011. }
  1012. //
  1013. // A try within an except
  1014. //
  1015. printf(" test12...");
  1016. Counter = 0;
  1017. try {
  1018. foo1(STATUS_ACCESS_VIOLATION);
  1019. }
  1020. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  1021. ? EXCEPTION_EXECUTE_HANDLER
  1022. : EXCEPTION_CONTINUE_SEARCH) {
  1023. Counter += 1;
  1024. try {
  1025. foo1(STATUS_SUCCESS);
  1026. }
  1027. except((GetExceptionCode() == STATUS_SUCCESS) ? EXCEPTION_EXECUTE_HANDLER
  1028. : EXCEPTION_CONTINUE_SEARCH) {
  1029. if (Counter != 1) {
  1030. printf("failed, count = %d\n", Counter);
  1031. } else {
  1032. printf("succeeded...");
  1033. }
  1034. Counter += 1;
  1035. }
  1036. }
  1037. if (Counter != 2) {
  1038. printf("failed, count = %d\n", Counter);
  1039. } else {
  1040. printf("succeeded\n");
  1041. }
  1042. //
  1043. // A try within an except
  1044. //
  1045. printf(" test13...");
  1046. Counter = 0;
  1047. try {
  1048. foo2(BlackHole, BadAddress);
  1049. }
  1050. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  1051. ? EXCEPTION_EXECUTE_HANDLER
  1052. : EXCEPTION_CONTINUE_SEARCH) {
  1053. Counter += 1;
  1054. try {
  1055. foo1(STATUS_SUCCESS);
  1056. }
  1057. except((GetExceptionCode() == STATUS_SUCCESS) ? EXCEPTION_EXECUTE_HANDLER
  1058. : EXCEPTION_CONTINUE_SEARCH) {
  1059. if (Counter != 1) {
  1060. printf("failed, count = %d\n", Counter);
  1061. } else {
  1062. printf("succeeded...");
  1063. }
  1064. Counter += 1;
  1065. }
  1066. }
  1067. if (Counter != 2) {
  1068. printf("failed, count = %d\n", Counter);
  1069. } else {
  1070. printf("succeeded\n");
  1071. }
  1072. #if !defined(WIN_CE) // gotos from except/finally not allowed on WinCE
  1073. //
  1074. // A goto from an exception clause that needs to pass
  1075. // through a finally
  1076. //
  1077. printf(" test14...");
  1078. Counter = 0;
  1079. try {
  1080. try {
  1081. foo1(STATUS_ACCESS_VIOLATION);
  1082. }
  1083. except((GetExceptionCode() == STATUS_ACCESS_VIOLATION)
  1084. ? EXCEPTION_EXECUTE_HANDLER
  1085. : EXCEPTION_CONTINUE_SEARCH) {
  1086. Counter += 1;
  1087. goto t9;
  1088. }
  1089. }
  1090. finally { Counter += 1; }
  1091. t9:
  1092. ;
  1093. if (Counter != 2) {
  1094. printf("failed, count = %d\n", Counter);
  1095. } else {
  1096. printf("succeeded\n");
  1097. }
  1098. //
  1099. // A goto from an finally clause that needs to pass
  1100. // through a finally
  1101. //
  1102. printf(" test15...");
  1103. Counter = 0;
  1104. try {
  1105. try {
  1106. Counter += 1;
  1107. }
  1108. finally {
  1109. Counter += 1;
  1110. goto t10;
  1111. }
  1112. }
  1113. finally { Counter += 1; }
  1114. t10:
  1115. ;
  1116. if (Counter != 3) {
  1117. printf("failed, count = %d\n", Counter);
  1118. } else {
  1119. printf("succeeded\n");
  1120. }
  1121. //
  1122. // A goto from an exception clause that needs to pass
  1123. // through a finally into the outer finally clause.
  1124. //
  1125. printf(" test16...");
  1126. Counter = 0;
  1127. try {
  1128. try {
  1129. try {
  1130. Counter += 1;
  1131. foo1(STATUS_INTEGER_OVERFLOW);
  1132. }
  1133. except(EXCEPTION_EXECUTE_HANDLER) {
  1134. Counter += 1;
  1135. goto t11;
  1136. }
  1137. }
  1138. finally { Counter += 1; }
  1139. t11:
  1140. ;
  1141. }
  1142. finally { Counter += 1; }
  1143. if (Counter != 4) {
  1144. printf("failed, count = %d\n", Counter);
  1145. } else {
  1146. printf("succeeded\n");
  1147. }
  1148. //
  1149. // A goto from an finally clause that needs to pass
  1150. // through a finally into the outer finally clause.
  1151. //
  1152. printf(" test17...");
  1153. Counter = 0;
  1154. try {
  1155. try {
  1156. Counter += 1;
  1157. }
  1158. finally {
  1159. Counter += 1;
  1160. goto t12;
  1161. }
  1162. t12:
  1163. ;
  1164. }
  1165. finally { Counter += 1; }
  1166. if (Counter != 3) {
  1167. printf("failed, count = %d\n", Counter);
  1168. } else {
  1169. printf("succeeded\n");
  1170. }
  1171. //
  1172. // A return from an except clause
  1173. //
  1174. printf(" test18...");
  1175. Counter = 0;
  1176. try {
  1177. Counter += 1;
  1178. eret(STATUS_ACCESS_VIOLATION, &Counter);
  1179. }
  1180. finally { Counter += 1; }
  1181. if (Counter != 4) {
  1182. printf("failed, count = %d\n", Counter);
  1183. } else {
  1184. printf("succeeded\n");
  1185. }
  1186. //
  1187. // A return from a finally clause
  1188. //
  1189. printf(" test19...");
  1190. Counter = 0;
  1191. try {
  1192. Counter += 1;
  1193. fret(&Counter);
  1194. }
  1195. finally { Counter += 1; }
  1196. if (Counter != 5) {
  1197. printf("failed, count = %d\n", Counter);
  1198. } else {
  1199. printf("succeeded\n");
  1200. }
  1201. #endif
  1202. //
  1203. // A simple set jump followed by a long jump.
  1204. //
  1205. printf(" test20...");
  1206. Counter = 0;
  1207. if (setjmp(JumpBuffer) == 0) {
  1208. Counter += 1;
  1209. longjmp(JumpBuffer, 1);
  1210. } else {
  1211. Counter += 1;
  1212. }
  1213. if (Counter != 2) {
  1214. printf("failed, count = %d\n", Counter);
  1215. } else {
  1216. printf("succeeded\n");
  1217. }
  1218. //
  1219. // A set jump followed by a long jump out of a finally clause that is
  1220. // sequentially executed.
  1221. //
  1222. printf(" test21...");
  1223. Counter = 0;
  1224. if (setjmp(JumpBuffer) == 0) {
  1225. try {
  1226. Counter += 1;
  1227. }
  1228. finally {
  1229. Counter += 1;
  1230. longjmp(JumpBuffer, 1);
  1231. }
  1232. } else {
  1233. Counter += 1;
  1234. }
  1235. if (Counter != 3) {
  1236. printf("failed, count = %d\n", Counter);
  1237. } else {
  1238. printf("succeeded\n");
  1239. }
  1240. //
  1241. // A set jump within a try clause followed by a long jump out of a
  1242. // finally clause that is sequentially executed.
  1243. //
  1244. printf(" test22...");
  1245. Counter = 0;
  1246. try {
  1247. if (setjmp(JumpBuffer) == 0) {
  1248. Counter += 1;
  1249. } else {
  1250. Counter += 1;
  1251. }
  1252. }
  1253. finally {
  1254. Counter += 1;
  1255. if (Counter == 2) {
  1256. Counter += 1;
  1257. longjmp(JumpBuffer, 1);
  1258. }
  1259. }
  1260. if (Counter != 5) {
  1261. printf("failed, count = %d\n", Counter);
  1262. } else {
  1263. printf("succeeded\n");
  1264. }
  1265. //
  1266. // A set jump followed by a try/except, followed by a try/finally where
  1267. // the try body of the try/finally raises an exception that is handled
  1268. // by the try/excecpt which causes the try/finally to do a long jump out
  1269. // of a finally clause. This will create a collided unwind.
  1270. //
  1271. printf(" test23...");
  1272. Counter = 0;
  1273. if (setjmp(JumpBuffer) == 0) {
  1274. try {
  1275. try {
  1276. Counter += 1;
  1277. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1278. }
  1279. finally {
  1280. Counter += 1;
  1281. longjmp(JumpBuffer, 1);
  1282. }
  1283. }
  1284. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 1; }
  1285. } else {
  1286. Counter += 1;
  1287. }
  1288. if (Counter != 3) {
  1289. printf("failed, count = %d\n", Counter);
  1290. } else {
  1291. printf("succeeded\n");
  1292. }
  1293. //
  1294. // A set jump followed by a try/except, followed by a several nested
  1295. // try/finally's where the inner try body of the try/finally raises an
  1296. // exception that is handled by the try/except which causes the
  1297. // try/finally to do a long jump out of a finally clause. This will
  1298. // create a collided unwind.
  1299. //
  1300. printf(" test24...");
  1301. Counter = 0;
  1302. if (setjmp(JumpBuffer) == 0) {
  1303. try {
  1304. try {
  1305. try {
  1306. try {
  1307. Counter += 1;
  1308. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1309. }
  1310. finally { Counter += 1; }
  1311. }
  1312. finally {
  1313. Counter += 1;
  1314. longjmp(JumpBuffer, 1);
  1315. }
  1316. }
  1317. finally { Counter += 1; }
  1318. }
  1319. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 1; }
  1320. } else {
  1321. Counter += 1;
  1322. }
  1323. if (Counter != 5) {
  1324. printf("failed, count = %d\n", Counter);
  1325. } else {
  1326. printf("succeeded\n");
  1327. }
  1328. //
  1329. // A set jump followed by a try/except, followed by a try/finally which
  1330. // calls a subroutine which contains a try finally that raises an
  1331. // exception that is handled to the try/except.
  1332. //
  1333. printf(" test25...");
  1334. Counter = 0;
  1335. if (setjmp(JumpBuffer) == 0) {
  1336. try {
  1337. try {
  1338. try {
  1339. Counter += 1;
  1340. dojump(JumpBuffer, &Counter);
  1341. }
  1342. finally { Counter += 1; }
  1343. }
  1344. finally { Counter += 1; }
  1345. }
  1346. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 1; }
  1347. } else {
  1348. Counter += 1;
  1349. }
  1350. if (Counter != 7) {
  1351. printf("failed, count = %d\n", Counter);
  1352. } else {
  1353. printf("succeeded\n");
  1354. }
  1355. //
  1356. // A set jump followed by a try/except, followed by a try/finally which
  1357. // calls a subroutine which contains a try finally that raises an
  1358. // exception that is handled to the try/except.
  1359. //
  1360. printf(" test26...");
  1361. Counter = 0;
  1362. if (setjmp(JumpBuffer) == 0) {
  1363. try {
  1364. try {
  1365. try {
  1366. try {
  1367. Counter += 1;
  1368. dojump(JumpBuffer, &Counter);
  1369. }
  1370. finally { Counter += 1; }
  1371. }
  1372. finally {
  1373. Counter += 1;
  1374. longjmp(JumpBuffer, 1);
  1375. }
  1376. }
  1377. finally { Counter += 1; }
  1378. }
  1379. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 1; }
  1380. } else {
  1381. Counter += 1;
  1382. }
  1383. if (Counter != 8) {
  1384. printf("failed, count = %d\n", Counter);
  1385. } else {
  1386. printf("succeeded\n");
  1387. }
  1388. //
  1389. // Test nested exceptions.
  1390. //
  1391. printf(" test27...");
  1392. Counter = 0;
  1393. try {
  1394. try {
  1395. Counter += 1;
  1396. except1(&Counter);
  1397. }
  1398. except(except2(GetExceptionInformation(), &Counter)) { Counter += 2; }
  1399. }
  1400. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 3; }
  1401. if (Counter != 55) {
  1402. printf("failed, count = %d\n", Counter);
  1403. } else {
  1404. printf("succeeded\n");
  1405. }
  1406. //
  1407. // Simple try that causes an integer overflow exception.
  1408. //
  1409. printf(" test28...");
  1410. Counter = 0;
  1411. try {
  1412. Counter += 1;
  1413. addtwo(0x7fff0000, 0x10000, &Counter);
  1414. }
  1415. except((GetExceptionCode() == STATUS_INTEGER_OVERFLOW)
  1416. ? EXCEPTION_EXECUTE_HANDLER
  1417. : EXCEPTION_CONTINUE_SEARCH) {
  1418. Counter += 1;
  1419. }
  1420. if (Counter != 2) {
  1421. printf("failed, count = %d\n", Counter);
  1422. } else {
  1423. printf("succeeded\n");
  1424. }
  1425. //
  1426. // Simple try that raises an misaligned data exception.
  1427. //
  1428. #if !defined(i386) && !defined(_M_IA64) && !defined(_M_AMD64) && \
  1429. !defined(_M_ARM) && !defined(_M_ARM64)
  1430. printf(" test29...");
  1431. Counter = 0;
  1432. try {
  1433. Counter += 1;
  1434. foo2(BlackHole, (PLONG)BadByte);
  1435. }
  1436. except((GetExceptionCode() == STATUS_DATATYPE_MISALIGNMENT)
  1437. ? EXCEPTION_EXECUTE_HANDLER
  1438. : EXCEPTION_CONTINUE_SEARCH) {
  1439. Counter += 1;
  1440. }
  1441. if (Counter != 2) {
  1442. printf("failed, count = %d\n", Counter);
  1443. } else {
  1444. printf("succeeded\n");
  1445. }
  1446. #endif
  1447. //
  1448. // Continue from a try body with an exception clause in a loop.
  1449. //
  1450. printf(" test30...");
  1451. Counter = 0;
  1452. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1453. try {
  1454. if ((Index1 & 0x1) == 0) {
  1455. continue;
  1456. } else {
  1457. Counter += 1;
  1458. }
  1459. }
  1460. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 40; }
  1461. Counter += 2;
  1462. }
  1463. if (Counter != 15) {
  1464. printf("failed, count = %d\n", Counter);
  1465. } else {
  1466. printf("succeeded\n");
  1467. }
  1468. #if !defined(WIN_CE) // gotos from try/finally not allowed on WinCE
  1469. //
  1470. // Continue from a try body with an finally clause in a loop.
  1471. //
  1472. printf(" test31...");
  1473. Counter = 0;
  1474. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1475. try {
  1476. if ((Index1 & 0x1) == 0) {
  1477. continue;
  1478. } else {
  1479. Counter += 1;
  1480. }
  1481. }
  1482. finally { Counter += 2; }
  1483. Counter += 3;
  1484. }
  1485. if (Counter != 40) {
  1486. printf("failed, count = %d\n", Counter);
  1487. } else {
  1488. printf("succeeded\n");
  1489. }
  1490. #endif
  1491. //
  1492. // Continue from doubly nested try body with an exception clause in a
  1493. // loop.
  1494. //
  1495. printf(" test32...");
  1496. Counter = 0;
  1497. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1498. try {
  1499. try {
  1500. if ((Index1 & 0x1) == 0) {
  1501. continue;
  1502. } else {
  1503. Counter += 1;
  1504. }
  1505. }
  1506. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 10; }
  1507. Counter += 2;
  1508. }
  1509. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 20; }
  1510. Counter += 3;
  1511. }
  1512. if (Counter != 30) {
  1513. printf("failed, count = %d\n", Counter);
  1514. } else {
  1515. printf("succeeded\n");
  1516. }
  1517. #if !defined(WIN_CE) // gotos from try/finally not allowed on WinCE
  1518. //
  1519. // Continue from doubly nested try body with an finally clause in a loop.
  1520. //
  1521. printf(" test33...");
  1522. Counter = 0;
  1523. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1524. try {
  1525. try {
  1526. if ((Index1 & 0x1) == 0) {
  1527. continue;
  1528. } else {
  1529. Counter += 1;
  1530. }
  1531. }
  1532. finally { Counter += 2; }
  1533. Counter += 3;
  1534. }
  1535. finally { Counter += 4; }
  1536. Counter += 5;
  1537. }
  1538. if (Counter != 105) {
  1539. printf("failed, count = %d\n", Counter);
  1540. } else {
  1541. printf("succeeded\n");
  1542. }
  1543. //
  1544. // Continue from a finally clause in a loop.
  1545. //
  1546. printf(" test34...");
  1547. Counter = 0;
  1548. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1549. try {
  1550. if ((Index1 & 0x1) == 0) {
  1551. Counter += 1;
  1552. }
  1553. }
  1554. finally {
  1555. Counter += 2;
  1556. continue;
  1557. }
  1558. Counter += 4;
  1559. }
  1560. if (Counter != 25) {
  1561. printf("failed, count = %d\n", Counter);
  1562. } else {
  1563. printf("succeeded\n");
  1564. }
  1565. //
  1566. // Continue from a doubly nested finally clause in a loop.
  1567. //
  1568. printf(" test35...");
  1569. Counter = 0;
  1570. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1571. try {
  1572. try {
  1573. if ((Index1 & 0x1) == 0) {
  1574. Counter += 1;
  1575. }
  1576. }
  1577. finally {
  1578. Counter += 2;
  1579. continue;
  1580. }
  1581. Counter += 4;
  1582. }
  1583. finally { Counter += 5; }
  1584. Counter += 6;
  1585. }
  1586. if (Counter != 75) {
  1587. printf("failed, count = %d\n", Counter);
  1588. } else {
  1589. printf("succeeded\n");
  1590. }
  1591. //
  1592. // Continue from a doubly nested finally clause in a loop.
  1593. //
  1594. printf(" test36...");
  1595. Counter = 0;
  1596. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1597. try {
  1598. try {
  1599. if ((Index1 & 0x1) == 0) {
  1600. Counter += 1;
  1601. }
  1602. }
  1603. finally { Counter += 2; }
  1604. Counter += 4;
  1605. }
  1606. finally {
  1607. Counter += 5;
  1608. continue;
  1609. }
  1610. Counter += 6;
  1611. }
  1612. if (Counter != 115) {
  1613. printf("failed, count = %d\n", Counter);
  1614. } else {
  1615. printf("succeeded\n");
  1616. }
  1617. #endif
  1618. //
  1619. // Break from a try body with an exception clause in a loop.
  1620. //
  1621. printf(" test37...");
  1622. Counter = 0;
  1623. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1624. try {
  1625. if ((Index1 & 0x1) == 1) {
  1626. break;
  1627. } else {
  1628. Counter += 1;
  1629. }
  1630. }
  1631. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 40; }
  1632. Counter += 2;
  1633. }
  1634. if (Counter != 3) {
  1635. printf("failed, count = %d\n", Counter);
  1636. } else {
  1637. printf("succeeded\n");
  1638. }
  1639. #if !defined(WIN_CE) // gotos from try/finally not allowed on WinCE
  1640. //
  1641. // Break from a try body with an finally clause in a loop.
  1642. //
  1643. printf(" test38...");
  1644. Counter = 0;
  1645. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1646. try {
  1647. if ((Index1 & 0x1) == 1) {
  1648. break;
  1649. } else {
  1650. Counter += 1;
  1651. }
  1652. }
  1653. finally { Counter += 2; }
  1654. Counter += 3;
  1655. }
  1656. if (Counter != 8) {
  1657. printf("failed, count = %d\n", Counter);
  1658. } else {
  1659. printf("succeeded\n");
  1660. }
  1661. #endif
  1662. //
  1663. // Break from doubly nested try body with an exception clause in a
  1664. // loop.
  1665. //
  1666. printf(" test39...");
  1667. Counter = 0;
  1668. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1669. try {
  1670. try {
  1671. if ((Index1 & 0x1) == 1) {
  1672. break;
  1673. } else {
  1674. Counter += 1;
  1675. }
  1676. }
  1677. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 10; }
  1678. Counter += 2;
  1679. }
  1680. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 20; }
  1681. Counter += 3;
  1682. }
  1683. if (Counter != 6) {
  1684. printf("failed, count = %d\n", Counter);
  1685. } else {
  1686. printf("succeeded\n");
  1687. }
  1688. #if !defined(WIN_CE) // gotos from try/finally not allowed on WinCE
  1689. //
  1690. // Break from doubly nested try body with an finally clause in a loop.
  1691. //
  1692. printf(" test40...");
  1693. Counter = 0;
  1694. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1695. try {
  1696. try {
  1697. if ((Index1 & 0x1) == 1) {
  1698. break;
  1699. } else {
  1700. Counter += 1;
  1701. }
  1702. }
  1703. finally { Counter += 2; }
  1704. Counter += 3;
  1705. }
  1706. finally { Counter += 4; }
  1707. Counter += 5;
  1708. }
  1709. if (Counter != 21) {
  1710. printf("failed, count = %d\n", Counter);
  1711. } else {
  1712. printf("succeeded\n");
  1713. }
  1714. //
  1715. // Break from a finally clause in a loop.
  1716. //
  1717. printf(" test41...");
  1718. Counter = 0;
  1719. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1720. try {
  1721. if ((Index1 & 0x1) == 1) {
  1722. Counter += 1;
  1723. }
  1724. }
  1725. finally {
  1726. Counter += 2;
  1727. break;
  1728. }
  1729. Counter += 4;
  1730. }
  1731. if (Counter != 2) {
  1732. printf("failed, count = %d\n", Counter);
  1733. } else {
  1734. printf("succeeded\n");
  1735. }
  1736. //
  1737. // Break from a doubly nested finally clause in a loop.
  1738. //
  1739. printf(" test42...");
  1740. Counter = 0;
  1741. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1742. try {
  1743. try {
  1744. if ((Index1 & 0x1) == 1) {
  1745. Counter += 1;
  1746. }
  1747. }
  1748. finally {
  1749. Counter += 2;
  1750. break;
  1751. }
  1752. Counter += 4;
  1753. }
  1754. finally { Counter += 5; }
  1755. Counter += 6;
  1756. }
  1757. if (Counter != 7) {
  1758. printf("failed, count = %d\n", Counter);
  1759. } else {
  1760. printf("succeeded\n");
  1761. }
  1762. //
  1763. // Break from a doubly nested finally clause in a loop.
  1764. //
  1765. printf(" test43...");
  1766. Counter = 0;
  1767. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1768. try {
  1769. try {
  1770. if ((Index1 & 0x1) == 1) {
  1771. Counter += 1;
  1772. }
  1773. }
  1774. finally { Counter += 2; }
  1775. Counter += 4;
  1776. }
  1777. finally {
  1778. Counter += 5;
  1779. break;
  1780. }
  1781. Counter += 6;
  1782. }
  1783. if (Counter != 11) {
  1784. printf("failed, count = %d\n", Counter);
  1785. } else {
  1786. printf("succeeded\n");
  1787. }
  1788. #endif
  1789. //
  1790. // Break from a try body with an exception clause in a switch.
  1791. //
  1792. printf(" test44...");
  1793. Counter = 0;
  1794. Index1 = 1;
  1795. switch (Index2) {
  1796. case BLUE:
  1797. Counter += 100;
  1798. break;
  1799. case RED:
  1800. try {
  1801. if ((Index1 & 0x1) == 1) {
  1802. break;
  1803. } else {
  1804. Counter += 1;
  1805. }
  1806. }
  1807. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 40; }
  1808. Counter += 2;
  1809. break;
  1810. }
  1811. if (Counter != 0) {
  1812. printf("failed, count = %d\n", Counter);
  1813. } else {
  1814. printf("succeeded\n");
  1815. }
  1816. #if !defined(WIN_CE) // gotos from try/finally not allowed on WinCE
  1817. //
  1818. // Break from a try body with an finally clause in a switch.
  1819. //
  1820. printf(" test45...");
  1821. Counter = 0;
  1822. Index1 = 1;
  1823. switch (Index2) {
  1824. case BLUE:
  1825. Counter += 100;
  1826. break;
  1827. case RED:
  1828. try {
  1829. if ((Index1 & 0x1) == 1) {
  1830. break;
  1831. } else {
  1832. Counter += 1;
  1833. }
  1834. }
  1835. finally { Counter += 2; }
  1836. Counter += 3;
  1837. }
  1838. if (Counter != 2) {
  1839. printf("failed, count = %d\n", Counter);
  1840. } else {
  1841. printf("succeeded\n");
  1842. }
  1843. #endif
  1844. //
  1845. // Break from doubly nested try body with an exception clause in a
  1846. // switch.
  1847. //
  1848. printf(" test46...");
  1849. Counter = 0;
  1850. Index1 = 1;
  1851. switch (Index2) {
  1852. case BLUE:
  1853. Counter += 100;
  1854. break;
  1855. case RED:
  1856. try {
  1857. try {
  1858. if ((Index1 & 0x1) == 1) {
  1859. break;
  1860. } else {
  1861. Counter += 1;
  1862. }
  1863. }
  1864. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 10; }
  1865. Counter += 2;
  1866. }
  1867. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 20; }
  1868. Counter += 3;
  1869. }
  1870. if (Counter != 0) {
  1871. printf("failed, count = %d\n", Counter);
  1872. } else {
  1873. printf("succeeded\n");
  1874. }
  1875. #if !defined(WIN_CE) // gotos from try/finally not allowed on WinCE
  1876. //
  1877. // Break from doubly nested try body with an finally clause in a switch.
  1878. //
  1879. printf(" test47...");
  1880. Counter = 0;
  1881. Index1 = 1;
  1882. switch (Index2) {
  1883. case BLUE:
  1884. Counter += 100;
  1885. break;
  1886. case RED:
  1887. try {
  1888. try {
  1889. if ((Index1 & 0x1) == 1) {
  1890. break;
  1891. } else {
  1892. Counter += 1;
  1893. }
  1894. }
  1895. finally { Counter += 2; }
  1896. Counter += 3;
  1897. }
  1898. finally { Counter += 4; }
  1899. Counter += 5;
  1900. }
  1901. if (Counter != 6) {
  1902. printf("failed, count = %d\n", Counter);
  1903. } else {
  1904. printf("succeeded\n");
  1905. }
  1906. //
  1907. // Break from a finally clause in a switch.
  1908. //
  1909. printf(" test48...");
  1910. Counter = 0;
  1911. Index1 = 1;
  1912. switch (Index2) {
  1913. case BLUE:
  1914. Counter += 100;
  1915. break;
  1916. case RED:
  1917. try {
  1918. if ((Index1 & 0x1) == 1) {
  1919. Counter += 1;
  1920. }
  1921. }
  1922. finally {
  1923. Counter += 2;
  1924. break;
  1925. }
  1926. Counter += 4;
  1927. }
  1928. if (Counter != 3) {
  1929. printf("failed, count = %d\n", Counter);
  1930. } else {
  1931. printf("succeeded\n");
  1932. }
  1933. //
  1934. // Break from a doubly nested finally clause in a switch.
  1935. //
  1936. printf(" test49...");
  1937. Counter = 0;
  1938. Index1 = 1;
  1939. switch (Index2) {
  1940. case BLUE:
  1941. Counter += 100;
  1942. break;
  1943. case RED:
  1944. try {
  1945. try {
  1946. if ((Index1 & 0x1) == 1) {
  1947. Counter += 1;
  1948. }
  1949. }
  1950. finally {
  1951. Counter += 2;
  1952. break;
  1953. }
  1954. Counter += 4;
  1955. }
  1956. finally { Counter += 5; }
  1957. Counter += 6;
  1958. }
  1959. if (Counter != 8) {
  1960. printf("failed, count = %d\n", Counter);
  1961. } else {
  1962. printf("succeeded\n");
  1963. }
  1964. //
  1965. // Break from a doubly nested finally clause in a switch.
  1966. //
  1967. printf(" test50...");
  1968. Counter = 0;
  1969. Index1 = 1;
  1970. switch (Index2) {
  1971. case BLUE:
  1972. Counter += 100;
  1973. break;
  1974. case RED:
  1975. try {
  1976. try {
  1977. if ((Index1 & 0x1) == 1) {
  1978. Counter += 1;
  1979. }
  1980. }
  1981. finally { Counter += 2; }
  1982. Counter += 4;
  1983. }
  1984. finally {
  1985. Counter += 5;
  1986. break;
  1987. }
  1988. Counter += 6;
  1989. }
  1990. if (Counter != 12) {
  1991. printf("failed, count = %d\n", Counter);
  1992. } else {
  1993. printf("succeeded\n");
  1994. }
  1995. #endif
  1996. //
  1997. // Leave from an if in a simple try/finally.
  1998. //
  1999. printf(" test51...");
  2000. Counter = 0;
  2001. try {
  2002. if (Echo(Counter) == Counter) {
  2003. Counter += 3;
  2004. leave;
  2005. } else {
  2006. Counter += 100;
  2007. }
  2008. }
  2009. finally {
  2010. if (abnormal_termination() == FALSE) {
  2011. Counter += 5;
  2012. }
  2013. }
  2014. if (Counter != 8) {
  2015. printf("failed, count = %d\n", Counter);
  2016. } else {
  2017. printf("succeeded\n");
  2018. }
  2019. //
  2020. // Leave from a loop in a simple try/finally.
  2021. //
  2022. printf(" test52...");
  2023. Counter = 0;
  2024. try {
  2025. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  2026. if (Echo(Index1) == Index1) {
  2027. Counter += 3;
  2028. leave;
  2029. }
  2030. Counter += 100;
  2031. }
  2032. }
  2033. finally {
  2034. if (abnormal_termination() == FALSE) {
  2035. Counter += 5;
  2036. }
  2037. }
  2038. if (Counter != 8) {
  2039. printf("failed, count = %d\n", Counter);
  2040. } else {
  2041. printf("succeeded\n");
  2042. }
  2043. //
  2044. // Leave from a switch in a simple try/finally.
  2045. //
  2046. printf(" test53...");
  2047. Counter = 0;
  2048. try {
  2049. switch (Index2) {
  2050. case BLUE:
  2051. break;
  2052. case RED:
  2053. Counter += 3;
  2054. leave;
  2055. }
  2056. Counter += 100;
  2057. }
  2058. finally {
  2059. if (abnormal_termination() == FALSE) {
  2060. Counter += 5;
  2061. }
  2062. }
  2063. if (Counter != 8) {
  2064. printf("failed, count = %d\n", Counter);
  2065. } else {
  2066. printf("succeeded\n");
  2067. }
  2068. //
  2069. // Leave from an if in doubly nested try/finally followed by a leave
  2070. // from an if in the outer try/finally.
  2071. //
  2072. printf(" test54...");
  2073. Counter = 0;
  2074. try {
  2075. try {
  2076. if (Echo(Counter) == Counter) {
  2077. Counter += 3;
  2078. leave;
  2079. } else {
  2080. Counter += 100;
  2081. }
  2082. }
  2083. finally {
  2084. if (abnormal_termination() == FALSE) {
  2085. Counter += 5;
  2086. }
  2087. }
  2088. if (Echo(Counter) == Counter) {
  2089. Counter += 3;
  2090. leave;
  2091. } else {
  2092. Counter += 100;
  2093. }
  2094. }
  2095. finally {
  2096. if (abnormal_termination() == FALSE) {
  2097. Counter += 5;
  2098. }
  2099. }
  2100. if (Counter != 16) {
  2101. printf("failed, count = %d\n", Counter);
  2102. } else {
  2103. printf("succeeded\n");
  2104. }
  2105. #if !defined(WIN_CE) // leave from finally not allowed on WinCE
  2106. //
  2107. // Leave from an if in doubly nested try/finally followed by a leave
  2108. // from the finally of the outer try/finally.
  2109. //
  2110. printf(" test55...");
  2111. Counter = 0;
  2112. try {
  2113. try {
  2114. if (Echo(Counter) == Counter) {
  2115. Counter += 3;
  2116. leave;
  2117. } else {
  2118. Counter += 100;
  2119. }
  2120. }
  2121. finally {
  2122. if (abnormal_termination() == FALSE) {
  2123. Counter += 5;
  2124. leave;
  2125. }
  2126. }
  2127. Counter += 100;
  2128. }
  2129. finally {
  2130. if (abnormal_termination() == FALSE) {
  2131. Counter += 5;
  2132. }
  2133. }
  2134. if (Counter != 13) {
  2135. printf("failed, count = %d\n", Counter);
  2136. } else {
  2137. printf("succeeded\n");
  2138. }
  2139. #endif
  2140. //
  2141. // Try/finally within the except clause of a try/except that is always
  2142. // executed.
  2143. //
  2144. printf(" test56...");
  2145. Counter = 0;
  2146. try {
  2147. Counter += 1;
  2148. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2149. }
  2150. except(Counter) {
  2151. try {
  2152. Counter += 3;
  2153. }
  2154. finally {
  2155. if (abnormal_termination() == FALSE) {
  2156. Counter += 5;
  2157. }
  2158. }
  2159. }
  2160. if (Counter != 9) {
  2161. printf("failed, count = %d\n", Counter);
  2162. } else {
  2163. printf("succeeded\n");
  2164. }
  2165. //
  2166. // Try/finally within the finally clause of a try/finally.
  2167. //
  2168. printf(" test57...");
  2169. Counter = 0;
  2170. try {
  2171. Counter += 1;
  2172. }
  2173. finally {
  2174. if (abnormal_termination() == FALSE) {
  2175. try {
  2176. Counter += 3;
  2177. }
  2178. finally {
  2179. if (abnormal_termination() == FALSE) {
  2180. Counter += 5;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. if (Counter != 9) {
  2186. printf("failed, count = %d\n", Counter);
  2187. } else {
  2188. printf("succeeded\n");
  2189. }
  2190. //
  2191. // Try/except within the finally clause of a try/finally.
  2192. //
  2193. printf(" test58...");
  2194. #if !defined(NEST_IN_FINALLY)
  2195. printf("skipped\n");
  2196. #else
  2197. Counter = 0;
  2198. try {
  2199. Counter -= 1;
  2200. }
  2201. finally {
  2202. try {
  2203. Counter += 2;
  2204. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2205. }
  2206. except(Counter) {
  2207. try {
  2208. Counter += 3;
  2209. }
  2210. finally {
  2211. if (abnormal_termination() == FALSE) {
  2212. Counter += 5;
  2213. }
  2214. }
  2215. }
  2216. }
  2217. if (Counter != 9) {
  2218. printf("failed, count = %d\n", Counter);
  2219. } else {
  2220. printf("succeeded\n");
  2221. }
  2222. #endif /* def(NEST_IN_FINALLY) */
  2223. //
  2224. // Try/except within the except clause of a try/except that is always
  2225. // executed.
  2226. //
  2227. printf(" test59...");
  2228. Counter = 0;
  2229. try {
  2230. Counter += 1;
  2231. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2232. }
  2233. except(Counter) {
  2234. try {
  2235. Counter += 3;
  2236. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2237. }
  2238. except(Counter - 3) { Counter += 5; }
  2239. }
  2240. if (Counter != 9) {
  2241. printf("failed, count = %d\n", Counter);
  2242. } else {
  2243. printf("succeeded\n");
  2244. }
  2245. //
  2246. // Try with a Try which exits the scope with a goto
  2247. //
  2248. printf(" test60...");
  2249. Counter = 0;
  2250. try {
  2251. try {
  2252. goto outside;
  2253. }
  2254. except(1) { Counter += 1; }
  2255. outside:
  2256. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2257. }
  2258. except(1) { Counter += 3; }
  2259. if (Counter != 3) {
  2260. printf("failed, count = %d\n", Counter);
  2261. } else {
  2262. printf("succeeded\n");
  2263. }
  2264. //
  2265. // Try/except which gets an exception from a subfunction within
  2266. // a try/finally which has a try/except in the finally clause
  2267. //
  2268. printf(" test61...");
  2269. #if !defined(NEST_IN_FINALLY)
  2270. printf("skipped\n");
  2271. #else
  2272. Counter = 0;
  2273. try {
  2274. Test61Part2(&Counter);
  2275. }
  2276. except(EXCEPTION_EXECUTE_HANDLER) { Counter += 11; }
  2277. if (Counter != 24) {
  2278. printf("failed, count = %d\n", Counter);
  2279. } else {
  2280. printf("succeeded\n");
  2281. }
  2282. #endif /* def(NEST_IN_FINALLY) */
  2283. //
  2284. // Check for precision of exception on floating point
  2285. //
  2286. printf(" test62...");
  2287. #if defined(i386) || defined(_M_IA64) || defined(_M_ALPHA) || defined(_M_AMD64)
  2288. /* enable floating point overflow */
  2289. #if defined(i386)
  2290. _control87(_control87(0, 0) & ~EM_OVERFLOW, _MCW_EM);
  2291. #else
  2292. //
  2293. // use portable version of _control87
  2294. //
  2295. _controlfp(_controlfp(0, 0) & ~EM_OVERFLOW, _MCW_EM);
  2296. #endif
  2297. Counter = 0;
  2298. try {
  2299. doubleresult = SquareDouble(1.7e300);
  2300. try {
  2301. doubleresult = SquareDouble(1.0);
  2302. }
  2303. except(1) { Counter += 3; }
  2304. }
  2305. except(1) { Counter += 1; }
  2306. if (Counter != 1) {
  2307. printf("failed, count = %d\n", Counter);
  2308. } else {
  2309. printf("succeeded\n");
  2310. }
  2311. /* clear up pending unmasked exceptions and restore FP control registers */
  2312. #if defined(i386)
  2313. _clear87();
  2314. _control87(_control87(0, 0) | EM_OVERFLOW, 0xfffff);
  2315. #else
  2316. _clearfp();
  2317. _controlfp(_controlfp(0, 0) | EM_OVERFLOW, 0xfffff);
  2318. #endif
  2319. #else
  2320. printf("skipped\n");
  2321. #endif
  2322. //
  2323. // A try/finally inside a try/except where an exception is raised in the
  2324. // try/finally.
  2325. //
  2326. printf(" test63...");
  2327. Counter = 0;
  2328. try {
  2329. try {
  2330. Counter += 1;
  2331. }
  2332. finally {
  2333. Counter += 3;
  2334. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2335. }
  2336. }
  2337. except(1) { Counter += 6; }
  2338. if (Counter != 10) {
  2339. printf("failed, count = %d\n", Counter);
  2340. } else {
  2341. printf("succeeded\n");
  2342. }
  2343. //
  2344. // A try/finally inside a try/except where an exception is raised in the
  2345. // in the try/except and the try/finally.
  2346. //
  2347. printf(" test64...");
  2348. Counter = 0;
  2349. try {
  2350. try {
  2351. Counter += 1;
  2352. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2353. }
  2354. finally {
  2355. Counter += 3;
  2356. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2357. }
  2358. }
  2359. except(1) { Counter += 6; }
  2360. if (Counter != 10) {
  2361. printf("failed, count = %d\n", Counter);
  2362. } else {
  2363. printf("succeeded\n");
  2364. }
  2365. //
  2366. // A try/finally inside a try/except where an exception is raised in the
  2367. // try/finally.
  2368. //
  2369. printf(" test65...");
  2370. Counter = 0;
  2371. try {
  2372. try {
  2373. Counter += 1;
  2374. }
  2375. finally {
  2376. Counter += 3;
  2377. *BlackHole += *BadAddress;
  2378. Counter += 13;
  2379. }
  2380. }
  2381. except(1) { Counter += 6; }
  2382. if (Counter != 10) {
  2383. printf("failed, count = %d\n", Counter);
  2384. } else {
  2385. printf("succeeded\n");
  2386. }
  2387. //
  2388. // A try/finally inside a try/except where an exception is raised in the
  2389. // in the try/except and the try/finally.
  2390. //
  2391. printf(" test66...");
  2392. Counter = 0;
  2393. try {
  2394. try {
  2395. Counter += 1;
  2396. *BlackHole += *BadAddress;
  2397. Counter += 13;
  2398. }
  2399. finally {
  2400. Counter += 3;
  2401. *BlackHole += *BadAddress;
  2402. Counter += 13;
  2403. }
  2404. }
  2405. except(1) { Counter += 6; }
  2406. if (Counter != 10) {
  2407. printf("failed, count = %d\n", Counter);
  2408. } else {
  2409. printf("succeeded\n");
  2410. }
  2411. //
  2412. // A try/finally inside a try/finally inside a try/except where an
  2413. // exception is raised in the in the try/except and in try/finally.
  2414. //
  2415. printf(" test67...");
  2416. try {
  2417. try {
  2418. *BlackHole += *BadAddress;
  2419. }
  2420. finally {
  2421. try {
  2422. Counter = 0;
  2423. }
  2424. finally {
  2425. if (Counter != 0) {
  2426. Counter += 1;
  2427. }
  2428. }
  2429. Counter += 1;
  2430. *BlackHole += *BadAddress;
  2431. }
  2432. }
  2433. except(1) { Counter += 1; }
  2434. if (Counter != 2) {
  2435. printf("failed, count = %d\n", Counter);
  2436. } else {
  2437. printf("succeeded\n");
  2438. }
  2439. //
  2440. // A try/finally inside a try/finally inside a try/except where an
  2441. // exception is raised in the in the try/except and in try/finally.
  2442. //
  2443. printf(" test68...");
  2444. try {
  2445. try {
  2446. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2447. }
  2448. finally {
  2449. try {
  2450. Counter = 0;
  2451. }
  2452. finally {
  2453. if (Counter != 0) {
  2454. Counter += 1;
  2455. }
  2456. }
  2457. Counter += 1;
  2458. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2459. }
  2460. }
  2461. except(1) { Counter += 1; }
  2462. if (Counter != 2) {
  2463. printf("failed, count = %d\n", Counter);
  2464. } else {
  2465. printf("succeeded\n");
  2466. }
  2467. //
  2468. // Patch guard test 69.
  2469. //
  2470. #if defined(_AMD64_) || defined(_X86_)
  2471. printf(" test69...");
  2472. Counter = 0;
  2473. try {
  2474. PgTest69(&Counter, BadAddress);
  2475. }
  2476. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2477. if (Counter != 2) {
  2478. printf("failed, count = %d\n", Counter);
  2479. } else {
  2480. printf("succeeded\n");
  2481. }
  2482. printf(" test70...");
  2483. Counter = 0;
  2484. try {
  2485. PgTest70(&Counter, BadAddress);
  2486. }
  2487. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2488. if (Counter != 2) {
  2489. printf("failed, count = %d\n", Counter);
  2490. } else {
  2491. printf("succeeded\n");
  2492. }
  2493. printf(" test71...");
  2494. Counter = 0;
  2495. try {
  2496. PgTest71(&Counter, BadAddress);
  2497. }
  2498. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2499. if (Counter != 9) {
  2500. printf("failed, count = %d\n", Counter);
  2501. } else {
  2502. printf("succeeded\n");
  2503. }
  2504. printf(" test72...");
  2505. Counter = 0;
  2506. try {
  2507. PgTest72(&Counter, BadAddress);
  2508. }
  2509. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2510. if (Counter != 12) {
  2511. printf("failed, count = %d\n", Counter);
  2512. } else {
  2513. printf("succeeded\n");
  2514. }
  2515. printf(" test73...");
  2516. Counter = 0;
  2517. try {
  2518. PgTest73(&Counter, BadAddress);
  2519. }
  2520. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2521. if (Counter != 15) {
  2522. printf("failed, count = %d\n", Counter);
  2523. } else {
  2524. printf("succeeded\n");
  2525. }
  2526. printf(" test74...");
  2527. Counter = 0;
  2528. try {
  2529. PgTest74(&Counter, BadAddress);
  2530. }
  2531. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2532. if (Counter != 18) {
  2533. printf("failed, count = %d\n", Counter);
  2534. } else {
  2535. printf("succeeded\n");
  2536. }
  2537. printf(" test75...");
  2538. Counter = 0;
  2539. try {
  2540. PgTest75(&Counter, BadAddress);
  2541. }
  2542. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2543. if (Counter != 35) {
  2544. printf("failed, count = %d\n", Counter);
  2545. } else {
  2546. printf("succeeded\n");
  2547. }
  2548. printf(" test76...");
  2549. Counter = 0;
  2550. try {
  2551. PgTest76(&Counter, BadAddress);
  2552. }
  2553. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2554. if (Counter != 40) {
  2555. printf("failed, count = %d\n", Counter);
  2556. } else {
  2557. printf("succeeded\n");
  2558. }
  2559. printf(" test77...");
  2560. Counter = 0;
  2561. try {
  2562. PgTest77(&Counter, BadAddress);
  2563. }
  2564. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2565. if (Counter != 45) {
  2566. printf("failed, count = %d\n", Counter);
  2567. } else {
  2568. printf("succeeded\n");
  2569. }
  2570. printf(" test78...");
  2571. Counter = 0;
  2572. try {
  2573. PgTest78(&Counter, BadAddress);
  2574. }
  2575. except(EXCEPTION_EXECUTE_HANDLER) { printf("unexpected exception..."); }
  2576. if (Counter != 50) {
  2577. printf("failed, count = %d\n", Counter);
  2578. } else {
  2579. printf("succeeded\n");
  2580. }
  2581. #else
  2582. printf(" test69...filter entered...succeeded\n");
  2583. printf(" test70...filter entered...succeeded\n");
  2584. printf(" test71...filter entered...succeeded\n");
  2585. printf(" test72...filter entered...succeeded\n");
  2586. printf(" test73...filter entered...succeeded\n");
  2587. printf(" test74...filter entered...succeeded\n");
  2588. printf(" test75...filter entered...succeeded\n");
  2589. printf(" test76...filter entered...succeeded\n");
  2590. printf(" test77...filter entered...succeeded\n");
  2591. printf(" test78...filter entered...succeeded\n");
  2592. #endif
  2593. if (LOBYTE(LOWORD(GetVersion())) < 6) {
  2594. printf(" test79...");
  2595. printf("filter 1...filter 2...finally 1...filter 1...filter 2...finally "
  2596. "2...passed\n");
  2597. } else {
  2598. printf(" test79...");
  2599. Counter = 0;
  2600. try {
  2601. Test79(&Counter, BadAddress);
  2602. }
  2603. except(printf("filter 2..."), EXCEPTION_EXECUTE_HANDLER) { Counter += 1; }
  2604. if (Counter == 3) {
  2605. printf("passed\n");
  2606. } else {
  2607. printf("failed %d \n", Counter);
  2608. }
  2609. }
  2610. printf(" test80...");
  2611. if (Test80() != 0) {
  2612. printf("failed\n");
  2613. } else {
  2614. printf("passed\n");
  2615. }
  2616. printf(" test81...");
  2617. Counter = 0;
  2618. Test81(&Counter);
  2619. if (Counter != 1) {
  2620. printf("failed %d \n", Counter);
  2621. } else {
  2622. printf("passed\n");
  2623. }
  2624. printf(" test82...");
  2625. Counter = 1;
  2626. Test82(&Counter);
  2627. if (Counter != 0) {
  2628. printf("failed\n");
  2629. } else {
  2630. printf("succeeded\n");
  2631. }
  2632. printf(" test83...");
  2633. if (Test83() != 0) {
  2634. printf("failed\n");
  2635. } else {
  2636. printf("succeeded\n");
  2637. }
  2638. printf(" test84...");
  2639. Counter = 0;
  2640. Test84(&Counter);
  2641. if (Counter != 2) {
  2642. printf("failed\n");
  2643. } else {
  2644. printf("succeeded\n");
  2645. }
  2646. printf(" test85...");
  2647. Counter = 0;
  2648. Test85(&Counter);
  2649. if (Counter != 7) {
  2650. printf("failed\n");
  2651. } else {
  2652. printf("succeeded\n");
  2653. }
  2654. printf(" test86...");
  2655. Counter = 0;
  2656. Test86(&Counter);
  2657. if (Counter != 4) {
  2658. printf("failed %d\n", Counter);
  2659. } else {
  2660. printf("succeeded\n");
  2661. }
  2662. printf(" test87...");
  2663. Counter = 0;
  2664. Test87(&Counter);
  2665. if (Counter != 104) {
  2666. printf("failed %d\n", Counter);
  2667. } else {
  2668. printf("succeeded\n");
  2669. }
  2670. printf(" test88...");
  2671. Counter = 0;
  2672. Test88(&Counter);
  2673. if (Counter != 6) {
  2674. printf("failed %d\n", Counter);
  2675. } else {
  2676. printf("succeeded\n");
  2677. }
  2678. //
  2679. // Announce end of exception test.
  2680. //
  2681. printf("End of exception test\n");
  2682. return;
  2683. }
  2684. #pragma optimize("a", off)
  2685. VOID addtwo(long First, long Second, long *Place)
  2686. {
  2687. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2688. *Place = First + Second;
  2689. return;
  2690. }
  2691. #pragma optimize("", on)
  2692. VOID bar1(IN NTSTATUS Status, IN PLONG Counter) {
  2693. try {
  2694. foo1(Status);
  2695. }
  2696. finally {
  2697. if (abnormal_termination() != FALSE) {
  2698. *Counter = 99;
  2699. } else {
  2700. *Counter = 100;
  2701. }
  2702. }
  2703. return;
  2704. }
  2705. VOID bar2(IN PLONG BlackHole, IN PLONG BadAddress, IN PLONG Counter) {
  2706. try {
  2707. foo2(BlackHole, BadAddress);
  2708. }
  2709. finally {
  2710. if (abnormal_termination() != FALSE) {
  2711. *Counter = 99;
  2712. } else {
  2713. *Counter = 100;
  2714. }
  2715. }
  2716. return;
  2717. }
  2718. VOID dojump(IN jmp_buf JumpBuffer, IN PLONG Counter)
  2719. {
  2720. try {
  2721. try {
  2722. *Counter += 1;
  2723. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2724. }
  2725. finally { *Counter += 1; }
  2726. }
  2727. finally {
  2728. *Counter += 1;
  2729. longjmp(JumpBuffer, 1);
  2730. }
  2731. }
  2732. #if !defined(WIN_CE) // return through finally not allowed on WinCE
  2733. VOID eret(IN NTSTATUS Status, IN PLONG Counter)
  2734. {
  2735. try {
  2736. try {
  2737. foo1(Status);
  2738. }
  2739. except((GetExceptionCode() == Status) ? EXCEPTION_EXECUTE_HANDLER
  2740. : EXCEPTION_CONTINUE_SEARCH) {
  2741. *Counter += 1;
  2742. return;
  2743. }
  2744. }
  2745. finally { *Counter += 1; }
  2746. return;
  2747. }
  2748. #endif
  2749. VOID except1(IN PLONG Counter)
  2750. {
  2751. try {
  2752. *Counter += 5;
  2753. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2754. }
  2755. except(except3(GetExceptionInformation(), Counter)) { *Counter += 7; }
  2756. *Counter += 9;
  2757. return;
  2758. }
  2759. ULONG
  2760. except2(IN PEXCEPTION_POINTERS ExceptionPointers, IN PLONG Counter)
  2761. {
  2762. PEXCEPTION_RECORD ExceptionRecord;
  2763. ExceptionRecord = ExceptionPointers->ExceptionRecord;
  2764. if ((ExceptionRecord->ExceptionCode == STATUS_UNSUCCESSFUL) &&
  2765. ((ExceptionRecord->ExceptionFlags & EXCEPTION_NESTED_CALL) == 0)) {
  2766. *Counter += 11;
  2767. return EXCEPTION_EXECUTE_HANDLER;
  2768. } else {
  2769. *Counter += 13;
  2770. return EXCEPTION_CONTINUE_SEARCH;
  2771. }
  2772. }
  2773. ULONG
  2774. except3(IN PEXCEPTION_POINTERS ExceptionPointers, IN PLONG Counter)
  2775. {
  2776. PEXCEPTION_RECORD ExceptionRecord;
  2777. ExceptionRecord = ExceptionPointers->ExceptionRecord;
  2778. if ((ExceptionRecord->ExceptionCode == STATUS_INTEGER_OVERFLOW) &&
  2779. ((ExceptionRecord->ExceptionFlags & EXCEPTION_NESTED_CALL) == 0)) {
  2780. *Counter += 17;
  2781. RtlRaiseStatus(STATUS_UNSUCCESSFUL);
  2782. } else if ((ExceptionRecord->ExceptionCode == STATUS_UNSUCCESSFUL) &&
  2783. ((ExceptionRecord->ExceptionFlags & EXCEPTION_NESTED_CALL) != 0)) {
  2784. *Counter += 19;
  2785. return EXCEPTION_CONTINUE_SEARCH;
  2786. }
  2787. *Counter += 23;
  2788. return EXCEPTION_EXECUTE_HANDLER;
  2789. }
  2790. VOID foo1(IN NTSTATUS Status)
  2791. {
  2792. //
  2793. // Raise exception.
  2794. //
  2795. RtlRaiseStatus(Status);
  2796. return;
  2797. }
  2798. VOID foo2(IN PLONG BlackHole, IN PLONG BadAddress)
  2799. {
  2800. //
  2801. // Raise exception.
  2802. //
  2803. *BlackHole += *BadAddress;
  2804. return;
  2805. }
  2806. #if !defined(WIN_CE) // return from finally not allowed on WinCE
  2807. VOID fret(IN PLONG Counter)
  2808. {
  2809. try {
  2810. try {
  2811. *Counter += 1;
  2812. }
  2813. finally {
  2814. *Counter += 1;
  2815. return;
  2816. }
  2817. }
  2818. finally { *Counter += 1; }
  2819. return;
  2820. }
  2821. #endif
  2822. LONG Echo(IN LONG Value)
  2823. {
  2824. return Value;
  2825. }
  2826. #if defined(NEST_IN_FINALLY)
  2827. VOID Test61Part2(IN OUT PULONG Counter) {
  2828. try {
  2829. *Counter -= 1;
  2830. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2831. }
  2832. finally {
  2833. try {
  2834. *Counter += 2;
  2835. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  2836. }
  2837. except(EXCEPTION_EXECUTE_HANDLER) { *Counter += 5; }
  2838. *Counter += 7;
  2839. }
  2840. }
  2841. #endif /* def(NEST_IN_FINALLY) */
  2842. double SquareDouble(IN double op) {
  2843. return exp(2.0 * log(op));
  2844. }