Source code of Windows XP (NT5)
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.

90 lines
1.5 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. umkm.c
  5. Abstract:
  6. Macros to simplify usermode & kernelmode shared code.
  7. Author:
  8. Scott Field (sfield) 19-Sep-99
  9. --*/
  10. #ifndef KMODE_RNG
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <zwapi.h>
  16. #else
  17. #include <ntosp.h>
  18. #include <windef.h>
  19. #endif // KMODE_RNG
  20. #include "umkm.h"
  21. #ifdef WIN95_RNG
  22. PVOID
  23. InterlockedCompareExchangePointerWin95(
  24. PVOID *Destination,
  25. PVOID Exchange,
  26. PVOID Comperand
  27. )
  28. /*++
  29. routine to allow Win95 to work. Isn't atomic, but Win95 doesn't support
  30. multiple processors. The worst case is we leak resources as a result,
  31. since we only use CompareExchange for initialization purposes.
  32. --*/
  33. {
  34. PVOID InitialValue;
  35. typedef PVOID INTERLOCKEDCOMPAREEXCHANGE(PVOID*, PVOID, PVOID);
  36. static BOOL fKnown;
  37. static INTERLOCKEDCOMPAREEXCHANGE *pilock;
  38. if( !fKnown ) {
  39. //
  40. // hacky code to bring in InterlockedCompareExchange, since
  41. // Win95 doesn't export it.
  42. //
  43. HMODULE hMod = LoadLibraryA( "kernel32.dll" );
  44. if( hMod ) {
  45. pilock = (INTERLOCKEDCOMPAREEXCHANGE*)GetProcAddress( hMod, "InterlockedCompareExchange" );
  46. }
  47. fKnown = TRUE;
  48. }
  49. if( pilock != NULL ) {
  50. return pilock( Destination, Exchange, Comperand );
  51. }
  52. InitialValue = *Destination;
  53. if ( InitialValue == Comperand ) {
  54. *Destination = Exchange;
  55. }
  56. return InitialValue;
  57. }
  58. #endif // WIN95_RNG