- Silence TCPIP.
[reactos.git] / reactos / ntoskrnl / ob / sdcache.c
index 0b26490..b1464c4 100644 (file)
@@ -1,19 +1,16 @@
-/* $Id: sdcache.c,v 1.1 2004/07/16 17:19:15 ekohl Exp $
+/* $Id$
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
- * FILE:            ntoskrnl/ps/kill.c
- * PURPOSE:         Terminating a thread
- * PROGRAMMER:      David Welch (welch@cwcom.net)
- * UPDATE HISTORY:
- *                  Created 22/05/98
+ * FILE:            ntoskrnl/ob/sdcache.c
+ * PURPOSE:         No purpose listed.
+ *
+ * PROGRAMMERS:     David Welch (welch@cwcom.net)
  */
 
 /* INCLUDES *****************************************************************/
 
-#include <ddk/ntddk.h>
-#include <internal/ob.h>
-
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <internal/debug.h>
 
@@ -31,51 +28,49 @@ typedef struct _SD_CACHE_ENTRY
 
 /* GLOBALS ******************************************************************/
 
-PLIST_ENTRY ObpSdCache;
-KSPIN_LOCK ObpSdCacheSpinLock;
-KIRQL ObpSdCacheIrql;
-
-
 #define SD_CACHE_ENTRIES 0x100
 
+LIST_ENTRY ObpSdCache[SD_CACHE_ENTRIES];
+FAST_MUTEX ObpSdCacheMutex;
+
 /* FUNCTIONS ****************************************************************/
 
 NTSTATUS
+NTAPI
 ObpInitSdCache(VOID)
 {
   ULONG i;
 
-  ObpSdCache = ExAllocatePool(NonPagedPool,
-                             SD_CACHE_ENTRIES * sizeof(LIST_ENTRY));
-  if (ObpSdCache == NULL)
-    {
-      return STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-  for (i = 0; i < SD_CACHE_ENTRIES; i++)
+  for (i = 0; i < (sizeof(ObpSdCache) / sizeof(ObpSdCache[0])); i++)
     {
       InitializeListHead(&ObpSdCache[i]);
     }
 
-  KeInitializeSpinLock(&ObpSdCacheSpinLock);
+  ExInitializeFastMutex(&ObpSdCacheMutex);
 
   return STATUS_SUCCESS;
 }
 
 
-static VOID
+static __inline VOID
 ObpSdCacheLock(VOID)
 {
-  KeAcquireSpinLock(&ObpSdCacheSpinLock,
-                   &ObpSdCacheIrql);
+  /* can't acquire a fast mutex in the early boot process... */
+  if(KeGetCurrentThread() != NULL)
+  {
+    ExAcquireFastMutex(&ObpSdCacheMutex);
+  }
 }
 
 
-static VOID
+static __inline VOID
 ObpSdCacheUnlock(VOID)
 {
-  KeReleaseSpinLock(&ObpSdCacheSpinLock,
-                   ObpSdCacheIrql);
+  /* can't acquire a fast mutex in the early boot process... */
+  if(KeGetCurrentThread() != NULL)
+  {
+    ExReleaseFastMutex(&ObpSdCacheMutex);
+  }
 }
 
 
@@ -213,6 +208,7 @@ ObpCompareSecurityDescriptors(IN PSECURITY_DESCRIPTOR Sd1,
 
 
 NTSTATUS
+NTAPI
 ObpAddSecurityDescriptor(IN PSECURITY_DESCRIPTOR SourceSD,
                         OUT PSECURITY_DESCRIPTOR *DestinationSD)
 {
@@ -283,6 +279,7 @@ ObpAddSecurityDescriptor(IN PSECURITY_DESCRIPTOR SourceSD,
 
 
 NTSTATUS
+NTAPI
 ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
 {
   PSD_CACHE_ENTRY CacheEntry;
@@ -309,4 +306,37 @@ ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
   return STATUS_SUCCESS;
 }
 
+
+VOID
+NTAPI
+ObpReferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
+{
+  PSD_CACHE_ENTRY CacheEntry;
+
+  DPRINT("ObpReferenceCachedSecurityDescriptor() called\n");
+
+  ObpSdCacheLock();
+
+  CacheEntry = (PSD_CACHE_ENTRY)((ULONG_PTR)SecurityDescriptor - sizeof(SD_CACHE_ENTRY));
+
+  CacheEntry->RefCount++;
+  DPRINT("RefCount %lu\n", CacheEntry->RefCount);
+
+  ObpSdCacheUnlock();
+
+  DPRINT("ObpReferenceCachedSecurityDescriptor() done\n");
+}
+
+
+VOID
+NTAPI
+ObpDereferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
+{
+  DPRINT("ObpDereferenceCachedSecurityDescriptor() called\n");
+
+  ObpRemoveSecurityDescriptor(SecurityDescriptor);
+
+  DPRINT("ObpDereferenceCachedSecurityDescriptor() done\n");
+}
+
 /* EOF */