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.

79 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. eballoc.c
  5. Abstract:
  6. Process/Thread Environment Block allocation functions
  7. Author:
  8. Steve Wood (stevewo) 10-May-1990
  9. Revision History:
  10. --*/
  11. #include "ntrtlp.h"
  12. #include <nturtl.h>
  13. #if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
  14. #pragma alloc_text(PAGE,RtlAcquirePebLock)
  15. #pragma alloc_text(PAGE,RtlReleasePebLock)
  16. #endif
  17. typedef VOID (*PEB_LOCK_ROUTINE)(PVOID FastLock);
  18. VOID
  19. RtlAcquirePebLock( VOID )
  20. {
  21. PEB_LOCK_ROUTINE LockRoutine;
  22. PPEB Peb;
  23. LARGE_INTEGER Timeout;
  24. RTL_PAGED_CODE();
  25. Peb = NtCurrentPeb();
  26. LockRoutine = (PEB_LOCK_ROUTINE)Peb->FastPebLockRoutine;
  27. ASSERT(LockRoutine);
  28. for (;;) {
  29. try {
  30. (LockRoutine)(Peb->FastPebLock);
  31. break;
  32. } except ( GetExceptionCode() == STATUS_INSUFFICIENT_RESOURCES
  33. ? EXCEPTION_EXECUTE_HANDLER
  34. : EXCEPTION_CONTINUE_SEARCH ) {
  35. //
  36. // Unfortunately, a number of things assume that
  37. // RtlAcquirePebLock can't fail. So we need to loop and
  38. // try again.
  39. //
  40. Timeout.QuadPart = UInt32x32To64( 10 /* Milliseconds to sleep */,
  41. 10000 /* Milliseconds to 100 Nanoseconds) */);
  42. Timeout.QuadPart *= -1; /* Make it a relative time */
  43. NtDelayExecution(FALSE, &Timeout);
  44. continue;
  45. }
  46. }
  47. }
  48. VOID
  49. RtlReleasePebLock( VOID )
  50. {
  51. PEB_LOCK_ROUTINE LockRoutine;
  52. PPEB Peb;
  53. RTL_PAGED_CODE();
  54. Peb = NtCurrentPeb();
  55. LockRoutine = (PEB_LOCK_ROUTINE)Peb->FastPebUnlockRoutine;
  56. ASSERT(LockRoutine);
  57. (LockRoutine)(Peb->FastPebLock);
  58. }