Clean up and more info about the LPC port handle.

svn path=/trunk/; revision=567
This commit is contained in:
Emanuele Aliberti 1999-06-27 07:11:25 +00:00
parent 4d7dcc6886
commit b3f7f2d945

View file

@ -1,4 +1,4 @@
/* $Id: conport.c,v 1.1 1999/06/24 22:54:27 ea Exp $ /* $Id: conport.c,v 1.2 1999/06/27 07:11:25 ea Exp $
* *
* reactos/apps/lpc/conport.c * reactos/apps/lpc/conport.c
* *
@ -24,34 +24,47 @@
#define LPC_CONNECT_FLAG4 0x00001000 #define LPC_CONNECT_FLAG4 0x00001000
#define LPC_CONNECT_FLAG5 0x00010000 #define LPC_CONNECT_FLAG5 0x00010000
#define QUERY_OBJECT_LPC_PORT_BASIC_INFORMATION_SIZE 55
NTSTATUS NTSTATUS
(STDCALL * ConnectPort)( (STDCALL * ConnectPort)(
PHANDLE, OUT PHANDLE PortHandle,
PUNICODE_STRING, IN PUNICODE_STRING PortName,
DWORD, IN POBJECT_ATTRIBUTES ObjectAttributes,
DWORD, IN DWORD Unknown3,
DWORD, IN DWORD Unknown4,
DWORD, IN DWORD Unknown5,
DWORD, IN DWORD Unknown6,
DWORD IN ULONG Flags
);
NTSTATUS
(STDCALL * QueryObject)(
IN HANDLE ObjectHandle,
IN CINT ObjectInformationClass,
OUT PVOID ObjectInformation,
IN ULONG Length,
OUT PULONG ResultLength
); );
NTSTATUS NTSTATUS
(STDCALL * YieldExecution)(VOID); (STDCALL * YieldExecution)(VOID);
#define BUF_SIZE 256 #define BUF_SIZE 1024
#define MAXARG 1000000
VOID VOID
DumpBuffer( DumpBuffer(
char *Name, char *Name,
BYTE *buffer BYTE *buffer,
ULONG size
) )
{ {
register int i = 0; register ULONG i = 0;
printf("%s = ",Name); printf("%s [%d] = ",size,Name);
for ( i = 0; for ( i = 0;
i < BUF_SIZE; i != size;
++i ++i
) )
{ {
@ -60,7 +73,135 @@ DumpBuffer(
printf("\n"); printf("\n");
} }
#define MAXARG 1000000
VOID
DumpInfo (
LPCSTR Name,
NTSTATUS Status,
HANDLE Port
)
{
int i;
BYTE ObjectInformation [BUF_SIZE] = {0};
ULONG ResultLength;
printf("Port \"%s\" connected:\n",Name);
printf("Status = %08X\n",Status);
printf("Port = %08X\n\n",Port);
/*
* Query object information.
*/
printf("Basic Information:\n");
Status = -1;
for ( i=1024000; i && Status != STATUS_SUCCESS; --i)
Status = QueryObject(
Port,
ObjectBasicInformation,
ObjectInformation,
QUERY_OBJECT_LPC_PORT_BASIC_INFORMATION_SIZE,
& ResultLength
);
if (Status == STATUS_SUCCESS)
{
DumpBuffer(
"RAW",
ObjectInformation,
ResultLength
);
}
else
{
printf("\tStatus = %08X\n",Status);
}
printf("Type Information:\n");
Status = QueryObject(
Port,
ObjectTypeInformation,
ObjectInformation,
sizeof ObjectInformation,
& ResultLength
);
if (Status == STATUS_SUCCESS)
{
OBJECT_TYPE_INFORMATION * i;
i = (OBJECT_TYPE_INFORMATION *) ObjectInformation;
wprintf(
L"\tName: \"%s\"\n",
(i->Name.Length ? i->Name.Buffer : L"")
);
/*
FIXME: why this always raise an access violation exception?
wprintf(
L"\tType: \"%s\"\n",
(i->Type.Length ? i->Type.Buffer : L"")
);
*/
printf(
"\tTotal Handles: %d\n",
i->TotalHandles
);
printf(
"\tReference Count: %d\n",
i->ReferenceCount
);
}
else
{
printf("\tStatus = %08X\n",Status);
}
printf("Name Information:\n");
Status = QueryObject(
Port,
ObjectNameInformation,
ObjectInformation,
sizeof ObjectInformation,
& ResultLength
);
if (Status == STATUS_SUCCESS)
{
OBJECT_NAME_INFORMATION * i;
i = (OBJECT_NAME_INFORMATION *) ObjectInformation;
wprintf(
L"\tName: \"%s\"\n",
(i->Name.Length ? i->Name.Buffer : L"")
);
}
else
{
printf("\tStatus = %08X\n",Status);
}
printf("Data Information:\n");
Status = QueryObject(
Port,
ObjectDataInformation,
ObjectInformation,
sizeof ObjectInformation,
& ResultLength
);
if (Status == STATUS_SUCCESS)
{
OBJECT_DATA_INFORMATION * i;
i = (OBJECT_DATA_INFORMATION *) ObjectInformation;
printf(
"\tInherit Handle: %s\n",
(i->bInheritHandle ? "TRUE" : "FALSE")
);
printf(
"\tProtect from Close: %s\n",
(i->bProtectFromClose ? "TRUE" : "FALSE")
);
}
else
{
printf("\tStatus = %08X\n",Status);
}
}
VOID VOID
TryConnectPort(char *port_name) TryConnectPort(char *port_name)
@ -69,10 +210,13 @@ TryConnectPort(char *port_name)
HANDLE Port = 0; HANDLE Port = 0;
int i; int i;
UNICODE_STRING PortName; UNICODE_STRING PortName;
OBJECT_ATTRIBUTES ObjectAttributes;
WORD Name [BUF_SIZE] = {0}; WORD Name [BUF_SIZE] = {0};
int dwx = 0; int dwx = 0;
BYTE bb [BUF_SIZE] = {0};
/*
* Convert the port's name to Unicode.
*/
for ( for (
PortName.Length = 0; PortName.Length = 0;
( *port_name ( *port_name
@ -87,28 +231,56 @@ TryConnectPort(char *port_name)
PortName.Length = PortName.Length * sizeof (WORD); PortName.Length = PortName.Length * sizeof (WORD);
PortName.MaximumLength = PortName.Length + sizeof (WORD); PortName.MaximumLength = PortName.Length + sizeof (WORD);
PortName.Buffer = (PWSTR) Name; PortName.Buffer = (PWSTR) Name;
/*
* Prepare the port object attributes.
*/
ObjectAttributes.Length =
sizeof (OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory =
NULL;
ObjectAttributes.ObjectName =
NULL /*& PortName */;
ObjectAttributes.Attributes =
OBJ_CASE_INSENSITIVE;
ObjectAttributes.SecurityDescriptor =
NULL;
ObjectAttributes.SecurityQualityOfService =
NULL;
/*
* Try to issue a connection request.
*/
Port = 0; Port = 0;
Status = ConnectPort( Status = ConnectPort(
& Port, & Port,
& PortName, & PortName,
bb, & ObjectAttributes,
0, 0,
0, 0,
0, 0,
0, 0,
LPC_CONNECT_FLAG5 LPC_CONNECT_FLAG5
); );
if (Port) if (Status == STATUS_SUCCESS)
{ {
printf("Status = %08X\n",Status); DumpInfo(port_name,Status,Port);
printf("Port = %08X\n\n",Port); /* Hot waiting */
for (dwx=0; dwx<MAXARG; ++dwx) for (dwx=0; dwx<MAXARG; ++dwx)
{ {
YieldExecution(); YieldExecution();
} }
CloseHandle(Port); if (FALSE == CloseHandle(Port))
{
printf(
"Could not close the port handle %08X.\n",
Port
);
} }
return;
}
printf(
"Connection to port \"%s\" failed (Status = %08X).\n",
Status
);
} }
@ -140,15 +312,26 @@ main( int argc, char * argv[] )
printf("Could not find NTDLL.NtConnectPort\n"); printf("Could not find NTDLL.NtConnectPort\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("GetProcAddress(NTDLL.NtQueryObject)\n");
QueryObject = (VOID*) GetProcAddress(
ntdll,
"NtQueryObject"
);
if (QueryObject == NULL)
{
FreeLibrary(ntdll);
printf("Could not find NTDLL.NtQueryObject\n");
return EXIT_FAILURE;
}
printf("GetProcAddress(NTDLL.NtYieldExecution)\n"); printf("GetProcAddress(NTDLL.NtYieldExecution)\n");
YieldExecution = (VOID*) GetProcAddress( YieldExecution = (VOID*) GetProcAddress(
ntdll, ntdll,
"NtYieldExecution" "NtYieldExecution"
); );
if (ConnectPort == NULL) if (YieldExecution == NULL)
{ {
FreeLibrary(ntdll); FreeLibrary(ntdll);
printf("Could not find NTDLL.NtConnectPort\n"); printf("Could not find NTDLL.NtYieldExecution\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("TryConnectPort(%s)\n",argv[1]); printf("TryConnectPort(%s)\n",argv[1]);
@ -156,3 +339,5 @@ main( int argc, char * argv[] )
printf("Done\n"); printf("Done\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* EOF */