Revert 45697:
[reactos.git] / 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 "precomp.h"
9
10 #define NDEBUG
11 #include <debug.h>
12
13 /**********************************************************************
14 * NAME EXPORTED
15 * SmExecuteProgram/2
16 *
17 * DESCRIPTION
18 * This function is used to make the SM start an environment
19 * subsystem server process.
20 *
21 * ARGUMENTS
22 * hSmApiPort: port handle returned by SmConnectApiPort;
23 * Pgm : name of the subsystem (to be used by the SM to
24 * lookup the image name from the registry).
25 * Valid names are: DEBUG, WINDOWS, POSIX, OS2,
26 * and VMS.
27 *
28 * RETURN VALUE
29 * Success status as handed by the SM reply; otherwise a failure
30 * status code.
31 */
32 NTSTATUS WINAPI
33 SmExecuteProgram (IN HANDLE hSmApiPort,
34 IN PUNICODE_STRING Pgm)
35 {
36 NTSTATUS Status;
37 SM_PORT_MESSAGE SmReqMsg;
38
39
40 DPRINT("SMLIB: %s(%08lx,'%S') called\n",
41 __FUNCTION__, hSmApiPort, Pgm->Buffer);
42
43 /* Check Pgm's length */
44 if (Pgm->Length > (sizeof (Pgm->Buffer[0]) * SM_EXEXPGM_MAX_LENGTH))
45 {
46 return STATUS_INVALID_PARAMETER;
47 }
48 /* Marshal Pgm in the LPC message */
49 RtlZeroMemory (& SmReqMsg, sizeof SmReqMsg);
50 SmReqMsg.Request.ExecPgm.NameLength = Pgm->Length;
51 RtlCopyMemory (SmReqMsg.Request.ExecPgm.Name,
52 Pgm->Buffer,
53 Pgm->Length);
54
55 /* SM API to invoke */
56 SmReqMsg.SmHeader.ApiIndex = SM_API_EXECUTE_PROGRAMME;
57
58 /* LPC message */
59 SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
60 SmReqMsg.Header.u1.s1.DataLength = SM_PORT_DATA_SIZE(SmReqMsg.Request);
61 SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;
62
63 DPRINT("SMLIB: %s:\n"
64 " u2.s2.Type = %d\n"
65 " u1.s1.DataLength = %d\n"
66 " u1.s1.TotalLength = %d\n"
67 " sizeof(PORT_MESSAGE)==%d\n",
68 __FUNCTION__,
69 SmReqMsg.Header.u2.s2.Type,
70 SmReqMsg.Header.u1.s1.DataLength,
71 SmReqMsg.Header.u1.s1.TotalLength,
72 sizeof(PORT_MESSAGE));
73
74 /* Call SM and wait for a reply */
75 Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
76 if (NT_SUCCESS(Status))
77 {
78 return SmReqMsg.SmHeader.Status;
79 }
80 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
81 return Status;
82 }
83
84 /* EOF */