HyperDbg Debugger
Loading...
Searching...
No Matches
nt-list.h
Go to the documentation of this file.
1
25#pragma once
26
27#ifndef _WIN32
28
29# include <stddef.h> // offsetof
30
31//
32// Given the address of a LIST_ENTRY field embedded in a struct, recover the
33// address of the containing struct.
34//
35# ifndef CONTAINING_RECORD
36# define CONTAINING_RECORD(address, type, field) \
37 ((type *)((char *)(address) - offsetof(type, field)))
38# endif
39
40//
41// Initialize a list head to the empty (points-to-self) state.
42//
43static inline VOID
44InitializeListHead(PLIST_ENTRY ListHead)
45{
46 ListHead->Flink = ListHead->Blink = ListHead;
47}
48
49//
50// TRUE if the list has no entries.
51//
52static inline BOOLEAN
53IsListEmpty(const LIST_ENTRY * ListHead)
54{
55 return (BOOLEAN)(ListHead->Flink == ListHead);
56}
57
58//
59// Unlink an entry. Returns TRUE if the list is now empty.
60//
61static inline BOOLEAN
62RemoveEntryList(PLIST_ENTRY Entry)
63{
64 PLIST_ENTRY Flink = Entry->Flink;
65 PLIST_ENTRY Blink = Entry->Blink;
66
67 Blink->Flink = Flink;
68 Flink->Blink = Blink;
69
70 return (BOOLEAN)(Flink == Blink);
71}
72
73//
74// Unlink and return the first entry.
75//
76static inline PLIST_ENTRY
77RemoveHeadList(PLIST_ENTRY ListHead)
78{
79 PLIST_ENTRY Entry = ListHead->Flink;
80 PLIST_ENTRY Flink = Entry->Flink;
81
82 ListHead->Flink = Flink;
83 Flink->Blink = ListHead;
84
85 return Entry;
86}
87
88//
89// Unlink and return the last entry.
90//
91static inline PLIST_ENTRY
92RemoveTailList(PLIST_ENTRY ListHead)
93{
94 PLIST_ENTRY Entry = ListHead->Blink;
95 PLIST_ENTRY Blink = Entry->Blink;
96
97 ListHead->Blink = Blink;
98 Blink->Flink = ListHead;
99
100 return Entry;
101}
102
103//
104// Insert an entry at the tail of the list.
105//
106static inline VOID
107InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
108{
109 PLIST_ENTRY Blink = ListHead->Blink;
110
111 Entry->Flink = ListHead;
112 Entry->Blink = Blink;
113 Blink->Flink = Entry;
114 ListHead->Blink = Entry;
115}
116
117//
118// Insert an entry at the head of the list.
119//
120static inline VOID
121InsertHeadList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
122{
123 PLIST_ENTRY Flink = ListHead->Flink;
124
125 Entry->Flink = Flink;
126 Entry->Blink = ListHead;
127 Flink->Blink = Entry;
128 ListHead->Flink = Entry;
129}
130
131//
132// Splice the entries of ListToAppend onto the tail of ListHead.
133//
134static inline VOID
135AppendTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListToAppend)
136{
137 PLIST_ENTRY ListEnd = ListHead->Blink;
138
139 ListHead->Blink->Flink = ListToAppend;
140 ListHead->Blink = ListToAppend->Blink;
141 ListToAppend->Blink->Flink = ListHead;
142 ListToAppend->Blink = ListEnd;
143}
144
145#endif // !_WIN32
UCHAR BOOLEAN
Definition BasicTypes.h:35