e13a50c30fa0f341daf08bdf93dd1aaf60ff9fde
[reactos.git] / reactos / lib / ntdll / csr / lpc.c
1 /* $Id: lpc.c,v 1.1 2001/06/17 20:05:09 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 NTSTATUS STDCALL
34 CsrClientCallServer(PCSRSS_XXX_REQUEST Request,
35 PCSRSS_XXX_REPLY Reply OPTIONAL,
36 ULONG CsrApiNumber,
37 ULONG MaxRequestReplyLength)
38
39 XXX_REQUEST and XXX_REPLY depend on the CsrApiNumber value and are not LPC
40 objects (the LPC_REQUEST is built here instead).
41 If Reply == NULL, use storage of Request to write the reply.
42
43 TO BE VERIFIED.
44
45 */
46 NTSTATUS STDCALL
47 CsrClientCallServer(PCSRSS_API_REQUEST Request,
48 PCSRSS_API_REPLY Reply OPTIONAL,
49 ULONG Length,
50 ULONG ReplyLength)
51 {
52 NTSTATUS Status;
53
54 if (INVALID_HANDLE_VALUE == WindowsApiPort)
55 {
56 DbgPrint ("NTDLL.%s: client not connected to CSRSS!\n", __FUNCTION__);
57 return (STATUS_UNSUCCESSFUL);
58 }
59
60 // DbgPrint("CsrClientCallServer(Request %x, Reply %x, Length %d, "
61 // "ReplyLength %d)\n", Request, Reply, Length, ReplyLength);
62
63 Request->Header.DataSize = Length;
64 Request->Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + Length;
65
66
67 Status = NtRequestWaitReplyPort(WindowsApiPort,
68 &Request->Header,
69 (Reply?&Reply->Header:&Request->Header));
70
71 // DbgPrint("Status %x\n", Status);
72
73 return(Status);
74 }
75
76 NTSTATUS STDCALL
77 CsrClientConnectToServer(VOID)
78 {
79 NTSTATUS Status;
80 UNICODE_STRING PortName;
81 ULONG ConnectInfoLength;
82 CSRSS_API_REQUEST Request;
83 CSRSS_API_REPLY Reply;
84
85 RtlInitUnicodeString(&PortName, L"\\Windows\\ApiPort");
86 ConnectInfoLength = 0;
87 Status = NtConnectPort(&WindowsApiPort,
88 &PortName,
89 NULL,
90 NULL,
91 NULL,
92 NULL,
93 NULL,
94 &ConnectInfoLength);
95 if (!NT_SUCCESS(Status))
96 {
97 return(Status);
98 }
99
100 Request.Type = CSRSS_CONNECT_PROCESS;
101 Status = CsrClientCallServer(&Request,
102 &Reply,
103 sizeof(CSRSS_API_REQUEST),
104 sizeof(CSRSS_API_REPLY));
105 if (!NT_SUCCESS(Status))
106 {
107 return(Status);
108 }
109 if (!NT_SUCCESS(Reply.Status))
110 {
111 return(Reply.Status);
112 }
113 return(STATUS_SUCCESS);
114 }
115
116 /* EOF */