test: tsecomm.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# tsecomm.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1989  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     tsecomm.c
    00008
    00009 Abstract:
    00010
    00011     Common security definitions and routines.
    00012
    00013     This module defines macros that provide a mode-independent
    00014     interface for security test procedures.
    00015
    00016     The mode must be specified by defining one, but not both,
    00017     of:
    00018          _TST_USER_    (for user mode tests)
    00019          _TST_KERNEL_  (for kernel mode tests)
    00020
    00021 Author:
    00022
    00023     Jim Kelly       (JimK)     23-Mar-1990
    00024
    00025 Environment:
    00026
    00027     Test of security.
    00028
    00029 Revision History:
    00030
    00031 --*/
    00032
    00033 #ifndef _TSECOMM_
    00034 #define _TSECOMM_
    00035
    00036
    00038 //                                                            //
    00039 // Common Definitions                                         //
    00040 //                                                            //
    00042
    00043 #define SEASSERT_SUCCESS(s) {                                                 \
    00044             if (!NT_SUCCESS((s))) {                                              \
    00045                 DbgPrint("** ! Failed ! **\n");                               \
    00046                 DbgPrint("Status is: 0x%lx \n", (s));                         \
    00047             }                                                                 \
    00048             ASSERT(NT_SUCCESS(s)); }
    00049
    00050
    00051
    00053 //                                                            //
    00054 // Kernel Mode Definitions                                    //
    00055 //                                                            //
    00057
    00058 #ifdef _TST_KERNEL_
    00059
    00060 #define TstAllocatePool(PoolType,NumberOfBytes)  \
    00061     (ExAllocatePool( (PoolType), (NumberOfBytes) ))
    00062
    00063 #define TstDeallocatePool(Pointer, NumberOfBytes) \
    00064     (ExFreePool( (Pointer) ))
    00065
    00066 #endif // _TST_KERNEL_
    00067
    00068
    00070 //                                                            //
    00071 // User Mode Definitions                                      //
    00072 //                                                            //
    00074
    00075
    00076 #ifdef _TST_USER_
    00077
    00078 #include <nt.h>
    00079 #include <ntrtl.h>
    00080 #include <nturtl.h>
    00081
    00082
    00083 #include "sep.h"
    00084
    00085 #define TstAllocatePool(IgnoredPoolType,NumberOfBytes)    \
    00086     (ITstAllocatePool( (NumberOfBytes) ))
    00087
    00088 #define TstDeallocatePool(Pointer, NumberOfBytes) \
    00089     (ITstDeallocatePool((Pointer),(NumberOfBytes) ))
    00090
    00091 PVOID
    00092 ITstAllocatePool(
    00093     IN ULONG NumberOfBytes
    00094     )
    00095 {
    00096     NTSTATUS Status;
    00097     PVOID PoolAddress = NULL;
    00098     ULONG RegionSize;
    00099
    00100     RegionSize = NumberOfBytes;
    00101
    00102     Status = NtAllocateVirtualMemory( NtCurrentProcess(),
    00103                                       &PoolAddress,
    00104                                       0,
    00105                                       &RegionSize,
    00106                                       MEM_COMMIT,
    00107                                       PAGE_READWRITE
    00108                                     );
    00109
    00110     return PoolAddress;
    00111 }
    00112
    00113 VOID
    00114 ITstDeallocatePool(
    00115     IN PVOID Pointer,
    00116     IN ULONG NumberOfBytes
    00117     )
    00118 {
    00119     NTSTATUS Status;
    00120     PVOID PoolAddress;
    00121     ULONG RegionSize;
    00122
    00123     RegionSize = NumberOfBytes;
    00124     PoolAddress = Pointer;
    00125
    00126     Status = NtFreeVirtualMemory( NtCurrentProcess(),
    00127                                   &PoolAddress,
    00128                                   &RegionSize,
    00129                                   MEM_DECOMMIT
    00130                                   );
    00131
    00132     return;
    00133 }
    00134 #endif // _TST_USER_
    00135
    00136 #endif //_TSECOMM_
    00137