00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "lpcp.h"
00022
00023
00024
00025
00026
00027 POBJECT_TYPE LpcPortObjectType;
00028 POBJECT_TYPE LpcWaitablePortObjectType;
00029
00030
00031
00032
00033
00034 GENERIC_MAPPING
LpcpPortMapping = {
00035 READ_CONTROL | PORT_CONNECT,
00036 DELETE | PORT_CONNECT,
00037 0,
00038 PORT_ALL_ACCESS
00039 };
00040
00041
00042
00043
00044
00045 LPC_MUTEX LpcpLock;
00046
00047
00048
00049
00050
00051
00052
#if ENABLE_LPC_TRACING
00053
00054
char *LpcpMessageTypeName[] = {
00055
"UNUSED_MSG_TYPE",
00056
"LPC_REQUEST",
00057
"LPC_REPLY",
00058
"LPC_DATAGRAM",
00059
"LPC_LOST_REPLY",
00060
"LPC_PORT_CLOSED",
00061
"LPC_CLIENT_DIED",
00062
"LPC_EXCEPTION",
00063
"LPC_DEBUG_EVENT",
00064
"LPC_ERROR_EVENT",
00065
"LPC_CONNECTION_REQUEST"
00066 };
00067
00068
#endif // ENABLE_LPC_TRACING
00069
00070
#ifdef ALLOC_PRAGMA
00071
#pragma alloc_text(INIT,LpcInitSystem)
00072
#endif
00073
00074
00075 BOOLEAN
00076 LpcInitSystem (
00077 VOID
00078 )
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 {
00102
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
00103 UNICODE_STRING PortTypeName;
00104 ULONG ZoneElementSize;
00105
NTSTATUS Status;
00106
00107
00108
00109
00110
00111
LpcpInitializeLpcpLock();
00112
00113
00114
00115
00116
00117
RtlInitUnicodeString( &PortTypeName,
L"Port" );
00118
00119 RtlZeroMemory( &ObjectTypeInitializer,
sizeof( ObjectTypeInitializer ));
00120
00121 ObjectTypeInitializer.Length =
sizeof( ObjectTypeInitializer );
00122 ObjectTypeInitializer.GenericMapping =
LpcpPortMapping;
00123 ObjectTypeInitializer.MaintainTypeList =
TRUE;
00124 ObjectTypeInitializer.PoolType =
PagedPool;
00125 ObjectTypeInitializer.DefaultPagedPoolCharge =
sizeof(
LPCP_PORT_OBJECT );
00126 ObjectTypeInitializer.DefaultNonPagedPoolCharge =
sizeof(
LPCP_NONPAGED_PORT_QUEUE );
00127 ObjectTypeInitializer.InvalidAttributes = OBJ_VALID_ATTRIBUTES ^ PORT_VALID_OBJECT_ATTRIBUTES;
00128 ObjectTypeInitializer.ValidAccessMask = PORT_ALL_ACCESS;
00129 ObjectTypeInitializer.CloseProcedure =
LpcpClosePort;
00130 ObjectTypeInitializer.DeleteProcedure =
LpcpDeletePort;
00131 ObjectTypeInitializer.UseDefaultObject =
TRUE ;
00132
00133
ObCreateObjectType( &PortTypeName,
00134 &ObjectTypeInitializer,
00135 (PSECURITY_DESCRIPTOR)
NULL,
00136 &
LpcPortObjectType );
00137
00138
00139
00140
00141
00142
RtlInitUnicodeString( &PortTypeName,
L"WaitablePort" );
00143 ObjectTypeInitializer.PoolType =
NonPagedPool ;
00144 ObjectTypeInitializer.UseDefaultObject =
FALSE ;
00145
00146
ObCreateObjectType( &PortTypeName,
00147 &ObjectTypeInitializer,
00148 (PSECURITY_DESCRIPTOR)
NULL,
00149 &
LpcWaitablePortObjectType );
00150
00151
00152
00153
00154
00155
LpcpNextMessageId = 1;
00156
LpcpNextCallbackId = 1;
00157
00158
00159
00160
00161
00162
00163
00164 ZoneElementSize = PORT_MAXIMUM_MESSAGE_LENGTH +
00165
sizeof(
LPCP_MESSAGE ) +
00166
sizeof(
LPCP_CONNECTION_MESSAGE );
00167
00168
00169
00170
00171
00172 ZoneElementSize = (ZoneElementSize +
LPCP_ZONE_ALIGNMENT - 1) &
00173
LPCP_ZONE_ALIGNMENT_MASK;
00174
00175
00176
00177
00178
00179
Status =
LpcpInitializePortZone( ZoneElementSize,
00180
PAGE_SIZE,
00181
LPCP_ZONE_MAX_POOL_USAGE );
00182
00183
if (!
NT_SUCCESS(
Status )) {
00184
00185
return(
FALSE );
00186 }
00187
00188
return(
TRUE );
00189 }
00190
00191
00192
char *
00193 LpcpGetCreatorName (
00194
PLPCP_PORT_OBJECT PortObject
00195 )
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 {
00215
NTSTATUS Status;
00216
PEPROCESS Process;
00217
00218
00219
00220
00221
00222
Status =
PsLookupProcessByProcessId( PortObject->
Creator.UniqueProcess, &Process );
00223
00224
00225
00226
00227
00228
00229
if (
NT_SUCCESS(
Status )) {
00230
00231
return Process->
ImageFileName;
00232
00233 }
else {
00234
00235
00236
00237
00238
00239
return "Unknown";
00240 }
00241 }
00242
00243
#ifdef LPCP_TRACE_SERVER_THREADS
00244
00245
VOID LpcpPortExtraDataCreate (
PLPCP_PORT_OBJECT PortObject )
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 {
00263 PLPCP_PORT_EXTRA_DATA PortData;
00264
00265 PortData =
ExAllocatePoolWithTag(NonPagedPool,
sizeof(LPCP_PORT_EXTRA_DATA), 'DEPL');
00266
00267 PortData->ThreadCount = 0;
00268
00269 PortData->PortObject = PortObject;
00270
00271 PortObject->
Reserved = (ULONG)PortData;
00272
00273 }
00274
00275
VOID LpcpPortExtraDataDestroy (
PLPCP_PORT_OBJECT PortObject)
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 {
00292 PLPCP_PORT_EXTRA_DATA PortData;
00293
00294 PortData = (PLPCP_PORT_EXTRA_DATA) PortObject->
Reserved;
00295
00296
if ((PortData !=
NULL) &&
00297 (PortData->PortObject == PortObject)) {
00298
00299
ExFreePoolWithTag( PortData, 'DEPL');
00300
00301 PortObject->
Reserved = 0;
00302 }
00303 }
00304
00305
VOID LpcpPortExtraDataPush (PLPCP_PORT_EXTRA_DATA PortData, PVOID Thread)
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 {
00327 ULONG Position;
00328 ULONG EndSearch;
00329
00330 EndSearch = PortData->ThreadCount;
00331
00332
if ( EndSearch >= LPCP_SERVER_THREAD_ARRAY_SIZE) {
00333
00334 EndSearch = LPCP_SERVER_THREAD_ARRAY_SIZE - 1;
00335 }
00336
00337
for (Position = 0; Position < EndSearch ; Position++) {
00338
00339
if ( PortData->Threads[Position] == Thread ) {
00340
00341
return;
00342 }
00343 }
00344
00345 PortData->Threads[PortData->ThreadCount % LPCP_SERVER_THREAD_ARRAY_SIZE] = Thread;
00346
00347 PortData->ThreadCount += 1;
00348
00349
00350
00351 }
00352
00353
00354
VOID LpcpSaveThread (
PLPCP_PORT_OBJECT PortObject)
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 {
00372
00373
if (PortObject->
Reserved == 0) {
00374
00375
LpcpPortExtraDataCreate( PortObject );
00376 }
00377
00378
if ( ((PortObject->
Flags &
PORT_TYPE) ==
SERVER_COMMUNICATION_PORT) &&
00379 (PortObject->
Reserved != 0) ) {
00380
00381 LpcpPortExtraDataPush( (PLPCP_PORT_EXTRA_DATA)PortObject->
Reserved,
PsGetCurrentThread());
00382 }
00383 }
00384
00385
#endif // LPCP_TRACE_SERVER_THREADS
00386