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.

222 lines
5.9 KiB

  1. #pragma once
  2. #include "nt.h"
  3. #include "ntrtl.h"
  4. #include "nturtl.h"
  5. #include "windows.h"
  6. #include <stddef.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <stdarg.h>
  10. #pragma warning(push)
  11. #pragma warning(disable: 4511)
  12. #pragma warning(disable: 4512)
  13. #pragma warning(disable: 4663)
  14. #include <yvals.h>
  15. #pragma warning(disable: 4663)
  16. #include <string>
  17. #include <deque>
  18. #include <vector>
  19. #pragma warning(pop)
  20. #include <algorithm>
  21. #include "sxsapi.h"
  22. #include "fusionlastwin32error.h"
  23. #include "fusionbuffer.h"
  24. #define SxStressToolGetCurrentProcessId() (HandleToUlong(NtCurrentTeb()->ClientId.UniqueProcess))
  25. #define SxStressToolGetCurrentThreadId() (HandleToUlong(NtCurrentTeb()->ClientId.UniqueThread))
  26. //
  27. // Conserve memory.
  28. //
  29. //typedef CGenericStringBuffer<1, CUnicodeCharTraits> CTinyUnicodeStringBuffer;
  30. typedef CTinyUnicodeStringBuffer CTinyStringBuffer;
  31. #include "fusiontrace.h"
  32. #include "fusiondeque.h"
  33. extern CEvent ResumeThreadsEvent;
  34. extern CEvent StopEvent;
  35. extern LONG ThreadsWaiting;
  36. extern LONG TotalThreads;
  37. extern CStringBuffer BaseDirectory;
  38. void ReportFailure(const char szFormat[], ...);
  39. BOOL InitializeMSIInstallTest();
  40. void WaitForMSIInstallTestThreads();
  41. void CleanupMSIInstallTest();
  42. void RequestShutdownMSIInstallTestThreads();
  43. DWORD WINAPI MSIInstallTestThreadProc(LPVOID);
  44. BOOL InitializeInstall();
  45. void WaitForInstallThreads();
  46. void CleanupInstall();
  47. DWORD WINAPI InstallThreadProc(LPVOID);
  48. BOOL InitializeCreateActCtx();
  49. void WaitForCreateActCtxThreads();
  50. void CleanupCreateActCtx();
  51. DWORD WINAPI CreateActCtxThreadProc(LPVOID);
  52. DWORD
  53. WINAPI
  54. InstallThreadProc(
  55. LPVOID pvData
  56. );
  57. void RequestShutdownInstallThreads();
  58. void RequestShutdownCreateActCtxThreads();
  59. //
  60. // std::string has specialized find_first_not_of that uses integral positions,
  61. // and globally there is only find_first_of. Here we provide the expected
  62. // iterator-based find_first_not_of, based on the std::string code.
  63. //
  64. // Find the first occurence in [first1, last1) of an element in [first2, last).
  65. //
  66. // eg:
  67. // find_first_not_of("abc":"12;3", ":;");
  68. // ^
  69. // find_first_not_of(":12;3", ":;");
  70. // ^
  71. // find_first_not_of("3", ":;");
  72. // ^
  73. //
  74. template <typename Iterator>
  75. inline Iterator FindFirstNotOf(Iterator first1, Iterator last1, Iterator first2, Iterator last2)
  76. {
  77. if (first2 == last2)
  78. return last1;
  79. for ( ; first1 != last1 ; ++first1)
  80. {
  81. if (std::find(first2, last2, *first1) == last2)
  82. {
  83. break;
  84. }
  85. }
  86. return first1;
  87. }
  88. template <typename Iterator>
  89. inline Iterator FindFirstOf(Iterator first1, Iterator last1, Iterator first2, Iterator last2)
  90. {
  91. return std::find_first_of(first1, last1, first2, last2);
  92. }
  93. class SxStressToolUnicodeString_t: public UNICODE_STRING
  94. {
  95. public:
  96. typedef PCWSTR const_iterator;
  97. typedef PWSTR iterator;
  98. SxStressToolUnicodeString_t(PCWSTR s) { RtlInitUnicodeString(this, s); }
  99. SxStressToolUnicodeString_t(PCWSTR s, PCWSTR t)
  100. {
  101. this->Buffer = const_cast<PWSTR>(s);
  102. const USHORT Length = static_cast<USHORT>(t - s) * sizeof(WCHAR);
  103. this->Length = Length;
  104. this->MaximumLength = Length;
  105. }
  106. SIZE_T size() const { return Length / sizeof(Buffer[0]); }
  107. SIZE_T length() const { return size(); }
  108. PCWSTR begin() const { return Buffer; }
  109. PCWSTR end() const { return begin() + size(); }
  110. PWSTR begin() { return Buffer; }
  111. PWSTR end() { return begin() + size(); }
  112. };
  113. template <typename String_t>
  114. inline void SxStressToolSplitString(
  115. const String_t& String,
  116. const String_t& Delim,
  117. std::vector<String_t>& Fields
  118. )
  119. {
  120. String_t::const_iterator FieldBegin;
  121. String_t::const_iterator FieldEnd = String.begin();
  122. while ((FieldBegin = FindFirstNotOf(FieldEnd, String.end(), Delim.begin(), Delim.end())) != String.end())
  123. {
  124. FieldEnd = FindFirstOf(FieldBegin, String.end(), Delim.begin(), Delim.end());
  125. Fields.push_back(String_t(FieldBegin, FieldEnd));
  126. }
  127. }
  128. typedef struct _FUSION_FLAG_FORMAT_MAP_ENTRY FUSION_FLAG_FORMAT_MAP_ENTRY, *PFUSION_FLAG_FORMAT_MAP_ENTRY;
  129. typedef const FUSION_FLAG_FORMAT_MAP_ENTRY *PCFUSION_FLAG_FORMAT_MAP_ENTRY;
  130. BOOL
  131. SxStressToolExtractFlagsFromString(
  132. ULONG Flags,
  133. PCFUSION_FLAG_FORMAT_MAP_ENTRY FlagData,
  134. ULONG NumberOfFlagData,
  135. PCWSTR FlagString,
  136. ULONG& FlagOut
  137. );
  138. LONG StringToNumber(PCWSTR s);
  139. PCWSTR StringToResourceString(PCWSTR s);
  140. BOOL
  141. SxStressToolGetStringSetting(
  142. ULONG Flags,
  143. PCWSTR IniFilePath,
  144. PCWSTR Section,
  145. PCWSTR Key,
  146. PCWSTR Default,
  147. CBaseStringBuffer& Buffer,
  148. PCWSTR* DumbPointer OPTIONAL = 0
  149. );
  150. BOOL
  151. SxStressToolGetFlagSetting(
  152. ULONG Flags,
  153. PCWSTR IniFilePath,
  154. PCWSTR Section,
  155. PCWSTR Key,
  156. ULONG& FlagsOut,
  157. PCFUSION_FLAG_FORMAT_MAP_ENTRY FlagData,
  158. ULONG NumberOfFlagData
  159. );
  160. BOOL
  161. SxStressToolGetResourceIdSetting(
  162. ULONG FutureFlags,
  163. PCWSTR IniFilePath,
  164. PCWSTR Section,
  165. PCWSTR Key,
  166. CBaseStringBuffer& Buffer,
  167. PCWSTR* DumbPointer
  168. );
  169. BOOL WaitForThreadResumeEvent();
  170. BOOL
  171. SxspGetPrivateProfileIntW(
  172. PCWSTR pcwszSection,
  173. PCWSTR pcwszKeyName,
  174. INT defaultValue,
  175. INT &Target,
  176. PCWSTR pcwszFilename
  177. );
  178. BOOL
  179. SxspGetPrivateProfileStringW(
  180. PCWSTR pcwszSection,
  181. PCWSTR pcwszKeyName,
  182. PCWSTR pcwszDefault,
  183. OUT CBaseStringBuffer &buffTarget,
  184. PCWSTR pcwszFileName
  185. );
  186. BOOL
  187. SxspIsPrivateProfileStringEqual(
  188. PCWSTR pcwszSection,
  189. PCWSTR pcwszKeyName,
  190. PCWSTR pcwszTestValue,
  191. BOOL &rfIsEqual,
  192. PCWSTR pcwszFileName
  193. );