I use the following class for that. Constructor must be called in the user
process context.
/////////////////////////////////////////////////////////////////
// File: lockedmem.cpp
// Description:
// Locked buffer class
// Author: Lyadvinsky M.V.
// Date: 23.11.2000
/////////////////////////////////////////////////////////////////
#include “lockedmem.h”
CLockedMem::CLockedMem(PVOID pBuffer,
ULONG uSize, NTSTATUS* pStatus) :
m_pBuffer(pBuffer),
m_pSysBuffer(NULL),
m_uSize(uSize),
m_pMdl(NULL)
{
NTSTATUS ntStatus;
// Check parameters
if (uSize && pBuffer)
ntStatus = STATUS_SUCCESS;
else
ntStatus = STATUS_INVALID_PARAMETER;
// Allocate MDL
if (NT_SUCCESS(ntStatus))
{
m_pMdl =
DL)nonpagednew(
MmSizeOfMdl(m_pBuffer, m_uSize));
if (!m_pMdl)
ntStatus = STATUS_NO_MEMORY;
}
// Initialize and lock MDL
if (NT_SUCCESS(ntStatus))
{
MmInitializeMdl(m_pMdl,
m_pBuffer, m_uSize);
__try
{
MmProbeAndLockPages(m_pMdl,
UserMode, IoWriteAccess);
m_pSysBuffer = MmGetSystemAddressForMdl(m_pMdl);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
m_pSysBuffer = NULL;
ntStatus = STATUS_ACCESS_VIOLATION;
}
}
// Return status
if (pStatus)
*pStatus = ntStatus;
}
CLockedMem::~CLockedMem()
{
if (m_pSysBuffer)
MmUnlockPages(m_pMdl);
if (m_pMdl)
delete m_pMdl;
}
Regards,
Max
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of
xxxxx@hotmail.com
Sent: Monday, June 18, 2001 6:52 AM
To: NT Developers Interest List
Subject: [ntdev] MmProbeAndLockPages() & UserMode address
Hi,
I need to access in KernelMode driver (in work item queued from worker
thread) some memory ptr UserMode app pass me via device control. I use
MmProbeAndLockPages( ptr, UserMode, IoModifyAccess ). Do I need to call
MmXxx from device control dispatcher before I’ve queued IRP and I’m still
in callers thread context or I can call MmXxx directly in work item when
I’m in system thread context? Right now I call it from dispatcher and get
sometimes exception code 0xC0000005 (access violation) on valid buffer ptrs
passed by UserMode app. What can it be?
Thanks for help,
Anton
CoolDev.Com - Toolkits for Network & Storage Software Developers
“KoolSockets” & “KoolStorage” - TDI Client, SCSI miniport, iSCSI
www.CoolDev.Com xxxxx@CoolDev.Com xxxxx@CoolDev.com
You are currently subscribed to ntdev as: xxxxx@acronis.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com