include/csrss/csrss.h: Include a define for the size of the common
[reactos.git] / reactos / lib / ntdll / csr / lpc.c
1 /* $Id: lpc.c,v 1.3 2001/11/25 15:21:09 dwelch Exp $
2 *
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
7 *
8 * REVISIONS:
9 * 2001-06-16 (ea)
10 * File api.c renamed lpc.c. Process/thread code moved
11 * in thread.c. Check added on the LPC port.
12 */
13
14 /* INCLUDES *****************************************************************/
15
16 #include <ddk/ntddk.h>
17 #include <ntdll/csr.h>
18 #include <string.h>
19
20 #include <csrss/csrss.h>
21
22 #define NDEBUG
23 #include <ntdll/ntdll.h>
24
25 /* GLOBALS *******************************************************************/
26
27 HANDLE WindowsApiPort = INVALID_HANDLE_VALUE;
28
29 /* FUNCTIONS *****************************************************************/
30
31 /* Possible CsrClientCallServer (the NT one):
32
33 #define CSR_CCS_NATIVE 0x0000
34 #define CSR_CCS_CSR 0x0001
35 #define CSR_CCS_GUI 0x0002
36
37 typedef union _CSR_CCS_API
38 {
39 WORD Index; // CSRSS API number
40 WORD Subsystem; // 0=NTDLL;1=KERNEL32;2=KERNEL32
41
42 } CSR_CCS_API, * PCSR_CCS_API;
43
44 NTSTATUS STDCALL
45 CsrClientCallServer(PVOID Request,
46 PVOID Unknown OPTIONAL,
47 CSR_CCS_API CsrApi,
48 ULONG SizeOfData);
49
50 Request is the family of PCSRSS_XXX_REQUEST objects.
51 XXX_REQUEST depend on the CsrApiNumber.Index.
52
53 */
54 NTSTATUS STDCALL
55 CsrClientCallServer(PCSRSS_API_REQUEST Request,
56 PCSRSS_API_REPLY Reply OPTIONAL,
57 ULONG Length,
58 ULONG ReplyLength)
59 {
60 NTSTATUS Status;
61
62 if (INVALID_HANDLE_VALUE == WindowsApiPort)
63 {
64 DbgPrint ("NTDLL.%s: client not connected to CSRSS!\n", __FUNCTION__);
65 return (STATUS_UNSUCCESSFUL);
66 }
67
68 Request->Header.DataSize = Length - sizeof(LPC_MESSAGE_HEADER);
69 Request->Header.MessageSize = Length;
70
71 Status = NtRequestWaitReplyPort(WindowsApiPort,
72 &Request->Header,
73 (Reply?&Reply->Header:&Request->Header));
74
75 return(Status);
76 }
77
78 NTSTATUS STDCALL
79 CsrClientConnectToServer(VOID)
80 {
81 NTSTATUS Status;
82 UNICODE_STRING PortName;
83 ULONG ConnectInfoLength;
84 CSRSS_API_REQUEST Request;
85 CSRSS_API_REPLY Reply;
86
87 RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
88 ConnectInfoLength = 0;
89 Status = NtConnectPort(&WindowsApiPort,
90 &PortName,
91 NULL,
92 NULL,
93 NULL,
94 NULL,
95 NULL,
96 &ConnectInfoLength);
97 if (!NT_SUCCESS(Status))
98 {
99 return(Status);
100 }
101
102 Request.Type = CSRSS_CONNECT_PROCESS;
103 Status = CsrClientCallServer(&Request,
104 &Reply,
105 sizeof(CSRSS_API_REQUEST),
106 sizeof(CSRSS_API_REPLY));
107 if (!NT_SUCCESS(Status))
108 {
109 return(Status);
110 }
111 if (!NT_SUCCESS(Reply.Status))
112 {
113 return(Reply.Status);
114 }
115 return(STATUS_SUCCESS);
116 }
117
118 /* EOF */