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 }