1 /* $Id: execpgm.c 13731 2005-02-23 23:37:06Z ea $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/smlib/execpgm.c
6 * PURPOSE: Call SM API SM_API_EXECPGM
10 #include <sm/helper.h>
16 /**********************************************************************
21 * This function is used to make the SM start an environment
22 * subsystem server process.
25 * hSmApiPort: port handle returned by SmConnectApiPort;
26 * Pgm : name of the subsystem (to be used by the SM to
27 * lookup the image name from the registry).
28 * Valid names are: DEBUG, WINDOWS, POSIX, OS2,
32 * Success status as handed by the SM reply; otherwise a failure
36 SmExecuteProgram (IN HANDLE hSmApiPort
,
37 IN PUNICODE_STRING Pgm
)
40 SM_PORT_MESSAGE SmReqMsg
;
43 DPRINT("SMLIB: %s(%08lx,'%S') called\n",
44 __FUNCTION__
, hSmApiPort
, Pgm
->Buffer
);
46 /* Check Pgm's length */
47 if (Pgm
->Length
> (sizeof (Pgm
->Buffer
[0]) * SM_EXEXPGM_MAX_LENGTH
))
49 return STATUS_INVALID_PARAMETER
;
51 /* Marshal Pgm in the LPC message */
52 RtlZeroMemory (& SmReqMsg
, sizeof SmReqMsg
);
53 SmReqMsg
.Request
.ExecPgm
.NameLength
= Pgm
->Length
;
54 RtlCopyMemory (SmReqMsg
.Request
.ExecPgm
.Name
,
58 /* SM API to invoke */
59 SmReqMsg
.SmHeader
.ApiIndex
= SM_API_EXECUTE_PROGRAMME
;
62 SmReqMsg
.Header
.MessageType
= LPC_NEW_MESSAGE
;
63 SmReqMsg
.Header
.DataSize
= SM_PORT_DATA_SIZE(SmReqMsg
.Request
);
64 SmReqMsg
.Header
.MessageSize
= SM_PORT_MESSAGE_SIZE
;
70 " sizeof(LPC_MESSAGE)==%d\n",
72 SmReqMsg
.Header
.MessageType
,
73 SmReqMsg
.Header
.DataSize
,
74 SmReqMsg
.Header
.MessageSize
,
77 /* Call SM and wait for a reply */
78 Status
= NtRequestWaitReplyPort (hSmApiPort
, (PLPC_MESSAGE
) & SmReqMsg
, (PLPC_MESSAGE
) & SmReqMsg
);
79 if (NT_SUCCESS(Status
))
81 return SmReqMsg
.SmHeader
.Status
;
83 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);