3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/csr/lpc.c
6 * PURPOSE: CSRSS Client/Server LPC API
10 * File api.c renamed lpc.c. Process/thread code moved
11 * in thread.c. Check added on the LPC port.
14 /* INCLUDES *****************************************************************/
16 #include <ddk/ntddk.h>
17 #include <ntdll/csr.h>
20 #include <csrss/csrss.h>
23 #include <ntdll/ntdll.h>
25 /* GLOBALS *******************************************************************/
27 HANDLE WindowsApiPort = INVALID_HANDLE_VALUE;
28 static PVOID CsrSectionMapBase = NULL;
29 static PVOID CsrSectionMapServerBase = NULL;
30 static HANDLE CsrCommHeap = NULL;
32 #define CSR_CONTROL_HEAP_SIZE (65536)
34 /* FUNCTIONS *****************************************************************/
36 /* Possible CsrClientCallServer (the NT one):
38 #define CSR_CCS_NATIVE 0x0000
39 #define CSR_CCS_CSR 0x0001
40 #define CSR_CCS_GUI 0x0002
42 typedef union _CSR_CCS_API
44 WORD Index; // CSRSS API number
45 WORD Subsystem; // 0=NTDLL;1=KERNEL32;2=KERNEL32
47 } CSR_CCS_API, * PCSR_CCS_API;
50 CsrClientCallServer(PVOID Request,
51 PVOID Unknown OPTIONAL,
55 Request is the family of PCSRSS_XXX_REQUEST objects.
56 XXX_REQUEST depend on the CsrApiNumber.Index.
61 CsrCaptureParameterBuffer(PVOID ParameterBuffer,
62 ULONG ParameterBufferSize,
68 Block = RtlAllocateHeap(CsrCommHeap, 0, ParameterBufferSize);
71 return(STATUS_NO_MEMORY);
73 memcpy(Block, ParameterBuffer, ParameterBufferSize);
74 *ClientAddress = Block;
75 *ServerAddress = Block - CsrSectionMapBase + CsrSectionMapServerBase;
76 return(STATUS_SUCCESS);
80 CsrReleaseParameterBuffer(PVOID ClientAddress)
82 RtlFreeHeap(CsrCommHeap, 0, ClientAddress);
83 return(STATUS_SUCCESS);
90 CsrClientCallServer(PCSRSS_API_REQUEST Request,
91 PCSRSS_API_REPLY Reply OPTIONAL,
97 if (INVALID_HANDLE_VALUE == WindowsApiPort)
99 DbgPrint ("NTDLL.%s: client not connected to CSRSS!\n", __FUNCTION__);
100 return (STATUS_UNSUCCESSFUL);
103 Request->Header.DataSize = Length - sizeof(LPC_MESSAGE);
104 Request->Header.MessageSize = Length;
106 Status = NtRequestWaitReplyPort(WindowsApiPort,
108 (Reply?&Reply->Header:&Request->Header));
117 CsrClientConnectToServer(VOID)
120 UNICODE_STRING PortName;
121 ULONG ConnectInfoLength;
122 CSRSS_API_REQUEST Request;
123 CSRSS_API_REPLY Reply;
124 LPC_SECTION_WRITE LpcWrite;
125 HANDLE CsrSectionHandle;
126 LARGE_INTEGER CsrSectionViewSize;
128 CsrSectionViewSize.QuadPart = CSR_CSRSS_SECTION_SIZE;
129 Status = NtCreateSection(&CsrSectionHandle,
136 if (!NT_SUCCESS(Status))
140 RtlInitUnicodeStringFromLiteral(&PortName, L"\\Windows\\ApiPort");
141 ConnectInfoLength = 0;
142 LpcWrite.Length = sizeof(LPC_SECTION_WRITE);
143 LpcWrite.SectionHandle = CsrSectionHandle;
144 LpcWrite.SectionOffset = 0;
145 LpcWrite.ViewSize = CsrSectionViewSize.u.LowPart;
146 Status = NtConnectPort(&WindowsApiPort,
154 if (!NT_SUCCESS(Status))
159 NtClose(CsrSectionHandle);
160 CsrSectionMapBase = LpcWrite.ViewBase;
161 CsrSectionMapServerBase = LpcWrite.TargetViewBase;
163 /* Create the heap for communication for csrss. */
164 CsrCommHeap = RtlCreateHeap(HEAP_NO_VALLOC,
166 CsrSectionViewSize.u.LowPart,
167 CsrSectionViewSize.u.LowPart,
170 if (CsrCommHeap == NULL)
172 return(STATUS_NO_MEMORY);
175 Request.Type = CSRSS_CONNECT_PROCESS;
176 Status = CsrClientCallServer(&Request,
178 sizeof(CSRSS_API_REQUEST),
179 sizeof(CSRSS_API_REPLY));
180 if (!NT_SUCCESS(Status))
184 if (!NT_SUCCESS(Reply.Status))
186 return(Reply.Status);
188 return(STATUS_SUCCESS);