ReactOS  0.4.15-dev-3175-g222acf5
slist.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for slist.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI RtlInitializeSListHead (_Out_ PSLIST_HEADER SListHead)
 
PSLIST_ENTRY NTAPI RtlFirstEntrySList (_In_ const SLIST_HEADER *SListHead)
 
WORD NTAPI RtlQueryDepthSList (_In_ PSLIST_HEADER SListHead)
 
PSLIST_ENTRY FASTCALL RtlInterlockedPushListSList (_Inout_ PSLIST_HEADER SListHead, _Inout_ __drv_aliasesMem PSLIST_ENTRY List, _Inout_ PSLIST_ENTRY ListEnd, _In_ ULONG Count)
 
PSLIST_ENTRY NTAPI RtlInterlockedPushEntrySList (_Inout_ PSLIST_HEADER SListHead, _Inout_ __drv_aliasesMem PSLIST_ENTRY SListEntry)
 
PSLIST_ENTRY NTAPI RtlInterlockedPopEntrySList (_Inout_ PSLIST_HEADER SListHead)
 
PSLIST_ENTRY NTAPI RtlInterlockedFlushSList (_Inout_ PSLIST_HEADER SListHead)
 

Variables

BOOLEAN RtlpExpectSListFault
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file slist.c.

Function Documentation

◆ RtlFirstEntrySList()

PSLIST_ENTRY NTAPI RtlFirstEntrySList ( _In_ const SLIST_HEADER SListHead)

Definition at line 51 of file slist.c.

53 {
54 #if defined(_WIN64)
55  /* Check if the header is initialized as 16 byte header */
56  if (SListHead->Header16.HeaderType)
57  {
58  return (PVOID)(SListHead->Region & ~0xFLL);
59  }
60  else
61  {
62  union {
64  struct {
65  ULONG64 Reserved:4;
66  ULONG64 NextEntry:39;
67  ULONG64 Reserved2:21;
68  } Bits;
69  } Pointer;
70 
71 #if defined(_IA64_)
72  /* On Itanium we stored the region in the list head */
73  Pointer.Region = SListHead->Region;
74 #else
75  /* On amd64 we just use the list head itself */
76  Pointer.Region = (ULONG64)SListHead;
77 #endif
78  Pointer.Bits.NextEntry = SListHead->Header8.NextEntry;
79  return (PVOID)Pointer.Region;
80  }
81 #else
82  return SListHead->Next.Next;
83 #endif
84 }
#define LL
Definition: tui.h:84
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
Definition: bcd.h:202
unsigned __int64 ULONG64
Definition: imports.h:198

Referenced by ShimLib_NotifyShims().

◆ RtlInitializeSListHead()

VOID NTAPI RtlInitializeSListHead ( _Out_ PSLIST_HEADER  SListHead)

Definition at line 25 of file slist.c.

27 {
28 #if defined(_WIN64)
29  /* Make sure the header is 16 byte aligned */
30  if (((ULONG_PTR)SListHead & 0xf) != 0)
31  {
32  DPRINT1("Unaligned SListHead: 0x%p\n", SListHead);
34  }
35 
36  /* Initialize the Region member */
37 #if defined(_IA64_)
38  /* On Itanium we store the region in the list head */
39  SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
40 #else
41  /* On amd64 we don't need to store anything */
42  SListHead->Region = 0;
43 #endif /* _IA64_ */
44 #endif /* _WIN64 */
45 
46  SListHead->Alignment = 0;
47 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define DPRINT1
Definition: precomp.h:8
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
#define ULONG_PTR
Definition: config.h:101

Referenced by RtlpDphInitializeDelayedFreeQueue(), and ShimLib_Init().

◆ RtlInterlockedFlushSList()

PSLIST_ENTRY NTAPI RtlInterlockedFlushSList ( _Inout_ PSLIST_HEADER  SListHead)

Definition at line 251 of file slist.c.

253 {
254  SLIST_HEADER OldHeader, NewHeader;
255  ULONGLONG Compare;
256 
257  /* Read the header */
258  OldHeader = *SListHead;
259 
260  do
261  {
262  /* Check for empty list */
263  if (OldHeader.Next.Next == NULL)
264  {
265  return NULL;
266  }
267 
268  /* Create a new header (keep the sequence number) */
269  NewHeader = OldHeader;
270  NewHeader.Next.Next = NULL;
271  NewHeader.Depth = 0;
272 
273  /* Try to exchange atomically */
274  Compare = OldHeader.Alignment;
275  OldHeader.Alignment = InterlockedCompareExchange64((PLONGLONG)&SListHead->Alignment,
276  NewHeader.Alignment,
277  Compare);
278  }
279  while (OldHeader.Alignment != Compare);
280 
281  /* Return the old first entry */
282  return OldHeader.Next.Next;
283 
284 }
ULONGLONG Alignment
Definition: rtltypes.h:139
#define InterlockedCompareExchange64
Definition: interlocked.h:114
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
SLIST_ENTRY Next
Definition: rtltypes.h:141
uint64_t ULONGLONG
Definition: typedefs.h:67
#define NULL
Definition: types.h:112
USHORT Depth
Definition: rtltypes.h:142

◆ RtlInterlockedPopEntrySList()

PSLIST_ENTRY NTAPI RtlInterlockedPopEntrySList ( _Inout_ PSLIST_HEADER  SListHead)

Definition at line 192 of file slist.c.

194 {
195  SLIST_HEADER OldHeader, NewHeader;
196  ULONGLONG Compare;
197 
198 restart:
199 
200  /* Read the header */
201  OldHeader = *SListHead;
202 
203  do
204  {
205  /* Check for empty list */
206  if (OldHeader.Next.Next == NULL)
207  {
208  return NULL;
209  }
210 
211  /* Create a new header */
212  NewHeader = OldHeader;
213 
214  /* HACK to let the kernel know that we are doing slist-magic */
216 
217  /* Wrapped in SEH, since OldHeader.Next.Next can already be freed */
218  _SEH2_TRY
219  {
220  NewHeader.Next = *OldHeader.Next.Next;
221  }
222  _SEH2_EXCEPT((SListHead->Next.Next != OldHeader.Next.Next) ?
224  {
225  /* We got an exception and the list head changed.
226  Restart the whole operation. */
228  goto restart;
229  }
230  _SEH2_END;
231 
232  /* We are done */
234 
235  /* Adjust depth */
236  NewHeader.Depth--;
237 
238  /* Try to exchange atomically */
239  Compare = OldHeader.Alignment;
240  OldHeader.Alignment = InterlockedCompareExchange64((PLONGLONG)SListHead->Alignment,
241  NewHeader.Alignment,
242  Compare);
243  }
244  while (OldHeader.Alignment != Compare);
245 
246  return OldHeader.Next.Next;
247 }
ULONGLONG Alignment
Definition: rtltypes.h:139
#define InterlockedCompareExchange64
Definition: interlocked.h:114
#define TRUE
Definition: types.h:120
_SEH2_TRY
Definition: create.c:4226
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
#define FALSE
Definition: types.h:117
BOOLEAN RtlpExpectSListFault
Definition: slist.c:153
void restart(int argc, const char *argv[])
Definition: cmds.c:2115
SLIST_ENTRY Next
Definition: rtltypes.h:141
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
uint64_t ULONGLONG
Definition: typedefs.h:67
_SEH2_END
Definition: create.c:4400
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
#define NULL
Definition: types.h:112
USHORT Depth
Definition: rtltypes.h:142
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40

◆ RtlInterlockedPushEntrySList()

PSLIST_ENTRY NTAPI RtlInterlockedPushEntrySList ( _Inout_ PSLIST_HEADER  SListHead,
_Inout_ __drv_aliasesMem PSLIST_ENTRY  SListEntry 
)

Definition at line 157 of file slist.c.

160 {
161  SLIST_HEADER OldHeader, NewHeader;
162  ULONGLONG Compare;
163 
164  /* Read the header */
165  OldHeader = *SListHead;
166 
167  do
168  {
169  /* Link the list entry */
170  SListEntry->Next = OldHeader.Next.Next;
171 
172  /* Create a new header */
173  NewHeader = OldHeader;
174  NewHeader.Next.Next = SListEntry;
175  NewHeader.Depth++;
176  NewHeader.Sequence++;
177 
178  /* Try to exchange atomically */
179  Compare = OldHeader.Alignment;
180  OldHeader.Alignment = InterlockedCompareExchange64((PLONGLONG)&SListHead->Alignment,
181  NewHeader.Alignment,
182  Compare);
183  }
184  while (OldHeader.Alignment != Compare);
185 
186  /* Return the old first entry */
187  return OldHeader.Next.Next;
188 }
ULONGLONG Alignment
Definition: rtltypes.h:139
#define InterlockedCompareExchange64
Definition: interlocked.h:114
USHORT Sequence
Definition: rtltypes.h:143
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
SLIST_ENTRY Next
Definition: rtltypes.h:141
uint64_t ULONGLONG
Definition: typedefs.h:67
USHORT Depth
Definition: rtltypes.h:142

Referenced by ShimLib_GetHookAPIs().

◆ RtlInterlockedPushListSList()

PSLIST_ENTRY FASTCALL RtlInterlockedPushListSList ( _Inout_ PSLIST_HEADER  SListHead,
_Inout_ __drv_aliasesMem PSLIST_ENTRY  List,
_Inout_ PSLIST_ENTRY  ListEnd,
_In_ ULONG  Count 
)

Definition at line 100 of file slist.c.

105 {
106 #ifdef _WIN64
108  DbgBreakPoint();
109  return NULL;
110 #else
111  SLIST_HEADER OldHeader, NewHeader;
112  ULONGLONG Compare;
113 
114  /* Read the header */
115  OldHeader = *SListHead;
116 
117  do
118  {
119  /* Link the last list entry */
120  ListEnd->Next = OldHeader.Next.Next;
121 
122  /* Create a new header */
123  NewHeader = OldHeader;
124  NewHeader.Next.Next = List;
125  NewHeader.Depth += Count;
126  NewHeader.Sequence++;
127 
128  /* Try to exchange atomically */
129  Compare = OldHeader.Alignment;
130  OldHeader.Alignment = InterlockedCompareExchange64((PLONGLONG)&SListHead->Alignment,
131  NewHeader.Alignment,
132  Compare);
133  }
134  while (OldHeader.Alignment != Compare);
135 
136  /* Return the old first entry */
137  return OldHeader.Next.Next;
138 #endif /* _WIN64 */
139 }
ULONGLONG Alignment
Definition: rtltypes.h:139
#define InterlockedCompareExchange64
Definition: interlocked.h:114
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY ListEnd
Definition: exfuncs.h:1223
USHORT Sequence
Definition: rtltypes.h:143
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
VOID NTAPI DbgBreakPoint(VOID)
int Count
Definition: noreturn.cpp:7
SLIST_ENTRY Next
Definition: rtltypes.h:141
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define NULL
Definition: types.h:112
#define UNIMPLEMENTED
Definition: debug.h:115
USHORT Depth
Definition: rtltypes.h:142

◆ RtlQueryDepthSList()

WORD NTAPI RtlQueryDepthSList ( _In_ PSLIST_HEADER  SListHead)

Definition at line 88 of file slist.c.

90 {
91 #if defined(_WIN64)
92  return (USHORT)(SListHead->Alignment & 0xffff);
93 #else
94  return SListHead->Depth;
95 #endif
96 }
unsigned short USHORT
Definition: pedump.c:61

Variable Documentation

◆ RtlpExpectSListFault

BOOLEAN RtlpExpectSListFault

Definition at line 153 of file slist.c.

Referenced by RtlInterlockedPopEntrySList().