NTDLL.CsrClientCallServer: more info on the interface.
[reactos.git] / reactos / lib / ntdll / csr / lpc.c
1 /* $Id: lpc.c,v 1.2 2001/08/31 20:06:17 ea 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 // DbgPrint("CsrClientCallServer(Request %x, Reply %x, Length %d, "
69 // "ReplyLength %d)\n", Request, Reply, Length, ReplyLength);
70
71 Request->Header.DataSize = Length;
72 Request->Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + Length;
73
74
75 Status = NtRequestWaitReplyPort(WindowsApiPort,
76 &Request->Header,
77 (Reply?&Reply->Header:&Request->Header));
78
79 // DbgPrint("Status %x\n", Status);
80
81 return(Status);
82 }
83
84 NTSTATUS STDCALL
85 CsrClientConnectToServer(VOID)
86 {
87 NTSTATUS Status;
88 UNICODE_STRING PortName;
89 ULONG ConnectInfoLength;
90 CSRSS_API_REQUEST Request;
91 CSRSS_API_REPLY Reply;
92
93 RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
94 ConnectInfoLength = 0;
95 Status = NtConnectPort(&WindowsApiPort,
96 &PortName,
97 NULL,
98 NULL,
99 NULL,
100 NULL,
101 NULL,
102 &ConnectInfoLength);
103 if (!NT_SUCCESS(Status))
104 {
105 return(Status);
106 }
107
108 Request.Type = CSRSS_CONNECT_PROCESS;
109 Status = CsrClientCallServer(&Request,
110 &Reply,
111 sizeof(CSRSS_API_REQUEST),
112 sizeof(CSRSS_API_REPLY));
113 if (!NT_SUCCESS(Status))
114 {
115 return(Status);
116 }
117 if (!NT_SUCCESS(Reply.Status))
118 {
119 return(Reply.Status);
120 }
121 return(STATUS_SUCCESS);
122 }
123
124 /* EOF */