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.

771 lines
19 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. heap.c
  5. Abstract:
  6. This module implements verification functions for
  7. heap management interfaces.
  8. Author:
  9. Silviu Calinoiu (SilviuC) 7-Mar-2001
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #include "verifier.h"
  14. #include "support.h"
  15. #include "critsect.h"
  16. #include "faults.h"
  17. //
  18. // During manipulation of DPH_BLOCK_INFORMATION we get this because
  19. // pointers have a default 8 byte aligned. However they will always
  20. // be 16-byte aligned because they are derived from heap allocated
  21. // blocks and these are 16 byte aligned anyway.
  22. //
  23. #if defined(_WIN64)
  24. #pragma warning(disable:4327)
  25. #endif
  26. //
  27. // Dirty unused portions of stack in order to catch usage of
  28. // uninitialized locals.
  29. //
  30. #define AVRFP_DIRTY_STACK_FREQUENCY 16
  31. LONG AVrfpDirtyStackCounter;
  32. #define AVRFP_DIRTY_THREAD_STACK() { \
  33. if ((AVrfpProvider.VerifierFlags & RTL_VRF_FLG_DIRTY_STACKS) != 0) { \
  34. if ((InterlockedIncrement(&AVrfpDirtyStackCounter) % AVRFP_DIRTY_STACK_FREQUENCY) == 0) { \
  35. AVrfpDirtyThreadStack (); \
  36. } \
  37. } \
  38. }
  39. //
  40. // Simple test to figure out if a heap was created by page heap or it is
  41. // just a normal heap.
  42. //
  43. #define IS_PAGE_HEAP(HeapHandle) (*(PULONG)HeapHandle == 0xEEEEEEEE)
  44. #define RAISE_NO_MEMORY_EXCEPTION() \
  45. { \
  46. EXCEPTION_RECORD ER; \
  47. ER.ExceptionCode = STATUS_NO_MEMORY; \
  48. ER.ExceptionFlags = 0; \
  49. ER.ExceptionRecord = NULL; \
  50. ER.ExceptionAddress = _ReturnAddress(); \
  51. ER.NumberParameters = 0; \
  52. RtlRaiseException( &ER ); \
  53. }
  54. #if defined(_X86_)
  55. #pragma optimize("y", off) // disable FPO
  56. #endif
  57. //NTSYSAPI
  58. PVOID
  59. NTAPI
  60. AVrfpRtlAllocateHeap(
  61. IN PVOID HeapHandle,
  62. IN ULONG Flags,
  63. IN SIZE_T Size
  64. )
  65. {
  66. PVOID Result;
  67. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  68. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  69. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  70. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  71. if ((Flags & HEAP_GENERATE_EXCEPTIONS)) {
  72. RAISE_NO_MEMORY_EXCEPTION ();
  73. }
  74. return NULL;
  75. }
  76. Result = RtlAllocateHeap (HeapHandle,
  77. Flags,
  78. Size);
  79. if (Result) {
  80. AVrfLogInTracker (AVrfHeapTracker,
  81. TRACK_HEAP_ALLOCATE,
  82. Result, (PVOID)Size, NULL, NULL, _ReturnAddress());
  83. }
  84. AVRFP_DIRTY_THREAD_STACK ();
  85. return Result;
  86. }
  87. #if defined(_X86_)
  88. #pragma optimize("y", off) // disable FPO
  89. #endif
  90. //NTSYSAPI
  91. BOOLEAN
  92. NTAPI
  93. AVrfpRtlFreeHeap(
  94. IN PVOID HeapHandle,
  95. IN ULONG Flags,
  96. IN PVOID BaseAddress
  97. )
  98. {
  99. BOOLEAN Result;
  100. BOOL BogusAddress;
  101. SIZE_T RequestedSize;
  102. PDPH_BLOCK_INFORMATION BlockInformation;
  103. //
  104. // Initialize RequestedSize in order to be able to compile W4.
  105. // The variable gets actually initialized when it matters but
  106. // the compiler is not able to realize that. If while initializing
  107. // it we get an exception then we will not use it.
  108. //
  109. RequestedSize = 0;
  110. if (BaseAddress != NULL && IS_PAGE_HEAP (HeapHandle)) {
  111. BogusAddress = FALSE;
  112. BlockInformation = (PDPH_BLOCK_INFORMATION)BaseAddress - 1;
  113. try {
  114. RequestedSize = BlockInformation->RequestedSize;
  115. }
  116. except (EXCEPTION_EXECUTE_HANDLER) {
  117. //
  118. // Let page heap handle the bogus block.
  119. //
  120. BogusAddress = TRUE;
  121. }
  122. if (BogusAddress == FALSE) {
  123. AVrfpFreeMemNotify (VerifierFreeMemTypeFreeHeap,
  124. BaseAddress,
  125. RequestedSize,
  126. NULL);
  127. }
  128. }
  129. Result = RtlFreeHeap (HeapHandle,
  130. Flags,
  131. BaseAddress);
  132. if (Result) {
  133. AVrfLogInTracker (AVrfHeapTracker,
  134. TRACK_HEAP_FREE,
  135. BaseAddress, NULL, NULL, NULL, _ReturnAddress());
  136. }
  137. AVRFP_DIRTY_THREAD_STACK ();
  138. return Result;
  139. }
  140. #if defined(_X86_)
  141. #pragma optimize("y", off) // disable FPO
  142. #endif
  143. //NTSYSAPI
  144. PVOID
  145. NTAPI
  146. AVrfpRtlReAllocateHeap(
  147. IN PVOID HeapHandle,
  148. IN ULONG Flags,
  149. IN PVOID BaseAddress,
  150. IN SIZE_T Size
  151. )
  152. {
  153. PVOID Result;
  154. BOOL BogusAddress;
  155. SIZE_T RequestedSize;
  156. PDPH_BLOCK_INFORMATION BlockInformation;
  157. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  158. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  159. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  160. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  161. if ((Flags & HEAP_GENERATE_EXCEPTIONS)) {
  162. RAISE_NO_MEMORY_EXCEPTION ();
  163. }
  164. return NULL;
  165. }
  166. //
  167. // Initialize RequestedSize in order to be able to compile W4.
  168. // The variable gets actually initialized when it matters but
  169. // the compiler is not able to realize that. If while initializing
  170. // it we get an exception then we will not use it.
  171. //
  172. RequestedSize = 0;
  173. if (BaseAddress != NULL &&
  174. IS_PAGE_HEAP (HeapHandle) &&
  175. ((Flags & HEAP_REALLOC_IN_PLACE_ONLY) != 0)) {
  176. BogusAddress = FALSE;
  177. BlockInformation = (PDPH_BLOCK_INFORMATION)BaseAddress - 1;
  178. try {
  179. RequestedSize = BlockInformation->RequestedSize;
  180. }
  181. except (EXCEPTION_EXECUTE_HANDLER)
  182. {
  183. //
  184. // Let page heap handle the bogus block.
  185. //
  186. BogusAddress = TRUE;
  187. }
  188. if (BogusAddress == FALSE) {
  189. AVrfpFreeMemNotify (VerifierFreeMemTypeFreeHeap,
  190. BaseAddress,
  191. RequestedSize,
  192. NULL);
  193. }
  194. }
  195. Result = RtlReAllocateHeap (HeapHandle,
  196. Flags,
  197. BaseAddress,
  198. Size);
  199. if (Result) {
  200. AVrfLogInTracker (AVrfHeapTracker,
  201. TRACK_HEAP_REALLOCATE,
  202. BaseAddress, Result, (PVOID)Size, NULL, _ReturnAddress());
  203. }
  204. AVRFP_DIRTY_THREAD_STACK ();
  205. return Result;
  206. }
  207. #if defined(_X86_)
  208. #pragma optimize("y", off) // disable FPO
  209. #endif
  210. VOID
  211. AVrfpNtdllHeapFreeCallback (
  212. PVOID AllocationBase,
  213. SIZE_T AllocationSize
  214. )
  215. {
  216. AVrfpFreeMemNotify (VerifierFreeMemTypeFreeHeap,
  217. AllocationBase,
  218. AllocationSize,
  219. NULL);
  220. }
  221. /////////////////////////////////////////////////////////////////////
  222. /////////////////////////////////////// kernel32.dll verified exports
  223. /////////////////////////////////////////////////////////////////////
  224. #if defined(_X86_)
  225. #pragma optimize("y", off) // disable FPO
  226. #endif
  227. //WINBASEAPI
  228. HANDLE
  229. WINAPI
  230. AVrfpHeapCreate(
  231. IN DWORD flOptions,
  232. IN SIZE_T dwInitialSize,
  233. IN SIZE_T dwMaximumSize
  234. )
  235. {
  236. typedef HANDLE (WINAPI * FUNCTION_TYPE) (DWORD, SIZE_T, SIZE_T);
  237. FUNCTION_TYPE Function;
  238. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpKernel32Thunks,
  239. AVRF_INDEX_KERNEL32_HEAPCREATE);
  240. BUMP_COUNTER (CNT_HEAPS_CREATED);
  241. return (* Function)(flOptions, dwInitialSize, dwMaximumSize);
  242. }
  243. #if defined(_X86_)
  244. #pragma optimize("y", off) // disable FPO
  245. #endif
  246. //WINBASEAPI
  247. BOOL
  248. WINAPI
  249. AVrfpHeapDestroy(
  250. IN OUT HANDLE hHeap
  251. )
  252. {
  253. typedef BOOL (WINAPI * FUNCTION_TYPE) (HANDLE);
  254. FUNCTION_TYPE Function;
  255. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpKernel32Thunks,
  256. AVRF_INDEX_KERNEL32_HEAPDESTROY);
  257. BUMP_COUNTER (CNT_HEAPS_DESTROYED);
  258. return (* Function)(hHeap);
  259. }
  260. #if defined(_X86_)
  261. #pragma optimize("y", off) // disable FPO
  262. #endif
  263. //WINBASEAPI
  264. HGLOBAL
  265. WINAPI
  266. AVrfpGlobalAlloc(
  267. IN UINT uFlags,
  268. IN SIZE_T dwBytes
  269. )
  270. {
  271. typedef HGLOBAL (WINAPI * FUNCTION_TYPE) (UINT, SIZE_T);
  272. FUNCTION_TYPE Function;
  273. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpKernel32Thunks,
  274. AVRF_INDEX_KERNEL32_GLOBALALLOC);
  275. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  276. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  277. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  278. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  279. NtCurrentTeb()->LastErrorValue = ERROR_OUTOFMEMORY;
  280. return NULL;
  281. }
  282. return (* Function)(uFlags, dwBytes);
  283. }
  284. #if defined(_X86_)
  285. #pragma optimize("y", off) // disable FPO
  286. #endif
  287. //WINBASEAPI
  288. HGLOBAL
  289. WINAPI
  290. AVrfpGlobalReAlloc(
  291. IN HGLOBAL hMem,
  292. IN SIZE_T dwBytes,
  293. IN UINT uFlags
  294. )
  295. {
  296. typedef HGLOBAL (WINAPI * FUNCTION_TYPE) (HGLOBAL, SIZE_T, UINT);
  297. FUNCTION_TYPE Function;
  298. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpKernel32Thunks,
  299. AVRF_INDEX_KERNEL32_GLOBALREALLOC);
  300. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  301. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  302. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  303. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  304. NtCurrentTeb()->LastErrorValue = ERROR_OUTOFMEMORY;
  305. return NULL;
  306. }
  307. return (* Function)(hMem, dwBytes, uFlags);
  308. }
  309. #if defined(_X86_)
  310. #pragma optimize("y", off) // disable FPO
  311. #endif
  312. //WINBASEAPI
  313. HLOCAL
  314. WINAPI
  315. AVrfpLocalAlloc(
  316. IN UINT uFlags,
  317. IN SIZE_T uBytes
  318. )
  319. {
  320. typedef HLOCAL (WINAPI * FUNCTION_TYPE) (UINT, SIZE_T);
  321. FUNCTION_TYPE Function;
  322. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpKernel32Thunks,
  323. AVRF_INDEX_KERNEL32_LOCALALLOC);
  324. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  325. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  326. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  327. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  328. NtCurrentTeb()->LastErrorValue = ERROR_OUTOFMEMORY;
  329. return NULL;
  330. }
  331. return (* Function)(uFlags, uBytes);
  332. }
  333. #if defined(_X86_)
  334. #pragma optimize("y", off) // disable FPO
  335. #endif
  336. //WINBASEAPI
  337. HLOCAL
  338. WINAPI
  339. AVrfpLocalReAlloc(
  340. IN HLOCAL hMem,
  341. IN SIZE_T uBytes,
  342. IN UINT uFlags
  343. )
  344. {
  345. typedef HLOCAL (WINAPI * FUNCTION_TYPE) (HLOCAL, SIZE_T, UINT);
  346. FUNCTION_TYPE Function;
  347. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpKernel32Thunks,
  348. AVRF_INDEX_KERNEL32_LOCALREALLOC);
  349. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  350. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  351. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  352. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  353. NtCurrentTeb()->LastErrorValue = ERROR_OUTOFMEMORY;
  354. return NULL;
  355. }
  356. return (* Function)(hMem, uBytes, uFlags);
  357. }
  358. /////////////////////////////////////////////////////////////////////
  359. ////////////////////////////////////////// msvcrt allocation routines
  360. /////////////////////////////////////////////////////////////////////
  361. #if defined(_X86_)
  362. #pragma optimize("y", off) // disable FPO
  363. #endif
  364. PVOID __cdecl
  365. AVrfp_malloc (
  366. IN SIZE_T Size
  367. )
  368. {
  369. typedef PVOID (__cdecl * FUNCTION_TYPE) (SIZE_T);
  370. FUNCTION_TYPE Function;
  371. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  372. AVRF_INDEX_MSVCRT_MALLOC);
  373. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  374. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  375. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  376. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  377. return NULL;
  378. }
  379. return (* Function)(Size);
  380. }
  381. #if defined(_X86_)
  382. #pragma optimize("y", off) // disable FPO
  383. #endif
  384. PVOID __cdecl
  385. AVrfp_calloc (
  386. IN SIZE_T Number,
  387. IN SIZE_T Size
  388. )
  389. {
  390. typedef PVOID (__cdecl * FUNCTION_TYPE) (SIZE_T, SIZE_T);
  391. FUNCTION_TYPE Function;
  392. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  393. AVRF_INDEX_MSVCRT_CALLOC);
  394. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  395. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  396. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  397. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  398. return NULL;
  399. }
  400. return (* Function)(Number, Size);
  401. }
  402. #if defined(_X86_)
  403. #pragma optimize("y", off) // disable FPO
  404. #endif
  405. PVOID __cdecl
  406. AVrfp_realloc (
  407. IN PVOID Address,
  408. IN SIZE_T Size
  409. )
  410. {
  411. typedef PVOID (__cdecl * FUNCTION_TYPE) (PVOID, SIZE_T);
  412. FUNCTION_TYPE Function;
  413. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  414. AVRF_INDEX_MSVCRT_REALLOC);
  415. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  416. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  417. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  418. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  419. return NULL;
  420. }
  421. return (* Function)(Address, Size);
  422. }
  423. #if defined(_X86_)
  424. #pragma optimize("y", off) // disable FPO
  425. #endif
  426. VOID __cdecl
  427. AVrfp_free (
  428. IN PVOID Address
  429. )
  430. {
  431. typedef VOID (__cdecl * FUNCTION_TYPE) (PVOID);
  432. FUNCTION_TYPE Function;
  433. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  434. AVRF_INDEX_MSVCRT_FREE);
  435. (* Function)(Address);
  436. }
  437. #if defined(_X86_)
  438. #pragma optimize("y", off) // disable FPO
  439. #endif
  440. PVOID __cdecl
  441. AVrfp_new (
  442. IN SIZE_T Size
  443. )
  444. {
  445. typedef PVOID (__cdecl * FUNCTION_TYPE) (SIZE_T);
  446. FUNCTION_TYPE Function;
  447. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  448. AVRF_INDEX_MSVCRT_NEW);
  449. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  450. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  451. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  452. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  453. return NULL;
  454. }
  455. return (* Function)(Size);
  456. }
  457. #if defined(_X86_)
  458. #pragma optimize("y", off) // disable FPO
  459. #endif
  460. VOID __cdecl
  461. AVrfp_delete (
  462. IN PVOID Address
  463. )
  464. {
  465. typedef VOID (__cdecl * FUNCTION_TYPE) (PVOID);
  466. FUNCTION_TYPE Function;
  467. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  468. AVRF_INDEX_MSVCRT_DELETE);
  469. (* Function)(Address);
  470. }
  471. #if defined(_X86_)
  472. #pragma optimize("y", off) // disable FPO
  473. #endif
  474. PVOID __cdecl
  475. AVrfp_newarray (
  476. IN SIZE_T Size
  477. )
  478. {
  479. typedef PVOID (__cdecl * FUNCTION_TYPE) (SIZE_T);
  480. FUNCTION_TYPE Function;
  481. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  482. AVRF_INDEX_MSVCRT_NEWARRAY);
  483. BUMP_COUNTER (CNT_HEAP_ALLOC_CALLS);
  484. if (SHOULD_FAULT_INJECT(CLS_HEAP_ALLOC_APIS)) {
  485. BUMP_COUNTER (CNT_HEAP_ALLOC_FAILS);
  486. CHECK_BREAK (BRK_HEAP_ALLOC_FAIL);
  487. return NULL;
  488. }
  489. return (* Function)(Size);
  490. }
  491. #if defined(_X86_)
  492. #pragma optimize("y", off) // disable FPO
  493. #endif
  494. VOID __cdecl
  495. AVrfp_deletearray (
  496. IN PVOID Address
  497. )
  498. {
  499. typedef VOID (__cdecl * FUNCTION_TYPE) (PVOID);
  500. FUNCTION_TYPE Function;
  501. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpMsvcrtThunks,
  502. AVRF_INDEX_MSVCRT_DELETEARRAY);
  503. (* Function)(Address);
  504. }
  505. /////////////////////////////////////////////////////////////////////
  506. /////////////////////////////////// oleaut32 BSTR allocation routines
  507. /////////////////////////////////////////////////////////////////////
  508. #if defined(_X86_)
  509. #pragma optimize("y", off) // disable FPO
  510. #endif
  511. BSTR
  512. STDAPICALLTYPE
  513. AVrfpSysAllocString(const OLECHAR * String)
  514. {
  515. typedef BSTR (STDAPICALLTYPE * FUNCTION_TYPE) (const OLECHAR *);
  516. FUNCTION_TYPE Function;
  517. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpOleaut32Thunks,
  518. AVRF_INDEX_OLEAUT32_SYSALLOCSTRING);
  519. BUMP_COUNTER (CNT_OLE_ALLOC_CALLS);
  520. if (SHOULD_FAULT_INJECT(CLS_OLE_ALLOC_APIS)) {
  521. BUMP_COUNTER (CNT_OLE_ALLOC_FAILS);
  522. CHECK_BREAK (BRK_OLE_ALLOC_FAIL);
  523. return NULL;
  524. }
  525. return (* Function)(String);
  526. }
  527. #if defined(_X86_)
  528. #pragma optimize("y", off) // disable FPO
  529. #endif
  530. INT
  531. STDAPICALLTYPE
  532. AVrfpSysReAllocString(BSTR * BStr, const OLECHAR *String)
  533. {
  534. typedef INT (STDAPICALLTYPE * FUNCTION_TYPE) (BSTR *, const OLECHAR *);
  535. FUNCTION_TYPE Function;
  536. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpOleaut32Thunks,
  537. AVRF_INDEX_OLEAUT32_SYSREALLOCSTRING);
  538. BUMP_COUNTER (CNT_OLE_ALLOC_CALLS);
  539. if (SHOULD_FAULT_INJECT(CLS_OLE_ALLOC_APIS)) {
  540. BUMP_COUNTER (CNT_OLE_ALLOC_FAILS);
  541. CHECK_BREAK (BRK_OLE_ALLOC_FAIL);
  542. return FALSE;
  543. }
  544. return (* Function)(BStr, String);
  545. }
  546. #if defined(_X86_)
  547. #pragma optimize("y", off) // disable FPO
  548. #endif
  549. BSTR
  550. STDAPICALLTYPE
  551. AVrfpSysAllocStringLen(const OLECHAR *String, UINT Length)
  552. {
  553. typedef BSTR (STDAPICALLTYPE * FUNCTION_TYPE) (const OLECHAR *, UINT);
  554. FUNCTION_TYPE Function;
  555. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpOleaut32Thunks,
  556. AVRF_INDEX_OLEAUT32_SYSALLOCSTRINGLEN);
  557. BUMP_COUNTER (CNT_OLE_ALLOC_CALLS);
  558. if (SHOULD_FAULT_INJECT(CLS_OLE_ALLOC_APIS)) {
  559. BUMP_COUNTER (CNT_OLE_ALLOC_FAILS);
  560. CHECK_BREAK (BRK_OLE_ALLOC_FAIL);
  561. return NULL;
  562. }
  563. return (* Function)(String, Length);
  564. }
  565. #if defined(_X86_)
  566. #pragma optimize("y", off) // disable FPO
  567. #endif
  568. INT
  569. STDAPICALLTYPE
  570. AVrfpSysReAllocStringLen(BSTR * BStr, const OLECHAR * String, UINT Length)
  571. {
  572. typedef INT (STDAPICALLTYPE * FUNCTION_TYPE) (BSTR *, const OLECHAR *, UINT);
  573. FUNCTION_TYPE Function;
  574. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpOleaut32Thunks,
  575. AVRF_INDEX_OLEAUT32_SYSREALLOCSTRINGLEN);
  576. BUMP_COUNTER (CNT_OLE_ALLOC_CALLS);
  577. if (SHOULD_FAULT_INJECT(CLS_OLE_ALLOC_APIS)) {
  578. BUMP_COUNTER (CNT_OLE_ALLOC_FAILS);
  579. CHECK_BREAK (BRK_OLE_ALLOC_FAIL);
  580. return FALSE;
  581. }
  582. return (* Function)(BStr, String, Length);
  583. }
  584. #if defined(_X86_)
  585. #pragma optimize("y", off) // disable FPO
  586. #endif
  587. BSTR
  588. STDAPICALLTYPE
  589. AVrfpSysAllocStringByteLen(LPCSTR psz, UINT len)
  590. {
  591. typedef BSTR (STDAPICALLTYPE * FUNCTION_TYPE) (LPCSTR, UINT);
  592. FUNCTION_TYPE Function;
  593. Function = AVRFP_GET_ORIGINAL_EXPORT (AVrfpOleaut32Thunks,
  594. AVRF_INDEX_OLEAUT32_SYSALLOCSTRINGBYTELEN);
  595. BUMP_COUNTER (CNT_OLE_ALLOC_CALLS);
  596. if (SHOULD_FAULT_INJECT(CLS_OLE_ALLOC_APIS)) {
  597. BUMP_COUNTER (CNT_OLE_ALLOC_FAILS);
  598. CHECK_BREAK (BRK_OLE_ALLOC_FAIL);
  599. return NULL;
  600. }
  601. return (* Function)(psz, len);
  602. }