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.

96 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. procswap.c
  5. Abstract:
  6. This module implements the platform dependent kernel function to swap
  7. processes.
  8. Author:
  9. David N. Cutler (davec) 10-Jun-2000
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. BOOLEAN
  16. KiSwapProcess (
  17. IN PKPROCESS NewProcess,
  18. IN PKPROCESS OldProcess
  19. )
  20. /*++
  21. Routine Description:
  22. This function swaps the address space to another process by flushing the
  23. the translation buffer and establishings a new directory table base. It
  24. also swaps the I/O permission map to the new process.
  25. N.B. There is code similar to this code in swap context.
  26. N.B. This code is executed at DPC level.
  27. Arguments:
  28. NewProcess - Supplies a pointer to the new process object.
  29. Oldprocess - Supplies a pointer to the old process object.
  30. Return Value:
  31. None.
  32. --*/
  33. {
  34. PKSPIN_LOCK_QUEUE LockQueue;
  35. PKPRCB Prcb;
  36. PKTSS64 TssBase;
  37. //
  38. // Acquire the context swap lock and update the active processor
  39. // masks for the new and old process.
  40. //
  41. Prcb = KeGetCurrentPrcb();
  42. #if !defined(NT_UP)
  43. LockQueue = &Prcb->LockQueue[LockQueueContextSwapLock];
  44. KeAcquireQueuedSpinLockAtDpcLevel(LockQueue);
  45. OldProcess->ActiveProcessors ^= Prcb->SetMember;
  46. ASSERT((OldProcess->ActiveProcessors & Prcb->SetMember) == 0);
  47. NewProcess->ActiveProcessors ^= Prcb->SetMember;
  48. ASSERT((NewProcess->ActiveProcessors & Prcb->SetMember) != 0);
  49. KeReleaseQueuedSpinLockFromDpcLevel(LockQueue);
  50. #endif // !defined(NT_UP)
  51. //
  52. // Set the offset of the I/O permissions map for the new process and
  53. // load the new directory table base.
  54. //
  55. TssBase = KeGetPcr()->TssBase;
  56. TssBase->IoMapBase = NewProcess->IopmOffset;
  57. WriteCR3(NewProcess->DirectoryTableBase[0]);
  58. return TRUE;
  59. }