Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 1989-2001 Microsoft Corporation
  3. Module Name:
  4. util.c
  5. Abstract:
  6. Platform independent utility functions
  7. Author:
  8. Jiandong Ruan
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #include "util.tmh"
  13. BOOL
  14. EntryIsInList(PLIST_ENTRY ListHead, PLIST_ENTRY SearchEntry)
  15. /*++
  16. Routine Description:
  17. This routine search SearchEntry in the list ListHead.
  18. NOTE: proper lock should be held before calling this function.
  19. Arguments:
  20. ListHead the head of the list
  21. SearchEntry the entry to be searched
  22. Return Value:
  23. TRUE if the entry is in the list
  24. FALSE otherwise
  25. --*/
  26. {
  27. PLIST_ENTRY Entry;
  28. KIRQL Irql;
  29. Irql = KeGetCurrentIrql();
  30. if (Irql < DISPATCH_LEVEL) {
  31. ASSERT(0);
  32. return FALSE;
  33. }
  34. Entry = ListHead->Flink;
  35. while(Entry != ListHead) {
  36. if (Entry == SearchEntry) {
  37. return TRUE;
  38. }
  39. Entry = Entry->Flink;
  40. }
  41. return FALSE;
  42. }
  43. PIRP
  44. SmbAllocIrp(
  45. CCHAR StackSize
  46. )
  47. {
  48. KIRQL Irql = 0;
  49. PIRP Irp = NULL;
  50. Irp = IoAllocateIrp(StackSize, FALSE);
  51. if (NULL == Irp) {
  52. return NULL;
  53. }
  54. KeAcquireSpinLock(&SmbCfg.UsedIrpsLock, &Irql);
  55. InsertTailList(&SmbCfg.UsedIrps, &Irp->ThreadListEntry);
  56. KeReleaseSpinLock(&SmbCfg.UsedIrpsLock, Irql);
  57. return Irp;
  58. }
  59. VOID
  60. SmbFreeIrp(
  61. PIRP Irp
  62. )
  63. {
  64. KIRQL Irql = 0;
  65. if (NULL == Irp) {
  66. ASSERT(0);
  67. return;
  68. }
  69. KeAcquireSpinLock(&SmbCfg.UsedIrpsLock, &Irql);
  70. ASSERT(EntryIsInList(&SmbCfg.UsedIrps, &Irp->ThreadListEntry));
  71. RemoveEntryList(&Irp->ThreadListEntry);
  72. KeReleaseSpinLock(&SmbCfg.UsedIrpsLock, Irql);
  73. //
  74. // Make the driver verifier happy
  75. //
  76. InitializeListHead(&Irp->ThreadListEntry);
  77. IoFreeIrp(Irp);
  78. }