Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
7.8 KiB

  1. /* cmd.h - main include file for command.lib
  2. *
  3. * Modification History
  4. *
  5. * Sudeepb 17-Sep-1991 Created
  6. */
  7. /*
  8. #define WIN
  9. #define FLAT_32
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #define _WINDOWS
  14. #include <windows.h>
  15. */
  16. #ifdef DOS
  17. #define SIGNALS
  18. #endif
  19. #ifdef OS2_16
  20. #define OS2
  21. #define SIGNALS
  22. #endif
  23. #ifdef OS2_32
  24. #define OS2
  25. #define FLAT_32
  26. #endif
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <malloc.h>
  32. #include <process.h>
  33. #ifdef WIN_16
  34. #define WIN
  35. #define API16
  36. #endif
  37. #ifdef WIN_32
  38. #define WIN
  39. #define FLAT_32
  40. #define TRUE_IF_WIN32 1
  41. #include <nt.h>
  42. #include <ntrtl.h>
  43. #include <nturtl.h>
  44. #else
  45. #define TRUE_IF_WIN32 0
  46. #endif
  47. #ifdef FLAT_32
  48. #ifndef i386
  49. #define ALIGN_32
  50. #else
  51. #define NOALIGN_32
  52. #endif
  53. #endif
  54. #ifdef WIN
  55. #define _WINDOWS
  56. #include <windows.h>
  57. #endif
  58. #ifdef SIGNALS
  59. #include <conio.h>
  60. #include <signal.h>
  61. #endif
  62. #ifdef OS2_32
  63. #include <excpt.h>
  64. #define XCPT_SIGNAL 0xC0010003
  65. #endif
  66. #include <vdmapi.h>
  67. #define COPY_STD_OUT 1
  68. #define COPY_STD_ERR 2
  69. #define CLOSE_ALL_HANDLES 1
  70. #define CLOSE_STD_OUT 2
  71. #define CLOSE_STD_ERR 4
  72. #define DEFAULT_REDIRECTION_SIZE 1024
  73. #define MAX_SHORTCUT_SIZE 128
  74. #define STDIN_BUF_SIZE 512
  75. /** Command Macros **/
  76. /** Command Basic Typedefs **/
  77. typedef VOID (*PFNSVC)(VOID);
  78. #pragma pack(1)
  79. typedef struct _PARAMBLOCK {
  80. USHORT SegEnv;
  81. USHORT OffCmdTail;
  82. USHORT SegCmdTail;
  83. ULONG pFCB1;
  84. ULONG pFCB2;
  85. } PARAMBLOCK,*PPARAMBLOCK;
  86. typedef struct _SCSINFO {
  87. CHAR SCS_ComSpec [64];
  88. CHAR SCS_CmdTail [128];
  89. PARAMBLOCK SCS_ParamBlock;
  90. CHAR SCS_ToSync;
  91. } SCSINFO, *PSCSINFO;
  92. typedef struct _STD_HANDLES {
  93. ULONG hStdErr;
  94. ULONG hStdOut;
  95. ULONG hStdIn;
  96. } STD_HANDLES, *PSTD_HANDLES;
  97. #define PIPE_INPUT_BUFFER_SIZE 512
  98. #define PIPE_OUTPUT_BUFFER_SIZE PIPE_INPUT_BUFFER_SIZE
  99. #define PIPE_INPUT_TIMEOUT 55
  100. #define PIPE_OUTPUT_TIMEOUT PIPE_INPUT_TIMEOUT
  101. typedef struct _PIPE_INPUT{
  102. struct _PIPE_INPUT *Next;
  103. HANDLE hFileRead;
  104. HANDLE hFileWrite;
  105. HANDLE hPipe;
  106. HANDLE hDataEvent;
  107. HANDLE hThread;
  108. CHAR *pFileName;
  109. DWORD BufferSize;
  110. BOOL fEOF;
  111. BOOL WaitData;
  112. BYTE *Buffer;
  113. CRITICAL_SECTION CriticalSection;
  114. } PIPE_INPUT, *PPIPE_INPUT;
  115. typedef struct _PIPE_OUTPUT {
  116. HANDLE hFile;
  117. HANDLE hPipe;
  118. HANDLE hExitEvent;
  119. CHAR *pFileName;
  120. DWORD BufferSize;
  121. BYTE *Buffer;
  122. } PIPE_OUTPUT, *PPIPE_OUTPUT;
  123. typedef struct _RedirComplete_Info {
  124. HANDLE ri_hStdErr;
  125. HANDLE ri_hStdOut;
  126. HANDLE ri_hStdIn;
  127. HANDLE ri_hStdErrFile;
  128. HANDLE ri_hStdOutFile;
  129. HANDLE ri_hStdInFile;
  130. HANDLE ri_hStdOutThread;
  131. HANDLE ri_hStdErrThread;
  132. PPIPE_INPUT ri_pPipeStdIn;
  133. PPIPE_OUTPUT ri_pPipeStdOut;
  134. PPIPE_OUTPUT ri_pPipeStdErr;
  135. } REDIRCOMPLETE_INFO, *PREDIRCOMPLETE_INFO;
  136. typedef struct _VDMENVBLK {
  137. DWORD cchEnv;
  138. DWORD cchRemain;
  139. CHAR *lpszzEnv;
  140. } VDMENVBLK, *PVDMENVBLK;
  141. #pragma pack()
  142. /** Command Function Prototypes */
  143. VOID cmdComSpec (VOID);
  144. VOID cmdGetEnv (VOID);
  145. VOID cmdGetNextCmd (VOID);
  146. VOID cmdGetNextCmdForSeparateWow (VOID);
  147. VOID cmdGetStdHandle (VOID);
  148. VOID cmdExec (VOID);
  149. VOID cmdExecComspec32 (VOID);
  150. VOID cmdExitVDM (VOID);
  151. VOID cmdReturnExitCode (VOID);
  152. VOID cmdSaveWorld (VOID);
  153. VOID cmdSetInfo (VOID);
  154. VOID cmdGetCurrentDir (VOID);
  155. VOID cmdSetDirectories (PCHAR,VDMINFO *);
  156. VOID CheckDotExeForWOW (LPSTR);
  157. BOOL cmdCheckCopyForRedirection (PREDIRCOMPLETE_INFO, BOOL);
  158. BOOL cmdCreateTempFile (PHANDLE,PCHAR *);
  159. VOID cmdCheckBinary (VOID);
  160. VOID cmdInitConsole (VOID);
  161. VOID nt_init_event_thread (VOID);
  162. VOID cmdExec32 (PCHAR,PCHAR);
  163. VOID cmdCreateProcess (PSTD_HANDLES pStdHandles);
  164. USHORT cmdMapCodePage (ULONG);
  165. VOID cmdCheckForPIF (PVDMINFO);
  166. VOID cmdGetConfigSys (VOID);
  167. VOID cmdGetAutoexecBat (VOID);
  168. VOID DeleteConfigFiles (VOID);
  169. VOID cmdGetKbdLayout (VOID);
  170. BOOL cmdXformEnvironment (PCHAR, PANSI_STRING);
  171. VOID cmdGetInitEnvironment (VOID);
  172. VOID cmdUpdateCurrentDirectories (BYTE);
  173. BOOL cmdCreateVDMEnvironment (PVDMENVBLK);
  174. DWORD cmdGetEnvironmentVariable (PVDMENVBLK, PCHAR, PCHAR, DWORD);
  175. BOOL cmdSetEnvironmentVariable (PVDMENVBLK, PCHAR, PCHAR);
  176. DWORD cmdExpandEnvironmentStrings (PVDMENVBLK, PCHAR, PCHAR, DWORD);
  177. PREDIRCOMPLETE_INFO cmdCheckStandardHandles (PVDMINFO,USHORT UNALIGNED *);
  178. VOID cmdGetStartInfo (VOID);
  179. BOOL cmdHandleStdinWithPipe (PREDIRCOMPLETE_INFO);
  180. BOOL cmdHandleStdOutErrWithPipe (PREDIRCOMPLETE_INFO, USHORT);
  181. LPSTR cmdSkipOverPathName (LPSTR);
  182. BOOL cmdPipeFileDataEOF (HANDLE, BOOL *);
  183. BOOL cmdPipeFileEOF (HANDLE);
  184. VOID cmdPipeInThread (LPVOID);
  185. VOID cmdPipeOutThread (LPVOID);
  186. VOID cmdSetWinTitle (VOID);
  187. BOOL cmdIllegalFunc(VOID);
  188. VOID cmdGetCursorPos(VOID);
  189. /** Command Externs **/
  190. extern USHORT nDrives;
  191. extern BOOL IsFirstVDMInSystem;
  192. extern BOOL VDMForWOW;
  193. extern CHAR lpszComSpec[];
  194. extern USHORT cbComSpec;
  195. extern BOOL IsFirstCall;
  196. extern BOOL IsRepeatCall;
  197. extern BOOL IsFirstWOWCheckBinary;
  198. extern BOOL IsFirstVDMInSystem;
  199. extern BOOL SaveWorldCreated;
  200. extern PCHAR pSCS_ToSync;
  201. extern BOOL fBlock;
  202. extern PCHAR pCommand32;
  203. extern PCHAR pEnv32;
  204. extern DWORD dwExitCode32;
  205. extern PSCSINFO pSCSInfo;
  206. extern HANDLE hFileStdOut;
  207. extern HANDLE hFileStdOutDup;
  208. extern HANDLE hFileStdErr;
  209. extern HANDLE hFileStdErrDup;
  210. extern VDMINFO VDMInfo;
  211. extern PSZ pszFileStdOut;
  212. extern PSZ pszFileStdErr;
  213. extern CHAR cmdHomeDirectory[];
  214. extern HANDLE SCS_hStdIn;
  215. extern HANDLE SCS_hStdOut;
  216. extern HANDLE SCS_hStdErr;
  217. extern CHAR chDefaultDrive;
  218. extern BOOL DontCheckDosBinaryType;
  219. extern WORD Exe32ActiveCount;
  220. extern BOOL fSoftpcRedirection;
  221. extern BOOL fSoftpcRedirectionOnShellOut;
  222. extern VOID nt_std_handle_notification (BOOL);
  223. extern VOID cmdPushExitInConsoleBuffer (VOID);
  224. // control handler state, defined in nt_event.h, nt_event.c
  225. extern ULONG CntrlHandlerState;
  226. #define CNTRL_SHELLCOUNT 0x0FFFF // The LOWORD is used for shell count
  227. #define CNTRL_PIFALLOWCLOSE 0x10000
  228. #define CNTRL_VDMBLOCKED 0x20000
  229. #define CNTRL_SYSTEMROOTCONSOLE 0x40000
  230. #define CNTRL_PUSHEXIT 0x80000
  231. // Temporary variable till we standardized on wowexec
  232. extern ULONG iWOWTaskId;
  233. extern CHAR comspec[];
  234. extern CHAR ShortCutInfo[];
  235. extern VOID nt_pif_callout (LPVOID);
  236. extern CHAR *lpszzInitEnvironment;
  237. extern WORD cchInitEnvironment;
  238. extern CHAR *lpszzCurrentDirectories;
  239. extern DWORD cchCurrentDirectories;
  240. extern BYTE * pIsDosBinary;
  241. extern WORD * pFDAccess;
  242. extern CHAR *lpszzcmdEnv16;
  243. extern BOOL DosEnvCreated;
  244. extern BOOL IsFirstVDM;
  245. extern VDMENVBLK cmdVDMEnvBlk;
  246. extern CHAR *lpszzVDMEnv32;
  247. extern DWORD cchVDMEnv32;
  248. extern UINT VdmExitCode;
  249. // application path name extention type.
  250. #define EXTENTION_STRING_LEN 4
  251. #define BAT_EXTENTION_STRING ".BAT"
  252. #define EXE_EXTENTION_STRING ".EXE"
  253. #define COM_EXTENTION_STRING ".COM"
  254. #ifdef DBCS // MUST fix for FE NT
  255. #define FIX_375051_NOW
  256. #endif
  257. #ifdef FIX_375051_NOW
  258. #define WOW32_strupr(psz) CharUpperA(psz)
  259. #else
  260. #define WOW32_strupr(psz) _strupr(psz)
  261. #endif