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);
87 CsrClientCallServer(PCSRSS_API_REQUEST Request,
88 PCSRSS_API_REPLY Reply OPTIONAL,
94 if (INVALID_HANDLE_VALUE == WindowsApiPort)
96 DbgPrint ("NTDLL.%s: client not connected to CSRSS!\n", __FUNCTION__);
97 return (STATUS_UNSUCCESSFUL);
100 Request->Header.DataSize = Length - sizeof(LPC_MESSAGE_HEADER);
101 Request->Header.MessageSize = Length;
103 Status = NtRequestWaitReplyPort(WindowsApiPort,
105 (Reply?&Reply->Header:&Request->Header));
111 CsrClientConnectToServer(VOID)
114 UNICODE_STRING PortName;
115 ULONG ConnectInfoLength;
116 CSRSS_API_REQUEST Request;
117 CSRSS_API_REPLY Reply;
118 LPC_SECTION_WRITE LpcWrite;
119 HANDLE CsrSectionHandle;
120 LARGE_INTEGER CsrSectionViewSize;
122 CsrSectionViewSize.QuadPart = CSR_CSRSS_SECTION_SIZE;
123 Status = NtCreateSection(&CsrSectionHandle,
130 if (!NT_SUCCESS(Status))
134 RtlInitUnicodeStringFromLiteral(&PortName, L"\\Windows\\ApiPort");
135 ConnectInfoLength = 0;
136 LpcWrite.Length = sizeof(LPC_SECTION_WRITE);
137 LpcWrite.SectionHandle = CsrSectionHandle;
138 LpcWrite.SectionOffset = 0;
139 LpcWrite.ViewSize = CsrSectionViewSize.u.LowPart;
140 Status = NtConnectPort(&WindowsApiPort,
148 if (!NT_SUCCESS(Status))
153 NtClose(CsrSectionHandle);
154 CsrSectionMapBase = LpcWrite.ViewBase;
155 CsrSectionMapServerBase = LpcWrite.TargetViewBase;
157 /* Create the heap for communication for csrss. */
158 CsrCommHeap = RtlCreateHeap(HEAP_NO_VALLOC,
160 CsrSectionViewSize.u.LowPart,
161 CsrSectionViewSize.u.LowPart,
164 if (CsrCommHeap == NULL)
166 return(STATUS_NO_MEMORY);
169 Request.Type = CSRSS_CONNECT_PROCESS;
170 Status = CsrClientCallServer(&Request,
172 sizeof(CSRSS_API_REQUEST),
173 sizeof(CSRSS_API_REPLY));
174 if (!NT_SUCCESS(Status))
178 if (!NT_SUCCESS(Reply.Status))
180 return(Reply.Status);
182 return(STATUS_SUCCESS);