test: lpcp.h Source File

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

# lpcp.h

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1989  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     lpcp.h
    00008
    00009 Abstract:
    00010
    00011     Private include file for the LPC subcomponent of the NTOS project
    00012
    00013 Author:
    00014
    00015     Steve Wood (stevewo) 15-May-1989
    00016
    00017 Revision History:
    00018
    00019
    00020 !!!!!!  WARNING : this file is included in ..\ob\obref.c
    00021
    00022 --*/
    00023
    00024 #include "ntos.h"
    00025 #include <zwapi.h>
    00026
    00027 //
    00028 //  define LPCP_TRACE_SERVER_THREADS symbol to track the server threads
    00029 //  on a LPCP_SERVER_COMMUNICATION port
    00030 //
    00031 //  #define LPCP_TRACE_SERVER_THREADS
    00032 //
    00033
    00034 //
    00035 //  Global Mutex to guard the following fields:
    00036 //
    00037 //      ETHREAD.LpcReplyMsg
    00038 //      LPCP_PORT_QUEUE.ReceiveHead
    00039 //
    00040 //  Mutex is never held longer than is necessary to modify or read the field.
    00041 //  Contains additional fields to track the owner of the lock and to allows recursive locks
    00042 //
    00043
    00044 typedef struct _LPC_MUTEX {
    00045
    00046     FAST_MUTEX  Lock;
    00047
    00048     //
    00049     //  field that holds the thread that owns the lock
    00050     //
    00051
    00052     PETHREAD    Owner;
    00053
    00054     //
    00055     //  Number of locks acquired
    00056     //
    00057
    00058     ULONG       Count;
    00059
    00060 } LPC_MUTEX, *PLPC_MUTEX;
    00061
    00062
    00063 extern LPC_MUTEX LpcpLock;
    00064
    00065 LPCP_PORT_ZONE LpcpZone;
    00066
    00067 ULONG LpcpNextMessageId;
    00068
    00069 ULONG LpcpNextCallbackId;
    00070
    00071 #define LpcpGenerateMessageId() \
    00072     LpcpNextMessageId++;    if (LpcpNextMessageId == 0) LpcpNextMessageId = 1;
    00073
    00074 #define LpcpGenerateCallbackId() \
    00075     LpcpNextCallbackId++;    if (LpcpNextCallbackId == 0) LpcpNextCallbackId = 1;
    00076
    00077 #if DEVL
    00078 ULONG LpcpTotalNumberOfMessages;
    00079 #endif
    00080
    00081 //
    00082 //  Global macrodefinitions to acquire and release the LPC_MUTEX
    00083 //  in order to track the owner and allow recursive calls
    00084 //
    00085
    00086 #define LpcpInitializeLpcpLock()                             \
    00087 {                                                            \
    00088     ExInitializeFastMutex( &LpcpLock.Lock );                 \
    00089     LpcpLock.Owner = NULL;                                   \
    00090     LpcpLock.Count = 0;                                      \
    00091 }
    00092
    00093 #define LpcpAcquireLpcpLock()                                       \
    00094 {                                                                   \
    00095     if ( LpcpLock.Owner == PsGetCurrentThread() ) {                 \
    00096                                                                     \
    00097         ASSERT ( LpcpLock.Count >= 1 );                             \
    00098         LpcpLock.Count += 1;                                        \
    00099                                                                     \
    00100     } else {                                                        \
    00101                                                                     \
    00102         ExAcquireFastMutex( &LpcpLock.Lock );                       \
    00103         LpcpLock.Owner = PsGetCurrentThread();                      \
    00104         LpcpLock.Count = 1;                                         \
    00105     }                                                               \
    00106 }
    00107
    00108 #define LpcpReleaseLpcpLock()                                               \
    00109 {                                                                           \
    00110     ASSERT( LpcpLock.Owner == PsGetCurrentThread() );                       \
    00111     ASSERT( LpcpLock.Count >= 1 );                                          \
    00112                                                                             \
    00113     LpcpLock.Count -= 1;                                                    \
    00114                                                                             \
    00115     if ( LpcpLock.Count == 0 ) {                                            \
    00116                                                                             \
    00117         LpcpLock.Owner = NULL;                                              \
    00118         ExReleaseFastMutex( &LpcpLock.Lock );                               \
    00119     }                                                                       \
    00120 }
    00121
    00122
    00123 #ifdef LPCP_TRACE_SERVER_THREADS
    00124
    00125 //
    00126 //  LPCP_PORT_EXTRA_DATA structure and manipulation functions
    00127 //
    00128
    00129 #define LPCP_SERVER_THREAD_ARRAY_SIZE   16
    00130
    00131 typedef struct _LPCP_PORT_EXTRA_DATA {
    00132
    00133     ULONG ThreadCount;
    00134
    00135     PLPCP_PORT_OBJECT PortObject;
    00136
    00137     PVOID Threads[LPCP_SERVER_THREAD_ARRAY_SIZE];
    00138
    00139 } LPCP_PORT_EXTRA_DATA, *PLPCP_PORT_EXTRA_DATA;
    00140
    00141 VOID LpcpPortExtraDataCreate ( PLPCP_PORT_OBJECT PortObject );
    00142
    00143 VOID LpcpPortExtraDataDestroy (PLPCP_PORT_OBJECT PortObject);
    00144
    00145 VOID LpcpSaveThread (PLPCP_PORT_OBJECT PortObject);
    00146
    00147 #else
    00148
    00149 #define LpcpPortExtraDataCreate(x)
    00150
    00151 #define LpcpPortExtraDataDestroy(x)
    00152
    00153 #define LpcpSaveThread(x)
    00154
    00155 #endif // LPCP_TRACE_SERVER_THREADS
    00156
    00157
    00158 //
    00159 //  Internal Entry Points defined in lpcclose.c
    00160 //
    00161
    00162 VOID
    00163 LpcpClosePort (
    00164     IN PEPROCESS Process OPTIONAL,
    00165     IN PVOID Object,
    00166     IN ACCESS_MASK GrantedAccess,
    00167     IN ULONG ProcessHandleCount,
    00168     IN ULONG SystemHandleCount
    00169     );
    00170
    00171 VOID
    00172 LpcpDeletePort (
    00173     IN PVOID Object
    00174     );
    00175
    00176
    00177 //
    00178 //  Entry points defined in lpcqueue.c
    00179 //
    00180
    00181 NTSTATUS
    00182 LpcpInitializePortQueue (
    00183     IN PLPCP_PORT_OBJECT Port
    00184     );
    00185
    00186 VOID
    00187 LpcpDestroyPortQueue (
    00188     IN PLPCP_PORT_OBJECT Port,
    00189     IN BOOLEAN CleanupAndDestroy
    00190     );
    00191
    00192 NTSTATUS
    00193 LpcpInitializePortZone (
    00194     IN ULONG MaxEntrySize,
    00195     IN ULONG SegmentSize,
    00196     IN ULONG MaxPoolUsage
    00197     );
    00198
    00199 NTSTATUS
    00200 LpcpExtendPortZone (
    00201     VOID
    00202     );
    00203
    00204 PLPCP_MESSAGE
    00205 FASTCALL
    00206 LpcpAllocateFromPortZone (
    00207     ULONG Size
    00208     );
    00209
    00210 VOID
    00211 FASTCALL
    00212 LpcpFreeToPortZone (
    00213     IN PLPCP_MESSAGE Msg,
    00214     IN BOOLEAN MutexOwned
    00215     );
    00216
    00217 VOID
    00218 LpcpSaveDataInfoMessage (
    00219     IN PLPCP_PORT_OBJECT Port,
    00220     PLPCP_MESSAGE Msg
    00221     );
    00222
    00223 VOID
    00224 LpcpFreeDataInfoMessage (
    00225     IN PLPCP_PORT_OBJECT Port,
    00226     IN ULONG MessageId,
    00227     IN ULONG CallbackId
    00228     );
    00229
    00230 PLPCP_MESSAGE
    00231 LpcpFindDataInfoMessage (
    00232     IN PLPCP_PORT_OBJECT Port,
    00233     IN ULONG MessageId,
    00234     IN ULONG CallbackId
    00235     );
    00236
    00237
    00238 //
    00239 //  Entry points defined in lpcquery.c
    00240 //
    00241
    00242
    00243 //
    00244 //  Entry points defined in lpcmove.s and lpcmove.asm
    00245 //
    00246
    00247 VOID
    00248 LpcpMoveMessage (
    00249     OUT PPORT_MESSAGE DstMsg,
    00250     IN PPORT_MESSAGE SrcMsg,
    00251     IN PVOID SrcMsgData,
    00252     IN ULONG MsgType OPTIONAL,
    00253     IN PCLIENT_ID ClientId OPTIONAL
    00254     );
    00255
    00256
    00257 //
    00258 //  Internal Entry Points defined in lpcpriv.c
    00259 //
    00260
    00261 VOID
    00262 LpcpFreePortClientSecurity (
    00263     IN PLPCP_PORT_OBJECT Port
    00264     );
    00265
    00266
    00267 //
    00268 //  Macro Procedures used by RequestWaitReply, Reply, ReplyWaitReceive,
    00269 //  and ReplyWaitReply services
    00270 //
    00271
    00272 #define LpcpGetDynamicClientSecurity(Thread,Port,DynamicSecurity) \
    00273     SeCreateClientSecurity((Thread),&(Port)->SecurityQos,FALSE,(DynamicSecurity))
    00274
    00275 #define LpcpFreeDynamicClientSecurity(DynamicSecurity) \
    00276     SeDeleteClientSecurity( DynamicSecurity )
    00277
    00278 #define LpcpReferencePortObject(PortHandle,PortAccess,PreviousMode,PortObject) \
    00279     ObReferenceObjectByHandle((PortHandle),(PortAccess),LpcPortObjectType,(PreviousMode),(PVOID *)(PortObject),NULL)
    00280
    00281
    00282 //
    00283 //  Entry Points defined in lpcinit.c
    00284 //
    00285
    00286 char *
    00287 LpcpGetCreatorName (
    00288     PLPCP_PORT_OBJECT PortObject
    00289     );
    00290
    00291 #if DBG
    00292 #define ENABLE_LPC_TRACING 1
    00293 #else
    00294 #define ENABLE_LPC_TRACING 0
    00295 #endif
    00296
    00297 #if ENABLE_LPC_TRACING
    00298 BOOLEAN LpcpStopOnReplyMismatch;
    00299 BOOLEAN LpcpTraceMessages;
    00300
    00301 char *LpcpMessageTypeName[];
    00302
    00303 char *
    00304 LpcpGetCreatorName (
    00305     PLPCP_PORT_OBJECT PortObject
    00306     );
    00307
    00308 #define LpcpPrint( _x_ ) {                              \
    00309     DbgPrint( "LPC[ %02x.%02x ]: ",                     \
    00310               PsGetCurrentThread()->Cid.UniqueProcess,  \
    00311               PsGetCurrentThread()->Cid.UniqueThread ); \
    00312     DbgPrint _x_ ;                                      \
    00313 }
    00314
    00315 #define LpcpTrace( _x_ ) if (LpcpTraceMessages) { LpcpPrint( _x_ ); }
    00316
    00317 #else
    00318
    00319 #define LpcpPrint( _x_ )
    00320 #define LpcpTrace( _x_ )
    00321
    00322 #endif // ENABLE_LPC_TRACING