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
13 /**********************************************************************
18 * This function is used to make the SM start an environment
19 * subsystem server process.
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,
29 * Success status as handed by the SM reply; otherwise a failure
33 SmExecuteProgram (IN HANDLE hSmApiPort
,
34 IN PUNICODE_STRING Pgm
)
37 SM_PORT_MESSAGE SmReqMsg
;
40 DPRINT("SMLIB: %s(%08lx,'%S') called\n",
41 __FUNCTION__
, hSmApiPort
, Pgm
->Buffer
);
43 /* Check Pgm's length */
44 if (Pgm
->Length
> (sizeof (Pgm
->Buffer
[0]) * SM_EXEXPGM_MAX_LENGTH
))
46 return STATUS_INVALID_PARAMETER
;
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
,
55 /* SM API to invoke */
56 SmReqMsg
.SmHeader
.ApiIndex
= SM_API_EXECUTE_PROGRAMME
;
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
;
65 " u1.s1.DataLength = %d\n"
66 " u1.s1.TotalLength = %d\n"
67 " sizeof(PORT_MESSAGE)==%d\n",
69 SmReqMsg
.Header
.u2
.s2
.Type
,
70 SmReqMsg
.Header
.u1
.s1
.DataLength
,
71 SmReqMsg
.Header
.u1
.s1
.TotalLength
,
72 sizeof(PORT_MESSAGE
));
74 /* Call SM and wait for a reply */
75 Status
= NtRequestWaitReplyPort (hSmApiPort
, (PPORT_MESSAGE
) & SmReqMsg
, (PPORT_MESSAGE
) & SmReqMsg
);
76 if (NT_SUCCESS(Status
))
78 return SmReqMsg
.SmHeader
.Status
;
80 DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__
, Status
);