2006-05-10 04:18:40 +02:00
|
|
|
/* Unit test suite for Ntdll Port API functions
|
|
|
|
*
|
|
|
|
* Copyright 2006 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-05-10 04:18:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
|
|
|
|
#ifndef __WINE_WINTERNL_H
|
|
|
|
|
|
|
|
typedef struct _CLIENT_ID
|
|
|
|
{
|
|
|
|
HANDLE UniqueProcess;
|
|
|
|
HANDLE UniqueThread;
|
|
|
|
} CLIENT_ID, *PCLIENT_ID;
|
|
|
|
|
|
|
|
typedef struct _LPC_SECTION_WRITE
|
|
|
|
{
|
|
|
|
ULONG Length;
|
|
|
|
HANDLE SectionHandle;
|
|
|
|
ULONG SectionOffset;
|
|
|
|
ULONG ViewSize;
|
|
|
|
PVOID ViewBase;
|
|
|
|
PVOID TargetViewBase;
|
|
|
|
} LPC_SECTION_WRITE, *PLPC_SECTION_WRITE;
|
|
|
|
|
|
|
|
typedef struct _LPC_SECTION_READ
|
|
|
|
{
|
|
|
|
ULONG Length;
|
|
|
|
ULONG ViewSize;
|
|
|
|
PVOID ViewBase;
|
|
|
|
} LPC_SECTION_READ, *PLPC_SECTION_READ;
|
|
|
|
|
|
|
|
typedef struct _LPC_MESSAGE
|
|
|
|
{
|
|
|
|
USHORT DataSize;
|
|
|
|
USHORT MessageSize;
|
|
|
|
USHORT MessageType;
|
|
|
|
USHORT VirtualRangesOffset;
|
|
|
|
CLIENT_ID ClientId;
|
2009-05-07 13:42:39 +02:00
|
|
|
ULONG_PTR MessageId;
|
|
|
|
ULONG_PTR SectionSize;
|
2006-05-10 04:18:40 +02:00
|
|
|
UCHAR Data[ANYSIZE_ARRAY];
|
|
|
|
} LPC_MESSAGE, *PLPC_MESSAGE;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
/* on Wow64 we have to use the 64-bit layout */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
USHORT DataSize;
|
|
|
|
USHORT MessageSize;
|
|
|
|
USHORT MessageType;
|
|
|
|
USHORT VirtualRangesOffset;
|
|
|
|
ULONGLONG ClientId[2];
|
|
|
|
ULONGLONG MessageId;
|
|
|
|
ULONGLONG SectionSize;
|
|
|
|
UCHAR Data[ANYSIZE_ARRAY];
|
|
|
|
} LPC_MESSAGE64;
|
|
|
|
|
|
|
|
union lpc_message
|
|
|
|
{
|
|
|
|
LPC_MESSAGE msg;
|
|
|
|
LPC_MESSAGE64 msg64;
|
|
|
|
};
|
|
|
|
|
2006-05-10 04:18:40 +02:00
|
|
|
/* Types of LPC messages */
|
|
|
|
#define UNUSED_MSG_TYPE 0
|
|
|
|
#define LPC_REQUEST 1
|
|
|
|
#define LPC_REPLY 2
|
|
|
|
#define LPC_DATAGRAM 3
|
|
|
|
#define LPC_LOST_REPLY 4
|
|
|
|
#define LPC_PORT_CLOSED 5
|
|
|
|
#define LPC_CLIENT_DIED 6
|
|
|
|
#define LPC_EXCEPTION 7
|
|
|
|
#define LPC_DEBUG_EVENT 8
|
|
|
|
#define LPC_ERROR_EVENT 9
|
|
|
|
#define LPC_CONNECTION_REQUEST 10
|
|
|
|
|
|
|
|
static const WCHAR PORTNAME[] = {'\\','M','y','P','o','r','t',0};
|
|
|
|
|
|
|
|
#define REQUEST1 "Request1"
|
|
|
|
#define REQUEST2 "Request2"
|
|
|
|
#define REPLY "Reply"
|
|
|
|
|
|
|
|
#define MAX_MESSAGE_LEN 30
|
|
|
|
|
2009-03-05 22:09:44 +01:00
|
|
|
static UNICODE_STRING port;
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
/* Function pointers for ntdll calls */
|
|
|
|
static HMODULE hntdll = 0;
|
|
|
|
static NTSTATUS (WINAPI *pNtCompleteConnectPort)(HANDLE);
|
|
|
|
static NTSTATUS (WINAPI *pNtAcceptConnectPort)(PHANDLE,ULONG,PLPC_MESSAGE,ULONG,
|
2015-05-14 14:45:04 +02:00
|
|
|
PLPC_SECTION_WRITE,PLPC_SECTION_READ);
|
2006-05-10 04:18:40 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtReplyPort)(HANDLE,PLPC_MESSAGE);
|
|
|
|
static NTSTATUS (WINAPI *pNtReplyWaitReceivePort)(PHANDLE,PULONG,PLPC_MESSAGE,
|
|
|
|
PLPC_MESSAGE);
|
|
|
|
static NTSTATUS (WINAPI *pNtCreatePort)(PHANDLE,POBJECT_ATTRIBUTES,ULONG,ULONG,ULONG);
|
|
|
|
static NTSTATUS (WINAPI *pNtRequestWaitReplyPort)(HANDLE,PLPC_MESSAGE,PLPC_MESSAGE);
|
|
|
|
static NTSTATUS (WINAPI *pNtRequestPort)(HANDLE,PLPC_MESSAGE);
|
|
|
|
static NTSTATUS (WINAPI *pNtRegisterThreadTerminatePort)(HANDLE);
|
|
|
|
static NTSTATUS (WINAPI *pNtConnectPort)(PHANDLE,PUNICODE_STRING,
|
|
|
|
PSECURITY_QUALITY_OF_SERVICE,
|
|
|
|
PLPC_SECTION_WRITE,PLPC_SECTION_READ,
|
|
|
|
PVOID,PVOID,PULONG);
|
|
|
|
static NTSTATUS (WINAPI *pRtlInitUnicodeString)(PUNICODE_STRING,LPCWSTR);
|
2010-03-31 14:20:09 +02:00
|
|
|
static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
|
|
|
|
|
|
|
|
static BOOL is_wow64;
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
static BOOL init_function_ptrs(void)
|
|
|
|
{
|
|
|
|
hntdll = LoadLibraryA("ntdll.dll");
|
|
|
|
|
2008-05-19 14:00:10 +02:00
|
|
|
if (!hntdll)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pNtCompleteConnectPort = (void *)GetProcAddress(hntdll, "NtCompleteConnectPort");
|
|
|
|
pNtAcceptConnectPort = (void *)GetProcAddress(hntdll, "NtAcceptConnectPort");
|
|
|
|
pNtReplyPort = (void *)GetProcAddress(hntdll, "NtReplyPort");
|
|
|
|
pNtReplyWaitReceivePort = (void *)GetProcAddress(hntdll, "NtReplyWaitReceivePort");
|
|
|
|
pNtCreatePort = (void *)GetProcAddress(hntdll, "NtCreatePort");
|
|
|
|
pNtRequestWaitReplyPort = (void *)GetProcAddress(hntdll, "NtRequestWaitReplyPort");
|
|
|
|
pNtRequestPort = (void *)GetProcAddress(hntdll, "NtRequestPort");
|
|
|
|
pNtRegisterThreadTerminatePort = (void *)GetProcAddress(hntdll, "NtRegisterThreadTerminatePort");
|
|
|
|
pNtConnectPort = (void *)GetProcAddress(hntdll, "NtConnectPort");
|
|
|
|
pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
if (!pNtCompleteConnectPort || !pNtAcceptConnectPort ||
|
|
|
|
!pNtReplyWaitReceivePort || !pNtCreatePort || !pNtRequestWaitReplyPort ||
|
|
|
|
!pNtRequestPort || !pNtRegisterThreadTerminatePort ||
|
|
|
|
!pNtConnectPort || !pRtlInitUnicodeString)
|
|
|
|
{
|
2021-07-20 11:59:54 +02:00
|
|
|
skip("Needed port functions are not available\n");
|
2008-05-19 14:00:10 +02:00
|
|
|
FreeLibrary(hntdll);
|
2006-05-10 04:18:40 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-11-05 22:44:42 +01:00
|
|
|
pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsWow64Process");
|
2010-03-31 14:20:09 +02:00
|
|
|
if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
|
2006-05-10 04:18:40 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
static void ProcessConnectionRequest(union lpc_message *LpcMessage, PHANDLE pAcceptPortHandle)
|
2006-05-10 04:18:40 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
if (is_wow64)
|
|
|
|
{
|
|
|
|
ok(LpcMessage->msg64.MessageType == LPC_CONNECTION_REQUEST,
|
|
|
|
"Expected LPC_CONNECTION_REQUEST, got %d\n", LpcMessage->msg64.MessageType);
|
|
|
|
ok(!*LpcMessage->msg64.Data, "Expected empty string!\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(LpcMessage->msg.MessageType == LPC_CONNECTION_REQUEST,
|
|
|
|
"Expected LPC_CONNECTION_REQUEST, got %d\n", LpcMessage->msg.MessageType);
|
|
|
|
ok(!*LpcMessage->msg.Data, "Expected empty string!\n");
|
|
|
|
}
|
2006-05-10 04:18:40 +02:00
|
|
|
|
2015-05-14 14:45:04 +02:00
|
|
|
status = pNtAcceptConnectPort(pAcceptPortHandle, 0, &LpcMessage->msg, 1, NULL, NULL);
|
2009-03-05 22:09:44 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
status = pNtCompleteConnectPort(*pAcceptPortHandle);
|
2009-03-05 22:09:44 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
2006-05-10 04:18:40 +02:00
|
|
|
}
|
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
static void ProcessLpcRequest(HANDLE PortHandle, union lpc_message *LpcMessage)
|
2006-05-10 04:18:40 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
if (is_wow64)
|
|
|
|
{
|
|
|
|
ok(LpcMessage->msg64.MessageType == LPC_REQUEST,
|
|
|
|
"Expected LPC_REQUEST, got %d\n", LpcMessage->msg64.MessageType);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg64.Data, REQUEST2),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REQUEST2, LpcMessage->msg64.Data);
|
2013-11-05 22:44:42 +01:00
|
|
|
strcpy((LPSTR)LpcMessage->msg64.Data, REPLY);
|
2010-03-31 14:20:09 +02:00
|
|
|
|
|
|
|
status = pNtReplyPort(PortHandle, &LpcMessage->msg);
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
|
|
|
ok(LpcMessage->msg64.MessageType == LPC_REQUEST,
|
|
|
|
"Expected LPC_REQUEST, got %d\n", LpcMessage->msg64.MessageType);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg64.Data, REPLY),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REPLY, LpcMessage->msg64.Data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(LpcMessage->msg.MessageType == LPC_REQUEST,
|
|
|
|
"Expected LPC_REQUEST, got %d\n", LpcMessage->msg.MessageType);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg.Data, REQUEST2),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REQUEST2, LpcMessage->msg.Data);
|
2013-11-05 22:44:42 +01:00
|
|
|
strcpy((LPSTR)LpcMessage->msg.Data, REPLY);
|
2010-03-31 14:20:09 +02:00
|
|
|
|
|
|
|
status = pNtReplyPort(PortHandle, &LpcMessage->msg);
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
|
|
|
ok(LpcMessage->msg.MessageType == LPC_REQUEST,
|
|
|
|
"Expected LPC_REQUEST, got %d\n", LpcMessage->msg.MessageType);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg.Data, REPLY),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REPLY, LpcMessage->msg.Data);
|
|
|
|
}
|
2006-05-10 04:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI test_ports_client(LPVOID arg)
|
|
|
|
{
|
|
|
|
SECURITY_QUALITY_OF_SERVICE sqos;
|
2010-03-31 14:20:09 +02:00
|
|
|
union lpc_message *LpcMessage, *out;
|
2006-05-10 04:18:40 +02:00
|
|
|
HANDLE PortHandle;
|
|
|
|
ULONG len, size;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
sqos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
|
|
|
|
sqos.ImpersonationLevel = SecurityImpersonation;
|
|
|
|
sqos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
|
|
|
|
sqos.EffectiveOnly = TRUE;
|
|
|
|
|
|
|
|
status = pNtConnectPort(&PortHandle, &port, &sqos, 0, 0, &len, NULL, NULL);
|
2009-03-05 22:09:44 +01:00
|
|
|
todo_wine ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
2007-01-10 11:30:47 +01:00
|
|
|
if (status != STATUS_SUCCESS) return 1;
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
status = pNtRegisterThreadTerminatePort(PortHandle);
|
2009-03-05 22:09:44 +01:00
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
2006-05-10 04:18:40 +02:00
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
if (is_wow64)
|
|
|
|
{
|
|
|
|
size = FIELD_OFFSET(LPC_MESSAGE64, Data[MAX_MESSAGE_LEN]);
|
|
|
|
LpcMessage = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
out = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
|
2013-11-05 22:44:42 +01:00
|
|
|
LpcMessage->msg64.DataSize = strlen(REQUEST1) + 1;
|
2010-03-31 14:20:09 +02:00
|
|
|
LpcMessage->msg64.MessageSize = FIELD_OFFSET(LPC_MESSAGE64, Data[LpcMessage->msg64.DataSize]);
|
2013-11-05 22:44:42 +01:00
|
|
|
strcpy((LPSTR)LpcMessage->msg64.Data, REQUEST1);
|
2010-03-31 14:20:09 +02:00
|
|
|
|
|
|
|
status = pNtRequestPort(PortHandle, &LpcMessage->msg);
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
|
|
|
ok(LpcMessage->msg64.MessageType == 0, "Expected 0, got %d\n", LpcMessage->msg64.MessageType);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg64.Data, REQUEST1),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REQUEST1, LpcMessage->msg64.Data);
|
|
|
|
|
|
|
|
/* Fill in the message */
|
|
|
|
memset(LpcMessage, 0, size);
|
2013-11-05 22:44:42 +01:00
|
|
|
LpcMessage->msg64.DataSize = strlen(REQUEST2) + 1;
|
2010-03-31 14:20:09 +02:00
|
|
|
LpcMessage->msg64.MessageSize = FIELD_OFFSET(LPC_MESSAGE64, Data[LpcMessage->msg64.DataSize]);
|
2013-11-05 22:44:42 +01:00
|
|
|
strcpy((LPSTR)LpcMessage->msg64.Data, REQUEST2);
|
2010-03-31 14:20:09 +02:00
|
|
|
|
|
|
|
/* Send the message and wait for the reply */
|
|
|
|
status = pNtRequestWaitReplyPort(PortHandle, &LpcMessage->msg, &out->msg);
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)out->msg64.Data, REPLY), "Expected %s, got %s\n", REPLY, out->msg64.Data);
|
2010-03-31 14:20:09 +02:00
|
|
|
ok(out->msg64.MessageType == LPC_REPLY, "Expected LPC_REPLY, got %d\n", out->msg64.MessageType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = FIELD_OFFSET(LPC_MESSAGE, Data[MAX_MESSAGE_LEN]);
|
|
|
|
LpcMessage = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
out = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
|
2013-11-05 22:44:42 +01:00
|
|
|
LpcMessage->msg.DataSize = strlen(REQUEST1) + 1;
|
2010-03-31 14:20:09 +02:00
|
|
|
LpcMessage->msg.MessageSize = FIELD_OFFSET(LPC_MESSAGE, Data[LpcMessage->msg.DataSize]);
|
2013-11-05 22:44:42 +01:00
|
|
|
strcpy((LPSTR)LpcMessage->msg.Data, REQUEST1);
|
2010-03-31 14:20:09 +02:00
|
|
|
|
|
|
|
status = pNtRequestPort(PortHandle, &LpcMessage->msg);
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
|
|
|
ok(LpcMessage->msg.MessageType == 0, "Expected 0, got %d\n", LpcMessage->msg.MessageType);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg.Data, REQUEST1),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REQUEST1, LpcMessage->msg.Data);
|
|
|
|
|
|
|
|
/* Fill in the message */
|
|
|
|
memset(LpcMessage, 0, size);
|
2013-11-05 22:44:42 +01:00
|
|
|
LpcMessage->msg.DataSize = strlen(REQUEST2) + 1;
|
2010-03-31 14:20:09 +02:00
|
|
|
LpcMessage->msg.MessageSize = FIELD_OFFSET(LPC_MESSAGE, Data[LpcMessage->msg.DataSize]);
|
2013-11-05 22:44:42 +01:00
|
|
|
strcpy((LPSTR)LpcMessage->msg.Data, REQUEST2);
|
2010-03-31 14:20:09 +02:00
|
|
|
|
|
|
|
/* Send the message and wait for the reply */
|
|
|
|
status = pNtRequestWaitReplyPort(PortHandle, &LpcMessage->msg, &out->msg);
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %x\n", status);
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)out->msg.Data, REPLY), "Expected %s, got %s\n", REPLY, out->msg.Data);
|
2010-03-31 14:20:09 +02:00
|
|
|
ok(out->msg.MessageType == LPC_REPLY, "Expected LPC_REPLY, got %d\n", out->msg.MessageType);
|
|
|
|
}
|
2006-05-10 04:18:40 +02:00
|
|
|
|
2008-06-10 12:09:38 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, out);
|
|
|
|
HeapFree(GetProcessHeap(), 0, LpcMessage);
|
|
|
|
|
2006-05-10 04:18:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-05 22:09:44 +01:00
|
|
|
static void test_ports_server( HANDLE PortHandle )
|
2006-05-10 04:18:40 +02:00
|
|
|
{
|
|
|
|
HANDLE AcceptPortHandle;
|
2010-03-31 14:20:09 +02:00
|
|
|
union lpc_message *LpcMessage;
|
2006-05-10 04:18:40 +02:00
|
|
|
ULONG size;
|
|
|
|
NTSTATUS status;
|
|
|
|
BOOL done = FALSE;
|
|
|
|
|
|
|
|
size = FIELD_OFFSET(LPC_MESSAGE, Data) + MAX_MESSAGE_LEN;
|
2007-04-25 00:57:55 +02:00
|
|
|
LpcMessage = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2010-03-31 14:20:09 +02:00
|
|
|
status = pNtReplyWaitReceivePort(PortHandle, NULL, NULL, &LpcMessage->msg);
|
2006-05-10 04:18:40 +02:00
|
|
|
todo_wine
|
|
|
|
{
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %d(%x)\n", status, status);
|
2006-05-10 04:18:40 +02:00
|
|
|
}
|
2006-05-13 09:15:50 +02:00
|
|
|
/* STATUS_INVALID_HANDLE: win2k without admin rights will perform an
|
|
|
|
* endless loop here
|
|
|
|
*/
|
|
|
|
if ((status == STATUS_NOT_IMPLEMENTED) ||
|
|
|
|
(status == STATUS_INVALID_HANDLE)) return;
|
2006-05-10 04:18:40 +02:00
|
|
|
|
2010-03-31 14:20:09 +02:00
|
|
|
switch (is_wow64 ? LpcMessage->msg64.MessageType : LpcMessage->msg.MessageType)
|
2006-05-10 04:18:40 +02:00
|
|
|
{
|
|
|
|
case LPC_CONNECTION_REQUEST:
|
|
|
|
ProcessConnectionRequest(LpcMessage, &AcceptPortHandle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LPC_REQUEST:
|
|
|
|
ProcessLpcRequest(PortHandle, LpcMessage);
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LPC_DATAGRAM:
|
2010-03-31 14:20:09 +02:00
|
|
|
if (is_wow64)
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg64.Data, REQUEST1),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REQUEST1, LpcMessage->msg64.Data);
|
|
|
|
else
|
2013-11-05 22:44:42 +01:00
|
|
|
ok(!strcmp((LPSTR)LpcMessage->msg.Data, REQUEST1),
|
2010-03-31 14:20:09 +02:00
|
|
|
"Expected %s, got %s\n", REQUEST1, LpcMessage->msg.Data);
|
2006-05-10 04:18:40 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LPC_CLIENT_DIED:
|
|
|
|
ok(done, "Expected LPC request to be completed!\n");
|
2008-06-10 12:09:38 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, LpcMessage);
|
2006-05-10 04:18:40 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2010-03-31 14:20:09 +02:00
|
|
|
ok(FALSE, "Unexpected message: %d\n",
|
|
|
|
is_wow64 ? LpcMessage->msg64.MessageType : LpcMessage->msg.MessageType);
|
2006-05-10 04:18:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-10 12:09:38 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, LpcMessage);
|
2006-05-10 04:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(port)
|
|
|
|
{
|
2009-03-05 22:09:44 +01:00
|
|
|
OBJECT_ATTRIBUTES obj;
|
|
|
|
HANDLE port_handle;
|
|
|
|
NTSTATUS status;
|
2006-05-10 04:18:40 +02:00
|
|
|
|
|
|
|
if (!init_function_ptrs())
|
|
|
|
return;
|
|
|
|
|
2009-03-05 22:09:44 +01:00
|
|
|
pRtlInitUnicodeString(&port, PORTNAME);
|
2006-05-10 04:18:40 +02:00
|
|
|
|
2009-03-05 22:09:44 +01:00
|
|
|
memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES));
|
|
|
|
obj.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
|
|
obj.ObjectName = &port;
|
2006-05-10 04:18:40 +02:00
|
|
|
|
2009-03-05 22:09:44 +01:00
|
|
|
status = pNtCreatePort(&port_handle, &obj, 100, 100, 0);
|
|
|
|
if (status == STATUS_ACCESS_DENIED) skip("Not enough rights\n");
|
2021-07-20 11:59:54 +02:00
|
|
|
else ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %d\n", status);
|
2008-05-19 14:00:10 +02:00
|
|
|
|
2009-03-05 22:09:44 +01:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
DWORD id;
|
|
|
|
HANDLE thread = CreateThread(NULL, 0, test_ports_client, NULL, 0, &id);
|
|
|
|
ok(thread != NULL, "Expected non-NULL thread handle!\n");
|
|
|
|
|
|
|
|
test_ports_server( port_handle );
|
|
|
|
ok( WaitForSingleObject( thread, 10000 ) == 0, "thread didn't exit\n" );
|
|
|
|
CloseHandle(thread);
|
|
|
|
}
|
2008-05-19 14:00:10 +02:00
|
|
|
FreeLibrary(hntdll);
|
2006-05-10 04:18:40 +02:00
|
|
|
}
|