2 Copyright (c) 2004 KJK::Hyperion
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define WIN32_LEAN_AND_MEAN
27 #include <pseh/framebased/internal.h>
30 /* Assembly helpers, see i386/framebased.asm */
31 extern void __cdecl
_SEHCleanHandlerEnvironment(void);
32 extern void __cdecl
_SEHRegisterFrame(_SEHRegistration_t
*);
33 extern void __cdecl
_SEHUnregisterFrame(const _SEHRegistration_t
*);
34 extern void __cdecl
_SEHUnwind(_SEHPortableFrame_t
*);
36 __declspec(noreturn
) void __cdecl
_SEHCallHandler(_SEHPortableFrame_t
* frame
)
38 frame
->SPF_Handling
= 1;
40 frame
->SPF_Handlers
->SH_Handler(frame
);
43 int __cdecl _SEHFrameHandler
45 struct _EXCEPTION_RECORD
* ExceptionRecord
,
46 void * EstablisherFrame
,
47 struct _CONTEXT
* ContextRecord
,
48 void * DispatcherContext
51 _SEHPortableFrame_t
* frame
;
53 _SEHCleanHandlerEnvironment();
55 frame
= EstablisherFrame
;
58 if(ExceptionRecord
->ExceptionFlags
& (4 | 2))
60 if(frame
->SPF_Handlers
->SH_Finally
&& !frame
->SPF_Handling
)
61 frame
->SPF_Handlers
->SH_Finally(frame
);
66 if(ExceptionRecord
->ExceptionCode
)
67 frame
->SPF_Code
= ExceptionRecord
->ExceptionCode
;
69 frame
->SPF_Code
= 0xC0000001;
71 if(frame
->SPF_Handlers
->SH_Filter
)
75 switch((UINT_PTR
)frame
->SPF_Handlers
->SH_Filter
)
77 case EXCEPTION_EXECUTE_HANDLER
+ 1:
78 case EXCEPTION_CONTINUE_SEARCH
+ 1:
79 case EXCEPTION_CONTINUE_EXECUTION
+ 1:
81 ret
= (int)((UINT_PTR
)frame
->SPF_Handlers
->SH_Filter
) - 1;
87 EXCEPTION_POINTERS ep
;
89 ep
.ExceptionRecord
= ExceptionRecord
;
90 ep
.ContextRecord
= ContextRecord
;
92 ret
= frame
->SPF_Handlers
->SH_Filter(&ep
, frame
);
97 /* EXCEPTION_CONTINUE_EXECUTION */
99 return ExceptionContinueExecution
;
100 /* EXCEPTION_EXECUTE_HANDLER */
102 _SEHCallHandler(frame
);
103 /* EXCEPTION_CONTINUE_SEARCH */
109 return ExceptionContinueSearch
;
112 void __stdcall
_SEHEnter(_SEHPortableFrame_t
* frame
)
114 frame
->SPF_Registration
.SER_Handler
= _SEHFrameHandler
;
116 frame
->SPF_Handling
= 0;
117 _SEHRegisterFrame(&frame
->SPF_Registration
);
120 void __stdcall
_SEHLeave(_SEHPortableFrame_t
* frame
)
122 _SEHUnregisterFrame(&frame
->SPF_Registration
);