1 /* $Id: api.c,v 1.1 2002/04/10 21:30:22 ea Exp $
3 * PROJECT : ReactOS / POSIX+ Environment Subsystem Server
4 * FILE : reactos/subsys/psx/server/port/api.c
5 * DESCRIPTION: \POSIX+\ApiPort LPC port logic.
7 * AUTHOR : Emanuele Aliberti <eal@users.sf.net>
9 * --------------------------------------------------------------------
11 * This software is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
16 * This software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this software; see the file COPYING. If not, write
23 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
26 * --------------------------------------------------------------------
29 #include <psx/lpcproto.h>
32 /**********************************************************************
33 * ProcessConnectionRequest/ PRIVATE
36 * This is called when a PSX process attaches to PSXDLL.DLL.
38 PRIVATE NTSTATUS STDCALL
39 ProcessConnectionRequest (PLPC_MAX_MESSAGE pRequest
)
41 PPSX_CONNECT_PORT_DATA pConnectData
= (PPSX_CONNECT_PORT_DATA
) & pRequest
->Data
;
43 HANDLE hConnectedPort
;
44 ULONG ulPortIdentifier
;
46 debug_print (L
"PSXSS: ->"__FUNCTION__
);
47 /* Check if the caller is a process */
48 Status
= PsxCheckConnectionRequest (
50 PSX_CONNECTION_TYPE_PROCESS
52 if (!NT_SUCCESS(Status
))
54 Status
= NtAcceptConnectPort (
58 FALSE
, /* reject connection request */
62 if (!NT_SUCCESS(Status
))
65 L
"PSXSS: "__FUNCTION__
": NtAcceptConnectPort failed with status=%08x",
69 return STATUS_UNSUCCESSFUL
;
71 /* OK, accept the connection */
72 Status
= NtAcceptConnectPort (
76 TRUE
, /* accept connection request */
80 if (!NT_SUCCESS(Status
))
82 debug_print(L
"PSXSS: "__FUNCTION__
": NtAcceptConnectPort failed with status=%08x", Status
);
85 Status
= PsxCreateProcess (pRequest
,hConnectedPort
,ulPortIdentifier
);
86 if (!NT_SUCCESS(Status
))
88 debug_print(L
"PSXSS: "__FUNCTION__
": PsxCreateProcess failed with status=%08x", Status
);
91 Status
= NtCompleteConnectPort (hConnectedPort
);
92 if (!NT_SUCCESS(Status
))
94 debug_print(L
"PSXSS: "__FUNCTION__
": NtCompleteConnectPort failed with status=%08x", Status
);
97 debug_print (L
"PSXSS: <-"__FUNCTION__
);
98 return STATUS_SUCCESS
;
100 /**********************************************************************
101 * ProcessRequest/ PRIVATE
104 * This is the actual POSIX system calls dispatcher.
106 PRIVATE NTSTATUS STDCALL
107 ProcessRequest (PPSX_MAX_MESSAGE pRequest
)
109 debug_print (L
"PSXSS: ->"__FUNCTION__
);
111 if (pRequest
->PsxHeader
.Procedure
< PSX_SYSCALL_APIPORT_COUNT
)
113 pRequest
->PsxHeader
.Status
=
114 SystemCall
[pRequest
->PsxHeader
.Procedure
] (pRequest
);
118 pRequest
->PsxHeader
.Status
= STATUS_INVALID_SYSTEM_SERVICE
;
120 return STATUS_SUCCESS
;
122 /**********************************************************************
126 * The thread to process messages from the \POSIX+\ApiPort
127 * LPC port. Mostly used by PSXDLL.DLL.
130 ApiPortListener (PVOID pArg
)
132 ULONG ulIndex
= (ULONG
) pArg
;
134 LPC_TYPE RequestType
;
135 ULONG PortIdentifier
;
136 PSX_MAX_MESSAGE Request
;
137 PPSX_MAX_MESSAGE Reply
= NULL
;
138 BOOL NullReply
= FALSE
;
140 debug_print (L
"PSXSS: ->"__FUNCTION__
" pArg=%d", ulIndex
);
148 Status
= NtReplyWaitReceivePort (
149 Server
.Port
[ulIndex
].hObject
,
151 (PLPC_MESSAGE
) Reply
,
152 (PLPC_MESSAGE
) & Request
154 if (!NT_SUCCESS(Status
))
158 RequestType
= PORT_MESSAGE_TYPE(Request
);
161 case LPC_CONNECTION_REQUEST
:
162 ProcessConnectionRequest ((PLPC_MAX_MESSAGE
) & Request
);
165 case LPC_CLIENT_DIED
:
166 case LPC_PORT_CLOSED
:
167 case LPC_DEBUG_EVENT
:
168 case LPC_ERROR_EVENT
:
173 if (RequestType
!= LPC_REQUEST
)
180 Reply
->PsxHeader
.Status
= ProcessRequest (& Request
);
183 if ((STATUS_INVALID_HANDLE
== Status
) ||
184 (STATUS_OBJECT_TYPE_MISMATCH
== Status
))
189 #ifdef __PSXSS_ON_W32__
190 TerminateThread(GetCurrentThread(),Status
);
192 NtTerminateThread(NtCurrentThread(),Status
);