Microsoft-specific exception handling mechanisms

Microsoft-specific exception handling mechanisms

Microsoft Windows OS family employs some exception handling mechanisms that are based on the operation system specifics.

Contents

Structured Exception Handling

Microsoft Structured Exception Handling is the native exception handling mechanism for Windows and a forerunner technology to VEH.[1] It features the finally mechanism not present in standard С++ exceptions (but present in most imperative languages introduced later).

SEH is set up and handled separately for each thread of execution.

Usage

Microsoft supports SEH as a programming technique at compiler level only. MS Visual C++ compiler features 3 non-standard keywords: __try, __except and __finally — for this purpose. Other exception handling aspects are backed up by a number of Win32 API functions,[2] e.g. RaiseException to raise SEH exceptions manually.

Implementation

Each thread of execution in Windows has a link to an undocumented _EXCEPTION_REGISTRATION_RECORD list at the start of its Thread Information Block. The __try statement essentially calls a compiler-defined EH_prolog function. That function allocates an _EXCEPTION_REGISTRATION_RECORD on the stack pointing to __except_handler3 function in msvcrt.dll,[3] then adds the record to the list's head. At the end of the __try block a compiler-defined EH_epilog function is called that does the reverse operation. Either of these compiler-defined routines can be inline. All the programmer-defined __except and __finally blocks are called from within __except_handler3. If such blocks are present, _EXCEPTION_REGISTRATION_RECORD being created is extended with a few additional fields used by __except_handler3.[4]

In a case of an exception in a user mode code, the operating system[5] parses the thread's _EXCEPTION_REGISTRATION_RECORD list and calls each exception handler in sequence until a handler signals it has handled the exception (by return value) or the list is exhausted. The last one in the list is always the kernel32!UnhandledExceptionFilter which displayes the General protection fault error message.[6] Then the list is traversed once more giving handlers a chance to clean up any resources used. Finally, the execution returns to kernel mode[7] where the process is either resumed or terminated.

Links

Vectored Exception Handling

Vectored Exception Handling was introduced in Windows XP.[8] Vectored Exception Handling is made available to Windows programmers using languages such as C++ and Visual Basic. VEH does not replace Structured Exception Handling (SEH), rather VEH and SEH coexist with VEH handlers having priority over SEH handlers.[8][1] Compared with SEH, VEH works more like a traditional notification callback scheme.[9]

Use of VEH

Use AddVectoredExceptionHandler API

References

  1. ^ a b "Vectored Exception Handling in Windows Server 2003 (Through Internet Archive)". Archived from the original on 2008-01-18. http://web.archive.org/web/20080118162324/http://www.devx.com/microsoftISV/Article/15992. 
  2. ^ Microsoft Corp. (11/12/2009). "Structured Exception Handling Functions". MSDN Library. http://msdn.microsoft.com/en-us/library/ms680659%28VS.85%29.aspx. Retrieved 2009-11-17. 
  3. ^ ntdll.dll and kernel32.dll have this function compiled-in instead
  4. ^ Peter Kleissner (February 2009). "Windows Exception Handling". http://web17.webbpro.de/index.php?page=windows-exception-handling. Retrieved 2009-11-21. , Compiler based Structured Exception Handling section
  5. ^ More specifically, ntdll!RtlDispatchException system routine called from ntdll!KiUserExceptionDispatcher which is in turn called from the nt!KiDispatchException kernel function. (See Ken Johnson (November 16th, 2007, 7:00 am). "A catalog of NTDLL kernel mode to user mode callbacks, part 2: KiUserExceptionDispatcher". http://www.nynaeve.net/?p=201.  for details)
  6. ^ The message can be silenced by altering the process's error mode; the default last handler can be replaced with SetUnhandledExceptionFilter API
  7. ^ ntdll!KiUserExceptionDispatcher calls either nt!ZwContinue or nt!ZwRaiseException
  8. ^ a b "New Vectored Exception Handling in Windows XP". http://msdn.microsoft.com/en-us/magazine/cc301714.aspx. 
  9. ^ "Windows Server 2003 Discover Improved System Info, New Kernel, Debugging, Security, and UI APIs". http://msdn.microsoft.com/en-us/magazine/cc300448.aspx. 

Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Exception handling — is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution. Programming languages differ considerably in their support… …   Wikipedia

  • Microsoft Data Access Components — MDAC redirects here. For other uses, see MDAC (disambiguation). MDAC (Microsoft Data Access Components) Microsoft Corporation s MDAC provides a uniform framework for accessing a variety of data sources on their Windows platform. Developer(s)… …   Wikipedia

  • Windows API — The Windows API, informally WinAPI, is Microsoft s core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name Windows API more accurately… …   Wikipedia

  • Comparison of C Sharp and Java — The correct title of this article is Comparison of C# and Java. The substitution or omission of the # sign is because of technical restrictions. Programming language comparisons General comparison Basic syntax Basic instructions …   Wikipedia

  • Security and safety features new to Windows Vista — There are a number of security and safety features new to Windows Vista, most of which are not available in any prior Microsoft Windows operating system release.Beginning in early 2002 with Microsoft s announcement of their Trustworthy Computing… …   Wikipedia

  • .NET Framework — This article is about the Microsoft technology. For the Top level domain, see .net. For other uses, see .NET. .NET Framework Developer(s) Microsoft …   Wikipedia

  • Comparison of Java and C Sharp — This is a comparison of the C# programming language with the Java programming language. As the two are both garbage collected runtime compiled languages with syntax derived from C and C++, there are many similarities between Java and C#. However …   Wikipedia

  • Oxygene (programming language) — Oxygene Developer RemObjects Software Stable release 3.0.21 (August 29, 2009; 2 years ago (2009 08 29)) Influenced by Object Pas …   Wikipedia

  • Eiffel (programming language) — Infobox programming language name = Eiffel paradigm = object oriented year = 1986 designer = Bertrand Meyer developer = Bertrand Meyer Eiffel Software latest release version = 4.2 latest release date = Feb 6, 1998 typing = static typing, strong… …   Wikipedia

  • C++ — The C++ Programming Language, written by its architect, is the seminal book on the language. Paradigm(s) Multi paradigm:[1] procedural …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”