Knowledge (XXG)

Microsoft-specific exception handling mechanisms

Source 📝

234:) interpreted by the system when an exception occurs. This means that the compiler does not have to generate extra code to manually perform stack unwinding and to call exception handlers appropriately. It merely has to emit information in the form of unwinding tables about the stack frame layout and specified exception handlers. 602:
Note that the examples given there do not work as-is on modern Windows systems (post XP SP2) due to the changes Microsoft made to address the security issues present in the early SEH design. The examples still work on later versions of Windows if compiled with
274:. VEH does not replace Structured Exception Handling (SEH); rather, VEH and SEH coexist, with VEH handlers having priority over SEH handlers. Compared with SEH, VEH works more like kernel-delivered 708: 440: 657: 211:
error message. Then the list is traversed once more giving handlers a chance to clean up any resources used. Finally, the execution returns to
66:
Microsoft supports SEH as a programming technique at the compiler level only. MS Visual C++ compiler features three non-standard keywords:
585: 666: 541: 523: 36:
Microsoft Structured Exception Handling is the native exception handling mechanism for Windows and a forerunner technology to
396: 138: 685: 636:
Covers the obscure details needed to get low-level SEH (and particularly SafeSEH) code to work on more modern Windows.
484: 61: 690:
An article explaining why Windows 7 SP1 ignores SafeSEH for some older binaries, while Windows XP SP3 honors it.
208: 123: 611: 199:
list and calls each exception handler in sequence until a handler signals it has handled the exception (by
444: 45: 703: 309:, as well as other programs linked statically with VC runtime, have this function compiled-in instead 160:
function is called that does the reverse operation. Either of these compiler-defined routines can be
153: 542:"Windows Server 2003 Discover Improved System Info, New Kernel, Debugging, Security, and UI APIs" 100: 49: 25: 266:. Vectored Exception Handling is made available to Windows programmers using languages such as 597: 17: 226:
SEH on 64-bit Windows does not involve a runtime exception handler list; instead, it uses a
161: 119: 21: 673: 631: 615: 545: 527: 470: 334:"A catalog of NTDLL kernel mode to user mode callbacks, part 2: KiUserExceptionDispatcher" 658:"Preventing the Exploitation of Structured Exception Handler (SEH) Overwrites with SEHOP" 563: 415: 352: 348: 697: 502: 581: 275: 271: 200: 400: 641: 212: 397:"Vectored Exception Handling in Windows Server 2003 (Through Internet Archive)" 78:— for this purpose. Other exception handling aspects are backed by a number of 623: 263: 227: 243: 192: 79: 48:
languages introduced later). SEH is set up and handled separately for each
44:
mechanism not present in standard C++ exceptions (but present in most
586:"A Crash Course on the Depths of Win32 Structured Exception Handling" 112: 267: 203:) or the list is exhausted. The last one in the list is always the 108: 104: 333: 247: 524:"Under the Hood: New Vectored Exception Handling in Windows XP" 149:, then adds the record to the list's head. At the end of the 218:
The patent on this mode of SEH, US5628016, expired in 2014.
642:"Reversing Microsoft Visual C++ Part I: Exception Handling" 686:"Old Meets New: Microsoft Windows SafeSEH Incompatibility" 471:"Exceptional Behavior - x64 Structured Exception Handling" 347:
The message can be silenced by altering the process's
176:. If the programmer-defined blocks are present, the 293:
The name varies in different versions of VC runtime
215:where the process is either resumed or terminated. 62:
Exception handling syntax § Microsoft-specific
184:is extended with a few additional fields used by 351:; the default last handler can be replaced with 37: 665:Stéfan Le Berre, Damien Cauquil (22 Dec 2009). 195:code, the operating system parses the thread's 130:statement essentially calls a compiler-defined 441:"Windows Exception Handling - Peter Kleissner" 262:Vectored Exception Handling was introduced in 246:supports using 64-bit SEH for C++ exceptions. 8: 709:Microsoft application programming interfaces 458:Compiler based Structured Exception Handling 612:"win32: Safe Structured Exception Handling" 416:"Structured Exception Handling Functions" 385: 286: 518: 516: 391: 389: 115:version has a link to an undocumented 624:US patent 7,480,919 - Safe exceptions 439:Peter Kleissner (February 14, 2009). 134:function. That function allocates an 7: 86:to raise SEH exceptions manually. 14: 640:Igor Skochinsky (March 6, 2006). 630:Johannes Passing (May 20, 2008). 332:Ken Johnson (November 16, 2007). 326:which is in turn called from the 205:kernel32!UnhandledExceptionFilter 684:Joshua J. Drake (10 Jan 2012). 564:"Structured Exception Handling" 365:ntdll!KiUserExceptionDispatcher 324:ntdll!KiUserExceptionDispatcher 191:In the case of an exception in 562:Microsoft Corp. (2009-11-12). 414:Microsoft Corp. (2009-11-12). 197:_EXCEPTION_REGISTRATION_RECORD 178:_EXCEPTION_REGISTRATION_RECORD 172:blocks are called from within 136:_EXCEPTION_REGISTRATION_RECORD 117:_EXCEPTION_REGISTRATION_RECORD 1: 164:. All the programmer-defined 32:Structured Exception Handling 353:SetUnhandledExceptionFilter 322:system routine called from 258:Vectored Exception Handling 38:Vectored Exception Handling 725: 672:. Sysdream. Archived from 656:Matt Miller (2 Feb 2009). 320:ntdll!RtlDispatchException 59: 632:"Fun with low level SEH" 485:"x64 exception handling" 209:General protection fault 124:Thread Information Block 111:emulation layer for the 82:functions, for example, 489:VC++ 2019 documentation 40:(VEH). It features the 507:Clang 11 documentation 330:kernel function. (See 328:nt!KiDispatchException 254:on both x86 and x64. 24:employ some specific 503:"MSVC compatibility" 122:at the start of its 596:(1). Archived from 447:on October 14, 2013 373:nt!ZwRaiseException 318:More specifically, 207:which displays the 156:a compiler-defined 101:thread of execution 50:thread of execution 26:exception handling 667:"Bypassing SEHOP" 605:/link /safeseh:no 473:. The NT Insider. 186:__except_handler3 174:__except_handler3 143:__except_handler3 22:operating systems 18:Microsoft Windows 716: 689: 680: 678: 671: 661: 652: 650: 649: 635: 626: 619: 606: 601: 577: 575: 574: 550: 549: 544:. Archived from 538: 532: 531: 526:. Archived from 520: 511: 510: 499: 493: 492: 481: 475: 474: 467: 461: 455: 453: 452: 443:. Archived from 436: 430: 429: 427: 426: 411: 405: 404: 399:. Archived from 393: 375: 374: 370: 366: 362: 356: 345: 339: 337: 329: 325: 321: 316: 310: 308: 304: 300: 294: 291: 253: 233: 206: 198: 187: 183: 179: 175: 171: 167: 159: 152: 148: 144: 141:pointing to the 137: 133: 129: 118: 85: 77: 73: 69: 43: 724: 723: 719: 718: 717: 715: 714: 713: 694: 693: 683: 676: 669: 664: 655: 647: 645: 639: 629: 622: 610: 604: 580: 572: 570: 561: 558: 553: 540: 539: 535: 522: 521: 514: 501: 500: 496: 483: 482: 478: 469: 468: 464: 450: 448: 438: 437: 433: 424: 422: 413: 412: 408: 395: 394: 387: 383: 378: 372: 368: 364: 363: 359: 346: 342: 331: 327: 323: 319: 317: 313: 306: 302: 301: 297: 292: 288: 284: 260: 251: 250:clang supports 240: 231: 228:stack unwinding 224: 204: 196: 185: 181: 177: 173: 169: 165: 157: 150: 146: 142: 135: 131: 127: 116: 107:edition or the 97: 92: 83: 75: 71: 67: 64: 58: 41: 34: 12: 11: 5: 722: 720: 712: 711: 706: 696: 695: 692: 691: 681: 679:on 2012-09-07. 662: 653: 637: 627: 620: 608: 600:on 2003-08-10. 578: 557: 556:External links 554: 552: 551: 548:on 2008-05-05. 533: 530:on 2008-09-15. 512: 494: 476: 462: 431: 406: 403:on 2008-01-18. 384: 382: 379: 377: 376: 357: 340: 311: 295: 285: 283: 280: 259: 256: 242:GCC 4.8+ from 239: 236: 223: 220: 96: 93: 91: 90:Implementation 88: 84:RaiseException 57: 54: 33: 30: 13: 10: 9: 6: 4: 3: 2: 721: 710: 707: 705: 702: 701: 699: 687: 682: 675: 668: 663: 659: 654: 643: 638: 633: 628: 625: 621: 617: 613: 609: 599: 595: 591: 587: 583: 579: 569: 565: 560: 559: 555: 547: 543: 537: 534: 529: 525: 519: 517: 513: 508: 504: 498: 495: 490: 486: 480: 477: 472: 466: 463: 459: 446: 442: 435: 432: 421: 417: 410: 407: 402: 398: 392: 390: 386: 380: 369:nt!ZwContinue 367:calls either 361: 358: 354: 350: 344: 341: 335: 315: 312: 299: 296: 290: 287: 281: 279: 277: 273: 269: 265: 257: 255: 249: 245: 237: 235: 229: 221: 219: 216: 214: 210: 202: 194: 189: 163: 155: 140: 125: 121: 114: 110: 106: 102: 94: 89: 87: 81: 63: 55: 53: 51: 47: 39: 31: 29: 27: 23: 19: 704:Control flow 674:the original 646:. Retrieved 598:the original 593: 589: 584:(Jan 1997). 582:Matt Pietrek 571:. Retrieved 568:MSDN Library 567: 546:the original 536: 528:the original 506: 497: 488: 479: 465: 457: 449:. Retrieved 445:the original 434: 423:. Retrieved 420:MSDN Library 419: 409: 401:the original 360: 343: 338:for details) 314: 307:kernel32.dll 298: 289: 276:Unix signals 272:Visual Basic 261: 241: 225: 217: 201:return value 190: 145:function in 139:on the stack 98: 65: 35: 28:mechanisms. 15: 232:UNWIND_INFO 213:kernel mode 180:created by 103:in Windows 698:Categories 660:. Technet. 648:2009-11-17 573:2022-07-23 451:2009-11-21 425:2022-07-23 381:References 349:error mode 264:Windows XP 147:msvcrt.dll 60:See also: 46:imperative 20:family of 644:. OpenRCE 303:ntdll.dll 244:Mingw-w64 193:user mode 182:EH_prolog 170:__finally 158:EH_epilog 132:EH_prolog 80:Win32 API 76:__finally 166:__except 72:__except 618:manual. 460:section 238:Support 230:table ( 42:finally 222:x86-64 162:inline 126:. The 113:x86-64 677:(PDF) 670:(PDF) 282:Notes 252:__try 154:block 151:__try 128:__try 109:WoW64 105:IA-32 99:Each 95:IA-32 68:__try 56:Usage 616:Yasm 305:and 270:and 248:LLVM 168:and 120:list 74:and 16:The 590:MSJ 371:or 355:API 268:C++ 700:: 614:. 594:12 592:. 588:. 566:. 515:^ 505:. 487:. 456:, 418:. 388:^ 278:. 188:. 70:, 52:. 688:. 651:. 634:. 607:. 576:. 509:. 491:. 454:. 428:. 336:.

Index

Microsoft Windows
operating systems
exception handling
Vectored Exception Handling
imperative
thread of execution
Exception handling syntax § Microsoft-specific
Win32 API
thread of execution
IA-32
WoW64
x86-64
list
Thread Information Block
on the stack
block
inline
user mode
return value
General protection fault
kernel mode
stack unwinding
Mingw-w64
LLVM
Windows XP
C++
Visual Basic
Unix signals
"A catalog of NTDLL kernel mode to user mode callbacks, part 2: KiUserExceptionDispatcher"
error mode

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.