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.

136 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. tsecomm.c
  5. Abstract:
  6. Common security definitions and routines.
  7. This module defines macros that provide a mode-independent
  8. interface for security test procedures.
  9. The mode must be specified by defining one, but not both,
  10. of:
  11. _TST_USER_ (for user mode tests)
  12. _TST_KERNEL_ (for kernel mode tests)
  13. Author:
  14. Jim Kelly (JimK) 23-Mar-1990
  15. Environment:
  16. Test of security.
  17. Revision History:
  18. --*/
  19. #ifndef _TSECOMM_
  20. #define _TSECOMM_
  21. ////////////////////////////////////////////////////////////////
  22. // //
  23. // Common Definitions //
  24. // //
  25. ////////////////////////////////////////////////////////////////
  26. #define SEASSERT_SUCCESS(s) { \
  27. if (!NT_SUCCESS((s))) { \
  28. DbgPrint("** ! Failed ! **\n"); \
  29. DbgPrint("Status is: 0x%lx \n", (s)); \
  30. } \
  31. ASSERT(NT_SUCCESS(s)); }
  32. ////////////////////////////////////////////////////////////////
  33. // //
  34. // Kernel Mode Definitions //
  35. // //
  36. ////////////////////////////////////////////////////////////////
  37. #ifdef _TST_KERNEL_
  38. #define TstAllocatePool(PoolType,NumberOfBytes) \
  39. (ExAllocatePool( (PoolType), (NumberOfBytes) ))
  40. #define TstDeallocatePool(Pointer, NumberOfBytes) \
  41. (ExFreePool( (Pointer) ))
  42. #endif // _TST_KERNEL_
  43. ////////////////////////////////////////////////////////////////
  44. // //
  45. // User Mode Definitions //
  46. // //
  47. ////////////////////////////////////////////////////////////////
  48. #ifdef _TST_USER_
  49. #include <nt.h>
  50. #include <ntrtl.h>
  51. #include <nturtl.h>
  52. // #include "sep.h"
  53. #define TstAllocatePool(IgnoredPoolType,NumberOfBytes) \
  54. (ITstAllocatePool( (NumberOfBytes) ))
  55. #define TstDeallocatePool(Pointer, NumberOfBytes) \
  56. (ITstDeallocatePool((Pointer),(NumberOfBytes) ))
  57. PVOID
  58. ITstAllocatePool(
  59. IN ULONG NumberOfBytes
  60. )
  61. {
  62. NTSTATUS Status;
  63. PVOID PoolAddress = NULL;
  64. ULONG RegionSize;
  65. RegionSize = NumberOfBytes;
  66. Status = NtAllocateVirtualMemory( NtCurrentProcess(),
  67. &PoolAddress,
  68. 0,
  69. &RegionSize,
  70. MEM_COMMIT,
  71. PAGE_READWRITE
  72. );
  73. return PoolAddress;
  74. }
  75. VOID
  76. ITstDeallocatePool(
  77. IN PVOID Pointer,
  78. IN ULONG NumberOfBytes
  79. )
  80. {
  81. NTSTATUS Status;
  82. PVOID PoolAddress;
  83. ULONG RegionSize;
  84. RegionSize = NumberOfBytes;
  85. PoolAddress = Pointer;
  86. Status = NtFreeVirtualMemory( NtCurrentProcess(),
  87. &PoolAddress,
  88. &RegionSize,
  89. MEM_DECOMMIT
  90. );
  91. return;
  92. }
  93. #endif // _TST_USER_
  94. #endif //_TSECOMM_