1 /* $Id: api.c,v 1.4 2003/12/21 20:11:46 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: ->%s", __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: %s: NtAcceptConnectPort failed with status=%08x",
70 return STATUS_UNSUCCESSFUL
;
72 /* OK, accept the connection */
73 Status
= NtAcceptConnectPort (
77 TRUE
, /* accept connection request */
81 if (!NT_SUCCESS(Status
))
83 debug_print(L
"PSXSS: %s: NtAcceptConnectPort failed with status=%08x", __FUNCTION__
, Status
);
86 Status
= PsxCreateProcess (pRequest
,hConnectedPort
,ulPortIdentifier
);
87 if (!NT_SUCCESS(Status
))
89 debug_print(L
"PSXSS: %s: PsxCreateProcess failed with status=%08x", __FUNCTION__
, Status
);
92 Status
= NtCompleteConnectPort (hConnectedPort
);
93 if (!NT_SUCCESS(Status
))
95 debug_print(L
"PSXSS: %s: NtCompleteConnectPort failed with status=%08x", __FUNCTION__
, Status
);
98 debug_print (L
"PSXSS: <-%s", __FUNCTION__
);
99 return STATUS_SUCCESS
;
101 /**********************************************************************
102 * ProcessRequest/ PRIVATE
105 * This is the actual POSIX system calls dispatcher.
107 PRIVATE NTSTATUS STDCALL
108 ProcessRequest (PPSX_MAX_MESSAGE pRequest
)
110 debug_print (L
"PSXSS: ->%s", __FUNCTION__
);
112 if (pRequest
->PsxHeader
.Procedure
< PSX_SYSCALL_APIPORT_COUNT
)
114 pRequest
->PsxHeader
.Status
=
115 SystemCall
[pRequest
->PsxHeader
.Procedure
] (pRequest
);
119 pRequest
->PsxHeader
.Status
= STATUS_INVALID_SYSTEM_SERVICE
;
121 return STATUS_SUCCESS
;
123 /**********************************************************************
127 * The thread to process messages from the \POSIX+\ApiPort
128 * LPC port. Mostly used by PSXDLL.DLL.
131 ApiPortListener (PVOID pArg
)
133 ULONG ulIndex
= (ULONG
) pArg
;
135 LPC_TYPE RequestType
;
136 ULONG PortIdentifier
;
137 PSX_MAX_MESSAGE Request
;
138 PPSX_MAX_MESSAGE Reply
= NULL
;
139 BOOL NullReply
= FALSE
;
141 debug_print (L
"PSXSS: ->%s pArg=%d", __FUNCTION__
, ulIndex
);
149 Status
= NtReplyWaitReceivePort (
150 Server
.Port
[ulIndex
].hObject
,
152 (PLPC_MESSAGE
) Reply
,
153 (PLPC_MESSAGE
) & Request
155 if (!NT_SUCCESS(Status
))
159 RequestType
= PORT_MESSAGE_TYPE(Request
);
162 case LPC_CONNECTION_REQUEST
:
163 ProcessConnectionRequest ((PLPC_MAX_MESSAGE
) & Request
);
166 case LPC_CLIENT_DIED
:
167 case LPC_PORT_CLOSED
:
168 case LPC_DEBUG_EVENT
:
169 case LPC_ERROR_EVENT
:
174 if (RequestType
!= LPC_REQUEST
)
181 Reply
->PsxHeader
.Status
= ProcessRequest (& Request
);
184 if ((STATUS_INVALID_HANDLE
== Status
) ||
185 (STATUS_OBJECT_TYPE_MISMATCH
== Status
))
190 #ifdef __PSXSS_ON_W32__
191 TerminateThread(GetCurrentThread(),Status
);
193 NtTerminateThread(NtCurrentThread(),Status
);