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.

71 lines
1.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: macros.c
  6. * Content: debugging macros
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 6/10/96 kipo created it
  12. * 12/22/00 aarono #190380 - use process heap for memory allocation
  13. *@@END_MSINTERNAL
  14. ***************************************************************************/
  15. #include "dpf.h"
  16. #include "memalloc.h"
  17. #define FAILMSG(condition) \
  18. if ((condition)) { \
  19. DPF(0, DPF_MODNAME " line %d : Failed because " #condition "", __LINE__); \
  20. }
  21. #define FAILERR(err, label) \
  22. if ((err)) { \
  23. DPF(0, DPF_MODNAME " line %d : Error = %d", __LINE__, (err)); \
  24. goto label; \
  25. }
  26. #define FAILIF(condition, label) \
  27. if ((condition)) { \
  28. DPF(0, DPF_MODNAME " line %d : Failed because " #condition "", __LINE__); \
  29. goto label; \
  30. }
  31. #define FAILWITHACTION(condition, action, label) \
  32. if ((condition)) { \
  33. DPF(0, DPF_MODNAME " line %d : Failed because " #condition "", __LINE__); \
  34. { action; } \
  35. goto label; \
  36. }
  37. extern CRITICAL_SECTION csMem;
  38. #define INIT_DPSP_CSECT() InitializeCriticalSection(&csMem);
  39. #define FINI_DPSP_CSECT() DeleteCriticalSection(&csMem);
  40. // Wrap Malloc
  41. void _inline __cdecl SP_MemFree( LPVOID lptr )
  42. {
  43. EnterCriticalSection(&csMem);
  44. MemFree(lptr);
  45. LeaveCriticalSection(&csMem);
  46. }
  47. LPVOID _inline __cdecl SP_MemAlloc(UINT size)
  48. {
  49. LPVOID lpv;
  50. EnterCriticalSection(&csMem);
  51. lpv = MemAlloc(size);
  52. LeaveCriticalSection(&csMem);
  53. return lpv;
  54. }
  55. LPVOID _inline __cdecl SP_MemReAlloc(LPVOID lptr, UINT size)
  56. {
  57. EnterCriticalSection(&csMem);
  58. lptr = MemReAlloc(lptr, size);
  59. LeaveCriticalSection(&csMem);
  60. return lptr;
  61. }