From d54e68673bd1b81cb7ab3513784cfe93c8f2f2d2 Mon Sep 17 00:00:00 2001 From: David Welch Date: Mon, 3 Apr 2000 21:54:42 +0000 Subject: [PATCH] Correct LPC implementation Removed thread leak in csrss Added notification of port closing svn path=/trunk/; revision=1103 --- reactos/apps/tests/hello/hello.c | 2 +- reactos/apps/tests/lpc/lpcclt.c | 21 ++- reactos/apps/tests/lpc/lpcsrv.c | 14 +- reactos/include/csrss/csrss.h | 4 + reactos/include/ddk/pstypes.h | 58 +++---- reactos/include/ddk/zw.h | 77 +------- reactos/include/ddk/zwtypes.h | 45 ----- reactos/include/internal/mm.h | 18 ++ reactos/include/internal/port.h | 19 +- reactos/include/napi/lpc.h | 129 ++++++++++++++ reactos/lib/kernel32/file/rw.c | 10 +- reactos/lib/kernel32/misc/console.c | 5 +- reactos/lib/ntdll/csr/api.c | 21 ++- reactos/lib/ntdll/rtl/thread.c | 5 +- reactos/loaders/dos/loadros.asm | 6 +- reactos/ntoskrnl/ex/napi.c | 1 + reactos/ntoskrnl/io/errlog.c | 174 +------------------ reactos/ntoskrnl/mm/section.c | 62 ++++++- reactos/ntoskrnl/nt/port.c | 260 ++++++++++++++++------------ reactos/ntoskrnl/ob/handle.c | 13 +- reactos/ntoskrnl/ob/object.c | 40 +++-- reactos/ntoskrnl/ps/create.c | 9 +- reactos/ntoskrnl/ps/kill.c | 57 +++++- reactos/ntoskrnl/ps/process.c | 2 +- reactos/subsys/csrss/api.h | 14 +- reactos/subsys/csrss/api/conio.c | 73 +++----- reactos/subsys/csrss/api/process.c | 49 ++---- reactos/subsys/csrss/api/wapi.c | 64 ++++--- reactos/subsys/smss/init.c | 3 +- reactos/subsys/smss/smapi.c | 8 +- 30 files changed, 627 insertions(+), 636 deletions(-) create mode 100644 reactos/include/napi/lpc.h diff --git a/reactos/apps/tests/hello/hello.c b/reactos/apps/tests/hello/hello.c index e178e982e17..9e793383d21 100644 --- a/reactos/apps/tests/hello/hello.c +++ b/reactos/apps/tests/hello/hello.c @@ -1,5 +1,5 @@ #include - +#include int main(int argc, char* argv[]) { diff --git a/reactos/apps/tests/lpc/lpcclt.c b/reactos/apps/tests/lpc/lpcclt.c index deb456eadd4..834de34c57a 100644 --- a/reactos/apps/tests/lpc/lpcclt.c +++ b/reactos/apps/tests/lpc/lpcclt.c @@ -1,9 +1,10 @@ -/* $Id: lpcclt.c,v 1.5 2000/01/22 22:22:48 ea Exp $ +/* $Id: lpcclt.c,v 1.6 2000/04/03 21:54:33 dwelch Exp $ * * DESCRIPTION: Simple LPC Client * PROGRAMMER: David Welch */ #include +#include #include #include #include @@ -29,7 +30,7 @@ int main(int argc, char* argv[]) UNICODE_STRING PortName; NTSTATUS Status; HANDLE PortHandle; - LPCMESSAGE Request; + LPC_MAX_MESSAGE Request; ULONG ConnectInfoLength; printf("(lpcclt.exe) Lpc client\n"); @@ -52,15 +53,19 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - strcpy(Request.MessageData, GetCommandLineA()); - Request.ActualMessageLength = strlen(Request.MessageData); - Request.TotalMessageLength = sizeof(LPCMESSAGE); + strcpy(Request.Data, GetCommandLineA()); + Request.Header.DataSize = strlen(Request.Data); + Request.Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + + Request.Header.DataSize; - printf("(lpcclt.exe) Sending message \"%s\"\n", (char *) Request.MessageData); - Status = NtRequestPort(PortHandle, &Request); + printf("(lpcclt.exe) Sending message \"%s\"\n", + (char *) Request.Data); + Status = NtRequestPort(PortHandle, + &Request.Header); if (!NT_SUCCESS(Status)) { - printf("(lpcclt.exe) Failed to send request (Status = 0x%=8X)\n", Status); + printf("(lpcclt.exe) Failed to send request (Status = 0x%8X)\n", + Status); return EXIT_FAILURE; } diff --git a/reactos/apps/tests/lpc/lpcsrv.c b/reactos/apps/tests/lpc/lpcsrv.c index 4b95feae80f..ea9818863ae 100644 --- a/reactos/apps/tests/lpc/lpcsrv.c +++ b/reactos/apps/tests/lpc/lpcsrv.c @@ -1,9 +1,10 @@ -/* $Id: lpcsrv.c,v 1.5 2000/03/10 13:46:07 ekohl Exp $ +/* $Id: lpcsrv.c,v 1.6 2000/04/03 21:54:33 dwelch Exp $ * * DESCRIPTION: Simple LPC Server * PROGRAMMER: David Welch */ #include +#include #include #include #include @@ -31,7 +32,7 @@ int main(int argc, char* argv[]) NTSTATUS Status; HANDLE NamedPortHandle; HANDLE PortHandle; - LPCMESSAGE ConnectMsg; + LPC_MAX_MESSAGE ConnectMsg; printf("(lpcsrv.exe) Lpc test server\n"); @@ -57,7 +58,7 @@ int main(int argc, char* argv[]) printf("(lpcsrv.exe) Listening for connections\n"); Status = NtListenPort(NamedPortHandle, - &ConnectMsg); + &ConnectMsg.Header); if (!NT_SUCCESS(Status)) { printf("(lpcsrv.exe) Failed to listen for connections (Status = 0x%08lX)\n", Status); @@ -87,19 +88,20 @@ int main(int argc, char* argv[]) for(;;) { - LPCMESSAGE Request; + LPC_MAX_MESSAGE Request; Status = NtReplyWaitReceivePort(PortHandle, 0, NULL, - &Request); + &Request.Header); if (!NT_SUCCESS(Status)) { printf("(lpcsrv.exe) Failed to receive request (Status = 0x%08lX)\n", Status); return EXIT_FAILURE; } - printf("(lpcsrv.exe) Message contents are <%s>\n", Request.MessageData); + printf("(lpcsrv.exe) Message contents are <%s>\n", + Request.Data); } return EXIT_SUCCESS; } diff --git a/reactos/include/csrss/csrss.h b/reactos/include/csrss/csrss.h index fec23cc5c31..ea968f28d3b 100644 --- a/reactos/include/csrss/csrss.h +++ b/reactos/include/csrss/csrss.h @@ -1,6 +1,8 @@ #ifndef __INCLUDE_CSRSS_CSRSS_H #define __INCLUDE_CSRSS_CSRSS_H +#include + typedef struct { } CSRSS_CONNECT_PROCESS_REQUEST, PCSRSS_CONNECT_PROCESS_REQUEST; @@ -54,6 +56,7 @@ typedef struct typedef struct { + LPC_MESSAGE_HEADER Header; ULONG Type; union { @@ -66,6 +69,7 @@ typedef struct typedef struct { + LPC_MESSAGE_HEADER Header; NTSTATUS Status; union { diff --git a/reactos/include/ddk/pstypes.h b/reactos/include/ddk/pstypes.h index e67da24033e..713c689d75e 100644 --- a/reactos/include/ddk/pstypes.h +++ b/reactos/include/ddk/pstypes.h @@ -175,35 +175,35 @@ typedef struct typedef struct _ETHREAD { - KTHREAD Tcb; - TIME CreateTime; - TIME ExitTime; - NTSTATUS ExitStatus; - LIST_ENTRY PostBlockList; - LIST_ENTRY TerminationPortList; - ULONG ActiveTimerListLock; - PVOID ActiveTimerListHead; - CLIENT_ID Cid; - PLARGE_INTEGER LpcReplySemaphore; - PVOID LpcReplyMessage; - PLARGE_INTEGER LpcReplyMessageId; - PPS_IMPERSONATION_INFO ImpersonationInfo; - LIST_ENTRY IrpList; // - TOP_LEVEL_IRP TopLevelIrp; - ULONG ReadClusterSize; - UCHAR ForwardClusterOnly; - UCHAR DisablePageFaultClustering; - UCHAR DeadThread; - UCHAR HasTerminated; - ACCESS_MASK GrantedAccess; - struct _EPROCESS* ThreadsProcess; - PKSTART_ROUTINE StartAddress; - LPTHREAD_START_ROUTINE Win32StartAddress; // Should Specify a win32 start func - UCHAR LpcExitThreadCalled; - UCHAR HardErrorsAreDisabled; - UCHAR LpcReceivedMsgIdValid; - UCHAR ActiveImpersonationInfo; - ULONG PerformanceCountHigh; + KTHREAD Tcb; + TIME CreateTime; + TIME ExitTime; + NTSTATUS ExitStatus; + LIST_ENTRY PostBlockList; + LIST_ENTRY TerminationPortList; + KSPIN_LOCK ActiveTimerListLock; + PVOID ActiveTimerListHead; + CLIENT_ID Cid; + PLARGE_INTEGER LpcReplySemaphore; + PVOID LpcReplyMessage; + PLARGE_INTEGER LpcReplyMessageId; + PPS_IMPERSONATION_INFO ImpersonationInfo; + LIST_ENTRY IrpList; + TOP_LEVEL_IRP TopLevelIrp; + ULONG ReadClusterSize; + UCHAR ForwardClusterOnly; + UCHAR DisablePageFaultClustering; + UCHAR DeadThread; + UCHAR HasTerminated; + ACCESS_MASK GrantedAccess; + struct _EPROCESS* ThreadsProcess; + PKSTART_ROUTINE StartAddress; + LPTHREAD_START_ROUTINE Win32StartAddress; + UCHAR LpcExitThreadCalled; + UCHAR HardErrorsAreDisabled; + UCHAR LpcReceivedMsgIdValid; + UCHAR ActiveImpersonationInfo; + ULONG PerformanceCountHigh; /* * Added by David Welch (welch@cwcom.net) diff --git a/reactos/include/ddk/zw.h b/reactos/include/ddk/zw.h index e08ad314685..7e7cf11044e 100644 --- a/reactos/include/ddk/zw.h +++ b/reactos/include/ddk/zw.h @@ -1,5 +1,5 @@ -/* $Id: zw.h,v 1.27 2000/03/26 22:00:06 dwelch Exp $ +/* $Id: zw.h,v 1.28 2000/04/03 21:54:34 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -5119,81 +5119,6 @@ ZwYieldExecution( * These prototypes are unknown as yet * (stack sizes by Peter-Michael Hager) */ -NTSTATUS STDCALL NtAcceptConnectPort (PHANDLE PortHandle, - HANDLE NamedPortHandle, - PLPCMESSAGE ServerReply, - ULONG AcceptIt, - ULONG Unknown3, - PLPCSECTIONMAPINFO MapInfo); - -NTSTATUS STDCALL NtCompleteConnectPort (IN HANDLE PortHandle); - -NTSTATUS STDCALL NtConnectPort(OUT PHANDLE PortHandle, - IN PUNICODE_STRING PortName, - IN PVOID Unknown1, - IN PLPCSECTIONINFO SectionInfo, - IN PLPCSECTIONMAPINFO MapInfo, - IN PVOID Unknown2, - IN PVOID ConnectInfo, - IN PULONG ConnectInfoLength); - -NTSTATUS STDCALL NtReplyWaitReplyPort(PVOID Unknown1, - PVOID Unknown2); - - -NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle, - POBJECT_ATTRIBUTES ObjectAttributes, - ULONG MaxConnectInfoLength, - ULONG MaxDataLength, - ULONG Unknown1); - -NTSTATUS STDCALL NtImpersonateClientOfPort (IN HANDLE PortHandle, - IN PLPCMESSAGE ClientMessage); - -NTSTATUS STDCALL NtListenPort (IN HANDLE PortHAndle, - IN PLPCMESSAGE LpcMessage); - -NTSTATUS -STDCALL -NtQueryInformationPort ( /* @20 */ - IN HANDLE PortHandle, - IN CINT PortInformationClass, /* guess */ - OUT PVOID PortInformation, /* guess */ - IN ULONG PortInformationLength, /* guess */ - OUT PULONG ReturnLength /* guess */ - ); -NTSTATUS STDCALL NtReplyPort (IN HANDLE PortHandle, - IN PLPCMESSAGE LpcReply); -NTSTATUS STDCALL NtReplyWaitReceivePort (IN HANDLE PortHandle, - PVOID Unknown1, - PLPCMESSAGE MessageReply, - PLPCMESSAGE MessageRequest); -NTSTATUS STDCALL NtRequestPort ( IN HANDLE PortHandle, - IN PLPCMESSAGE LpcMessage); -NTSTATUS STDCALL NtRequestWaitReplyPort (IN HANDLE PortHandle, - IN OUT PLPCMESSAGE LpcReply, - OUT PLPCMESSAGE LpcRequest); -NTSTATUS -STDCALL -NtReadRequestData ( /* @24 */ - DWORD a0, - DWORD a1, - DWORD a2, - DWORD a3, - DWORD a4, - DWORD a5 - ); -NTSTATUS -STDCALL -NtWriteRequestData ( /* @24 */ - DWORD a0, - DWORD a1, - DWORD a2, - DWORD a3, - DWORD a4, - DWORD a5 - ); - /* --- REGISTRY --- */ diff --git a/reactos/include/ddk/zwtypes.h b/reactos/include/ddk/zwtypes.h index da5abaab513..07ae07cab26 100644 --- a/reactos/include/ddk/zwtypes.h +++ b/reactos/include/ddk/zwtypes.h @@ -1,51 +1,6 @@ #ifndef __INCLUDE_DDK_ZWTYPES_H #define __INCLUDE_DDK_ZWTYPES_H -#define MAX_MESSAGE_DATA (0x130) - -#define UNUSED_MSG_TYPE (0x0) -#define LPC_REQUEST (0x1) -#define LPC_REPLY (0x2) -#define LPC_DATAGRAM (0x3) -#define LPC_LOST_REPLY (0x4) -#define LPC_PORT_CLOSED (0x5) -#define LPC_CLIENT_DIED (0x6) -#define LPC_EXCEPTION (0x7) -#define LPC_DEBUG_EVENT (0x8) -#define LPC_ERROR_EVENT (0x9) -#define LPC_CONNECTION_REQUEST (0xa) -#define LPC_CONNECTION_REFUSED (0xb) - -typedef struct _LPCSECTIONINFO -{ - DWORD Length; - HANDLE SectionHandle; - DWORD Unknown1; - DWORD SectionSize; - DWORD ClientBaseAddress; - DWORD ServerBaseAddress; -} LPCSECTION, *PLPCSECTIONINFO; - -typedef struct _LPCSECTIONMAPINFO -{ - DWORD Length; - DWORD SectionSize; - DWORD ServerBaseAddress; -} LPCSECTIONMAPINFO, *PLPCSECTIONMAPINFO; - -typedef struct _LPCMESSAGE -{ - WORD ActualMessageLength; - WORD TotalMessageLength; - DWORD MessageType; - DWORD ClientProcessId; - DWORD ClientThreadId; - DWORD MessageId; - DWORD SharedSectionSize; - BYTE MessageData[MAX_MESSAGE_DATA]; -} LPCMESSAGE, *PLPCMESSAGE; - - #define NtCurrentProcess() ( (HANDLE) 0xFFFFFFFF ) #define NtCurrentThread() ( (HANDLE) 0xFFFFFFFE ) diff --git a/reactos/include/internal/mm.h b/reactos/include/internal/mm.h index fb2f648a89d..689e35a7c97 100644 --- a/reactos/include/internal/mm.h +++ b/reactos/include/internal/mm.h @@ -26,6 +26,22 @@ enum MEMORY_AREA_CACHE_SEGMENT, }; +#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) ((x) / (4*1024*1024)) +#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) (((x) % 4*1024*1024) / (4*1024)) + +#define NR_SECTION_PAGE_TABLES (1024) +#define NR_SECTION_PAGE_ENTRIES (1024) + +typedef struct +{ + PVOID Pages[NR_SECTION_PAGE_ENTRIES]; +} SECTION_PAGE_TABLE, *PSECTION_PAGE_TABLE; + +typedef struct +{ + PSECTION_PAGE_TABLE PageTables[NR_SECTION_PAGE_TABLES]; +} SECTION_PAGE_DIRECTORY, *PSECTION_PAGE_DIRECTORY; + typedef struct { CSHORT Type; @@ -36,6 +52,8 @@ typedef struct PFILE_OBJECT FileObject; LIST_ENTRY ViewListHead; KSPIN_LOCK ViewListLock; + KMUTEX Lock; + SECTION_PAGE_DIRECTORY PageDirectory; } SECTION_OBJECT, *PSECTION_OBJECT; typedef struct diff --git a/reactos/include/internal/port.h b/reactos/include/internal/port.h index 772a4cb5d79..0ea3876302b 100644 --- a/reactos/include/internal/port.h +++ b/reactos/include/internal/port.h @@ -1,8 +1,15 @@ +#ifndef __INCLUDE_INTERNAL_PORT_H +#define __INCLUDE_INTERNAL_PORT_H + +#include + typedef struct _EPORT { KSPIN_LOCK Lock; KEVENT Event; + ULONG State; + struct _EPORT* OtherPort; ULONG QueueLength; @@ -15,9 +22,19 @@ typedef struct _EPORT ULONG MaxConnectInfoLength; } EPORT, *PEPORT; +typedef struct _EPORT_TERMINATION_REQUEST +{ + LIST_ENTRY ThreadListEntry; + PEPORT Port; +} EPORT_TERMINATION_REQUEST, *PEPORT_TERMINATION_REQUEST; + NTSTATUS STDCALL LpcRequestPort(PEPORT Port, - PLPCMESSAGE LpcMessage); + PLPC_MESSAGE LpcMessage); +NTSTATUS STDCALL LpcSendTerminationPort(PEPORT Port, + TIME CreationTime); #define PORT_ALL_ACCESS (0x1) extern POBJECT_TYPE ExPortType; + +#endif /* __INCLUDE_INTERNAL_PORT_H */ diff --git a/reactos/include/napi/lpc.h b/reactos/include/napi/lpc.h new file mode 100644 index 00000000000..50027551e1b --- /dev/null +++ b/reactos/include/napi/lpc.h @@ -0,0 +1,129 @@ +#ifndef __INCLUDE_NAPI_LPC_H +#define __INCLUDE_NAPI_LPC_H + +#include + +#define MAX_MESSAGE_DATA (0x130) + +#define UNUSED_MSG_TYPE (0x0) +#define LPC_REQUEST (0x1) +#define LPC_REPLY (0x2) +#define LPC_DATAGRAM (0x3) +#define LPC_LOST_REPLY (0x4) +#define LPC_PORT_CLOSED (0x5) +#define LPC_CLIENT_DIED (0x6) +#define LPC_EXCEPTION (0x7) +#define LPC_DEBUG_EVENT (0x8) +#define LPC_ERROR_EVENT (0x9) +#define LPC_CONNECTION_REQUEST (0xa) +#define LPC_CONNECTION_REFUSED (0xb) + +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_HEADER +{ + USHORT DataSize; + USHORT MessageSize; + USHORT MessageType; + USHORT VirtualRangesOffset; + CLIENT_ID Cid; + ULONG MessageId; + ULONG SharedSectionSize; +} LPC_MESSAGE_HEADER, *PLPC_MESSAGE_HEADER; + +typedef struct _LPC_TERMINATION_MESSAGE +{ + LPC_MESSAGE_HEADER Header; + TIME CreationTime; +} LPC_TERMINATION_MESSAGE, *PLPC_TERMINATION_MESSAGE; + +typedef LPC_MESSAGE_HEADER LPC_MESSAGE, *PLPC_MESSAGE; + +typedef struct _LPC_MAX_MESSAGE +{ + LPC_MESSAGE_HEADER Header; + BYTE Data[MAX_MESSAGE_DATA]; +} LPC_MAX_MESSAGE, *PLPC_MAX_MESSAGE; + +NTSTATUS STDCALL NtAcceptConnectPort (PHANDLE PortHandle, + HANDLE NamedPortHandle, + PLPC_MESSAGE ServerReply, + BOOLEAN AcceptIt, + PLPC_SECTION_WRITE WriteMap, + PLPC_SECTION_READ ReadMap); + +NTSTATUS STDCALL NtCompleteConnectPort (HANDLE PortHandle); + +NTSTATUS STDCALL NtConnectPort(PHANDLE PortHandle, + PUNICODE_STRING PortName, + PSECURITY_QUALITY_OF_SERVICE SecurityQos, + PLPC_SECTION_WRITE SectionInfo, + PLPC_SECTION_READ MapInfo, + PULONG MaxMessageSize, + PVOID ConnectInfo, + PULONG ConnectInfoLength); + +NTSTATUS STDCALL NtReplyWaitReplyPort (HANDLE PortHandle, + PLPC_MESSAGE ReplyMessage); + +NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle, + POBJECT_ATTRIBUTES ObjectAttributes, + ULONG MaxConnectInfoLength, + ULONG MaxDataLength, + ULONG Reserved); + +NTSTATUS STDCALL NtImpersonateClientOfPort (HANDLE PortHandle, + PLPC_MESSAGE ClientMessage); + +NTSTATUS STDCALL NtListenPort (HANDLE PortHandle, + PLPC_MESSAGE LpcMessage); + +NTSTATUS STDCALL NtQueryInformationPort (HANDLE PortHandle, + CINT PortInformationClass, + PVOID PortInformation, + ULONG PortInformationLength, + PULONG ReturnLength); +NTSTATUS STDCALL NtReplyPort (HANDLE PortHandle, + PLPC_MESSAGE LpcReply); +NTSTATUS STDCALL NtReplyWaitReceivePort (HANDLE PortHandle, + PULONG PortId, + PLPC_MESSAGE MessageReply, + PLPC_MESSAGE MessageRequest); +NTSTATUS STDCALL NtRequestPort (HANDLE PortHandle, + PLPC_MESSAGE LpcMessage); + +NTSTATUS STDCALL NtRequestWaitReplyPort (HANDLE PortHandle, + PLPC_MESSAGE LpcReply, + PLPC_MESSAGE LpcRequest); + +NTSTATUS STDCALL NtReadRequestData (HANDLE PortHandle, + PLPC_MESSAGE Message, + ULONG Index, + PVOID Buffer, + ULONG BufferLength, + PULONG ReturnLength); + +NTSTATUS STDCALL NtWriteRequestData (HANDLE PortHandle, + PLPC_MESSAGE Message, + ULONG Index, + PVOID Buffer, + ULONG BufferLength, + PULONG ReturnLength); + + +#endif /* __INCLUDE_NAPI_LPC_H */ diff --git a/reactos/lib/kernel32/file/rw.c b/reactos/lib/kernel32/file/rw.c index 65f8097f7ac..ed15609a68b 100644 --- a/reactos/lib/kernel32/file/rw.c +++ b/reactos/lib/kernel32/file/rw.c @@ -1,4 +1,4 @@ -/* $Id: rw.c,v 1.10 2000/03/26 22:00:07 dwelch Exp $ +/* $Id: rw.c,v 1.11 2000/04/03 21:54:35 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -35,6 +35,8 @@ WINBOOL STDCALL WriteFile(HANDLE hFile, PIO_STATUS_BLOCK IoStatusBlock; PLARGE_INTEGER ptrOffset; + DPRINT("WriteFile(hFile %x)\n",hFile); + if (IsConsoleHandle(hFile)) { return(WriteConsoleA(hFile, @@ -43,9 +45,7 @@ WINBOOL STDCALL WriteFile(HANDLE hFile, lpNumberOfBytesWritten, NULL)); } - - DPRINT("WriteFile(hFile %x)\n",hFile); - + if (lpOverLapped != NULL) { Offset.u.LowPart = lpOverLapped->Offset; @@ -100,6 +100,8 @@ WINBOOL STDCALL ReadFile(HANDLE hFile, PIO_STATUS_BLOCK IoStatusBlock; PLARGE_INTEGER ptrOffset; + DbgPrint("ReadFile(hFile %x)\n", hFile); + if (IsConsoleHandle(hFile)) { return(ReadConsoleA(hFile, diff --git a/reactos/lib/kernel32/misc/console.c b/reactos/lib/kernel32/misc/console.c index 468564ecffc..dd786bd5782 100644 --- a/reactos/lib/kernel32/misc/console.c +++ b/reactos/lib/kernel32/misc/console.c @@ -47,10 +47,13 @@ HANDLE STDCALL GetStdHandle(DWORD nStdHandle) { PRTL_USER_PROCESS_PARAMETERS Ppb; - DPRINT("GetStdHandle(nStdHandle %d)\n",nStdHandle); +// DbgPrint("GetStdHandle(nStdHandle %d)\n",nStdHandle); SetLastError(ERROR_SUCCESS); /* OK */ +// DbgPrint("NtCurrentPeb() %x\n", NtCurrentPeb()); Ppb = NtCurrentPeb()->ProcessParameters; +// DbgPrint("Ppb %x\n", Ppb); +// DbgPrint("Ppb->OutputHandle %x\n", Ppb->OutputHandle); switch (nStdHandle) { case STD_INPUT_HANDLE: return Ppb->InputHandle; diff --git a/reactos/lib/ntdll/csr/api.c b/reactos/lib/ntdll/csr/api.c index 1d4aeff4d51..966745cd3ac 100644 --- a/reactos/lib/ntdll/csr/api.c +++ b/reactos/lib/ntdll/csr/api.c @@ -1,4 +1,4 @@ -/* $Id: api.c,v 1.4 2000/03/22 18:35:50 dwelch Exp $ +/* $Id: api.c,v 1.5 2000/04/03 21:54:36 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -28,21 +28,20 @@ NTSTATUS STDCALL CsrClientCallServer(PCSRSS_API_REQUEST Request, ULONG Length, ULONG ReplyLength) { - LPCMESSAGE LpcRequest; - LPCMESSAGE LpcReply; NTSTATUS Status; -// DbgPrint("Length %d\n", Length); +// DbgPrint("CsrClientCallServer(Request %x, Reply %x, Length %d, " +// "ReplyLength %d)\n", Request, Reply, Length, ReplyLength); - LpcRequest.ActualMessageLength = Length; - LpcRequest.TotalMessageLength = sizeof(LPCMESSAGE) + Length; - memcpy(LpcRequest.MessageData, Request, Length); + Request->Header.DataSize = Length; + Request->Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + Length; Status = NtRequestWaitReplyPort(WindowsApiPort, - &LpcRequest, - &LpcReply); - memcpy(Reply, LpcReply.MessageData, ReplyLength); -// DbgPrint("Status %x Reply.Status %x\n", Status, Reply->Status); + &Request->Header, + &Reply->Header); + +// DbgPrint("Status %x\n", Status); + return(Status); } diff --git a/reactos/lib/ntdll/rtl/thread.c b/reactos/lib/ntdll/rtl/thread.c index 0b88e609694..482eb9ace64 100644 --- a/reactos/lib/ntdll/rtl/thread.c +++ b/reactos/lib/ntdll/rtl/thread.c @@ -239,12 +239,9 @@ RtlInitializeContext(HANDLE ProcessHandle, } -NTSTATUS STDCALL -RtlDestroyUserThreadStack(param1, param2) +NTSTATUS STDCALL RtlDestroyUserThreadStack(param1, param2) { - - } /* EOF */ diff --git a/reactos/loaders/dos/loadros.asm b/reactos/loaders/dos/loadros.asm index 39fbd796e33..9f30f4a4d08 100644 --- a/reactos/loaders/dos/loadros.asm +++ b/reactos/loaders/dos/loadros.asm @@ -875,9 +875,9 @@ _to_pmode: mov ah,12 int 10h -; mov ax,1112h ;! Use 8x8 font -; xor bl,bl -; int 10h + mov ax,1112h ;! Use 8x8 font + xor bl,bl + int 10h mov ax,1200h ;! Use alternate print screen mov bl,20h int 10h diff --git a/reactos/ntoskrnl/ex/napi.c b/reactos/ntoskrnl/ex/napi.c index ac1f957969e..b62848cb26b 100644 --- a/reactos/ntoskrnl/ex/napi.c +++ b/reactos/ntoskrnl/ex/napi.c @@ -9,6 +9,7 @@ /* INCLUDES *****************************************************************/ #include +#include #include /* GLOBALS ******************************************************************/ diff --git a/reactos/ntoskrnl/io/errlog.c b/reactos/ntoskrnl/io/errlog.c index b6894ac0b48..2141edf17ea 100644 --- a/reactos/ntoskrnl/io/errlog.c +++ b/reactos/ntoskrnl/io/errlog.c @@ -1,4 +1,4 @@ -/* $Id: errlog.c,v 1.4 2000/03/26 19:38:22 ea Exp $ +/* $Id: errlog.c,v 1.5 2000/04/03 21:54:38 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -36,169 +36,13 @@ typedef struct _IO_ERROR_LOG_PACKET ULONG DumpData[1]; } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET; -typedef struct _ERROR_LOG_MESSAGE -{ - PIO_ERROR_LOG_PACKET Packet; - LIST_ENTRY ListEntry; -} IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE; - -/* GLOBALS *******************************************************************/ - -static HANDLE ErrorLogPortHandle; -static HANDLE ErrorLogThreadHandle; -static PEPORT ErrorLogPort; - -static LIST_ENTRY ErrorLogListHead; -static KSPIN_LOCK ErrorLogListLock; -static KSEMAPHORE ErrorLogSemaphore; - /* FUNCTIONS *****************************************************************/ -static VOID IoSendErrorLogEntry(PIO_ERROR_LOG_PACKET Packet) -{ - LPCMESSAGE Message; - ULONG Size; - ULONG i; - - Size = sizeof(IO_ERROR_LOG_PACKET) + - (Packet->DumpDataSize * sizeof(UCHAR)); - - for (i=0; i<((Size % MAX_MESSAGE_DATA) - 1); i++) - { - Message.ActualMessageLength = MAX_MESSAGE_DATA; - Message.TotalMessageLength = sizeof(LPCMESSAGE); - Message.MessageType = i; - memcpy(Message.MessageData, (PVOID)Packet, MAX_MESSAGE_DATA); - LpcRequestPort(ErrorLogPort, &Message); - } - Message.ActualMessageLength = MAX_MESSAGE_DATA; - Message.TotalMessageLength = sizeof(LPCMESSAGE); - Message.MessageType = i; - memcpy(Message.MessageData, (PVOID)Packet, Size % MAX_MESSAGE_DATA); - LpcRequestPort(ErrorLogPort, &Message); -} - -NTSTATUS IoErrorLogThreadMain(PVOID Context) -{ - NTSTATUS Status; - LPCMESSAGE ConnectMsg; - HANDLE PortHandle; - PIO_ERROR_LOG_MESSAGE Message; - KIRQL oldIrql; - PLIST_ENTRY ListEntry; - - for (;;) - { - Status = NtListenPort(ErrorLogPortHandle, &ConnectMsg); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - Status = NtAcceptConnectPort(&PortHandle, - ErrorLogPortHandle, - NULL, - 1, - 0, - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - Status = NtCompleteConnectPort(PortHandle); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - Status = ObReferenceObjectByHandle(PortHandle, - PORT_ALL_ACCESS, - ExPortType, - UserMode, - (PVOID*)&ErrorLogPort, - NULL); - if (!NT_SUCCESS(Status)) - { - ZwClose(PortHandle); - return(Status); - } - - ZwClose(PortHandle); - - for (;;) - { - - KeWaitForSingleObject(&ErrorLogSemaphore, - UserRequest, - KernelMode, - FALSE, - NULL); - - KeAcquireSpinLock(&ErrorLogListLock, &oldIrql); - - ListEntry = RemoveHeadList(&ErrorLogListHead); - - KeReleaseSpinLock(&ErrorLogListLock, oldIrql); - - Message = CONTAINING_RECORD(ListEntry, - IO_ERROR_LOG_MESSAGE, - ListEntry); - - IoSendErrorLogEntry(Message->Packet); - - ExFreePool(Message->Packet); - ExFreePool(Message); - } - } -} - NTSTATUS IoInitErrorLog(VOID) { - NTSTATUS Status; - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING PortName; - CLIENT_ID Cid; - - InitializeListHead(&ErrorLogListHead); - KeInitializeSpinLock(&ErrorLogListLock); - - KeInitializeSemaphore(&ErrorLogSemaphore, - 0, - 500); - - RtlInitUnicodeString(&PortName, L"\\ErrorLogPort"); - InitializeObjectAttributes(&ObjectAttributes, - &PortName, - 0, - NULL, - NULL); - Status = NtCreatePort(&ErrorLogPortHandle, - &ObjectAttributes, - 0, - 0, - 0); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - Status = PsCreateSystemThread(ErrorLogThreadHandle, - 0, - NULL, - NULL, - &Cid, - IoErrorLogThreadMain, - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - return(STATUS_SUCCESS); } - PVOID STDCALL IoAllocateErrorLogEntry(PVOID IoObject, UCHAR EntrySize) { UNIMPLEMENTED; @@ -206,22 +50,6 @@ PVOID STDCALL IoAllocateErrorLogEntry(PVOID IoObject, UCHAR EntrySize) VOID STDCALL IoWriteErrorLogEntry(PVOID ElEntry) { - KIRQL oldIrql; - PIO_ERROR_LOG_MESSAGE Message; - - Message = ExAllocatePool(NonPagedPool, sizeof(IO_ERROR_LOG_MESSAGE)); - Message->Packet = (PIO_ERROR_LOG_PACKET)ElEntry; - - KeAcquireSpinLock(&ErrorLogListLock, &oldIrql); - - InsertTailList(&ErrorLogListHead, &Message->ListEntry); - - KeReleaseSemaphore(&ErrorLogSemaphore, - IO_NO_INCREMENT, - 1, - FALSE); - - KeReleaseSpinLock(&ErrorLogListLock, oldIrql); } diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index fbd83447795..a82174d39cf 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -1,4 +1,4 @@ -/* $Id: section.c,v 1.27 2000/04/02 13:32:41 ea Exp $ +/* $Id: section.c,v 1.28 2000/04/03 21:54:39 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -27,6 +27,45 @@ POBJECT_TYPE EXPORTED MmSectionObjectType = NULL; /* FUNCTIONS *****************************************************************/ +VOID MmSetPageEntrySection(PSECTION_OBJECT Section, + ULONG Offset, + PVOID Entry) +{ + PSECTION_PAGE_TABLE Table; + ULONG DirectoryOffset; + ULONG TableOffset; + + DirectoryOffset = PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(Offset); + Table = Section->PageDirectory.PageTables[DirectoryOffset]; + if (Table == NULL) + { + Table = + Section->PageDirectory.PageTables[DirectoryOffset] = + ExAllocatePool(NonPagedPool, sizeof(SECTION_PAGE_TABLE)); + } + TableOffset = PAGE_TO_SECTION_PAGE_TABLE_OFFSET(Offset); + Table->Pages[TableOffset] = Entry; +} + +PVOID MmGetPageEntrySection(PSECTION_OBJECT Section, + ULONG Offset) +{ + PSECTION_PAGE_TABLE Table; + PVOID Entry; + ULONG DirectoryOffset; + ULONG TableOffset; + + DirectoryOffset = PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(Offset); + Table = Section->PageDirectory.PageTables[DirectoryOffset]; + if (Table == NULL) + { + return(NULL); + } + TableOffset = PAGE_TO_SECTION_PAGE_TABLE_OFFSET(Offset); + Entry = Table->Pages[TableOffset]; + return(Entry); +} + PVOID MiTryToSharePageInSection(PSECTION_OBJECT Section, ULONG Offset) { @@ -72,6 +111,14 @@ PVOID MiTryToSharePageInSection(PSECTION_OBJECT Section, VOID MmpDeleteSection(PVOID ObjectBody) { + DPRINT1("MmpDeleteSection(ObjectBody %x)\n", ObjectBody); +} + +VOID MmpCloseSection(PVOID ObjectBody, + ULONG HandleCount) +{ + DPRINT1("MmpCloseSection(OB %x, HC %d) RC %d\n", + ObjectBody, HandleCount, ObGetReferenceCount(ObjectBody)); } NTSTATUS MmpCreateSection(PVOID ObjectBody, @@ -111,10 +158,10 @@ NTSTATUS MmpCreateSection(PVOID ObjectBody, NTSTATUS MmInitSectionImplementation(VOID) { - ANSI_STRING AnsiString; - MmSectionObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE)); + RtlInitUnicodeString(&MmSectionObjectType->TypeName, L"Section"); + MmSectionObjectType->TotalObjects = 0; MmSectionObjectType->TotalHandles = 0; MmSectionObjectType->MaxObjects = ULONG_MAX; @@ -123,7 +170,7 @@ NTSTATUS MmInitSectionImplementation(VOID) MmSectionObjectType->NonpagedPoolCharge = sizeof(SECTION_OBJECT); MmSectionObjectType->Dump = NULL; MmSectionObjectType->Open = NULL; - MmSectionObjectType->Close = NULL; + MmSectionObjectType->Close = MmpCloseSection; MmSectionObjectType->Delete = MmpDeleteSection; MmSectionObjectType->Parse = NULL; MmSectionObjectType->Security = NULL; @@ -131,9 +178,6 @@ NTSTATUS MmInitSectionImplementation(VOID) MmSectionObjectType->OkayToClose = NULL; MmSectionObjectType->Create = MmpCreateSection; - RtlInitAnsiString(&AnsiString,"Section"); - RtlAnsiStringToUnicodeString(&MmSectionObjectType->TypeName, - &AnsiString,TRUE); return(STATUS_SUCCESS); } @@ -448,6 +492,10 @@ NTSTATUS STDCALL MmUnmapViewOfSection(PEPROCESS Process, KIRQL oldIrql; Section = MemoryArea->Data.SectionData.Section; + + DPRINT1("MmUnmapViewOfSection(Section %x) SectionRC %d\n", + Section, ObGetReferenceCount(Section)); + KeAcquireSpinLock(&Section->ViewListLock, &oldIrql); RemoveEntryList(&MemoryArea->Data.SectionData.ViewListEntry); KeReleaseSpinLock(&Section->ViewListLock, oldIrql); diff --git a/reactos/ntoskrnl/nt/port.c b/reactos/ntoskrnl/nt/port.c index 53e409a4ba8..9d8d66e543f 100644 --- a/reactos/ntoskrnl/nt/port.c +++ b/reactos/ntoskrnl/nt/port.c @@ -1,23 +1,14 @@ -/* $Id: port.c,v 1.17 2000/01/26 10:07:28 dwelch Exp $ +/* $Id: port.c,v 1.18 2000/04/03 21:54:39 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * FILE: ntoskrnl/nt/port.c - * PURPOSE: Communication mechanism (like Mach?) + * PURPOSE: Communication mechanism * PROGRAMMER: David Welch (welch@cwcom.net) * UPDATE HISTORY: * Created 22/05/98 */ -/* NOTES ******************************************************************** - * - * This is a very rough implementation, not compatible with mach or nt - * - * - * - * - */ - /* INCLUDES *****************************************************************/ #include @@ -37,7 +28,9 @@ #define EPORT_WAIT_FOR_ACCEPT (2) #define EPORT_WAIT_FOR_COMPLETE_SRV (3) #define EPORT_WAIT_FOR_COMPLETE_CLT (4) -#define EPORT_CONNECTED (5) +#define EPORT_CONNECTED_CLIENT (5) +#define EPORT_CONNECTED_SERVER (6) +#define EPORT_DISCONNECTED (7) struct _EPORT; @@ -45,7 +38,8 @@ typedef struct _QUEUEDMESSAGE { struct _EPORT* Sender; LIST_ENTRY QueueListEntry; - LPCMESSAGE Message; + LPC_MESSAGE Message; + UCHAR MessageData[MAX_MESSAGE_DATA]; } QUEUEDMESSAGE, *PQUEUEDMESSAGE; /* GLOBALS *******************************************************************/ @@ -92,7 +86,7 @@ PQUEUEDMESSAGE EiDequeueConnectMessagePort(PEPORT Port) } NTSTATUS EiReplyOrRequestPort(PEPORT Port, - PLPCMESSAGE LpcReply, + PLPC_MESSAGE LpcReply, ULONG MessageType, PEPORT Sender) { @@ -104,11 +98,11 @@ NTSTATUS EiReplyOrRequestPort(PEPORT Port, if (LpcReply != NULL) { - memcpy(&MessageReply->Message, LpcReply, sizeof(LPCMESSAGE)); + memcpy(&MessageReply->Message, LpcReply, LpcReply->MessageSize); } - MessageReply->Message.ClientProcessId = (DWORD)PsGetCurrentProcessId(); - MessageReply->Message.ClientThreadId = (DWORD)PsGetCurrentThreadId(); + MessageReply->Message.Cid.UniqueProcess = PsGetCurrentProcessId(); + MessageReply->Message.Cid.UniqueThread = PsGetCurrentThreadId(); MessageReply->Message.MessageType = MessageType; MessageReply->Message.MessageId = InterlockedIncrement(&EiNextLpcMessageId); @@ -119,9 +113,51 @@ NTSTATUS EiReplyOrRequestPort(PEPORT Port, return(STATUS_SUCCESS); } +VOID NiClosePort(PVOID ObjectBody, + ULONG HandleCount) +{ + PEPORT Port = (PEPORT)ObjectBody; + LPC_MESSAGE Message; + +// DPRINT1("NiClosePort(ObjectBody %x, HandleCount %d) RefCount %d\n", +// ObjectBody, HandleCount, ObGetReferenceCount(Port)); + + if (HandleCount == 0 && + Port->State == EPORT_CONNECTED_CLIENT && + ObGetReferenceCount(Port) == 2) + { +// DPRINT1("All handles closed to client port\n"); + + Message.MessageSize = sizeof(LPC_MESSAGE); + Message.DataSize = 0; + + EiReplyOrRequestPort(Port->OtherPort, + &Message, + LPC_PORT_CLOSED, + Port); + KeSetEvent(&Port->OtherPort->Event, IO_NO_INCREMENT, FALSE); + + Port->OtherPort->OtherPort = NULL; + Port->OtherPort->State = EPORT_DISCONNECTED; + ObDereferenceObject(Port); + } + if (HandleCount == 0 && + Port->State == EPORT_CONNECTED_SERVER && + ObGetReferenceCount(Port) == 2) + { +// DPRINT("All handles closed to server\n"); + + Port->OtherPort->OtherPort = NULL; + Port->OtherPort->State = EPORT_DISCONNECTED; + ObDereferenceObject(Port->OtherPort); + } +} VOID NiDeletePort(PVOID ObjectBody) { +// PEPORT Port = (PEPORT)ObjectBody; + +// DPRINT1("Deleting port %x\n", Port); } NTSTATUS NiCreatePort(PVOID ObjectBody, @@ -170,7 +206,7 @@ NTSTATUS NiInitPort(VOID) ExPortType->NonpagedPoolCharge = sizeof(EPORT); ExPortType->Dump = NULL; ExPortType->Open = NULL; - ExPortType->Close = NULL; + ExPortType->Close = NiClosePort; ExPortType->Delete = NiDeletePort; ExPortType->Parse = NULL; ExPortType->Security = NULL; @@ -191,6 +227,7 @@ static NTSTATUS NiInitializePort(PEPORT Port) Port->OtherPort = NULL; Port->QueueLength = 0; Port->ConnectQueueLength = 0; + Port->State = EPORT_INACTIVE; InitializeListHead(&Port->QueueListHead); InitializeListHead(&Port->ConnectQueueListHead); @@ -201,7 +238,7 @@ NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle, POBJECT_ATTRIBUTES ObjectAttributes, ULONG MaxConnectInfoLength, ULONG MaxDataLength, - ULONG Unknown1) + ULONG Reserved) { PEPORT Port; NTSTATUS Status; @@ -221,17 +258,19 @@ NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle, Port->MaxConnectInfoLength = 260; Port->MaxDataLength = 328; + ObDereferenceObject(Port); + return(Status); } -NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, - IN PUNICODE_STRING PortName, - IN PVOID Unknown1, - IN PLPCSECTIONINFO SectionInfo, - IN PLPCSECTIONMAPINFO MapInfo, - IN PVOID Unknown2, - IN PVOID ConnectInfo, - IN PULONG uConnectInfoLength) +NTSTATUS STDCALL NtConnectPort (PHANDLE ConnectedPort, + PUNICODE_STRING PortName, + PSECURITY_QUALITY_OF_SERVICE Qos, + PLPC_SECTION_WRITE WriteMap, + PLPC_SECTION_READ ReadMap, + PULONG MaxMessageSize, + PVOID ConnectInfo, + PULONG UserConnectInfoLength) /* * FUNCTION: Connect to a named port and wait for the other side to * accept the connection @@ -241,7 +280,7 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, PEPORT NamedPort; PEPORT OurPort; HANDLE OurPortHandle; - LPCMESSAGE Request; + PLPC_MESSAGE Request; PQUEUEDMESSAGE Reply; ULONG ConnectInfoLength; KIRQL oldIrql; @@ -252,7 +291,9 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, /* * Copy in user parameters */ - memcpy(&ConnectInfoLength, uConnectInfoLength, sizeof(*uConnectInfoLength)); + memcpy(&ConnectInfoLength, + UserConnectInfoLength, + sizeof(*UserConnectInfoLength)); /* * Get access to the port @@ -285,12 +326,15 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, */ DPRINT("Creating request message\n"); - Request.ActualMessageLength = ConnectInfoLength; - Request.TotalMessageLength = sizeof(LPCMESSAGE) + ConnectInfoLength; - Request.SharedSectionSize = 0; + Request = ExAllocatePool(NonPagedPool, + sizeof(LPC_MESSAGE) + ConnectInfoLength); + + Request->DataSize = ConnectInfoLength; + Request->MessageSize = sizeof(LPC_MESSAGE) + ConnectInfoLength; + Request->SharedSectionSize = 0; if (ConnectInfo != NULL && ConnectInfoLength > 0) { - memcpy(Request.MessageData, ConnectInfo, ConnectInfoLength); + memcpy((PVOID)(Request + 1), ConnectInfo, ConnectInfoLength); } /* @@ -298,7 +342,7 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, */ DPRINT("Queuing message\n"); - EiReplyOrRequestPort(NamedPort, &Request, LPC_CONNECTION_REQUEST, OurPort); + EiReplyOrRequestPort(NamedPort, Request, LPC_CONNECTION_REQUEST, OurPort); KeSetEvent(&NamedPort->Event, IO_NO_INCREMENT, FALSE); DPRINT("Waiting for connection completion\n"); @@ -316,19 +360,25 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, KeAcquireSpinLock(&OurPort->Lock, &oldIrql); Reply = EiDequeueMessagePort(OurPort); KeReleaseSpinLock(&OurPort->Lock, oldIrql); - memcpy(ConnectInfo, Reply->Message.MessageData, - Reply->Message.ActualMessageLength); - *uConnectInfoLength = Reply->Message.ActualMessageLength; + memcpy(ConnectInfo, + Reply->MessageData, + Reply->Message.DataSize); + *UserConnectInfoLength = Reply->Message.DataSize; if (Reply->Message.MessageType == LPC_CONNECTION_REFUSED) { + ObDereferenceObject(NamedPort); + ObDereferenceObject(OurPort); ZwClose(OurPortHandle); + ExFreePool(Request); ExFreePool(Reply); return(STATUS_UNSUCCESSFUL); } - *ConnectedPort = OurPortHandle; + OurPort->State = EPORT_CONNECTED_CLIENT; + *ConnectedPort = OurPortHandle; ExFreePool(Reply); + ExFreePool(Request); DPRINT("Exited successfully\n"); @@ -338,10 +388,10 @@ NTSTATUS STDCALL NtConnectPort (OUT PHANDLE ConnectedPort, NTSTATUS STDCALL NtAcceptConnectPort (PHANDLE ServerPortHandle, HANDLE NamedPortHandle, - PLPCMESSAGE LpcMessage, - ULONG AcceptIt, - ULONG Unknown2, - PLPCSECTIONMAPINFO MapInfo) + PLPC_MESSAGE LpcMessage, + BOOLEAN AcceptIt, + PLPC_SECTION_WRITE WriteMap, + PLPC_SECTION_READ ReadMap) { NTSTATUS Status; PEPORT NamedPort; @@ -386,7 +436,8 @@ NTSTATUS STDCALL NtAcceptConnectPort (PHANDLE ServerPortHandle, LPC_CONNECTION_REFUSED, NamedPort); KeSetEvent(&ConnectionRequest->Sender->Event, IO_NO_INCREMENT, FALSE); - ExFreePool(ConnectionRequest); + ObDereferenceObject(ConnectionRequest->Sender); + ExFreePool(ConnectionRequest); ObDereferenceObject(NamedPort); return(STATUS_SUCCESS); } @@ -402,6 +453,7 @@ NTSTATUS STDCALL NtAcceptConnectPort (PHANDLE ServerPortHandle, OurPort); ExFreePool(ConnectionRequest); + ObDereferenceObject(OurPort); ObDereferenceObject(NamedPort); return(STATUS_SUCCESS); @@ -428,20 +480,22 @@ NTSTATUS STDCALL NtCompleteConnectPort (HANDLE PortHandle) KeSetEvent(&OurPort->OtherPort->Event, IO_NO_INCREMENT, FALSE); + OurPort->State = EPORT_CONNECTED_SERVER; + ObDereferenceObject(OurPort); return(STATUS_SUCCESS); } -NTSTATUS STDCALL NtImpersonateClientOfPort (IN HANDLE PortHandle, - IN PLPCMESSAGE ClientMessage) +NTSTATUS STDCALL NtImpersonateClientOfPort (HANDLE PortHandle, + PLPC_MESSAGE ClientMessage) { UNIMPLEMENTED; } NTSTATUS STDCALL NtListenPort (IN HANDLE PortHandle, - IN PLPCMESSAGE ConnectMsg) + IN PLPC_MESSAGE ConnectMsg) /* * FUNCTION: Listen on a named port and wait for a connection attempt */ @@ -466,17 +520,17 @@ NTSTATUS STDCALL NtListenPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtQueryInformationPort (IN HANDLE PortHandle, - IN CINT PortInformationClass, /* guess */ - OUT PVOID PortInformation, /* guess */ - IN ULONG PortInformationLength, /* guess */ - OUT PULONG ReturnLength /* guess */) + IN CINT PortInformationClass, + OUT PVOID PortInformation, + IN ULONG PortInformationLength, + OUT PULONG ReturnLength) { UNIMPLEMENTED; } NTSTATUS STDCALL NtReplyPort (IN HANDLE PortHandle, - IN PLPCMESSAGE LpcReply) + IN PLPC_MESSAGE LpcReply) { NTSTATUS Status; PEPORT Port; @@ -507,10 +561,10 @@ NTSTATUS STDCALL NtReplyPort (IN HANDLE PortHandle, } -NTSTATUS STDCALL NtReplyWaitReceivePort (IN HANDLE PortHandle, - PVOID Unknown, - IN PLPCMESSAGE LpcReply, - OUT PLPCMESSAGE LpcMessage) +NTSTATUS STDCALL NtReplyWaitReceivePort (HANDLE PortHandle, + PULONG PortId, + PLPC_MESSAGE LpcReply, + PLPC_MESSAGE LpcMessage) { NTSTATUS Status; PEPORT Port; @@ -566,7 +620,7 @@ NTSTATUS STDCALL NtReplyWaitReceivePort (IN HANDLE PortHandle, */ KeAcquireSpinLock(&Port->Lock, &oldIrql); Request = EiDequeueMessagePort(Port); - memcpy(LpcMessage, &Request->Message, sizeof(*LpcMessage)); + memcpy(LpcMessage, &Request->Message, Request->Message.MessageSize); if (Request->Message.MessageType == LPC_CONNECTION_REQUEST) { EiEnqueueConnectMessagePort(Port, Request); @@ -585,8 +639,23 @@ NTSTATUS STDCALL NtReplyWaitReceivePort (IN HANDLE PortHandle, return(STATUS_SUCCESS); } +NTSTATUS STDCALL LpcSendTerminationPort(PEPORT Port, + TIME CreationTime) +{ + NTSTATUS Status; + LPC_TERMINATION_MESSAGE Msg; + + Msg.CreationTime = CreationTime; + Status = EiReplyOrRequestPort(Port, + &Msg.Header, + LPC_DATAGRAM, + NULL); + KeSetEvent(&Port->Event, IO_NO_INCREMENT, FALSE); + return(STATUS_SUCCESS); +} + NTSTATUS STDCALL LpcRequestPort(PEPORT Port, - PLPCMESSAGE LpcMessage) + PLPC_MESSAGE LpcMessage) { NTSTATUS Status; @@ -602,7 +671,7 @@ NTSTATUS STDCALL LpcRequestPort(PEPORT Port, } NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle, - IN PLPCMESSAGE LpcMessage /* guess */) + IN PLPC_MESSAGE LpcMessage) { NTSTATUS Status; PEPORT Port; @@ -630,8 +699,8 @@ NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle, NTSTATUS STDCALL NtRequestWaitReplyPort(IN HANDLE PortHandle, - PLPCMESSAGE LpcRequest, - PLPCMESSAGE LpcReply) + PLPC_MESSAGE LpcRequest, + PLPC_MESSAGE LpcReply) { NTSTATUS Status; PEPORT Port; @@ -661,6 +730,7 @@ NTSTATUS STDCALL NtRequestWaitReplyPort(IN HANDLE PortHandle, if (!NT_SUCCESS(Status)) { + DbgPrint("Enqueue failed\n"); ObDereferenceObject(Port); return(Status); } @@ -680,70 +750,38 @@ NTSTATUS STDCALL NtRequestWaitReplyPort(IN HANDLE PortHandle, KeAcquireSpinLock(&Port->Lock, &oldIrql); Message = EiDequeueMessagePort(Port); KeReleaseSpinLock(&Port->Lock, oldIrql); - memcpy(LpcReply, &Message->Message, sizeof(*LpcReply)); + DPRINT("Message->Message.MessageSize %d\n", + Message->Message.MessageSize); + memcpy(LpcReply, &Message->Message, Message->Message.MessageSize); ExFreePool(Message); + ObDereferenceObject(Port); + return(STATUS_SUCCESS); } -NTSTATUS STDCALL NtReplyWaitReplyPort(PVOID a, PVOID b) +NTSTATUS STDCALL NtReplyWaitReplyPort(HANDLE PortHandle, + PLPC_MESSAGE ReplyMessage) { UNIMPLEMENTED; } -/********************************************************************** - * NAME SYSTEM - * NtReadRequestData NOT EXPORTED - * - * DESCRIPTION - * Probably used only for FastLPC, to read data from the - * recipient's address space directly. - * - * ARGUMENTS - * - * RETURN VALUE - * - * NOTE - * The number of arguments is the same as in NT's. - * - * REVISIONS - * - */ -NTSTATUS STDCALL NtReadRequestData (DWORD a0, - DWORD a1, - DWORD a2, - DWORD a3, - DWORD a4, - DWORD a5) +NTSTATUS STDCALL NtReadRequestData (HANDLE PortHandle, + PLPC_MESSAGE Message, + ULONG Index, + PVOID Buffer, + ULONG BufferLength, + PULONG Returnlength) { UNIMPLEMENTED; } - -/********************************************************************** - * NAME SYSTEM - * NtWriteRequestData NOT EXPORTED - * - * DESCRIPTION - * Probably used only for FastLPC, to write data in the - * recipient's address space directly. - * - * ARGUMENTS - * - * RETURN VALUE - * - * NOTE - * The number of arguments is the same as in NT's. - * - * REVISIONS - * - */ -NTSTATUS STDCALL NtWriteRequestData (DWORD a0, - DWORD a1, - DWORD a2, - DWORD a3, - DWORD a4, - DWORD a5) +NTSTATUS STDCALL NtWriteRequestData (HANDLE PortHandle, + PLPC_MESSAGE Message, + ULONG Index, + PVOID Buffer, + ULONG BufferLength, + PULONG ReturnLength) { UNIMPLEMENTED; } diff --git a/reactos/ntoskrnl/ob/handle.c b/reactos/ntoskrnl/ob/handle.c index a6c100846d8..9a8cb2e18ed 100644 --- a/reactos/ntoskrnl/ob/handle.c +++ b/reactos/ntoskrnl/ob/handle.c @@ -1,4 +1,4 @@ -/* $Id: handle.c,v 1.19 2000/03/26 22:00:09 dwelch Exp $ +/* $Id: handle.c,v 1.20 2000/04/03 21:54:40 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -464,8 +464,8 @@ NTSTATUS ObReferenceObjectByHandle(HANDLE Handle, ASSERT_IRQL(PASSIVE_LEVEL); DPRINT("ObReferenceObjectByHandle(Handle %x, DesiredAccess %x, " - "ObjectType %x, AccessMode %d, Object %x)\n",Handle,DesiredAccess, - ObjectType,AccessMode,Object); + "ObjectType %x, AccessMode %d, Object %x)\n",Handle,DesiredAccess, + ObjectType,AccessMode,Object); /* @@ -474,6 +474,8 @@ NTSTATUS ObReferenceObjectByHandle(HANDLE Handle, if (Handle == NtCurrentProcess() && (ObjectType == PsProcessType || ObjectType == NULL)) { + DPRINT("Reference from %x\n", ((PULONG)&Handle)[-1]); + ObReferenceObjectByPointer(PsGetCurrentProcess(), PROCESS_ALL_ACCESS, PsProcessType, @@ -531,6 +533,11 @@ NTSTATUS ObReferenceObjectByHandle(HANDLE Handle, return(STATUS_OBJECT_TYPE_MISMATCH); } + if (ObjectHeader->ObjectType == PsProcessType) + { + DPRINT("Reference from %x\n", ((PULONG)&Handle)[-1]); + } + if (!(GrantedAccess & DesiredAccess) && !((~GrantedAccess) & DesiredAccess)) { diff --git a/reactos/ntoskrnl/ob/object.c b/reactos/ntoskrnl/ob/object.c index eaf13d0b861..4080edb0cd7 100644 --- a/reactos/ntoskrnl/ob/object.c +++ b/reactos/ntoskrnl/ob/object.c @@ -1,4 +1,4 @@ -/* $Id: object.c,v 1.21 2000/02/20 22:52:49 ea Exp $ +/* $Id: object.c,v 1.22 2000/04/03 21:54:40 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -334,24 +334,20 @@ ULONG ObGetHandleCount(PVOID ObjectBody) * RETURN VALUE * The current value of the reference counter. */ -ULONG -FASTCALL -ObfReferenceObject (PVOID ObjectBody) +ULONG FASTCALL ObfReferenceObject(PVOID ObjectBody) { - POBJECT_HEADER Header = BODY_TO_HEADER(ObjectBody); - ULONG ReferenceCount; - - ReferenceCount = ++ Header->RefCount; + POBJECT_HEADER Header = BODY_TO_HEADER(ObjectBody); + ULONG ReferenceCount; - ObPerformRetentionChecks (Header); - - return (ReferenceCount); + ReferenceCount = Header->RefCount++; + + ObPerformRetentionChecks (Header); + + return(ReferenceCount); } -VOID -FASTCALL -ObfDereferenceObject (PVOID ObjectBody) +VOID FASTCALL ObfDereferenceObject (PVOID ObjectBody) /* * FUNCTION: Decrements a given object's reference count and performs * retention checks @@ -384,11 +380,19 @@ ObfDereferenceObject (PVOID ObjectBody) } -VOID -STDCALL -ObDereferenceObject (PVOID ObjectBody) +VOID STDCALL ObDereferenceObject (PVOID ObjectBody) { - ObfDereferenceObject (ObjectBody); + POBJECT_HEADER Header = BODY_TO_HEADER(ObjectBody); + extern POBJECT_TYPE PsProcessType; + + if (Header->ObjectType == PsProcessType) + { + DPRINT("Deref p 0x%x with refcount %d type %x ", + ObjectBody, Header->RefCount, PsProcessType); + DPRINT("eip %x\n", ((PULONG)&ObjectBody)[-1]); + } + + ObfDereferenceObject (ObjectBody); } diff --git a/reactos/ntoskrnl/ps/create.c b/reactos/ntoskrnl/ps/create.c index 07c54f2fbcb..b794729fe68 100644 --- a/reactos/ntoskrnl/ps/create.c +++ b/reactos/ntoskrnl/ps/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.12 2000/03/22 18:35:57 dwelch Exp $ +/* $Id: create.c,v 1.13 2000/04/03 21:54:40 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -368,14 +368,13 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle, KeInitializeDpc(&Thread->Tcb.TimerDpc, PiTimeoutThread, Thread); Thread->Tcb.WaitBlockList = NULL; InsertTailList(&Thread->ThreadsProcess->Pcb.ThreadListHead, - &Thread->Tcb.ProcessThreadListEntry ); -// DPRINT1("Inserting %x into process %x list\n", -// Thread, Thread->ThreadsProcess); + &Thread->Tcb.ProcessThreadListEntry); + InitializeListHead(&Thread->TerminationPortList); KeInitializeDispatcherHeader(&Thread->Tcb.DispatcherHeader, InternalThreadType, sizeof(ETHREAD), FALSE); - + KeInitializeSpinLock(&Thread->ActiveTimerListLock); InitializeListHead(&Thread->IrpList); Thread->Cid.UniqueThread = (HANDLE)InterlockedIncrement( &PiNextThreadUniqueId); diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index bc155bc56fe..c6fe783cd74 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -15,6 +15,7 @@ #include #include #include +#include #define NDEBUG #include @@ -170,8 +171,8 @@ VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus) NTSTATUS STDCALL PiTerminateProcess(PEPROCESS Process, NTSTATUS ExitStatus) { - DPRINT("PiTerminateProcess(Process %x, ExitStatus %x)\n", - Process, ExitStatus); + DPRINT1("PiTerminateProcess(Process %x, ExitStatus %x) RC %d\n", + Process, ExitStatus, ObGetReferenceCount(Process)); if (Process->Pcb.ProcessState == PROCESS_STATE_TERMINATED) { @@ -185,6 +186,7 @@ NTSTATUS STDCALL PiTerminateProcess(PEPROCESS Process, Process->Pcb.DispatcherHeader.SignalState = TRUE; KeDispatcherObjectWake(&Process->Pcb.DispatcherHeader); KeReleaseDispatcherDatabaseLock(FALSE); + DPRINT("RC %d\n", ObGetReferenceCount(Process)); return(STATUS_SUCCESS); } @@ -262,8 +264,53 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) return(STATUS_SUCCESS); } - -NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort) +NTSTATUS STDCALL NtCallTerminatePorts(PETHREAD Thread) { - UNIMPLEMENTED; + KIRQL oldIrql; + PLIST_ENTRY current_entry; + PEPORT_TERMINATION_REQUEST current; + + KeAcquireSpinLock(&Thread->ActiveTimerListLock, &oldIrql); + while ((current_entry = RemoveHeadList(&Thread->TerminationPortList)) != + &Thread->TerminationPortList); + { + current = CONTAINING_RECORD(current_entry, + EPORT_TERMINATION_REQUEST, + ThreadListEntry); + KeReleaseSpinLock(&Thread->ActiveTimerListLock, oldIrql); + LpcSendTerminationPort(current->Port, + Thread->CreateTime); + KeAcquireSpinLock(&Thread->ActiveTimerListLock, &oldIrql); + } + KeReleaseSpinLock(&Thread->ActiveTimerListLock, oldIrql); + return(STATUS_SUCCESS); +} + +NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPortHandle) +{ + NTSTATUS Status; + PEPORT_TERMINATION_REQUEST Request; + PEPORT TerminationPort; + KIRQL oldIrql; + PETHREAD Thread; + + Status = ObReferenceObjectByHandle(TerminationPortHandle, + PORT_ALL_ACCESS, + ExPortType, + UserMode, + (PVOID*)&TerminationPort, + NULL); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + Request = ExAllocatePool(NonPagedPool, sizeof(Request)); + Request->Port = TerminationPort; + Thread = PsGetCurrentThread(); + KeAcquireSpinLock(&Thread->ActiveTimerListLock, &oldIrql); + InsertTailList(&Thread->TerminationPortList, &Request->ThreadListEntry); + KeReleaseSpinLock(&Thread->ActiveTimerListLock, oldIrql); + + return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index e60ccd043f2..85499458255 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -186,7 +186,7 @@ VOID PiDeleteProcess(PVOID ObjectBody) { KIRQL oldIrql; - DPRINT("PiDeleteProcess(ObjectBody %x)\n",ObjectBody); + DPRINT1("PiDeleteProcess(ObjectBody %x)\n",ObjectBody); KeAcquireSpinLock(&PsProcessListLock, &oldIrql); RemoveEntryList(&((PEPROCESS)ObjectBody)->Pcb.ProcessListEntry); diff --git a/reactos/subsys/csrss/api.h b/reactos/subsys/csrss/api.h index 8ed376264f9..6954fae3e63 100644 --- a/reactos/subsys/csrss/api.h +++ b/reactos/subsys/csrss/api.h @@ -25,31 +25,31 @@ VOID CsrInitProcessData(VOID); NTSTATUS CsrCreateProcess (PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CREATE_PROCESS_REQUEST Request, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); NTSTATUS CsrTerminateProcess(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); NTSTATUS CsrWriteConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); NTSTATUS CsrAllocConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); NTSTATUS CsrFreeConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); NTSTATUS CsrReadConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); NTSTATUS CsrConnectProcess(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST Request, - PLPCMESSAGE* Reply); + PCSRSS_API_REPLY Reply); /* print.c */ VOID DisplayString(LPCWSTR lpwString); diff --git a/reactos/subsys/csrss/api/conio.c b/reactos/subsys/csrss/api/conio.c index a0eb811f1d3..03edb3bb3e4 100644 --- a/reactos/subsys/csrss/api/conio.c +++ b/reactos/subsys/csrss/api/conio.c @@ -1,4 +1,4 @@ -/* $Id: conio.c,v 1.3 2000/03/22 18:35:59 dwelch Exp $ +/* $Id: conio.c,v 1.4 2000/04/03 21:54:41 dwelch Exp $ * * reactos/subsys/csrss/api/conio.c * @@ -23,53 +23,40 @@ static HANDLE KeyboardDeviceHandle; NTSTATUS CsrAllocConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY LpcReply) { - PCSRSS_API_REPLY Reply; - - (*LpcReply) = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY); - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); + LpcReply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + LpcReply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + sizeof(LPC_MESSAGE_HEADER); - Reply->Status = STATUS_NOT_IMPLEMENTED; + LpcReply->Status = STATUS_NOT_IMPLEMENTED; return(STATUS_NOT_IMPLEMENTED); } NTSTATUS CsrFreeConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY LpcReply) { - PCSRSS_API_REPLY Reply; - - (*LpcReply) = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY); - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); + LpcReply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + LpcReply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + sizeof(LPC_MESSAGE_HEADER); - Reply->Status = STATUS_NOT_IMPLEMENTED; + LpcReply->Status = STATUS_NOT_IMPLEMENTED; return(STATUS_NOT_IMPLEMENTED); } NTSTATUS CsrReadConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY LpcReply) { KEY_EVENT_RECORD KeyEventRecord; - BOOL stat = TRUE; PCHAR Buffer; - DWORD Result; int i; ULONG nNumberOfCharsToRead; NTSTATUS Status; IO_STATUS_BLOCK Iosb; - PCSRSS_API_REPLY Reply; // DbgPrint("CSR: CsrReadConsole()\n"); @@ -78,14 +65,11 @@ NTSTATUS CsrReadConsole(PCSRSS_PROCESS_DATA ProcessData, // DbgPrint("CSR: NrCharactersToRead %d\n", nNumberOfCharsToRead); - (*LpcReply) = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY) + + LpcReply->Header.MessageSize = sizeof(CSRSS_API_REPLY) + nNumberOfCharsToRead; - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); - Buffer = Reply->Data.ReadConsoleReply.Buffer; + LpcReply->Header.DataSize = LpcReply->Header.MessageSize - + sizeof(LPC_MESSAGE_HEADER); + Buffer = LpcReply->Data.ReadConsoleReply.Buffer; Status = STATUS_SUCCESS; @@ -104,35 +88,31 @@ NTSTATUS CsrReadConsole(PCSRSS_PROCESS_DATA ProcessData, 0); if (!NT_SUCCESS(Status)) { - DbgPrint("CSR: Read failed, bailing\n"); +// DbgPrint("CSR: Read failed, bailing\n"); } if (KeyEventRecord.bKeyDown && KeyEventRecord.uChar.AsciiChar != 0) { Buffer[i] = KeyEventRecord.uChar.AsciiChar; - //DbgPrint("CSR: Read '%c'\n", Buffer[i]); +// DbgPrint("CSR: Read '%c'\n", Buffer[i]); i++; } } - Reply->Data.ReadConsoleReply.NrCharactersRead = i; - Reply->Status = Status; + LpcReply->Data.ReadConsoleReply.NrCharactersRead = i; + LpcReply->Status = Status; return(Status); } NTSTATUS CsrWriteConsole(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST Message, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY LpcReply) { IO_STATUS_BLOCK Iosb; NTSTATUS Status; - PCSRSS_API_REPLY Reply; - (*LpcReply) = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY); - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); + LpcReply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + LpcReply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + sizeof(LPC_MESSAGE_HEADER); // DbgPrint("CSR: CsrWriteConsole()\n"); // DbgPrint("CSR: ConsoleDeviceHandle %x\n", ConsoleDeviceHandle); @@ -155,8 +135,8 @@ NTSTATUS CsrWriteConsole(PCSRSS_PROCESS_DATA ProcessData, // DbgPrint("CSR: Write failed\n"); return(Status); } - Reply->Data.WriteConsoleReply.NrCharactersWritten = Iosb.Information; - Reply->Status = STATUS_SUCCESS; + LpcReply->Data.WriteConsoleReply.NrCharactersWritten = Iosb.Information; + LpcReply->Status = STATUS_SUCCESS; return(STATUS_SUCCESS); } @@ -207,7 +187,6 @@ VOID CsrInitConsoleSupport(VOID) if (!NT_SUCCESS(Status)) { DbgPrint("CSR: Failed to open keyboard. Expect problems.\n"); - for(;;); } DbgPrint("CSR: KeyboardDeviceHandle %x\n", KeyboardDeviceHandle); diff --git a/reactos/subsys/csrss/api/process.c b/reactos/subsys/csrss/api/process.c index d06ea0a0e54..ceb07e5e253 100644 --- a/reactos/subsys/csrss/api/process.c +++ b/reactos/subsys/csrss/api/process.c @@ -1,4 +1,4 @@ -/* $Id: process.c,v 1.6 2000/03/22 18:36:00 dwelch Exp $ +/* $Id: process.c,v 1.7 2000/04/03 21:54:41 dwelch Exp $ * * reactos/subsys/csrss/api/process.c * @@ -60,24 +60,20 @@ PCSRSS_PROCESS_DATA CsrGetProcessData(ULONG ProcessId) return(ProcessData[i]); } } - DbgPrint("CSR: CsrGetProcessData() failed\n"); +// DbgPrint("CSR: CsrGetProcessData() failed\n"); return(NULL); } NTSTATUS CsrCreateProcess (PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CREATE_PROCESS_REQUEST Request, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY Reply) { PCSRSS_PROCESS_DATA NewProcessData; - PCSRSS_API_REPLY Reply; - (*LpcReply) = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY); - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + sizeof(LPC_MESSAGE_HEADER); + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); NewProcessData = CsrGetProcessData(Request->NewProcessId); @@ -111,25 +107,21 @@ NTSTATUS CsrCreateProcess (PCSRSS_PROCESS_DATA ProcessData, &Reply->Data.CreateProcessReply.ConsoleHandle, NewProcessData->Console); - DbgPrint("CSR: ConsoleHandle %x\n", - Reply->Data.CreateProcessReply.ConsoleHandle); - DisplayString(L"CSR: Did CreateProcess successfully\n"); +// DbgPrint("CSR: ConsoleHandle %x\n", +// Reply->Data.CreateProcessReply.ConsoleHandle); +// DisplayString(L"CSR: Did CreateProcess successfully\n"); +// DbgPrint("Reply->Header.MessageSize %d\n", Reply->Header.MessageSize); return(STATUS_SUCCESS); } NTSTATUS CsrTerminateProcess(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST LpcMessage, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY Reply) { - PCSRSS_API_REPLY Reply; - - (*LpcReply) = (PLPCMESSAGE)RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY); - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY) + - sizeof(LPC_MESSAGE_HEADER); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY); Reply->Status = STATUS_NOT_IMPLEMENTED; @@ -138,16 +130,11 @@ NTSTATUS CsrTerminateProcess(PCSRSS_PROCESS_DATA ProcessData, NTSTATUS CsrConnectProcess(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_API_REQUEST Request, - PLPCMESSAGE* LpcReply) + PCSRSS_API_REPLY Reply) { - PCSRSS_API_REPLY Reply; - - (*LpcReply) = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - (*LpcReply)->ActualMessageLength = sizeof(CSRSS_API_REPLY); - (*LpcReply)->TotalMessageLength = sizeof(LPCMESSAGE); - Reply = (PCSRSS_API_REPLY)((*LpcReply)->MessageData); + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + sizeof(LPC_MESSAGE_HEADER); Reply->Status = STATUS_SUCCESS; diff --git a/reactos/subsys/csrss/api/wapi.c b/reactos/subsys/csrss/api/wapi.c index 4c9e0fbfb8d..6187d0899f7 100644 --- a/reactos/subsys/csrss/api/wapi.c +++ b/reactos/subsys/csrss/api/wapi.c @@ -1,4 +1,4 @@ -/* $Id: wapi.c,v 1.5 2000/03/22 18:36:00 dwelch Exp $ +/* $Id: wapi.c,v 1.6 2000/04/03 21:54:41 dwelch Exp $ * * reactos/subsys/csrss/api/wapi.c * @@ -25,36 +25,37 @@ HANDLE CsrssApiHeap; static void Thread_Api2(HANDLE ServerPort) { NTSTATUS Status; - PLPCMESSAGE LpcReply; - LPCMESSAGE LpcRequest; + LPC_MAX_MESSAGE LpcReply; + LPC_MAX_MESSAGE LpcRequest; PCSRSS_API_REQUEST Request; PCSRSS_PROCESS_DATA ProcessData; PCSRSS_API_REPLY Reply; - LpcReply = NULL; + Reply = NULL; for (;;) { Status = NtReplyWaitReceivePort(ServerPort, 0, - LpcReply, - &LpcRequest); + &Reply->Header, + &LpcRequest.Header); if (!NT_SUCCESS(Status)) { DisplayString(L"CSR: NtReplyWaitReceivePort failed\n"); } - if (LpcReply != NULL) + + if (LpcRequest.Header.MessageType == LPC_PORT_CLOSED) { - RtlFreeHeap(CsrssApiHeap, - 0, - LpcReply); +// DbgPrint("Client closed port\n"); + NtClose(ServerPort); + NtTerminateThread(NtCurrentThread(), STATUS_SUCCESS); } - Request = (PCSRSS_API_REQUEST)LpcRequest.MessageData; - LpcReply = NULL; - Reply = NULL; + Request = (PCSRSS_API_REQUEST)&LpcRequest; + Reply = (PCSRSS_API_REPLY)&LpcReply; - ProcessData = CsrGetProcessData(LpcRequest.ClientProcessId); + ProcessData = CsrGetProcessData( + (ULONG)LpcRequest.Header.Cid.UniqueProcess); // DisplayString(L"CSR: Received request\n"); @@ -63,58 +64,51 @@ static void Thread_Api2(HANDLE ServerPort) case CSRSS_CREATE_PROCESS: Status = CsrCreateProcess(ProcessData, &Request->Data.CreateProcessRequest, - &LpcReply); + Reply); break; case CSRSS_TERMINATE_PROCESS: Status = CsrTerminateProcess(ProcessData, Request, - &LpcReply); + Reply); break; case CSRSS_WRITE_CONSOLE: Status = CsrWriteConsole(ProcessData, Request, - &LpcReply); + Reply); break; case CSRSS_READ_CONSOLE: Status = CsrReadConsole(ProcessData, Request, - &LpcReply); + Reply); break; case CSRSS_ALLOC_CONSOLE: Status = CsrAllocConsole(ProcessData, Request, - &LpcReply); + Reply); break; case CSRSS_FREE_CONSOLE: Status = CsrFreeConsole(ProcessData, Request, - &LpcReply); + Reply); break; case CSRSS_CONNECT_PROCESS: Status = CsrConnectProcess(ProcessData, Request, - &LpcReply); + Reply); break; default: - LpcReply = RtlAllocateHeap(CsrssApiHeap, - HEAP_ZERO_MEMORY, - sizeof(LPCMESSAGE)); - Reply = (PCSRSS_API_REPLY)(LpcReply->MessageData); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + sizeof(LPC_MESSAGE_HEADER); + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); Reply->Status = STATUS_NOT_IMPLEMENTED; } - - Reply = (PCSRSS_API_REPLY)(LpcReply->MessageData); - if (Reply->Status == STATUS_SUCCESS) - { -// DisplayString(L"CSR: Returning STATUS_SUCCESS\n"); - } } } @@ -129,8 +123,9 @@ static void Thread_Api2(HANDLE ServerPort) void Thread_Api(PVOID PortHandle) { NTSTATUS Status; - LPCMESSAGE Request; + LPC_MAX_MESSAGE Request; HANDLE ServerPort; + HANDLE ServerThread; CsrssApiHeap = RtlCreateHeap(HEAP_GROWABLE, NULL, @@ -149,7 +144,7 @@ void Thread_Api(PVOID PortHandle) for (;;) { - Status = NtListenPort(PortHandle, &Request); + Status = NtListenPort(PortHandle, &Request.Header); if (!NT_SUCCESS(Status)) { DisplayString(L"CSR: NtListenPort() failed\n"); @@ -183,7 +178,7 @@ void Thread_Api(PVOID PortHandle) NULL, (PTHREAD_START_ROUTINE)Thread_Api2, ServerPort, - NULL, + &ServerThread, NULL); if (!NT_SUCCESS(Status)) { @@ -191,6 +186,7 @@ void Thread_Api(PVOID PortHandle) NtClose(ServerPort); NtTerminateThread(NtCurrentThread(), Status); } + NtClose(ServerThread); } } diff --git a/reactos/subsys/smss/init.c b/reactos/subsys/smss/init.c index e84590fedea..1f4f75b82c6 100644 --- a/reactos/subsys/smss/init.c +++ b/reactos/subsys/smss/init.c @@ -1,4 +1,4 @@ -/* $Id: init.c,v 1.16 2000/03/22 18:36:00 dwelch Exp $ +/* $Id: init.c,v 1.17 2000/04/03 21:54:41 dwelch Exp $ * * init.c - Session Manager initialization * @@ -28,6 +28,7 @@ */ #include #include +#include #include "smss.h" diff --git a/reactos/subsys/smss/smapi.c b/reactos/subsys/smss/smapi.c index e74d0b4aea4..a66ad9556dc 100644 --- a/reactos/subsys/smss/smapi.c +++ b/reactos/subsys/smss/smapi.c @@ -1,4 +1,4 @@ -/* $Id: smapi.c,v 1.3 1999/12/28 16:25:21 ekohl Exp $ +/* $Id: smapi.c,v 1.4 2000/04/03 21:54:42 dwelch Exp $ * * Reactos Session Manager * @@ -6,7 +6,7 @@ */ #include - +#include #include "smss.h" @@ -18,8 +18,8 @@ SmApiThread (HANDLE Port) { NTSTATUS Status; ULONG Unknown; - PLPCMESSAGE Reply = NULL; - LPCMESSAGE Message; + PLPC_MESSAGE Reply = NULL; + LPC_MESSAGE Message; #ifndef NDEBUG DisplayString (L"SmApiThread: running\n");