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.

153 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. deviosup.c
  5. Abstract:
  6. This module implements the memory locking routines for the netware
  7. redirector.
  8. Author:
  9. Manny Weiser (mannyw) 10-Mar-1993
  10. Revision History:
  11. --*/
  12. #include "procs.h"
  13. //
  14. // Local debug trace level
  15. //
  16. #define Dbg (DEBUG_TRACE_DEVIOSUP)
  17. #ifdef ALLOC_PRAGMA
  18. #pragma alloc_text( PAGE, NwMapUserBuffer )
  19. #pragma alloc_text( PAGE, NwLockUserBuffer )
  20. #endif
  21. VOID
  22. NwMapUserBuffer (
  23. IN OUT PIRP Irp,
  24. IN KPROCESSOR_MODE AccessMode,
  25. OUT PVOID *UserBuffer
  26. )
  27. /*++
  28. Routine Description:
  29. This routine obtains a usable virtual address for the user buffer
  30. for the current I/O request in the specified mode.
  31. Arguments:
  32. Irp - Pointer to the Irp for the request.
  33. AccessMode - UserMode or KernelMode.
  34. UserBuffer - Returns pointer to mapped user buffer.
  35. Return Value:
  36. None.
  37. --*/
  38. {
  39. PAGED_CODE();
  40. AccessMode;
  41. //
  42. // If there is no Mdl, then we must be in the Fsd, and we can simply
  43. // return the UserBuffer field from the Irp.
  44. //
  45. if (Irp->MdlAddress == NULL) {
  46. *UserBuffer = Irp->UserBuffer;
  47. return;
  48. }
  49. //
  50. // Get a system virtual address for the buffer.
  51. //
  52. *UserBuffer = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority );
  53. return;
  54. }
  55. VOID
  56. NwLockUserBuffer (
  57. IN OUT PIRP Irp,
  58. IN LOCK_OPERATION Operation,
  59. IN ULONG BufferLength
  60. )
  61. /*++
  62. Routine Description:
  63. This routine locks the specified buffer for the specified type of
  64. access. The file system requires this routine since it does not
  65. ask the I/O system to lock its buffers for direct I/O. This routine
  66. may only be called from the FSD while still in the user context.
  67. Arguments:
  68. Irp - Pointer to the IRP for which the buffer is to be locked.
  69. Operation - IoWriteAccess for read operations, or IoReadAccess for
  70. write operations.
  71. BufferLength - Length of user buffer.
  72. Return Value:
  73. None
  74. --*/
  75. {
  76. PMDL mdl;
  77. PAGED_CODE();
  78. if (Irp->MdlAddress == NULL) {
  79. //
  80. // This read is bound for the current process. Perform the
  81. // same functions as above, only do not switch processes.
  82. //
  83. mdl = IoAllocateMdl( Irp->UserBuffer, BufferLength, FALSE, TRUE, Irp );
  84. if (mdl == NULL) {
  85. ExRaiseStatus( STATUS_INSUFFICIENT_RESOURCES );
  86. }
  87. try {
  88. MmProbeAndLockPages( mdl,
  89. Irp->RequestorMode,
  90. Operation );
  91. } except(EXCEPTION_EXECUTE_HANDLER) {
  92. IoFreeMdl( mdl );
  93. Irp->MdlAddress = NULL;
  94. ExRaiseStatus( FsRtlNormalizeNtstatus( GetExceptionCode(),
  95. STATUS_INVALID_USER_BUFFER ));
  96. }
  97. }
  98. }