Source code of Windows XP (NT5)
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.

128 lines
3.0 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Module: alloc.c
  4. //
  5. // Description:
  6. //
  7. //
  8. //@@BEGIN_MSINTERNAL
  9. // Development Team:
  10. // Mike McLaughlin
  11. //
  12. // History: Date Author Comment
  13. //
  14. // To Do: Date Author Comment
  15. //
  16. //@@END_MSINTERNAL
  17. //
  18. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  19. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  20. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  21. // PURPOSE.
  22. //
  23. // Copyright (c) 1996-1999 Microsoft Corporation. All Rights Reserved.
  24. //
  25. //---------------------------------------------------------------------------
  26. #include "common.h"
  27. //---------------------------------------------------------------------------
  28. //---------------------------------------------------------------------------
  29. NTSTATUS
  30. AllocatorDispatchCreate(
  31. IN PDEVICE_OBJECT pDeviceObject,
  32. IN PIRP pIrp
  33. )
  34. {
  35. PSTART_NODE_INSTANCE pStartNodeInstance;
  36. PKSALLOCATOR_FRAMING pAllocatorFraming;
  37. PINSTANCE pInstance = NULL;
  38. NTSTATUS Status;
  39. GrabMutex();
  40. Status = GetRelatedStartNodeInstance(pIrp, &pStartNodeInstance);
  41. if(!NT_SUCCESS(Status)) {
  42. goto exit;
  43. }
  44. Assert(pStartNodeInstance);
  45. Status = KsValidateAllocatorCreateRequest(
  46. pIrp,
  47. &pAllocatorFraming);
  48. if(!NT_SUCCESS(Status)) {
  49. DPF1(5,
  50. "AllocatorDispatchCreate: KsValidateAllocatorCreateReq FAILED %08x",
  51. Status);
  52. goto exit;
  53. }
  54. // Allocate per allocator instance data
  55. pInstance = new INSTANCE(
  56. &pStartNodeInstance->pPinInstance->ParentInstance);
  57. if(pInstance == NULL) {
  58. Trap();
  59. Status = STATUS_INSUFFICIENT_RESOURCES;
  60. goto exit;
  61. }
  62. Status = pInstance->DispatchCreate(
  63. pIrp,
  64. (UTIL_PFN)AllocatorDispatchCreateKP,
  65. pAllocatorFraming);
  66. if(!NT_SUCCESS(Status)) {
  67. DPF1(5, "AllocatorDispatchCreateKP: FAILED %08x", Status);
  68. goto exit;
  69. }
  70. exit:
  71. if(!NT_SUCCESS(Status) && (pInstance != NULL)) {
  72. delete pInstance;
  73. }
  74. ReleaseMutex();
  75. pIrp->IoStatus.Status = Status;
  76. IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  77. return Status;
  78. }
  79. NTSTATUS
  80. AllocatorDispatchCreateKP(
  81. PINSTANCE pInstance,
  82. PKSALLOCATOR_FRAMING pAllocatorFraming
  83. )
  84. {
  85. PPIN_INSTANCE pPinInstance;
  86. HANDLE hAllocator = NULL;
  87. NTSTATUS Status;
  88. Assert(pInstance);
  89. pPinInstance = pInstance->GetParentInstance();
  90. Assert(pPinInstance);
  91. Assert(pPinInstance->pStartNodeInstance);
  92. Assert(pPinInstance->pStartNodeInstance->pPinNodeInstance);
  93. ASSERT(pPinInstance->pStartNodeInstance->pPinNodeInstance->hPin != NULL);
  94. Status = KsCreateAllocator(
  95. pPinInstance->pStartNodeInstance->pPinNodeInstance->hPin,
  96. pAllocatorFraming,
  97. &hAllocator);
  98. if(!NT_SUCCESS(Status)) {
  99. goto exit;
  100. }
  101. Status = pInstance->SetNextFileObject(hAllocator);
  102. if(!NT_SUCCESS(Status)) {
  103. Trap();
  104. goto exit;
  105. }
  106. exit:
  107. if(hAllocator != NULL) {
  108. ZwClose(hAllocator);
  109. }
  110. return(Status);
  111. }