ReactOS  0.4.14-dev-342-gdc047f9
execpgm.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: lib/smlib/execpgm.c
5  * PURPOSE: Call SM API SM_API_EXECPGM
6  */
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  */
34  IN PUNICODE_STRING Pgm)
35 {
37  SM_PORT_MESSAGE SmReqMsg;
38 
39 
40  DPRINT("SMLIB: %s(%p,'%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  {
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)==%u\n",
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 */
#define IN
Definition: typedefs.h:38
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
struct _SM_PORT_MESSAGE::@3390::@3392::@3394 SmHeader
#define SM_PORT_DATA_SIZE(c)
Definition: api.h:149
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WINAPI
Definition: msvc.h:8
NTSTATUS WINAPI SmExecuteProgram(IN HANDLE hSmApiPort, IN PUNICODE_STRING Pgm)
Definition: execpgm.c:33
Status
Definition: gdiplustypes.h:24
#define SM_API_EXECUTE_PROGRAMME
Definition: api.h:55
PORT_MESSAGE Header
Definition: api.h:112
#define SM_PORT_MESSAGE_SIZE
Definition: api.h:150
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define __FUNCTION__
Definition: types.h:112
#define SM_EXEXPGM_MAX_LENGTH
Definition: api.h:57
union _SM_PORT_MESSAGE::@3390::@3392::@3395::@3397 Request