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.

484 lines
12 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: threadpoolparamval.cpp
  6. *
  7. * Content: DirectPlay Thread Pool parameter validation functions.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 10/31/01 VanceO Created.
  13. *
  14. ******************************************************************************/
  15. #include "dpnthreadpooli.h"
  16. #ifndef DPNBUILD_NOPARAMVAL
  17. #if ((! defined(DPNBUILD_ONLYONETHREAD)) || (! defined(DPNBUILD_LIBINTERFACE)))
  18. #undef DPF_MODNAME
  19. #define DPF_MODNAME "IsValidDirectPlay8ThreadPoolObject"
  20. //=============================================================================
  21. // IsValidDirectPlay8ThreadPoolObject
  22. //-----------------------------------------------------------------------------
  23. //
  24. // Description: Ensures the given pointer is a valid IDirectPlay8ThreadPool
  25. // interface and object.
  26. //
  27. // Arguments:
  28. // PVOID pvObject - Pointer to interface to validate.
  29. //
  30. // Returns: BOOL
  31. // TRUE - The object is valid.
  32. // FALSE - The object is not valid.
  33. //=============================================================================
  34. BOOL IsValidDirectPlay8ThreadPoolObject(PVOID pvObject)
  35. {
  36. INTERFACE_LIST * pIntList = (INTERFACE_LIST*) pvObject;
  37. DPTHREADPOOLOBJECT * pDPTPObject;
  38. if (!DNVALID_READPTR(pvObject, sizeof(INTERFACE_LIST)))
  39. {
  40. DPFX(DPFPREP, 0, "Invalid object pointer!");
  41. return FALSE;
  42. }
  43. if (pIntList->lpVtbl != &DPTP_Vtbl)
  44. {
  45. DPFX(DPFPREP, 0, "Invalid object - bad vtable!");
  46. return FALSE;
  47. }
  48. if (pIntList->iid != IID_IDirectPlay8ThreadPool)
  49. {
  50. DPFX(DPFPREP, 0, "Invalid object - bad iid!");
  51. return FALSE;
  52. }
  53. if ((pIntList->pObject == NULL) ||
  54. (! DNVALID_READPTR(pIntList->pObject, sizeof(OBJECT_DATA))))
  55. {
  56. DPFX(DPFPREP, 0, "Invalid object data!");
  57. return FALSE;
  58. }
  59. pDPTPObject = (DPTHREADPOOLOBJECT*) GET_OBJECT_FROM_INTERFACE(pvObject);
  60. if ((pDPTPObject == NULL) ||
  61. (! DNVALID_READPTR(pDPTPObject, sizeof(DPTHREADPOOLOBJECT))))
  62. {
  63. DPFX(DPFPREP, 0, "Invalid object!");
  64. return FALSE;
  65. }
  66. return TRUE;
  67. } // IsValidDirectPlay8ThreadPoolObject
  68. #undef DPF_MODNAME
  69. #define DPF_MODNAME "DPTPValidateInitialize"
  70. //=============================================================================
  71. // DPTPValidateInitialize
  72. //-----------------------------------------------------------------------------
  73. //
  74. // Description: Validation for IDirectPlay8ThreadPool::Initialize.
  75. //
  76. // Arguments: See DPTP_Initialize.
  77. //
  78. // Returns: HRESULT
  79. //=============================================================================
  80. HRESULT DPTPValidateInitialize(IDirectPlay8ThreadPool * pInterface,
  81. PVOID const pvUserContext,
  82. const PFNDPNMESSAGEHANDLER pfn,
  83. const DWORD dwFlags)
  84. {
  85. HRESULT hr;
  86. if (! IsValidDirectPlay8ThreadPoolObject(pInterface))
  87. {
  88. DPFX(DPFPREP, 0, "Invalid object specified!");
  89. hr = DPNERR_INVALIDOBJECT;
  90. goto Exit;
  91. }
  92. if (pfn == NULL)
  93. {
  94. DPFX(DPFPREP, 0, "Invalid message handler function!");
  95. hr = DPNERR_INVALIDPARAM;
  96. goto Exit;
  97. }
  98. if (dwFlags & ~(DPNINITIALIZE_DISABLEPARAMVAL))
  99. {
  100. DPFX(DPFPREP, 0, "Invalid flags!");
  101. hr = DPNERR_INVALIDFLAGS;
  102. goto Exit;
  103. }
  104. hr = DPN_OK;
  105. Exit:
  106. return hr;
  107. } // DPTPValidateInitialize
  108. #undef DPF_MODNAME
  109. #define DPF_MODNAME "DPTPValidateClose"
  110. //=============================================================================
  111. // DPTPValidateClose
  112. //-----------------------------------------------------------------------------
  113. //
  114. // Description: Validation for IDirectPlay8ThreadPool::Close.
  115. //
  116. // Arguments: See DPTP_Close.
  117. //
  118. // Returns: HRESULT
  119. //=============================================================================
  120. HRESULT DPTPValidateClose(IDirectPlay8ThreadPool * pInterface,
  121. const DWORD dwFlags)
  122. {
  123. HRESULT hr;
  124. if (! IsValidDirectPlay8ThreadPoolObject(pInterface))
  125. {
  126. DPFX(DPFPREP, 0, "Invalid object specified!");
  127. hr = DPNERR_INVALIDOBJECT;
  128. goto Exit;
  129. }
  130. if (dwFlags != 0)
  131. {
  132. DPFX(DPFPREP, 0, "Invalid flags!");
  133. hr = DPNERR_INVALIDFLAGS;
  134. goto Exit;
  135. }
  136. hr = DPN_OK;
  137. Exit:
  138. return hr;
  139. } // DPTPValidateClose
  140. #undef DPF_MODNAME
  141. #define DPF_MODNAME "DPTPValidateGetThreadCount"
  142. //=============================================================================
  143. // DPTPValidateGetThreadCount
  144. //-----------------------------------------------------------------------------
  145. //
  146. // Description: Validation for IDirectPlay8ThreadPool::GetThreadCount.
  147. //
  148. // Arguments: See DPTP_GetThreadCount.
  149. //
  150. // Returns: HRESULT
  151. //=============================================================================
  152. HRESULT DPTPValidateGetThreadCount(IDirectPlay8ThreadPool * pInterface,
  153. const DWORD dwProcessorNum,
  154. DWORD * const pdwNumThreads,
  155. const DWORD dwFlags)
  156. {
  157. HRESULT hr;
  158. #ifndef DPNBUILD_ONLYONEPROCESSOR
  159. SYSTEM_INFO SystemInfo;
  160. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  161. if (! IsValidDirectPlay8ThreadPoolObject(pInterface))
  162. {
  163. DPFX(DPFPREP, 0, "Invalid object specified!");
  164. hr = DPNERR_INVALIDOBJECT;
  165. goto Exit;
  166. }
  167. #ifdef DPNBUILD_ONLYONEPROCESSOR
  168. if ((dwProcessorNum != 0) && (dwProcessorNum != -1))
  169. {
  170. DPFX(DPFPREP, 0, "Invalid processor number!");
  171. hr = DPNERR_INVALIDPARAM;
  172. goto Exit;
  173. }
  174. #else // ! DPNBUILD_ONLYONEPROCESSOR
  175. GetSystemInfo(&SystemInfo);
  176. if ((dwProcessorNum > SystemInfo.dwNumberOfProcessors) && (dwProcessorNum != -1))
  177. {
  178. DPFX(DPFPREP, 0, "Invalid processor number!");
  179. hr = DPNERR_INVALIDPARAM;
  180. goto Exit;
  181. }
  182. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  183. if ((pdwNumThreads == NULL) ||
  184. (! DNVALID_WRITEPTR(pdwNumThreads, sizeof(DWORD))))
  185. {
  186. DPFX(DPFPREP, 0, "Invalid pointer specified for storing number of threads!");
  187. hr = DPNERR_INVALIDPOINTER;
  188. goto Exit;
  189. }
  190. if (dwFlags != 0)
  191. {
  192. DPFX(DPFPREP, 0, "Invalid flags!");
  193. hr = DPNERR_INVALIDFLAGS;
  194. goto Exit;
  195. }
  196. hr = DPN_OK;
  197. Exit:
  198. return hr;
  199. } // DPTPValidateGetThreadCount
  200. #undef DPF_MODNAME
  201. #define DPF_MODNAME "DPTPValidateSetThreadCount"
  202. //=============================================================================
  203. // DPTPValidateSetThreadCount
  204. //-----------------------------------------------------------------------------
  205. //
  206. // Description: Validation for IDirectPlay8ThreadPool::SetThreadCount.
  207. //
  208. // Arguments: See DPTP_SetThreadCount.
  209. //
  210. // Returns: HRESULT
  211. //=============================================================================
  212. HRESULT DPTPValidateSetThreadCount(IDirectPlay8ThreadPool * pInterface,
  213. const DWORD dwProcessorNum,
  214. const DWORD dwNumThreads,
  215. const DWORD dwFlags)
  216. {
  217. HRESULT hr;
  218. #ifndef DPNBUILD_ONLYONEPROCESSOR
  219. SYSTEM_INFO SystemInfo;
  220. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  221. if (! IsValidDirectPlay8ThreadPoolObject(pInterface))
  222. {
  223. DPFX(DPFPREP, 0, "Invalid object specified!");
  224. hr = DPNERR_INVALIDOBJECT;
  225. goto Exit;
  226. }
  227. #ifdef DPNBUILD_ONLYONEPROCESSOR
  228. if ((dwProcessorNum != 0) && (dwProcessorNum != -1))
  229. {
  230. DPFX(DPFPREP, 0, "Invalid processor number!");
  231. hr = DPNERR_INVALIDPARAM;
  232. goto Exit;
  233. }
  234. #else // ! DPNBUILD_ONLYONEPROCESSOR
  235. GetSystemInfo(&SystemInfo);
  236. if ((dwProcessorNum > SystemInfo.dwNumberOfProcessors) && (dwProcessorNum != -1))
  237. {
  238. DPFX(DPFPREP, 0, "Invalid processor number!");
  239. hr = DPNERR_INVALIDPARAM;
  240. goto Exit;
  241. }
  242. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  243. //
  244. // It doesn't make sense given current (or foreseeable) hardware, OSes, and
  245. // DPlay behavior for anyone to start more than a handful of threads per
  246. // processor, so we should prevent the user from hurting him/herself.
  247. // We'll be generous and allow the user to request up to 5,000, but I
  248. // imagine the system will be brought to its knees long before that.
  249. //
  250. // The only true requirement is that it not be the special -1 value, and
  251. // that the total number of threads for all processors doesn't equal -1 or
  252. // overflow the DWORD counter.
  253. //
  254. // The value of 0 is acceptable, it means the user wants to run in DoWork
  255. // mode (or reset some parameters that require that no threads be running).
  256. //
  257. if ((dwNumThreads == -1) || (dwNumThreads > 5000))
  258. {
  259. DPFX(DPFPREP, 0, "Invalid number of threads!");
  260. hr = DPNERR_INVALIDPARAM;
  261. goto Exit;
  262. }
  263. if (dwFlags != 0)
  264. {
  265. DPFX(DPFPREP, 0, "Invalid flags!");
  266. hr = DPNERR_INVALIDFLAGS;
  267. goto Exit;
  268. }
  269. hr = DPN_OK;
  270. Exit:
  271. return hr;
  272. } // DPTPValidateSetThreadCount
  273. #endif // ! DPNBUILD_ONLYONETHREAD or ! DPNBUILD_LIBINTERFACE
  274. #undef DPF_MODNAME
  275. #define DPF_MODNAME "DPTPValidateDoWork"
  276. //=============================================================================
  277. // DPTPValidateDoWork
  278. //-----------------------------------------------------------------------------
  279. //
  280. // Description: Validation for IDirectPlay8ThreadPool::DoWork.
  281. //
  282. // Arguments: See DPTP_DoWork.
  283. //
  284. // Returns: HRESULT
  285. //=============================================================================
  286. #ifdef DPNBUILD_LIBINTERFACE
  287. HRESULT DPTPValidateDoWork(const DWORD dwAllowedTimeSlice,
  288. const DWORD dwFlags)
  289. #else // ! DPNBUILD_LIBINTERFACE
  290. HRESULT DPTPValidateDoWork(IDirectPlay8ThreadPool * pInterface,
  291. const DWORD dwAllowedTimeSlice,
  292. const DWORD dwFlags)
  293. #endif // ! DPNBUILD_LIBINTERFACE
  294. {
  295. HRESULT hr;
  296. #ifndef DPNBUILD_LIBINTERFACE
  297. if (! IsValidDirectPlay8ThreadPoolObject(pInterface))
  298. {
  299. DPFX(DPFPREP, 0, "Invalid object specified!");
  300. hr = DPNERR_INVALIDOBJECT;
  301. goto Exit;
  302. }
  303. #endif // ! DPNBUILD_LIBINTERFACE
  304. if ((dwAllowedTimeSlice != INFINITE) && (dwAllowedTimeSlice > 60000))
  305. {
  306. DPFX(DPFPREP, 0, "Allowed time slice is too large!");
  307. hr = DPNERR_INVALIDPARAM;
  308. goto Exit;
  309. }
  310. if (dwFlags != 0)
  311. {
  312. DPFX(DPFPREP, 0, "Invalid flags!");
  313. hr = DPNERR_INVALIDFLAGS;
  314. goto Exit;
  315. }
  316. hr = DPN_OK;
  317. Exit:
  318. return hr;
  319. } // DPTPValidateDoWork
  320. /*
  321. #undef DPF_MODNAME
  322. #define DPF_MODNAME "IsValidDirectPlay8ThreadPoolWorkObject"
  323. //=============================================================================
  324. // IsValidDirectPlay8ThreadPoolWorkObject
  325. //-----------------------------------------------------------------------------
  326. //
  327. // Description: Ensures the given pointer is a valid
  328. // IDirectPlay8ThreadPoolWork interface and object.
  329. //
  330. // Arguments:
  331. // PVOID pvObject - Pointer to interface to validate.
  332. //
  333. // Returns: BOOL
  334. // TRUE - The object is valid.
  335. // FALSE - The object is not valid.
  336. //=============================================================================
  337. BOOL IsValidDirectPlay8ThreadPoolWorkObject(PVOID pvObject)
  338. #ifdef DPNBUILD_LIBINTERFACE
  339. {
  340. DPTHREADPOOLOBJECT * pDPTPObject;
  341. pDPTPObject = (DPTHREADPOOLOBJECT*) GET_OBJECT_FROM_INTERFACE(pvObject);
  342. if ((pDPTPObject == NULL) ||
  343. (! DNVALID_READPTR(pDPTPObject, sizeof(DPTHREADPOOLOBJECT))))
  344. {
  345. DPFX(DPFPREP, 0, "Invalid object!");
  346. return FALSE;
  347. }
  348. if (pDPTPObject->lpVtbl != &DPTPW_Vtbl)
  349. {
  350. DPFX(DPFPREP, 0, "Invalid object - bad vtable!");
  351. return FALSE;
  352. }
  353. return TRUE;
  354. }
  355. #else // ! DPNBUILD_LIBINTERFACE
  356. {
  357. INTERFACE_LIST * pIntList = (INTERFACE_LIST*) pvObject;
  358. DPTHREADPOOLOBJECT * pDPTPObject;
  359. if (!DNVALID_READPTR(pvObject, sizeof(INTERFACE_LIST)))
  360. {
  361. DPFX(DPFPREP, 0, "Invalid object pointer!");
  362. return FALSE;
  363. }
  364. if (pIntList->lpVtbl != &DPTPW_Vtbl)
  365. {
  366. DPFX(DPFPREP, 0, "Invalid object - bad vtable!");
  367. return FALSE;
  368. }
  369. if (pIntList->iid != IID_IDirectPlay8ThreadPoolWork)
  370. {
  371. DPFX(DPFPREP, 0, "Invalid object - bad iid!");
  372. return FALSE;
  373. }
  374. if ((pIntList->pObject == NULL) ||
  375. (! DNVALID_READPTR(pIntList->pObject, sizeof(OBJECT_DATA))))
  376. {
  377. DPFX(DPFPREP, 0, "Invalid object data!");
  378. return FALSE;
  379. }
  380. pDPTPObject = (DPTHREADPOOLOBJECT*) GET_OBJECT_FROM_INTERFACE(pvObject);
  381. if ((pDPTPObject == NULL) ||
  382. (! DNVALID_READPTR(pDPTPObject, sizeof(DPTHREADPOOLOBJECT))))
  383. {
  384. DPFX(DPFPREP, 0, "Invalid object!");
  385. return FALSE;
  386. }
  387. return TRUE;
  388. } // IsValidDirectPlay8ThreadPoolWorkObject
  389. #endif // ! DPNBUILD_LIBINTERFACE
  390. */
  391. #endif // ! DPNBUILD_NOPARAMVAL