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.

103 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. umkm.h
  5. Abstract:
  6. Macros to simplify usermode & kernelmode shared code.
  7. Author:
  8. Scott Field (sfield) 19-Sep-99
  9. --*/
  10. #ifndef __UMKM_H__
  11. #define __UMKM_H__
  12. #ifndef KMODE_RNG
  13. #define __LOCK_TYPE CRITICAL_SECTION
  14. #ifdef WINNT_RNG
  15. #define INIT_LOCK(x) NT_SUCCESS( RtlInitializeCriticalSection( x ) )
  16. #else
  17. BOOLEAN
  18. __forceinline
  19. INIT_LOCK(
  20. PCRITICAL_SECTION x
  21. )
  22. {
  23. __try {
  24. InitializeCriticalSection(x);
  25. return TRUE;
  26. } __except(EXCEPTION_EXECUTE_HANDLER)
  27. {
  28. return FALSE;
  29. }
  30. }
  31. #endif
  32. //#define INIT_LOCK(x) InitializeCriticalSectionAndSpinCount(x, 0x333)
  33. #define DELETE_LOCK(x) DeleteCriticalSection(x)
  34. #define ENTER_LOCK(x) EnterCriticalSection(x)
  35. #define LEAVE_LOCK(x) LeaveCriticalSection(x)
  36. #define ALLOC(cb) HeapAlloc(GetProcessHeap(), 0, cb)
  37. #define ALLOC_NP(cb) ALLOC(cb)
  38. #define FREE(pv) HeapFree(GetProcessHeap(), 0, pv)
  39. #define REGCLOSEKEY(x) RegCloseKey( x )
  40. #ifdef WIN95_RNG
  41. PVOID
  42. InterlockedCompareExchangePointerWin95(
  43. PVOID *Destination,
  44. PVOID Exchange,
  45. PVOID Comperand
  46. );
  47. #define INTERLOCKEDCOMPAREEXCHANGEPOINTER(x,y,z) InterlockedCompareExchangePointerWin95(x,y,z)
  48. #else
  49. #define INTERLOCKEDCOMPAREEXCHANGEPOINTER(x,y,z) InterlockedCompareExchangePointer(x,y,z)
  50. #endif // WIN95_RNG
  51. #else
  52. //#define __LOCK_TYPE KSPIN_LOCK
  53. #define __LOCK_TYPE ERESOURCE
  54. #define RNG_TAG 'cesK'
  55. //#define INIT_LOCK(x) KeInitializeSpinLock( x )
  56. //#define DELETE_LOCK(x)
  57. //#define ENTER_LOCK(x) ExAcquireSpinLock( x, &OldIrql )
  58. //#define LEAVE_LOCK(x) ExReleaseSpinLock( x, OldIrql )
  59. #define ALLOC(cb) ExAllocatePoolWithTag(PagedPool, cb, RNG_TAG)
  60. #define ALLOC_NP(cb) ExAllocatePoolWithTag(NonPagedPool, cb, RNG_TAG)
  61. #define FREE(pv) ExFreePool(pv)
  62. #define INIT_LOCK(x) NT_SUCCESS( ExInitializeResourceLite( x ) )
  63. #define DELETE_LOCK(x) ExDeleteResourceLite( x )
  64. #define ENTER_LOCK(x) KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite( x, TRUE )
  65. #define LEAVE_LOCK(x) ExReleaseResourceLite( x ); KeLeaveCriticalRegion()
  66. #define REGCLOSEKEY(x) ZwClose( x )
  67. #define INTERLOCKEDCOMPAREEXCHANGEPOINTER(x,y,z) InterlockedCompareExchangePointer(x,y,z)
  68. #endif
  69. #endif // __UMKM_H__