Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2400 lines
45 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. xcpt4.c
  5. Abstract:
  6. This module implements user mode exception tests.
  7. Author:
  8. David N. Cutler (davec) 18-Sep-1990
  9. Environment:
  10. Kernel mode only.
  11. Revision History:
  12. --*/
  13. #include "stdio.h"
  14. #include "nt.h"
  15. #include "ntrtl.h"
  16. #include "setjmpex.h"
  17. #include "float.h"
  18. #pragma warning(disable:4532)
  19. //
  20. // Define switch constants.
  21. //
  22. #define BLUE 0
  23. #define RED 1
  24. //
  25. // Define function prototypes.
  26. //
  27. VOID
  28. addtwo (
  29. IN LONG First,
  30. IN LONG Second,
  31. IN PLONG Place
  32. );
  33. VOID
  34. bar1 (
  35. IN NTSTATUS Status,
  36. IN PLONG Counter
  37. );
  38. VOID
  39. bar2 (
  40. IN PLONG BlackHole,
  41. IN PLONG BadAddress,
  42. IN PLONG Counter
  43. );
  44. VOID
  45. dojump (
  46. IN jmp_buf JumpBuffer,
  47. IN PLONG Counter
  48. );
  49. LONG
  50. Echo(
  51. IN LONG Value
  52. );
  53. VOID
  54. eret (
  55. IN NTSTATUS Status,
  56. IN PLONG Counter
  57. );
  58. VOID
  59. except1 (
  60. IN PLONG Counter
  61. );
  62. ULONG
  63. except2 (
  64. IN PEXCEPTION_POINTERS ExceptionPointers,
  65. IN PLONG Counter
  66. );
  67. ULONG
  68. except3 (
  69. IN PEXCEPTION_POINTERS ExceptionPointers,
  70. IN PLONG Counter
  71. );
  72. VOID
  73. foo1 (
  74. IN NTSTATUS Status
  75. );
  76. VOID
  77. foo2 (
  78. IN PLONG BlackHole,
  79. IN PLONG BadAddress
  80. );
  81. VOID
  82. fret (
  83. IN PLONG Counter
  84. );
  85. BOOLEAN
  86. Tkm (
  87. VOID
  88. );
  89. VOID
  90. Test61Part2 (
  91. IN OUT PULONG Counter
  92. );
  93. VOID
  94. PerformFpTest(
  95. VOID
  96. );
  97. double
  98. SquareDouble (
  99. IN double op
  100. );
  101. VOID
  102. SquareDouble17E300 (
  103. OUT PVOID ans
  104. );
  105. VOID
  106. __cdecl
  107. main(
  108. int argc,
  109. char *argv[]
  110. )
  111. {
  112. PLONG BadAddress;
  113. PCHAR BadByte;
  114. PLONG BlackHole;
  115. ULONG Index1;
  116. ULONG Index2 = RED;
  117. jmp_buf JumpBuffer;
  118. LONG Counter;
  119. EXCEPTION_RECORD ExceptionRecord;
  120. double doubleresult;
  121. //
  122. // Announce start of exception test.
  123. //
  124. printf("Start of exception test\n");
  125. //
  126. // Initialize exception record.
  127. //
  128. ExceptionRecord.ExceptionCode = STATUS_INTEGER_OVERFLOW;
  129. ExceptionRecord.ExceptionFlags = 0;
  130. ExceptionRecord.ExceptionRecord = NULL;
  131. ExceptionRecord.NumberParameters = 0;
  132. //
  133. // Initialize pointers.
  134. //
  135. BadAddress = (PLONG)NULL;
  136. BadByte = (PCHAR)NULL;
  137. BadByte += 1;
  138. BlackHole = &Counter;
  139. //
  140. // Simply try statement with a finally clause that is entered sequentially.
  141. //
  142. printf(" test1...");
  143. Counter = 0;
  144. try {
  145. Counter += 1;
  146. } finally {
  147. if (abnormal_termination() == FALSE) {
  148. Counter += 1;
  149. }
  150. }
  151. if (Counter != 2) {
  152. printf("failed, count = %d\n", Counter);
  153. } else {
  154. printf("succeeded\n");
  155. }
  156. //
  157. // Simple try statement with an exception clause that is never executed
  158. // because there is no exception raised in the try clause.
  159. //
  160. printf(" test2...");
  161. Counter = 0;
  162. try {
  163. Counter += 1;
  164. } except (Counter) {
  165. Counter += 1;
  166. }
  167. if (Counter != 1) {
  168. printf("failed, count = %d\n", Counter);
  169. } else {
  170. printf("succeeded\n");
  171. }
  172. //
  173. // Simple try statement with an exception handler that is never executed
  174. // because the exception expression continues execution.
  175. //
  176. printf(" test3...");
  177. Counter = 0;
  178. try {
  179. Counter -= 1;
  180. RtlRaiseException(&ExceptionRecord);
  181. } except (Counter) {
  182. Counter -= 1;
  183. }
  184. if (Counter != - 1) {
  185. printf("failed, count = %d\n", Counter);
  186. } else {
  187. printf("succeeded\n");
  188. }
  189. //
  190. // Simple try statement with an exception clause that is always executed.
  191. //
  192. printf(" test4...");
  193. Counter = 0;
  194. try {
  195. Counter += 1;
  196. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  197. } except (Counter) {
  198. Counter += 1;
  199. }
  200. if (Counter != 2) {
  201. printf("failed, count = %d\n", Counter);
  202. } else {
  203. printf("succeeded\n");
  204. }
  205. //
  206. // Simple try statement with an exception clause that is always executed.
  207. //
  208. printf(" test5...");
  209. Counter = 0;
  210. try {
  211. Counter += 1;
  212. *BlackHole += *BadAddress;
  213. } except (Counter) {
  214. Counter += 1;
  215. }
  216. if (Counter != 2) {
  217. printf("failed, count = %d\n", Counter);
  218. } else {
  219. printf("succeeded\n");
  220. }
  221. //
  222. // Simply try statement with a finally clause that is entered as the
  223. // result of an exception.
  224. //
  225. printf(" test6...");
  226. Counter = 0;
  227. try {
  228. try {
  229. Counter += 1;
  230. RtlRaiseException(&ExceptionRecord);
  231. } finally {
  232. if (abnormal_termination() != FALSE) {
  233. Counter += 1;
  234. }
  235. }
  236. } except (Counter) {
  237. if (Counter == 2) {
  238. Counter += 1;
  239. }
  240. }
  241. if (Counter != 3) {
  242. printf("failed, count = %d\n", Counter);
  243. } else {
  244. printf("succeeded\n");
  245. }
  246. //
  247. // Simply try statement with a finally clause that is entered as the
  248. // result of an exception.
  249. //
  250. printf(" test7...");
  251. Counter = 0;
  252. try {
  253. try {
  254. Counter += 1;
  255. *BlackHole += *BadAddress;
  256. } finally {
  257. if (abnormal_termination() != FALSE) {
  258. Counter += 1;
  259. }
  260. }
  261. } except (Counter) {
  262. if (Counter == 2) {
  263. Counter += 1;
  264. }
  265. }
  266. if (Counter != 3) {
  267. printf("failed, count = %d\n", Counter);
  268. } else {
  269. printf("succeeded\n");
  270. }
  271. //
  272. // Simple try that calls a function which raises an exception.
  273. //
  274. printf(" test8...");
  275. Counter = 0;
  276. try {
  277. Counter += 1;
  278. foo1(STATUS_ACCESS_VIOLATION);
  279. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  280. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  281. Counter += 1;
  282. }
  283. if (Counter != 2) {
  284. printf("failed, count = %d\n", Counter);
  285. } else {
  286. printf("succeeded\n");
  287. }
  288. //
  289. // Simple try that calls a function which raises an exception.
  290. //
  291. printf(" test9...");
  292. Counter = 0;
  293. try {
  294. Counter += 1;
  295. foo2(BlackHole, BadAddress);
  296. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  297. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  298. Counter += 1;
  299. }
  300. if (Counter != 2) {
  301. printf("failed, count = %d\n", Counter);
  302. } else {
  303. printf("succeeded\n");
  304. }
  305. //
  306. // Simple try that calls a function which calls a function that
  307. // raises an exception. The first function has a finally clause
  308. // that must be executed for this test to work.
  309. //
  310. printf(" test10...");
  311. Counter = 0;
  312. try {
  313. bar1(STATUS_ACCESS_VIOLATION, &Counter);
  314. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  315. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  316. Counter -= 1;
  317. }
  318. if (Counter != 98) {
  319. printf("failed, count = %d\n", Counter);
  320. } else {
  321. printf("succeeded\n");
  322. }
  323. //
  324. // Simple try that calls a function which calls a function that
  325. // raises an exception. The first function has a finally clause
  326. // that must be executed for this test to work.
  327. //
  328. printf(" test11...");
  329. Counter = 0;
  330. try {
  331. bar2(BlackHole, BadAddress, &Counter);
  332. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  333. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  334. Counter -= 1;
  335. }
  336. if (Counter != 98) {
  337. printf("failed, count = %d\n", Counter);
  338. } else {
  339. printf("succeeded\n");
  340. }
  341. //
  342. // A try within an except
  343. //
  344. printf(" test12...");
  345. Counter = 0;
  346. try {
  347. foo1(STATUS_ACCESS_VIOLATION);
  348. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  349. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  350. Counter += 1;
  351. try {
  352. foo1(STATUS_SUCCESS);
  353. } except ((GetExceptionCode() == STATUS_SUCCESS) ?
  354. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  355. if (Counter != 1) {
  356. printf("failed, count = %d\n", Counter);
  357. } else {
  358. printf("succeeded...");
  359. }
  360. Counter += 1;
  361. }
  362. }
  363. if (Counter != 2) {
  364. printf("failed, count = %d\n", Counter);
  365. } else {
  366. printf("succeeded\n");
  367. }
  368. //
  369. // A try within an except
  370. //
  371. printf(" test13...");
  372. Counter = 0;
  373. try {
  374. foo2(BlackHole, BadAddress);
  375. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  376. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  377. Counter += 1;
  378. try {
  379. foo1(STATUS_SUCCESS);
  380. } except ((GetExceptionCode() == STATUS_SUCCESS) ?
  381. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  382. if (Counter != 1) {
  383. printf("failed, count = %d\n", Counter);
  384. } else {
  385. printf("succeeded...");
  386. }
  387. Counter += 1;
  388. }
  389. }
  390. if (Counter != 2) {
  391. printf("failed, count = %d\n", Counter);
  392. } else {
  393. printf("succeeded\n");
  394. }
  395. //
  396. // A goto from an exception clause that needs to pass
  397. // through a finally
  398. //
  399. printf(" test14...");
  400. Counter = 0;
  401. try {
  402. try {
  403. foo1(STATUS_ACCESS_VIOLATION);
  404. } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ?
  405. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  406. Counter += 1;
  407. goto t9;
  408. }
  409. } finally {
  410. Counter += 1;
  411. }
  412. t9:;
  413. if (Counter != 2) {
  414. printf("failed, count = %d\n", Counter);
  415. } else {
  416. printf("succeeded\n");
  417. }
  418. //
  419. // A goto from an finally clause that needs to pass
  420. // through a finally
  421. //
  422. printf(" test15...");
  423. Counter = 0;
  424. try {
  425. try {
  426. Counter += 1;
  427. } finally {
  428. Counter += 1;
  429. goto t10;
  430. }
  431. } finally {
  432. Counter += 1;
  433. }
  434. t10:;
  435. if (Counter != 3) {
  436. printf("failed, count = %d\n", Counter);
  437. } else {
  438. printf("succeeded\n");
  439. }
  440. //
  441. // A goto from an exception clause that needs to pass
  442. // through a finally into the outer finally clause.
  443. //
  444. printf(" test16...");
  445. Counter = 0;
  446. try {
  447. try {
  448. try {
  449. Counter += 1;
  450. foo1(STATUS_INTEGER_OVERFLOW);
  451. } except (EXCEPTION_EXECUTE_HANDLER) {
  452. Counter += 1;
  453. goto t11;
  454. }
  455. } finally {
  456. Counter += 1;
  457. }
  458. t11:;
  459. } finally {
  460. Counter += 1;
  461. }
  462. if (Counter != 4) {
  463. printf("failed, count = %d\n", Counter);
  464. } else {
  465. printf("succeeded\n");
  466. }
  467. //
  468. // A goto from an finally clause that needs to pass
  469. // through a finally into the outer finally clause.
  470. //
  471. printf(" test17...");
  472. Counter = 0;
  473. try {
  474. try {
  475. Counter += 1;
  476. } finally {
  477. Counter += 1;
  478. goto t12;
  479. }
  480. t12:;
  481. } finally {
  482. Counter += 1;
  483. }
  484. if (Counter != 3) {
  485. printf("failed, count = %d\n", Counter);
  486. } else {
  487. printf("succeeded\n");
  488. }
  489. //
  490. // A return from an except clause
  491. //
  492. printf(" test18...");
  493. Counter = 0;
  494. try {
  495. Counter += 1;
  496. eret(STATUS_ACCESS_VIOLATION, &Counter);
  497. } finally {
  498. Counter += 1;
  499. }
  500. if (Counter != 4) {
  501. printf("failed, count = %d\n", Counter);
  502. } else {
  503. printf("succeeded\n");
  504. }
  505. //
  506. // A return from a finally clause
  507. //
  508. printf(" test19...");
  509. Counter = 0;
  510. try {
  511. Counter += 1;
  512. fret(&Counter);
  513. } finally {
  514. Counter += 1;
  515. }
  516. if (Counter != 5) {
  517. printf("failed, count = %d\n", Counter);
  518. } else {
  519. printf("succeeded\n");
  520. }
  521. //
  522. // A simple set jump followed by a long jump.
  523. //
  524. printf(" test20...");
  525. Counter = 0;
  526. if (setjmp(JumpBuffer) == 0) {
  527. Counter += 1;
  528. longjmp(JumpBuffer, 1);
  529. } else {
  530. Counter += 1;
  531. }
  532. if (Counter != 2) {
  533. printf("failed, count = %d\n", Counter);
  534. } else {
  535. printf("succeeded\n");
  536. }
  537. //
  538. // A set jump followed by a long jump out of a finally clause that is
  539. // sequentially executed.
  540. //
  541. printf(" test21...");
  542. Counter = 0;
  543. if (setjmp(JumpBuffer) == 0) {
  544. try {
  545. Counter += 1;
  546. } finally {
  547. Counter += 1;
  548. longjmp(JumpBuffer, 1);
  549. }
  550. } else {
  551. Counter += 1;
  552. }
  553. if (Counter != 3) {
  554. printf("failed, count = %d\n", Counter);
  555. } else {
  556. printf("succeeded\n");
  557. }
  558. //
  559. // A set jump within a try clause followed by a long jump out of a
  560. // finally clause that is sequentially executed.
  561. //
  562. printf(" test22...");
  563. Counter = 0;
  564. try {
  565. if (setjmp(JumpBuffer) == 0) {
  566. Counter += 1;
  567. } else {
  568. Counter += 1;
  569. }
  570. } finally {
  571. Counter += 1;
  572. if (Counter == 2) {
  573. Counter += 1;
  574. longjmp(JumpBuffer, 1);
  575. }
  576. }
  577. if (Counter != 5) {
  578. printf("failed, count = %d\n", Counter);
  579. } else {
  580. printf("succeeded\n");
  581. }
  582. //
  583. // A set jump followed by a try/except, followed by a try/finally where
  584. // the try body of the try/finally raises an exception that is handled
  585. // by the try/excecpt which causes the try/finally to do a long jump out
  586. // of a finally clause. This will create a collided unwind.
  587. //
  588. printf(" test23...");
  589. Counter = 0;
  590. if (setjmp(JumpBuffer) == 0) {
  591. try {
  592. try {
  593. Counter += 1;
  594. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  595. } finally {
  596. Counter += 1;
  597. longjmp(JumpBuffer, 1);
  598. }
  599. } except(EXCEPTION_EXECUTE_HANDLER) {
  600. Counter += 1;
  601. }
  602. } else {
  603. Counter += 1;
  604. }
  605. if (Counter != 3) {
  606. printf("failed, count = %d\n", Counter);
  607. } else {
  608. printf("succeeded\n");
  609. }
  610. //
  611. // A set jump followed by a try/except, followed by a several nested
  612. // try/finally's where the inner try body of the try/finally raises an
  613. // exception that is handled by the try/except which causes the
  614. // try/finally to do a long jump out of a finally clause. This will
  615. // create a collided unwind.
  616. //
  617. printf(" test24...");
  618. Counter = 0;
  619. if (setjmp(JumpBuffer) == 0) {
  620. try {
  621. try {
  622. try {
  623. try {
  624. Counter += 1;
  625. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  626. } finally {
  627. Counter += 1;
  628. }
  629. } finally {
  630. Counter += 1;
  631. longjmp(JumpBuffer, 1);
  632. }
  633. } finally {
  634. Counter += 1;
  635. }
  636. } except(EXCEPTION_EXECUTE_HANDLER) {
  637. Counter += 1;
  638. }
  639. } else {
  640. Counter += 1;
  641. }
  642. if (Counter != 5) {
  643. printf("failed, count = %d\n", Counter);
  644. } else {
  645. printf("succeeded\n");
  646. }
  647. //
  648. // A set jump followed by a try/except, followed by a try/finally which
  649. // calls a subroutine which contains a try finally that raises an
  650. // exception that is handled to the try/except.
  651. //
  652. printf(" test25...");
  653. Counter = 0;
  654. if (setjmp(JumpBuffer) == 0) {
  655. try {
  656. try {
  657. try {
  658. Counter += 1;
  659. dojump(JumpBuffer, &Counter);
  660. } finally {
  661. Counter += 1;
  662. }
  663. } finally {
  664. Counter += 1;
  665. }
  666. } except(EXCEPTION_EXECUTE_HANDLER) {
  667. Counter += 1;
  668. }
  669. } else {
  670. Counter += 1;
  671. }
  672. if (Counter != 7) {
  673. printf("failed, count = %d\n", Counter);
  674. } else {
  675. printf("succeeded\n");
  676. }
  677. //
  678. // A set jump followed by a try/except, followed by a try/finally which
  679. // calls a subroutine which contains a try finally that raises an
  680. // exception that is handled to the try/except.
  681. //
  682. printf(" test26...");
  683. Counter = 0;
  684. if (setjmp(JumpBuffer) == 0) {
  685. try {
  686. try {
  687. try {
  688. try {
  689. Counter += 1;
  690. dojump(JumpBuffer, &Counter);
  691. } finally {
  692. Counter += 1;
  693. }
  694. } finally {
  695. Counter += 1;
  696. longjmp(JumpBuffer, 1);
  697. }
  698. } finally {
  699. Counter += 1;
  700. }
  701. } except(EXCEPTION_EXECUTE_HANDLER) {
  702. Counter += 1;
  703. }
  704. } else {
  705. Counter += 1;
  706. }
  707. if (Counter != 8) {
  708. printf("failed, count = %d\n", Counter);
  709. } else {
  710. printf("succeeded\n");
  711. }
  712. //
  713. // Test nested exceptions.
  714. //
  715. printf(" test27...");
  716. Counter = 0;
  717. try {
  718. try {
  719. Counter += 1;
  720. except1(&Counter);
  721. } except(except2(GetExceptionInformation(), &Counter)) {
  722. Counter += 2;
  723. }
  724. } except(EXCEPTION_EXECUTE_HANDLER) {
  725. Counter += 3;
  726. }
  727. if (Counter != 55) {
  728. printf("failed, count = %d\n", Counter);
  729. } else {
  730. printf("succeeded\n");
  731. }
  732. //
  733. // Simple try that causes an integer overflow exception.
  734. //
  735. printf(" test28...");
  736. Counter = 0;
  737. try {
  738. Counter += 1;
  739. addtwo(0x7fff0000, 0x10000, &Counter);
  740. } except ((GetExceptionCode() == STATUS_INTEGER_OVERFLOW) ?
  741. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  742. Counter += 1;
  743. }
  744. if (Counter != 2) {
  745. printf("failed, count = %d\n", Counter);
  746. } else {
  747. printf("succeeded\n");
  748. }
  749. //
  750. // Simple try that raises an misaligned data exception.
  751. //
  752. #ifndef i386
  753. printf(" test29...");
  754. Counter = 0;
  755. try {
  756. Counter += 1;
  757. foo2(BlackHole, (PLONG)BadByte);
  758. } except ((GetExceptionCode() == STATUS_DATATYPE_MISALIGNMENT) ?
  759. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  760. Counter += 1;
  761. }
  762. if (Counter != 2) {
  763. printf("failed, count = %d\n", Counter);
  764. } else {
  765. printf("succeeded\n");
  766. }
  767. #endif
  768. //
  769. // Continue from a try body with an exception clause in a loop.
  770. //
  771. printf(" test30...");
  772. Counter = 0;
  773. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  774. try {
  775. if ((Index1 & 0x1) == 0) {
  776. continue;
  777. } else {
  778. Counter += 1;
  779. }
  780. } except (EXCEPTION_EXECUTE_HANDLER) {
  781. Counter += 40;
  782. }
  783. Counter += 2;
  784. }
  785. if (Counter != 15) {
  786. printf("failed, count = %d\n", Counter);
  787. } else {
  788. printf("succeeded\n");
  789. }
  790. //
  791. // Continue from a try body with an finally clause in a loop.
  792. //
  793. printf(" test31...");
  794. Counter = 0;
  795. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  796. try {
  797. if ((Index1 & 0x1) == 0) {
  798. continue;
  799. } else {
  800. Counter += 1;
  801. }
  802. } finally {
  803. Counter += 2;
  804. }
  805. Counter += 3;
  806. }
  807. if (Counter != 40) {
  808. printf("failed, count = %d\n", Counter);
  809. } else {
  810. printf("succeeded\n");
  811. }
  812. //
  813. // Continue from doubly nested try body with an exception clause in a
  814. // loop.
  815. //
  816. printf(" test32...");
  817. Counter = 0;
  818. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  819. try {
  820. try {
  821. if ((Index1 & 0x1) == 0) {
  822. continue;
  823. } else {
  824. Counter += 1;
  825. }
  826. } except (EXCEPTION_EXECUTE_HANDLER) {
  827. Counter += 10;
  828. }
  829. Counter += 2;
  830. } except (EXCEPTION_EXECUTE_HANDLER) {
  831. Counter += 20;
  832. }
  833. Counter += 3;
  834. }
  835. if (Counter != 30) {
  836. printf("failed, count = %d\n", Counter);
  837. } else {
  838. printf("succeeded\n");
  839. }
  840. //
  841. // Continue from doubly nested try body with an finally clause in a loop.
  842. //
  843. printf(" test33...");
  844. Counter = 0;
  845. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  846. try {
  847. try {
  848. if ((Index1 & 0x1) == 0) {
  849. continue;
  850. } else {
  851. Counter += 1;
  852. }
  853. } finally {
  854. Counter += 2;
  855. }
  856. Counter += 3;
  857. } finally {
  858. Counter += 4;
  859. }
  860. Counter += 5;
  861. }
  862. if (Counter != 105) {
  863. printf("failed, count = %d\n", Counter);
  864. } else {
  865. printf("succeeded\n");
  866. }
  867. //
  868. // Continue from a finally clause in a loop.
  869. //
  870. printf(" test34...");
  871. Counter = 0;
  872. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  873. try {
  874. if ((Index1 & 0x1) == 0) {
  875. Counter += 1;
  876. }
  877. } finally {
  878. Counter += 2;
  879. continue;
  880. }
  881. Counter += 4;
  882. }
  883. if (Counter != 25) {
  884. printf("failed, count = %d\n", Counter);
  885. } else {
  886. printf("succeeded\n");
  887. }
  888. //
  889. // Continue from a doubly nested finally clause in a loop.
  890. //
  891. printf(" test35...");
  892. Counter = 0;
  893. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  894. try {
  895. try {
  896. if ((Index1 & 0x1) == 0) {
  897. Counter += 1;
  898. }
  899. } finally {
  900. Counter += 2;
  901. continue;
  902. }
  903. Counter += 4;
  904. } finally {
  905. Counter += 5;
  906. }
  907. Counter += 6;
  908. }
  909. if (Counter != 75) {
  910. printf("failed, count = %d\n", Counter);
  911. } else {
  912. printf("succeeded\n");
  913. }
  914. //
  915. // Continue from a doubly nested finally clause in a loop.
  916. //
  917. printf(" test36...");
  918. Counter = 0;
  919. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  920. try {
  921. try {
  922. if ((Index1 & 0x1) == 0) {
  923. Counter += 1;
  924. }
  925. } finally {
  926. Counter += 2;
  927. }
  928. Counter += 4;
  929. } finally {
  930. Counter += 5;
  931. continue;
  932. }
  933. Counter += 6;
  934. }
  935. if (Counter != 115) {
  936. printf("failed, count = %d\n", Counter);
  937. } else {
  938. printf("succeeded\n");
  939. }
  940. //
  941. // Break from a try body with an exception clause in a loop.
  942. //
  943. printf(" test37...");
  944. Counter = 0;
  945. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  946. try {
  947. if ((Index1 & 0x1) == 1) {
  948. break;
  949. } else {
  950. Counter += 1;
  951. }
  952. } except (EXCEPTION_EXECUTE_HANDLER) {
  953. Counter += 40;
  954. }
  955. Counter += 2;
  956. }
  957. if (Counter != 3) {
  958. printf("failed, count = %d\n", Counter);
  959. } else {
  960. printf("succeeded\n");
  961. }
  962. //
  963. // Break from a try body with an finally clause in a loop.
  964. //
  965. printf(" test38...");
  966. Counter = 0;
  967. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  968. try {
  969. if ((Index1 & 0x1) == 1) {
  970. break;
  971. } else {
  972. Counter += 1;
  973. }
  974. } finally {
  975. Counter += 2;
  976. }
  977. Counter += 3;
  978. }
  979. if (Counter != 8) {
  980. printf("failed, count = %d\n", Counter);
  981. } else {
  982. printf("succeeded\n");
  983. }
  984. //
  985. // Break from doubly nested try body with an exception clause in a
  986. // loop.
  987. //
  988. printf(" test39...");
  989. Counter = 0;
  990. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  991. try {
  992. try {
  993. if ((Index1 & 0x1) == 1) {
  994. break;
  995. } else {
  996. Counter += 1;
  997. }
  998. } except (EXCEPTION_EXECUTE_HANDLER) {
  999. Counter += 10;
  1000. }
  1001. Counter += 2;
  1002. } except (EXCEPTION_EXECUTE_HANDLER) {
  1003. Counter += 20;
  1004. }
  1005. Counter += 3;
  1006. }
  1007. if (Counter != 6) {
  1008. printf("failed, count = %d\n", Counter);
  1009. } else {
  1010. printf("succeeded\n");
  1011. }
  1012. //
  1013. // Break from doubly nested try body with an finally clause in a loop.
  1014. //
  1015. printf(" test40...");
  1016. Counter = 0;
  1017. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1018. try {
  1019. try {
  1020. if ((Index1 & 0x1) == 1) {
  1021. break;
  1022. } else {
  1023. Counter += 1;
  1024. }
  1025. } finally {
  1026. Counter += 2;
  1027. }
  1028. Counter += 3;
  1029. } finally {
  1030. Counter += 4;
  1031. }
  1032. Counter += 5;
  1033. }
  1034. if (Counter != 21) {
  1035. printf("failed, count = %d\n", Counter);
  1036. } else {
  1037. printf("succeeded\n");
  1038. }
  1039. //
  1040. // Break from a finally clause in a loop.
  1041. //
  1042. printf(" test41...");
  1043. Counter = 0;
  1044. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1045. try {
  1046. if ((Index1 & 0x1) == 1) {
  1047. Counter += 1;
  1048. }
  1049. } finally {
  1050. Counter += 2;
  1051. break;
  1052. }
  1053. Counter += 4;
  1054. }
  1055. if (Counter != 2) {
  1056. printf("failed, count = %d\n", Counter);
  1057. } else {
  1058. printf("succeeded\n");
  1059. }
  1060. //
  1061. // Break from a doubly nested finally clause in a loop.
  1062. //
  1063. printf(" test42...");
  1064. Counter = 0;
  1065. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1066. try {
  1067. try {
  1068. if ((Index1 & 0x1) == 1) {
  1069. Counter += 1;
  1070. }
  1071. } finally {
  1072. Counter += 2;
  1073. break;
  1074. }
  1075. Counter += 4;
  1076. } finally {
  1077. Counter += 5;
  1078. }
  1079. Counter += 6;
  1080. }
  1081. if (Counter != 7) {
  1082. printf("failed, count = %d\n", Counter);
  1083. } else {
  1084. printf("succeeded\n");
  1085. }
  1086. //
  1087. // Break from a doubly nested finally clause in a loop.
  1088. //
  1089. printf(" test43...");
  1090. Counter = 0;
  1091. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1092. try {
  1093. try {
  1094. if ((Index1 & 0x1) == 1) {
  1095. Counter += 1;
  1096. }
  1097. } finally {
  1098. Counter += 2;
  1099. }
  1100. Counter += 4;
  1101. } finally {
  1102. Counter += 5;
  1103. break;
  1104. }
  1105. Counter += 6;
  1106. }
  1107. if (Counter != 11) {
  1108. printf("failed, count = %d\n", Counter);
  1109. } else {
  1110. printf("succeeded\n");
  1111. }
  1112. //
  1113. // Break from a try body with an exception clause in a switch.
  1114. //
  1115. printf(" test44...");
  1116. Counter = 0;
  1117. Index1 = 1;
  1118. switch (Index2) {
  1119. case BLUE:
  1120. Counter += 100;
  1121. break;
  1122. case RED:
  1123. try {
  1124. if ((Index1 & 0x1) == 1) {
  1125. break;
  1126. } else {
  1127. Counter += 1;
  1128. }
  1129. } except (EXCEPTION_EXECUTE_HANDLER) {
  1130. Counter += 40;
  1131. }
  1132. Counter += 2;
  1133. break;
  1134. }
  1135. if (Counter != 0) {
  1136. printf("failed, count = %d\n", Counter);
  1137. } else {
  1138. printf("succeeded\n");
  1139. }
  1140. //
  1141. // Break from a try body with an finally clause in a switch.
  1142. //
  1143. printf(" test45...");
  1144. Counter = 0;
  1145. Index1 = 1;
  1146. switch (Index2) {
  1147. case BLUE:
  1148. Counter += 100;
  1149. break;
  1150. case RED:
  1151. try {
  1152. if ((Index1 & 0x1) == 1) {
  1153. break;
  1154. } else {
  1155. Counter += 1;
  1156. }
  1157. } finally {
  1158. Counter += 2;
  1159. }
  1160. Counter += 3;
  1161. }
  1162. if (Counter != 2) {
  1163. printf("failed, count = %d\n", Counter);
  1164. } else {
  1165. printf("succeeded\n");
  1166. }
  1167. //
  1168. // Break from doubly nested try body with an exception clause in a
  1169. // switch.
  1170. //
  1171. printf(" test46...");
  1172. Counter = 0;
  1173. Index1 = 1;
  1174. switch (Index2) {
  1175. case BLUE:
  1176. Counter += 100;
  1177. break;
  1178. case RED:
  1179. try {
  1180. try {
  1181. if ((Index1 & 0x1) == 1) {
  1182. break;
  1183. } else {
  1184. Counter += 1;
  1185. }
  1186. } except (EXCEPTION_EXECUTE_HANDLER) {
  1187. Counter += 10;
  1188. }
  1189. Counter += 2;
  1190. } except (EXCEPTION_EXECUTE_HANDLER) {
  1191. Counter += 20;
  1192. }
  1193. Counter += 3;
  1194. }
  1195. if (Counter != 0) {
  1196. printf("failed, count = %d\n", Counter);
  1197. } else {
  1198. printf("succeeded\n");
  1199. }
  1200. //
  1201. // Break from doubly nested try body with an finally clause in a switch.
  1202. //
  1203. printf(" test47...");
  1204. Counter = 0;
  1205. Index1 = 1;
  1206. switch (Index2) {
  1207. case BLUE:
  1208. Counter += 100;
  1209. break;
  1210. case RED:
  1211. try {
  1212. try {
  1213. if ((Index1 & 0x1) == 1) {
  1214. break;
  1215. } else {
  1216. Counter += 1;
  1217. }
  1218. } finally {
  1219. Counter += 2;
  1220. }
  1221. Counter += 3;
  1222. } finally {
  1223. Counter += 4;
  1224. }
  1225. Counter += 5;
  1226. }
  1227. if (Counter != 6) {
  1228. printf("failed, count = %d\n", Counter);
  1229. } else {
  1230. printf("succeeded\n");
  1231. }
  1232. //
  1233. // Break from a finally clause in a switch.
  1234. //
  1235. printf(" test48...");
  1236. Counter = 0;
  1237. Index1 = 1;
  1238. switch (Index2) {
  1239. case BLUE:
  1240. Counter += 100;
  1241. break;
  1242. case RED:
  1243. try {
  1244. if ((Index1 & 0x1) == 1) {
  1245. Counter += 1;
  1246. }
  1247. } finally {
  1248. Counter += 2;
  1249. break;
  1250. }
  1251. Counter += 4;
  1252. }
  1253. if (Counter != 3) {
  1254. printf("failed, count = %d\n", Counter);
  1255. } else {
  1256. printf("succeeded\n");
  1257. }
  1258. //
  1259. // Break from a doubly nested finally clause in a switch.
  1260. //
  1261. printf(" test49...");
  1262. Counter = 0;
  1263. Index1 = 1;
  1264. switch (Index2) {
  1265. case BLUE:
  1266. Counter += 100;
  1267. break;
  1268. case RED:
  1269. try {
  1270. try {
  1271. if ((Index1 & 0x1) == 1) {
  1272. Counter += 1;
  1273. }
  1274. } finally {
  1275. Counter += 2;
  1276. break;
  1277. }
  1278. Counter += 4;
  1279. } finally {
  1280. Counter += 5;
  1281. }
  1282. Counter += 6;
  1283. }
  1284. if (Counter != 8) {
  1285. printf("failed, count = %d\n", Counter);
  1286. } else {
  1287. printf("succeeded\n");
  1288. }
  1289. //
  1290. // Break from a doubly nested finally clause in a switch.
  1291. //
  1292. printf(" test50...");
  1293. Counter = 0;
  1294. Index1 = 1;
  1295. switch (Index2) {
  1296. case BLUE:
  1297. Counter += 100;
  1298. break;
  1299. case RED:
  1300. try {
  1301. try {
  1302. if ((Index1 & 0x1) == 1) {
  1303. Counter += 1;
  1304. }
  1305. } finally {
  1306. Counter += 2;
  1307. }
  1308. Counter += 4;
  1309. } finally {
  1310. Counter += 5;
  1311. break;
  1312. }
  1313. Counter += 6;
  1314. }
  1315. if (Counter != 12) {
  1316. printf("failed, count = %d\n", Counter);
  1317. } else {
  1318. printf("succeeded\n");
  1319. }
  1320. //
  1321. // Leave from an if in a simple try/finally.
  1322. //
  1323. printf(" test51...");
  1324. Counter = 0;
  1325. try {
  1326. if (Echo(Counter) == Counter) {
  1327. Counter += 3;
  1328. leave;
  1329. } else {
  1330. Counter += 100;
  1331. }
  1332. } finally {
  1333. if (abnormal_termination() == FALSE) {
  1334. Counter += 5;
  1335. }
  1336. }
  1337. if (Counter != 8) {
  1338. printf("failed, count = %d\n", Counter);
  1339. } else {
  1340. printf("succeeded\n");
  1341. }
  1342. //
  1343. // Leave from a loop in a simple try/finally.
  1344. //
  1345. printf(" test52...");
  1346. Counter = 0;
  1347. try {
  1348. for (Index1 = 0; Index1 < 10; Index1 += 1) {
  1349. if (Echo(Index1) == Index1) {
  1350. Counter += 3;
  1351. leave;
  1352. }
  1353. Counter += 100;
  1354. }
  1355. } finally {
  1356. if (abnormal_termination() == FALSE) {
  1357. Counter += 5;
  1358. }
  1359. }
  1360. if (Counter != 8) {
  1361. printf("failed, count = %d\n", Counter);
  1362. } else {
  1363. printf("succeeded\n");
  1364. }
  1365. //
  1366. // Leave from a switch in a simple try/finally.
  1367. //
  1368. printf(" test53...");
  1369. Counter = 0;
  1370. try {
  1371. switch (Index2) {
  1372. case BLUE:
  1373. break;
  1374. case RED:
  1375. Counter += 3;
  1376. leave;
  1377. }
  1378. Counter += 100;
  1379. } finally {
  1380. if (abnormal_termination() == FALSE) {
  1381. Counter += 5;
  1382. }
  1383. }
  1384. if (Counter != 8) {
  1385. printf("failed, count = %d\n", Counter);
  1386. } else {
  1387. printf("succeeded\n");
  1388. }
  1389. //
  1390. // Leave from an if in doubly nested try/finally followed by a leave
  1391. // from an if in the outer try/finally.
  1392. //
  1393. printf(" test54...");
  1394. Counter = 0;
  1395. try {
  1396. try {
  1397. if (Echo(Counter) == Counter) {
  1398. Counter += 3;
  1399. leave;
  1400. } else {
  1401. Counter += 100;
  1402. }
  1403. } finally {
  1404. if (abnormal_termination() == FALSE) {
  1405. Counter += 5;
  1406. }
  1407. }
  1408. if (Echo(Counter) == Counter) {
  1409. Counter += 3;
  1410. leave;
  1411. } else {
  1412. Counter += 100;
  1413. }
  1414. } finally {
  1415. if (abnormal_termination() == FALSE) {
  1416. Counter += 5;
  1417. }
  1418. }
  1419. if (Counter != 16) {
  1420. printf("failed, count = %d\n", Counter);
  1421. } else {
  1422. printf("succeeded\n");
  1423. }
  1424. //
  1425. // Leave from an if in doubly nested try/finally followed by a leave
  1426. // from the finally of the outer try/finally.
  1427. //
  1428. printf(" test55...");
  1429. Counter = 0;
  1430. try {
  1431. try {
  1432. if (Echo(Counter) == Counter) {
  1433. Counter += 3;
  1434. leave;
  1435. } else {
  1436. Counter += 100;
  1437. }
  1438. } finally {
  1439. if (abnormal_termination() == FALSE) {
  1440. Counter += 5;
  1441. leave;
  1442. }
  1443. }
  1444. Counter += 100;
  1445. } finally {
  1446. if (abnormal_termination() == FALSE) {
  1447. Counter += 5;
  1448. }
  1449. }
  1450. if (Counter != 13) {
  1451. printf("failed, count = %d\n", Counter);
  1452. } else {
  1453. printf("succeeded\n");
  1454. }
  1455. //
  1456. // Try/finally within the except clause of a try/except that is always
  1457. // executed.
  1458. //
  1459. printf(" test56...");
  1460. Counter = 0;
  1461. try {
  1462. Counter += 1;
  1463. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1464. } except (Counter) {
  1465. try {
  1466. Counter += 3;
  1467. } finally {
  1468. if (abnormal_termination() == FALSE) {
  1469. Counter += 5;
  1470. }
  1471. }
  1472. }
  1473. if (Counter != 9) {
  1474. printf("failed, count = %d\n", Counter);
  1475. } else {
  1476. printf("succeeded\n");
  1477. }
  1478. //
  1479. // Try/finally within the finally clause of a try/finally.
  1480. //
  1481. printf(" test57...");
  1482. Counter = 0;
  1483. try {
  1484. Counter += 1;
  1485. } finally {
  1486. if (abnormal_termination() == FALSE) {
  1487. try {
  1488. Counter += 3;
  1489. } finally {
  1490. if (abnormal_termination() == FALSE) {
  1491. Counter += 5;
  1492. }
  1493. }
  1494. }
  1495. }
  1496. if (Counter != 9) {
  1497. printf("failed, count = %d\n", Counter);
  1498. } else {
  1499. printf("succeeded\n");
  1500. }
  1501. //
  1502. // Try/except within the finally clause of a try/finally.
  1503. //
  1504. /*
  1505. printf(" test58...");
  1506. Counter = 0;
  1507. try {
  1508. Counter -= 1;
  1509. } finally {
  1510. try {
  1511. Counter += 2;
  1512. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1513. } except (Counter) {
  1514. try {
  1515. Counter += 3;
  1516. } finally {
  1517. if (abnormal_termination() == FALSE) {
  1518. Counter += 5;
  1519. }
  1520. }
  1521. }
  1522. }
  1523. if (Counter != 9) {
  1524. printf("failed, count = %d\n", Counter);
  1525. } else {
  1526. printf("succeeded\n");
  1527. }
  1528. */
  1529. //
  1530. // Try/except within the except clause of a try/except that is always
  1531. // executed.
  1532. //
  1533. printf(" test59...");
  1534. Counter = 0;
  1535. try {
  1536. Counter += 1;
  1537. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1538. } except (Counter) {
  1539. try {
  1540. Counter += 3;
  1541. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1542. } except(Counter - 3) {
  1543. Counter += 5;
  1544. }
  1545. }
  1546. if (Counter != 9) {
  1547. printf("failed, count = %d\n", Counter);
  1548. } else {
  1549. printf("succeeded\n");
  1550. }
  1551. //
  1552. // Try with a Try which exits the scope with a goto
  1553. //
  1554. printf(" test60...");
  1555. Counter = 0;
  1556. try {
  1557. try {
  1558. goto outside;
  1559. } except(1) {
  1560. Counter += 1;
  1561. }
  1562. outside:
  1563. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1564. } except(1) {
  1565. Counter += 3;
  1566. }
  1567. if (Counter != 3) {
  1568. printf("failed, count = %d\n", Counter);
  1569. } else {
  1570. printf("succeeded\n");
  1571. }
  1572. //
  1573. // Try/except which gets an exception from a subfunction within
  1574. // a try/finally which has a try/except in the finally clause
  1575. //
  1576. printf(" test61...");
  1577. Counter = 0;
  1578. try {
  1579. Test61Part2 (&Counter);
  1580. } except (EXCEPTION_EXECUTE_HANDLER) {
  1581. Counter += 11;
  1582. }
  1583. if (Counter != 24) {
  1584. printf("failed, count = %d\n", Counter);
  1585. } else {
  1586. printf("succeeded\n");
  1587. }
  1588. //
  1589. // Check for precision of floating point exception
  1590. //
  1591. printf(" test62...");
  1592. /* enable floating point overflow */
  1593. _controlfp(_controlfp(0,0) & ~EM_OVERFLOW, _MCW_EM);
  1594. Counter = 0;
  1595. try {
  1596. doubleresult = SquareDouble (1.7e300);
  1597. try {
  1598. doubleresult = SquareDouble (1.0);
  1599. } except (1) {
  1600. Counter += 3;
  1601. }
  1602. } except (1) {
  1603. Counter += 1;
  1604. }
  1605. if (Counter != 1) {
  1606. printf("failed, count = %d\n", Counter);
  1607. } else {
  1608. printf("succeeded\n");
  1609. }
  1610. _clearfp ();
  1611. //
  1612. // Callout for test #63 due to bogus compiler behaviour caused by test #62.
  1613. //
  1614. PerformFpTest ();
  1615. //
  1616. // Announce end of exception test.
  1617. //
  1618. printf("End of exception test\n");
  1619. return;
  1620. }
  1621. VOID
  1622. PerformFpTest()
  1623. {
  1624. LONG Counter;
  1625. double doubleresult;
  1626. //
  1627. // Check for precision of floating point exception in subfunction
  1628. //
  1629. printf(" test63...");
  1630. Counter = 0;
  1631. try {
  1632. SquareDouble17E300 ((PVOID) &doubleresult);
  1633. try {
  1634. SquareDouble17E300 ((PVOID) &doubleresult);
  1635. } except (1) {
  1636. Counter += 3;
  1637. }
  1638. } except (1) {
  1639. Counter += 1;
  1640. }
  1641. if (Counter != 1) {
  1642. printf("failed, count = %d\n", Counter);
  1643. } else {
  1644. printf("succeeded\n");
  1645. }
  1646. _clearfp ();
  1647. }
  1648. VOID
  1649. addtwo (
  1650. long First,
  1651. long Second,
  1652. long *Place
  1653. )
  1654. {
  1655. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1656. *Place = First + Second;
  1657. return;
  1658. }
  1659. VOID
  1660. bar1 (
  1661. IN NTSTATUS Status,
  1662. IN PLONG Counter
  1663. )
  1664. {
  1665. try {
  1666. foo1(Status);
  1667. } finally {
  1668. if (abnormal_termination() != FALSE) {
  1669. *Counter = 99;
  1670. } else {
  1671. *Counter = 100;
  1672. }
  1673. }
  1674. return;
  1675. }
  1676. VOID
  1677. bar2 (
  1678. IN PLONG BlackHole,
  1679. IN PLONG BadAddress,
  1680. IN PLONG Counter
  1681. )
  1682. {
  1683. try {
  1684. foo2(BlackHole, BadAddress);
  1685. } finally {
  1686. if (abnormal_termination() != FALSE) {
  1687. *Counter = 99;
  1688. } else {
  1689. *Counter = 100;
  1690. }
  1691. }
  1692. return;
  1693. }
  1694. VOID
  1695. dojump (
  1696. IN jmp_buf JumpBuffer,
  1697. IN PLONG Counter
  1698. )
  1699. {
  1700. try {
  1701. try {
  1702. *Counter += 1;
  1703. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1704. } finally {
  1705. *Counter += 1;
  1706. }
  1707. } finally {
  1708. *Counter += 1;
  1709. longjmp(JumpBuffer, 1);
  1710. }
  1711. }
  1712. VOID
  1713. eret(
  1714. IN NTSTATUS Status,
  1715. IN PLONG Counter
  1716. )
  1717. {
  1718. try {
  1719. try {
  1720. foo1(Status);
  1721. } except ((GetExceptionCode() == Status) ?
  1722. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  1723. *Counter += 1;
  1724. return;
  1725. }
  1726. } finally {
  1727. *Counter += 1;
  1728. }
  1729. return;
  1730. }
  1731. VOID
  1732. except1 (
  1733. IN PLONG Counter
  1734. )
  1735. {
  1736. try {
  1737. *Counter += 5;
  1738. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1739. } except (except3(GetExceptionInformation(), Counter)) {
  1740. *Counter += 7;
  1741. }
  1742. *Counter += 9;
  1743. return;
  1744. }
  1745. ULONG
  1746. except2 (
  1747. IN PEXCEPTION_POINTERS ExceptionPointers,
  1748. IN PLONG Counter
  1749. )
  1750. {
  1751. PEXCEPTION_RECORD ExceptionRecord;
  1752. ExceptionRecord = ExceptionPointers->ExceptionRecord;
  1753. if ((ExceptionRecord->ExceptionCode == STATUS_UNSUCCESSFUL) &&
  1754. ((ExceptionRecord->ExceptionFlags & EXCEPTION_NESTED_CALL) == 0)) {
  1755. *Counter += 11;
  1756. return EXCEPTION_EXECUTE_HANDLER;
  1757. } else {
  1758. *Counter += 13;
  1759. return EXCEPTION_CONTINUE_SEARCH;
  1760. }
  1761. }
  1762. ULONG
  1763. except3 (
  1764. IN PEXCEPTION_POINTERS ExceptionPointers,
  1765. IN PLONG Counter
  1766. )
  1767. {
  1768. PEXCEPTION_RECORD ExceptionRecord;
  1769. ExceptionRecord = ExceptionPointers->ExceptionRecord;
  1770. if ((ExceptionRecord->ExceptionCode == STATUS_INTEGER_OVERFLOW) &&
  1771. ((ExceptionRecord->ExceptionFlags & EXCEPTION_NESTED_CALL) == 0)) {
  1772. *Counter += 17;
  1773. RtlRaiseStatus(STATUS_UNSUCCESSFUL);
  1774. } else if ((ExceptionRecord->ExceptionCode == STATUS_UNSUCCESSFUL) &&
  1775. ((ExceptionRecord->ExceptionFlags & EXCEPTION_NESTED_CALL) != 0)) {
  1776. *Counter += 19;
  1777. return EXCEPTION_CONTINUE_SEARCH;
  1778. }
  1779. *Counter += 23;
  1780. return EXCEPTION_EXECUTE_HANDLER;
  1781. }
  1782. VOID
  1783. foo1 (
  1784. IN NTSTATUS Status
  1785. )
  1786. {
  1787. //
  1788. // Raise exception.
  1789. //
  1790. RtlRaiseStatus(Status);
  1791. return;
  1792. }
  1793. VOID
  1794. foo2 (
  1795. IN PLONG BlackHole,
  1796. IN PLONG BadAddress
  1797. )
  1798. {
  1799. //
  1800. // Raise exception.
  1801. //
  1802. *BlackHole += *BadAddress;
  1803. return;
  1804. }
  1805. VOID
  1806. fret(
  1807. IN PLONG Counter
  1808. )
  1809. {
  1810. try {
  1811. try {
  1812. *Counter += 1;
  1813. } finally {
  1814. *Counter += 1;
  1815. return;
  1816. }
  1817. } finally {
  1818. *Counter += 1;
  1819. }
  1820. return;
  1821. }
  1822. LONG
  1823. Echo(
  1824. IN LONG Value
  1825. )
  1826. {
  1827. return Value;
  1828. }
  1829. VOID
  1830. Test61Part2 (
  1831. IN OUT PULONG Counter
  1832. )
  1833. {
  1834. try {
  1835. *Counter -= 1;
  1836. RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
  1837. } finally {
  1838. *Counter += 2;
  1839. *Counter += 5;
  1840. *Counter += 7;
  1841. }
  1842. }
  1843. double
  1844. SquareDouble (
  1845. IN double op
  1846. )
  1847. {
  1848. return op * op;
  1849. }
  1850. VOID
  1851. SquareDouble17E300 (
  1852. OUT PVOID output
  1853. )
  1854. {
  1855. double ans;
  1856. ans = SquareDouble (1.7e300);
  1857. *(double *) output = ans;
  1858. }