Leaked source code of windows server 2003
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.

272 lines
8.2 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // General utility functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef _UTIL_H_
  9. #define _UTIL_H_
  10. // error codes
  11. #define OVERFLOW 0x1000
  12. #define SYNTAX 0x1001
  13. #define BADRANGE 0x1002
  14. #define VARDEF 0x1003
  15. #define EXTRACHARS 0x1004
  16. #define LISTSIZE 0x1005
  17. #define STRINGSIZE 0x1006
  18. #define MEMORY 0x1007
  19. #define BADREG 0x1008
  20. #define BADOPCODE 0x1009
  21. #define SUFFIX 0x100a
  22. #define OPERAND 0x100b
  23. #define ALIGNMENT 0x100c
  24. #define PREFIX 0x100d
  25. #define DISPLACEMENT 0x100e
  26. #define BPLISTFULL 0x100f
  27. #define BPDUPLICATE 0x1010
  28. #define BADTHREAD 0x1011
  29. #define DIVIDE 0x1012
  30. #define TOOFEW 0x1013
  31. #define TOOMANY 0x1014
  32. #define BADSIZE 0x1015
  33. #define BADSEG 0x1016
  34. #define RELOC 0x1017
  35. #define BADPROCESS 0x1018
  36. #define AMBIGUOUS 0x1019
  37. #define FILEREAD 0x101a
  38. #define LINENUMBER 0x101b
  39. #define BADSEL 0x101c
  40. #define SYMTOOSMALL 0x101d
  41. #define BPIONOTSUP 0x101e
  42. #define NOTFOUND 0x101f
  43. #define SESSIONNOTSUP 0x1020
  44. #define BADSYSTEM 0x1021
  45. #define NOMEMORY 0x1022
  46. #define TYPECONFLICT 0x1023
  47. #define TYPEDATA 0x1024
  48. #define NOTMEMBER 0x1025
  49. #define IMPLERR 0x1026
  50. #define ENGBUSY 0x1027
  51. #define TARGETNOTSUP 0x1028
  52. #define NORUNNABLE 0x1029
  53. #define NOTSECURE 0x102a
  54. #define UNIMPLEMENT 0x1099
  55. extern PCSTR g_DefaultLogFileName;
  56. extern char g_OpenLogFileName[];
  57. extern BOOL g_OpenLogFileAppended;
  58. extern int g_LogFile;
  59. extern ULONG g_DisableErrorPrint;
  60. extern char g_Blanks[];
  61. ULONG CheckUserInterrupt(void);
  62. BOOL PollUserInterrupt(BOOL AllowPendingBreak);
  63. LONG MappingExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo);
  64. void RemoveDelChar(PSTR Buffer);
  65. ULONG64 HexValue(ULONG Size);
  66. void HexList(PUCHAR Buffer, ULONG BufferSize,
  67. ULONG EltSize, PULONG CountRet);
  68. ULONG64 FloatValue(ULONG Size);
  69. void FloatList(PUCHAR Buffer, ULONG BufferSize,
  70. ULONG EltSize, PULONG CountRet);
  71. void AsciiList(PSTR Buffer, ULONG BufferSize,
  72. PULONG CountRet);
  73. #define STRV_SPACE_IS_SEPARATOR 0x00000001
  74. #define STRV_TRIM_TRAILING_SPACE 0x00000002
  75. #define STRV_ALLOW_ESCAPED_CHARACTERS 0x00000004
  76. #define STRV_COMPRESS_ESCAPED_CHARACTERS 0x00000008
  77. #define STRV_ALLOW_EMPTY_STRING 0x00000010
  78. #define STRV_NO_MODIFICATION 0x00000020
  79. #define STRV_ESCAPED_CHARACTERS \
  80. (STRV_ALLOW_ESCAPED_CHARACTERS | STRV_COMPRESS_ESCAPED_CHARACTERS)
  81. PSTR BufferStringValue(PSTR* Buf, ULONG Flags,
  82. PULONG Len, PCHAR Save);
  83. PSTR StringValue(ULONG Flags, PCHAR Save);
  84. void CompressEscapes(PSTR Str);
  85. PCSTR ErrorString(ULONG Code);
  86. void DECLSPEC_NORETURN ReportError(ULONG Code, PCSTR* Desc);
  87. inline void DECLSPEC_NORETURN ErrorDesc(ULONG Code, PCSTR Desc)
  88. {
  89. ReportError(Code, &Desc);
  90. }
  91. #define error(Code) ReportError(Code, NULL)
  92. void OpenLogFile(PCSTR File, BOOL Append);
  93. void CloseLogFile(void);
  94. void ParseLogOpen(BOOL Append);
  95. void lprintf(PCSTR Str);
  96. #define SYMADDR_FORCE 0x00000001
  97. #define SYMADDR_LABEL 0x00000002
  98. #define SYMADDR_SOURCE 0x00000004
  99. #define SYMADDR_OFFSET 0x00000008
  100. void OutputSymAddr(ULONG64 Offset,
  101. ULONG Flags,
  102. PCSTR Prefix);
  103. BOOL OutputLineAddr(ULONG64 Offset,
  104. PCSTR Format);
  105. LPSTR FormatMachineAddr64(MachineInfo* Machine,
  106. ULONG64 Addr);
  107. #define FormatAddr64(Addr) \
  108. FormatMachineAddr64(g_Target ? g_Target->m_Machine : NULL, Addr)
  109. LPSTR FormatDisp64(ULONG64 Addr);
  110. //
  111. // Output that can be displayed about the current register set.
  112. //
  113. void OutCurInfo(ULONG Flags, ULONG AllMask, ULONG RegMask);
  114. // Items displayed if the flag is given.
  115. // Display symbol nearest PC.
  116. #define OCI_SYMBOL 0x00000001
  117. // Display disassembly at PC.
  118. #define OCI_DISASM 0x00000002
  119. // Items which may be displayed if the flag is given. Other global
  120. // settings ultimately control whether information is displayed or not;
  121. // these flags indicate whether such output is allowed or not. Each
  122. // of these flags also has a FORCE bit to force display regardless of
  123. // the global settings.
  124. // Allow registers to be displayed.
  125. #define OCI_ALLOW_REG 0x00000004
  126. // Allow display of source code and/or source line.
  127. #define OCI_ALLOW_SOURCE 0x00000008
  128. // Allow EA memory to be displayed during disasm.
  129. #define OCI_ALLOW_EA 0x00000010
  130. // Force all output to be shown regardless of global settings.
  131. #define OCI_FORCE_ALL 0x80000000
  132. // Force display of registers.
  133. #define OCI_FORCE_REG 0x40000000
  134. // Force source output.
  135. #define OCI_FORCE_SOURCE 0x20000000
  136. // Force display of EA memory during disasm.
  137. #define OCI_FORCE_EA 0x10000000
  138. // Don't check for running state.
  139. #define OCI_IGNORE_STATE 0x08000000
  140. BOOL
  141. __inline
  142. ConvertQwordsToDwords(
  143. PULONG64 Qwords,
  144. PULONG Dwords,
  145. ULONG Count
  146. )
  147. {
  148. BOOL rval = TRUE;
  149. while (Count--) {
  150. rval = rval && (*Qwords >> 32) == 0;
  151. *Dwords++ = (ULONG)*Qwords++;
  152. }
  153. return rval;
  154. }
  155. DWORD
  156. NetworkPathCheck(
  157. LPCSTR PathList
  158. );
  159. #define ALL_ID_LIST 0xffffffff
  160. ULONG GetIdList(BOOL AllowMulti);
  161. void AppendComponentsToPath(PSTR Path, PCSTR Components,
  162. BOOL Validate);
  163. HRESULT ChangePath(PSTR* Path, PCSTR New, BOOL Append, ULONG SymNotify);
  164. void CheckPath(PCSTR Path);
  165. HRESULT ChangeString(PSTR* Str, PULONG StrLen, PCSTR New);
  166. void
  167. ExceptionRecordTo64(PEXCEPTION_RECORD Rec,
  168. PEXCEPTION_RECORD64 Rec64);
  169. void
  170. ExceptionRecord64To(PEXCEPTION_RECORD64 Rec64,
  171. PEXCEPTION_RECORD Rec);
  172. void
  173. MemoryBasicInformationTo64(PMEMORY_BASIC_INFORMATION Mbi,
  174. PMEMORY_BASIC_INFORMATION64 Mbi64);
  175. void
  176. MemoryBasicInformation32To64(PMEMORY_BASIC_INFORMATION32 Mbi32,
  177. PMEMORY_BASIC_INFORMATION64 Mbi64);
  178. void
  179. DebugEvent32To64(LPDEBUG_EVENT32 Event32,
  180. LPDEBUG_EVENT64 Event64);
  181. void
  182. WaitStateChange32ToAny(IN PDBGKD_WAIT_STATE_CHANGE32 Ws32,
  183. IN ULONG ControlReportSize,
  184. OUT PDBGKD_ANY_WAIT_STATE_CHANGE WsAny);
  185. PSTR TimeToStr(ULONG TimeDateStamp);
  186. PSTR LONG64FileTimeToStr(LONG64 UTCFileTimeStamp);
  187. PSTR FileTimeToStr(FILETIME UTCFileTime);
  188. PSTR DurationToStr(ULONG64 Duration);
  189. PCSTR PathTail(PCSTR Path);
  190. PCWSTR PathTailW(PCWSTR Path);
  191. BOOL MatchPathTails(PCSTR Path1, PCSTR Path2, BOOL Wild);
  192. BOOL IsValidName(PSTR String);
  193. BOOL MakeFileNameUnique(PSTR OriginalName,
  194. PSTR Buffer, ULONG BufferChars,
  195. BOOL AppendTime, ProcessInfo* Pid);
  196. BOOL GetEngineDirectory(PSTR Buffer, ULONG BufferChars);
  197. BOOL IsInternalPackage(void);
  198. void TranslateNtPathName(PSTR Path);
  199. class ShellProcess
  200. {
  201. public:
  202. ShellProcess(void);
  203. ~ShellProcess(void);
  204. DWORD ReaderThread(void);
  205. static DWORD WINAPI ReaderThreadCb(LPVOID Param);
  206. static BOOL CreateAsyncPipePair(OUT LPHANDLE ReadPipe,
  207. OUT LPHANDLE WritePipe,
  208. IN LPSECURITY_ATTRIBUTES SecAttr,
  209. IN DWORD Size,
  210. IN DWORD ReadMode,
  211. IN DWORD WriteMode);
  212. HRESULT Start(PCSTR CmdString,
  213. PCSTR InFile,
  214. PCSTR OutFile,
  215. PCSTR ErrFile);
  216. void WaitForProcessExit(void);
  217. void Close(void);
  218. HANDLE m_IoIn, m_IoOut;
  219. HANDLE m_ProcIn, m_ProcOut, m_ProcErr;
  220. HANDLE m_IoSignal;
  221. HANDLE m_ProcThread, m_Process;
  222. HANDLE m_ReaderThread;
  223. ULONG m_DefaultTimeout;
  224. static ULONG s_PipeSerialNumber;
  225. };
  226. #endif // #ifndef _UTIL_H_