00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "ulpc.h"
00022
00023 #define MAX_CLIENT_PROCESSES 9
00024 #define MAX_CLIENT_THREADS 9
00025
00026 CHAR ProcessName[ 32 ];
00027 HANDLE
PortHandle =
NULL;
00028
00029 HANDLE
ClientThreadHandles[
MAX_CLIENT_THREADS ] = {
NULL};
00030 DWORD ClientThreadClientIds[
MAX_CLIENT_THREADS ];
00031
00032
DWORD
00033 ClientThread(
00034 LPVOID Context
00035 )
00036 {
00037
CHAR ThreadName[ 64 ];
00038
NTSTATUS Status = STATUS_SUCCESS;
00039 ULONG MsgLength;
00040 PTEB Teb = NtCurrentTeb();
00041
00042 Teb->ActiveRpcHandle =
NULL;
00043
00044 strcpy( ThreadName,
"Client Thread Id: " );
00045
RtlIntegerToChar( (ULONG)Teb->ClientId.UniqueProcess, 16, 9,
00046 ThreadName +
strlen( ThreadName )
00047 );
00048 strcat( ThreadName,
"." );
00049
RtlIntegerToChar( (ULONG)Teb->ClientId.UniqueThread, 16, 9,
00050 ThreadName +
strlen( ThreadName )
00051 );
00052
00053
EnterThread( ThreadName, (ULONG)Context );
00054
00055 MsgLength = 0;
00056
while (
NT_SUCCESS(
Status )) {
00057
Status =
SendRequest( 1,
00058 ThreadName,
00059
PortHandle,
00060 Context,
00061 MsgLength,
00062
NULL,
00063
FALSE
00064 );
00065 MsgLength +=
sizeof( ULONG );
00066
if (MsgLength >= (
TLPC_MAX_MSG_DATA_LENGTH *
sizeof( ULONG ))) {
00067
break;
00068 }
00069 }
00070
00071
if (
PortHandle !=
NULL) {
00072
if (!CloseHandle(
PortHandle )) {
00073 fprintf( stderr,
"CloseHandle( 0x%lx ) failed - %u\n",
PortHandle, GetLastError() );
00074 }
00075
else {
00076
PortHandle =
NULL;
00077 }
00078 }
00079
00080 fprintf( stderr,
"%s %s\n",
00081
NT_SUCCESS(
Status ) ?
"Exiting" :
"ABORTING",
00082 ThreadName
00083 );
00084
00085
return RtlNtStatusToDosError(
Status );
00086 }
00087
00088
00089
VOID
00090 Usage( VOID )
00091 {
00092 fprintf( stderr,
"usage: UCLIENT ClientNumber [#threads]\n" );
00093 ExitProcess( 1 );
00094 }
00095
00096
00097
int
00098 _cdecl
00099 main(
00100
int argc,
00101
char *argv[]
00102 )
00103 {
00104
NTSTATUS Status;
00105
DWORD rc;
00106 PORT_VIEW ClientView;
00107 REMOTE_PORT_VIEW ServerView;
00108 ULONG ClientNumber;
00109 ULONG NumberOfThreads;
00110 ULONG MaxMessageLength;
00111 ULONG ConnectionInformationLength;
00112 UCHAR ConnectionInformation[ 64 ];
00113 ULONG i;
00114 PULONG p;
00115 PTEB Teb = NtCurrentTeb();
00116 LARGE_INTEGER MaximumSize;
00117
00118
Status = STATUS_SUCCESS;
00119
00120 fprintf( stderr,
"Entering UCLIENT User Mode LPC Test Program\n" );
00121
00122
if (argc < 2) {
00123
Usage();
00124 }
00125
00126 ClientNumber = atoi( argv[ 1 ] );
00127
if (argc < 3) {
00128 NumberOfThreads = 1;
00129 }
00130
else {
00131 NumberOfThreads = atoi( argv[ 2 ] );
00132 }
00133
00134
if (ClientNumber >
MAX_CLIENT_PROCESSES ||
00135 NumberOfThreads >
MAX_CLIENT_THREADS
00136 ) {
00137
Usage();
00138 }
00139
00140
sprintf(
ProcessName,
"Client Process %08x", Teb->ClientId.UniqueProcess );
00141 strcpy( ConnectionInformation,
ProcessName );
00142 ConnectionInformationLength =
strlen(
ProcessName ) + 1;
00143
00144
RtlInitUnicodeString( &
PortName,
PORT_NAME );
00145 fprintf( stderr,
"Creating Port Memory Section" );
00146
00147 MaximumSize.QuadPart = 0x4000 * NumberOfThreads;
00148
Status =
NtCreateSection( &ClientView.SectionHandle,
00149 SECTION_MAP_READ | SECTION_MAP_WRITE,
00150
NULL,
00151 &MaximumSize,
00152 PAGE_READWRITE,
00153 SEC_COMMIT,
00154
NULL
00155 );
00156
00157
if (
ShowHandleOrStatus(
Status, ClientView.SectionHandle )) {
00158 ClientView.Length =
sizeof( ClientView );
00159 ClientView.SectionOffset = 0;
00160 ClientView.ViewSize = 0x2000;
00161 ClientView.ViewBase = 0;
00162 ClientView.ViewRemoteBase = 0;
00163 ServerView.Length =
sizeof( ServerView );
00164 ServerView.ViewSize = 0;
00165 ServerView.ViewBase = 0;
00166
00167 fprintf( stderr,
"%s calling NtConnectPort( %wZ )\n",
ProcessName, &
PortName );
00168
Status =
NtConnectPort( &
PortHandle,
00169 &
PortName,
00170 &
DynamicQos,
00171 &ClientView,
00172 &ServerView,
00173 (PULONG)&MaxMessageLength,
00174 (PVOID)ConnectionInformation,
00175 (PULONG)&ConnectionInformationLength
00176 );
00177
00178
00179
00180
if (
ShowHandleOrStatus(
Status,
PortHandle )) {
00181 fprintf( stderr,
" MaxMessageLength: %ld\n", MaxMessageLength );
00182 fprintf( stderr,
" ConnectionInfo: (%ld) '%.*s'\n",
00183 ConnectionInformationLength,
00184 ConnectionInformationLength,
00185 (PSZ)&ConnectionInformation[0]
00186 );
00187 fprintf( stderr,
" ClientView: Base=%lx, Size=%lx, RemoteBase: %lx\n",
00188 ClientView.ViewBase,
00189 ClientView.ViewSize,
00190 ClientView.ViewRemoteBase
00191 );
00192 fprintf( stderr,
" ServerView: Base=%lx, Size=%lx\n",
00193 ServerView.ViewBase,
00194 ServerView.ViewSize
00195 );
00196
ClientMemoryBase = ClientView.ViewBase;
00197
ClientMemorySize = ClientView.ViewSize;
00198
ServerMemoryBase = ClientView.ViewRemoteBase;
00199
ServerMemoryDelta = (ULONG)
ServerMemoryBase -
00200 (ULONG)
ClientMemoryBase;
00201
00202 p = (PULONG)
ClientMemoryBase;
00203 i =
ClientMemorySize;
00204
while (i) {
00205 fprintf( stderr,
"ClientView[%lx] == %lx (%lx)\n",
00206 p,
00207 *p,
00208 *p -
ServerMemoryDelta
00209 );
00210 p += (0x1000/
sizeof( ULONG ));
00211 i -= 0x1000;
00212 }
00213 p = (PULONG)ServerView.ViewBase;
00214 i = ServerView.ViewSize;
00215
while (i) {
00216 fprintf( stderr,
"ServerView[%lx] == %lx\n", p, *p );
00217 p += (0x1000/
sizeof( ULONG ));
00218 i -= 0x1000;
00219 }
00220 }
00221 }
00222
00223 rc =
RtlNtStatusToDosError(
Status );
00224
if (rc == NO_ERROR) {
00225
ClientThreadHandles[ 0 ] = GetCurrentThread();
00226
ClientThreadClientIds[ 0 ] = GetCurrentThreadId();
00227
for (i=1; i< NumberOfThreads; i++) {
00228 fprintf( stderr,
"Creating %s, Thread %ld\n",
ProcessName, i+1 );
00229 rc = NO_ERROR;
00230
ClientThreadHandles[ i ] = CreateThread(
NULL,
00231 0,
00232 (LPTHREAD_START_ROUTINE)
ClientThread,
00233 (
LPVOID)((ClientNumber << 4) | (i+1)),
00234 CREATE_SUSPENDED,
00235 &
ClientThreadClientIds[ i ]
00236 );
00237
if (
ClientThreadHandles[ i ] ==
NULL) {
00238 rc = GetLastError();
00239
break;
00240 }
00241 }
00242
00243
if (rc == NO_ERROR) {
00244
for (i=1; i<NumberOfThreads; i++) {
00245 ResumeThread(
ClientThreadHandles[ i ] );
00246 }
00247
00248
ClientThread( (
LPVOID)((ClientNumber << 4) | 1) );
00249 }
00250 }
00251
00252
if (rc == NO_ERROR) {
00253 }
00254
else {
00255 fprintf( stderr,
"UCLIENT: Initialization Failed - %u\n", rc );
00256 ExitProcess( rc );
00257 }
00258
00259
return( rc );
00260 }