SMDLL + SMLIB (static code in SMSS.EXE)
[reactos.git] / reactos / lib / smlib / execpgm.c
1 /* $Id: execpgm.c 13731 2005-02-23 23:37:06Z ea $
2 *
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
7 */
8 #define NTOS_MODE_USER
9 #include <ntos.h>
10 #include <sm/api.h>
11 #include <sm/helper.h>
12 #include <string.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 /**********************************************************************
18 * NAME EXPORTED
19 * SmExecuteProgram/2
20 *
21 * DESCRIPTION
22 * This function is used to make the SM start an environment
23 * subsystem server process.
24 *
25 * ARGUMENTS
26 * hSmApiPort: port handle returned by SmConnectApiPort;
27 * Pgm : name of the subsystem (to be used by the SM to
28 * lookup the image name from the registry).
29 * Valid names are: DEBUG, WINDOWS, POSIX, OS2,
30 * and VMS.
31 *
32 * RETURN VALUE
33 * Success status as handed by the SM reply; otherwise a failure
34 * status code.
35 */
36 NTSTATUS STDCALL
37 SmExecuteProgram (IN HANDLE hSmApiPort,
38 IN PUNICODE_STRING Pgm)
39 {
40 NTSTATUS Status;
41 SM_PORT_MESSAGE SmReqMsg;
42
43
44 DPRINT("SMLIB: %s called\n", __FUNCTION__);
45
46 /* Check Pgm's length */
47 if (Pgm->Length > (sizeof (Pgm->Buffer[0]) * SM_EXEXPGM_MAX_LENGTH))
48 {
49 return STATUS_INVALID_PARAMETER;
50 }
51 /* Marshal Pgm in the LPC message */
52 RtlZeroMemory (& SmReqMsg, sizeof SmReqMsg);
53 SmReqMsg.ExecPgm.NameLength = Pgm->Length;
54 RtlCopyMemory (SmReqMsg.ExecPgm.Name,
55 Pgm->Buffer,
56 Pgm->Length);
57
58 /* SM API to invoke */
59 SmReqMsg.ApiIndex = SM_API_EXECUTE_PROGRAMME;
60
61 /* LPC message */
62 SmReqMsg.Header.MessageType = LPC_NEW_MESSAGE;
63 SmReqMsg.Header.DataSize = SM_PORT_DATA_SIZE(SmReqMsg.ExecPgm);
64 SmReqMsg.Header.MessageSize = SM_PORT_MESSAGE_SIZE;
65
66 /* Call SM and wait for a reply */
67 Status = NtRequestWaitReplyPort (hSmApiPort, (PLPC_MESSAGE) & SmReqMsg, (PLPC_MESSAGE) & SmReqMsg);
68 if (NT_SUCCESS(Status))
69 {
70 return SmReqMsg.Status;
71 }
72 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
73 return Status;
74 }
75
76 /* EOF */