1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Macros to deal with doubly-linked lists using the LIST_ENTRY structure
16 : // declared in the Platform SDK.
17 : //
18 : // The macros below are copied verbatim from msputils.h for convenience.
19 :
20 : #ifndef SYZYGY_AGENT_COMMON_DLIST_H_
21 : #define SYZYGY_AGENT_COMMON_DLIST_H_
22 :
23 : #include <windows.h>
24 : #include <winnt.h>
25 :
26 : //
27 : // Calculate the address of the base of the structure given its type, and an
28 : // address of a field within the structure.
29 : //
30 : #ifndef CONTAINING_RECORD
31 : #define CONTAINING_RECORD(address, type, field) \
32 m : ((type *)((PCHAR)(address) - (ULONG_PTR)(&((type *)0)->field))) // NOLINT
33 : #endif
34 :
35 :
36 : #ifndef InitializeListHead
37 : //
38 : // VOID
39 : // InitializeListHead(
40 : // PLIST_ENTRY ListHead
41 : // );
42 : //
43 :
44 : #define InitializeListHead(ListHead) (\
45 m : (ListHead)->Flink = (ListHead)->Blink = (ListHead))
46 :
47 : //
48 : // BOOLEAN
49 : // IsListEmpty(
50 : // PLIST_ENTRY ListHead
51 : // );
52 : //
53 :
54 : #define IsListEmpty(ListHead) \
55 m : ((ListHead)->Flink == (ListHead))
56 :
57 : //
58 : // PLIST_ENTRY
59 : // RemoveHeadList(
60 : // PLIST_ENTRY ListHead
61 : // );
62 : //
63 :
64 : #define RemoveHeadList(ListHead) \
65 m : (ListHead)->Flink;\
66 m : {RemoveEntryList((ListHead)->Flink)}
67 :
68 : //
69 : // PLIST_ENTRY
70 : // RemoveTailList(
71 : // PLIST_ENTRY ListHead
72 : // );
73 : //
74 :
75 : #define RemoveTailList(ListHead) \
76 m : (ListHead)->Blink;\
77 m : {RemoveEntryList((ListHead)->Blink)}
78 :
79 : //
80 : // VOID
81 : // RemoveEntryList(
82 : // PLIST_ENTRY Entry
83 : // );
84 : //
85 :
86 : #define RemoveEntryList(Entry) {\
87 m : PLIST_ENTRY _EX_Blink;\
88 m : PLIST_ENTRY _EX_Flink;\
89 m : _EX_Flink = (Entry)->Flink;\
90 m : _EX_Blink = (Entry)->Blink;\
91 m : _EX_Blink->Flink = _EX_Flink;\
92 m : _EX_Flink->Blink = _EX_Blink;\
93 m : }
94 :
95 : //
96 : // VOID
97 : // InsertTailList(
98 : // PLIST_ENTRY ListHead,
99 : // PLIST_ENTRY Entry
100 : // );
101 : //
102 :
103 : #define InsertTailList(ListHead, Entry) {\
104 m : PLIST_ENTRY _EX_Blink;\
105 m : PLIST_ENTRY _EX_ListHead;\
106 m : _EX_ListHead = (ListHead);\
107 m : _EX_Blink = _EX_ListHead->Blink;\
108 m : (Entry)->Flink = _EX_ListHead;\
109 m : (Entry)->Blink = _EX_Blink;\
110 m : _EX_Blink->Flink = (Entry);\
111 m : _EX_ListHead->Blink = (Entry);\
112 m : }
113 :
114 : //
115 : // VOID
116 : // InsertHeadList(
117 : // PLIST_ENTRY ListHead,
118 : // PLIST_ENTRY Entry
119 : // );
120 : //
121 :
122 : #define InsertHeadList(ListHead, Entry) {\
123 m : PLIST_ENTRY _EX_Flink;\
124 m : PLIST_ENTRY _EX_ListHead;\
125 m : _EX_ListHead = (ListHead);\
126 m : _EX_Flink = _EX_ListHead->Flink;\
127 m : (Entry)->Flink = _EX_Flink;\
128 m : (Entry)->Blink = _EX_ListHead;\
129 m : _EX_Flink->Blink = (Entry);\
130 m : _EX_ListHead->Flink = (Entry);\
131 m : }
132 :
133 : #endif // InitializeListHead
134 :
135 :
136 m : BOOL IsNodeOnList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry);
137 :
138 :
139 : #endif // SYZYGY_AGENT_COMMON_DLIST_H_
|