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.

218 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. vdmint21.c
  5. Abstract:
  6. This module implements interfaces that support manipulation of i386
  7. int 21 entry of IDT. These entry points only exist on i386 machines.
  8. Author:
  9. Shie-Lin Tzong (shielint) 26-Dec-1993
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. #pragma hdrstop
  16. #include "vdmntos.h"
  17. #define IDT_ACCESS_DPL_USER 0x6000
  18. #define IDT_ACCESS_TYPE_386_TRAP 0xF00
  19. #define IDT_ACCESS_TYPE_286_TRAP 0x700
  20. #define IDT_ACCESS_PRESENT 0x8000
  21. #define LDT_MASK 4
  22. //
  23. // External Reference
  24. //
  25. BOOLEAN
  26. Ki386GetSelectorParameters(
  27. IN USHORT Selector,
  28. OUT PULONG Flags,
  29. OUT PULONG Base,
  30. OUT PULONG Limit
  31. );
  32. //
  33. // Define forward referenced function prototypes.
  34. //
  35. VOID
  36. Ki386LoadTargetInt21Entry (
  37. IN PKIPI_CONTEXT SignalDone,
  38. IN PVOID Parameter1,
  39. IN PVOID Parameter2,
  40. IN PVOID Parameter3
  41. );
  42. #define KiLoadInt21Entry() \
  43. KeGetPcr()->IDT[0x21] = PsGetCurrentProcess()->Pcb.Int21Descriptor
  44. typedef struct _INT21INFO {
  45. KIDTENTRY IdtDescriptor;
  46. PKPROCESS Process;
  47. } INT21INFO, *PINT21INFO;
  48. NTSTATUS
  49. Ke386SetVdmInterruptHandler (
  50. PKPROCESS Process,
  51. ULONG Interrupt,
  52. USHORT Selector,
  53. ULONG Offset,
  54. BOOLEAN Gate32
  55. )
  56. /*++
  57. Routine Description:
  58. The specified (software) interrupt entry of IDT will be updated to
  59. point to the specified handler. For all threads which belong to the
  60. specified process, their execution processors will be notified to
  61. make the same change.
  62. This function only exists on i386 and i386 compatible processors.
  63. No checking is done on the validity of the interrupt handler.
  64. Arguments:
  65. Process - Pointer to KPROCESS object describing the process for
  66. which the int 21 entry is to be set.
  67. Interrupt - The software interrupt vector which will be updated.
  68. Selector, offset - Specified the address of the new handler.
  69. Gate32 - True if the gate should be 32 bit, false otherwise
  70. Return Value:
  71. NTSTATUS.
  72. --*/
  73. {
  74. KIDTENTRY IdtDescriptor;
  75. ULONG Flags, Base, Limit;
  76. INT21INFO Int21Info;
  77. //
  78. // Check the validity of the request
  79. // 1. Currently, we support int21 redirection only
  80. // 2. The specified interrupt handler must be in user space.
  81. //
  82. if (Interrupt != 0x21 || Offset >= (ULONG)MM_HIGHEST_USER_ADDRESS ||
  83. !Ki386GetSelectorParameters(Selector, &Flags, &Base, &Limit) ){
  84. return STATUS_INVALID_PARAMETER;
  85. }
  86. //
  87. // Initialize the contents of the IDT entry
  88. //
  89. IdtDescriptor.Offset = (USHORT)Offset;
  90. IdtDescriptor.Selector = Selector | RPL_MASK | LDT_MASK;
  91. IdtDescriptor.ExtendedOffset = (USHORT)(Offset >> 16);
  92. IdtDescriptor.Access = IDT_ACCESS_DPL_USER | IDT_ACCESS_PRESENT;
  93. if (Gate32) {
  94. IdtDescriptor.Access |= IDT_ACCESS_TYPE_386_TRAP;
  95. } else {
  96. IdtDescriptor.Access |= IDT_ACCESS_TYPE_286_TRAP;
  97. }
  98. Int21Info.IdtDescriptor = IdtDescriptor;
  99. Int21Info.Process = Process;
  100. KeGenericCallDpc (Ki386LoadTargetInt21Entry,
  101. &Int21Info);
  102. return STATUS_SUCCESS;
  103. }
  104. VOID
  105. Ki386LoadTargetInt21Entry (
  106. PKDPC Dpc,
  107. IN PVOID DeferredContext,
  108. IN PVOID SystemArgument1,
  109. IN PVOID SystemArgument2
  110. )
  111. /*++
  112. Routine Description:
  113. Reload local Ldt register and clear signal bit in TargetProcessor mask
  114. Arguments:
  115. Argument - pointer to a ipi packet structure.
  116. ReadyFlag - Pointer to flag to be set once LDTR has been reloaded
  117. Return Value:
  118. none.
  119. --*/
  120. {
  121. PINT21INFO Int21Info;
  122. UNREFERENCED_PARAMETER (Dpc);
  123. Int21Info = DeferredContext;
  124. //
  125. // Make sure all DPC's are running so a load of the process
  126. // LdtDescriptor field can't be torn
  127. //
  128. if (KeSignalCallDpcSynchronize (SystemArgument2)) {
  129. //
  130. // Set the Ldt fields in the process object
  131. //
  132. Int21Info->Process->Int21Descriptor = Int21Info->IdtDescriptor;
  133. }
  134. //
  135. // Wait till everyone is at this point before continuing
  136. //
  137. KeSignalCallDpcSynchronize (SystemArgument2);
  138. //
  139. // Set the int 21 entry of IDT from currently active process object
  140. //
  141. KiLoadInt21Entry ();
  142. //
  143. // Signal that all processing has been done
  144. //
  145. KeSignalCallDpcDone (SystemArgument1);
  146. return;
  147. }