Merge 13159:13510 from trunk
[reactos.git] / reactos / include / pseh.h
1 /*
2 Copyright (c) 2004 KJK::Hyperion
3
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:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
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
20 SOFTWARE.
21 */
22
23 #ifndef KJK_PSEH_H_
24 #define KJK_PSEH_H_
25
26 /* Some useful macros */
27 #if defined(__cplusplus)
28 # define _SEH_PVOID_CAST(TYPE_, P_) ((TYPE_)(P_))
29 #else
30 # define _SEH_PVOID_CAST(TYPE_, P_) (P_)
31 #endif
32
33 #if defined(FIELD_OFFSET)
34 # define _SEH_FIELD_OFFSET FIELD_OFFSET
35 #else
36 # include <stddef.h>
37 # define _SEH_FIELD_OFFSET offsetof
38 #endif
39
40 #if defined(CONTAINING_RECORD)
41 # define _SEH_CONTAINING_RECORD CONTAINING_RECORD
42 #else
43 # define _SEH_CONTAINING_RECORD(ADDR_, TYPE_, FIELD_) \
44 ((TYPE_ *)(((char *)(ADDR_)) - _SEH_FIELD_OFFSET(TYPE_, FIELD_)))
45 #endif
46
47 #if defined(__CONCAT)
48 # define _SEH_CONCAT __CONCAT
49 #else
50 # define _SEH_CONCAT1(X_, Y_) X_ ## Y_
51 # define _SEH_CONCAT(X_, Y_) _SEH_CONCAT1(X_, Y_)
52 #endif
53
54 /* Locals sharing support */
55 #define _SEH_LOCALS_TYPENAME(BASENAME_) \
56 struct _SEH_CONCAT(_SEHLocalsTag, BASENAME_)
57
58 #define _SEH_DEFINE_LOCALS(BASENAME_) \
59 _SEH_LOCALS_TYPENAME(BASENAME_)
60
61 #define _SEH_DECLARE_LOCALS(BASENAME_) \
62 _SEH_LOCALS_TYPENAME(BASENAME_) _SEHLocals; \
63 _SEH_LOCALS_TYPENAME(BASENAME_) * _SEHPLocals; \
64 _SEHPLocals = &_SEHLocals;
65
66 /* Dummy locals */
67 static _SEH_LOCALS_TYPENAME(_SEHDummyLocals) { int Dummy_; } _SEHLocals;
68 static void __inline _SEHDummyLocalsUser(void) { (void)_SEHLocals; }
69
70 /* TODO: <pseh/native.h> to wrap native SEH implementations */
71 #include <pseh/framebased.h>
72
73 #endif
74
75 /* EOF */