set most of trunk svn property eol-style:native
[reactos.git] / reactos / ntoskrnl / include / internal / ob_x.h
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/ob_x.h
5 * PURPOSE: Intenral Inlined Functions for the Object Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 VOID
10 FORCEINLINE
11 ObpEnterObjectTypeMutex(IN POBJECT_TYPE ObjectType)
12 {
13 /* Sanity check */
14 ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
15
16 /* Enter a critical region and acquire the resource */
17 KeEnterCriticalRegion();
18 ExAcquireResourceExclusiveLite(&ObjectType->Mutex, TRUE);
19 }
20
21 VOID
22 FORCEINLINE
23 ObpLeaveObjectTypeMutex(IN POBJECT_TYPE ObjectType)
24 {
25 /* Enter a critical region and acquire the resource */
26 ExReleaseResourceLite(&ObjectType->Mutex);
27 KeLeaveCriticalRegion();
28
29 /* Sanity check */
30 ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
31 }
32
33 VOID
34 FORCEINLINE
35 ObpReleaseCapturedAttributes(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
36 {
37 /* Check if we have a security descriptor */
38 if (ObjectCreateInfo->SecurityDescriptor)
39 {
40 /* Release it */
41 SeReleaseSecurityDescriptor(ObjectCreateInfo->SecurityDescriptor,
42 ObjectCreateInfo->ProbeMode,
43 TRUE);
44 ObjectCreateInfo->SecurityDescriptor = NULL;
45 }
46 }
47
48 PVOID
49 FORCEINLINE
50 ObpAllocateCapturedAttributes(IN PP_NPAGED_LOOKASIDE_NUMBER Type)
51 {
52 PVOID Buffer;
53 PNPAGED_LOOKASIDE_LIST List;
54 PKPRCB Prcb = KeGetCurrentPrcb();
55
56 /* Get the P list first */
57 List = (PNPAGED_LOOKASIDE_LIST)Prcb->PPLookasideList[Type].P;
58
59 /* Attempt allocation */
60 List->L.TotalAllocates++;
61 Buffer = (PVOID)InterlockedPopEntrySList(&List->L.ListHead);
62 if (!Buffer)
63 {
64 /* Let the balancer know that the P list failed */
65 List->L.AllocateMisses++;
66
67 /* Try the L List */
68 List = (PNPAGED_LOOKASIDE_LIST)Prcb->PPLookasideList[Type].L;
69 List->L.TotalAllocates++;
70 Buffer = (PVOID)InterlockedPopEntrySList(&List->L.ListHead);
71 if (!Buffer)
72 {
73 /* Let the balancer know the L list failed too */
74 List->L.AllocateMisses++;
75
76 /* Allocate it */
77 Buffer = List->L.Allocate(List->L.Type, List->L.Size, List->L.Tag);
78 }
79 }
80
81 /* Return buffer */
82 return Buffer;
83 }
84
85 VOID
86 static __inline
87 ObpFreeCapturedAttributes(IN PVOID Buffer,
88 IN PP_NPAGED_LOOKASIDE_NUMBER Type)
89 {
90 PNPAGED_LOOKASIDE_LIST List;
91 PKPRCB Prcb = KeGetCurrentPrcb();
92
93 /* Use the P List */
94 List = (PNPAGED_LOOKASIDE_LIST)Prcb->PPLookasideList[Type].P;
95 List->L.TotalFrees++;
96
97 /* Check if the Free was within the Depth or not */
98 if (ExQueryDepthSList(&List->L.ListHead) >= List->L.Depth)
99 {
100 /* Let the balancer know */
101 List->L.FreeMisses++;
102
103 /* Use the L List */
104 List = (PNPAGED_LOOKASIDE_LIST)Prcb->PPLookasideList[Type].L;
105 List->L.TotalFrees++;
106
107 /* Check if the Free was within the Depth or not */
108 if (ExQueryDepthSList(&List->L.ListHead) >= List->L.Depth)
109 {
110 /* All lists failed, use the pool */
111 List->L.FreeMisses++;
112 List->L.Free(Buffer);
113 }
114 }
115 else
116 {
117 /* The free was within the Depth */
118 InterlockedPushEntrySList(&List->L.ListHead,
119 (PSINGLE_LIST_ENTRY)Buffer);
120 }
121 }
122
123 VOID
124 static __inline
125 ObpReleaseCapturedName(IN PUNICODE_STRING Name)
126 {
127 /* We know this is a pool-allocation if the size doesn't match */
128 if (Name->MaximumLength != 248)
129 {
130 ExFreePool(Name->Buffer);
131 }
132 else
133 {
134 /* Otherwise, free from the lookaside */
135 ObpFreeCapturedAttributes(Name, LookasideNameBufferList);
136 }
137 }
138
139 VOID
140 static __inline
141 ObpFreeAndReleaseCapturedAttributes(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
142 {
143 /* First release the attributes, then free them from the lookaside list */
144 ObpReleaseCapturedAttributes(ObjectCreateInfo);
145 ObpFreeCapturedAttributes(ObjectCreateInfo, LookasideCreateInfoList);
146 }
147