d8c0b4b1e7c11badaf579ea94a4411cb27b9d3d7
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 <ndk/ntndk.h>
12 #include <sm/helper.h>
17 /**********************************************************************
22 * This function is used to make the SM start an environment
23 * subsystem server process.
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,
33 * Success status as handed by the SM reply; otherwise a failure
37 SmExecuteProgram (IN HANDLE hSmApiPort
,
38 IN PUNICODE_STRING Pgm
)
41 SM_PORT_MESSAGE SmReqMsg
;
44 DPRINT("SMLIB: %s(%08lx,'%S') called\n",
45 __FUNCTION__
, hSmApiPort
, Pgm
->Buffer
);
47 /* Check Pgm's length */
48 if (Pgm
->Length
> (sizeof (Pgm
->Buffer
[0]) * SM_EXEXPGM_MAX_LENGTH
))
50 return STATUS_INVALID_PARAMETER
;
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
,
59 /* SM API to invoke */
60 SmReqMsg
.SmHeader
.ApiIndex
= SM_API_EXECUTE_PROGRAMME
;
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
;
69 " u1.s1.DataLength = %d\n"
70 " u1.s1.TotalLength = %d\n"
71 " sizeof(PORT_MESSAGE)==%d\n",
73 SmReqMsg
.Header
.u2
.s2
.Type
,
74 SmReqMsg
.Header
.u1
.s1
.DataLength
,
75 SmReqMsg
.Header
.u1
.s1
.TotalLength
,
76 sizeof(PORT_MESSAGE
));
78 /* Call SM and wait for a reply */
79 Status
= NtRequestWaitReplyPort (hSmApiPort
, (PPORT_MESSAGE
) & SmReqMsg
, (PPORT_MESSAGE
) & SmReqMsg
);
80 if (NT_SUCCESS(Status
))
82 return SmReqMsg
.SmHeader
.Status
;
84 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);