d8c0b4b1e7c11badaf579ea94a4411cb27b9d3d7
[reactos.git] / reactos / lib / smlib / execpgm.c
1 /* $Id$
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 #include <windows.h>
9 #define NTOS_MODE_USER
10 #include <ndk/ntndk.h>
11
12 #include <sm/helper.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(%08lx,'%S') called\n",
45 __FUNCTION__, hSmApiPort, Pgm->Buffer);
46
47 /* Check Pgm's length */
48 if (Pgm->Length > (sizeof (Pgm->Buffer[0]) * SM_EXEXPGM_MAX_LENGTH))
49 {
50 return STATUS_INVALID_PARAMETER;
51 }
52 /* Marshal Pgm in the LPC message */
53 RtlZeroMemory (& SmReqMsg, sizeof SmReqMsg);
54 SmReqMsg.Request.ExecPgm.NameLength = Pgm->Length;
55 RtlCopyMemory (SmReqMsg.Request.ExecPgm.Name,
56 Pgm->Buffer,
57 Pgm->Length);
58
59 /* SM API to invoke */
60 SmReqMsg.SmHeader.ApiIndex = SM_API_EXECUTE_PROGRAMME;
61
62 /* LPC message */
63 SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
64 SmReqMsg.Header.u1.s1.DataLength = SM_PORT_DATA_SIZE(SmReqMsg.Request);
65 SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;
66
67 DPRINT("SMLIB: %s:\n"
68 " u2.s2.Type = %d\n"
69 " u1.s1.DataLength = %d\n"
70 " u1.s1.TotalLength = %d\n"
71 " sizeof(PORT_MESSAGE)==%d\n",
72 __FUNCTION__,
73 SmReqMsg.Header.u2.s2.Type,
74 SmReqMsg.Header.u1.s1.DataLength,
75 SmReqMsg.Header.u1.s1.TotalLength,
76 sizeof(PORT_MESSAGE));
77
78 /* Call SM and wait for a reply */
79 Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
80 if (NT_SUCCESS(Status))
81 {
82 return SmReqMsg.SmHeader.Status;
83 }
84 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
85 return Status;
86 }
87
88 /* EOF */