ARIF:
It is dangerous, et. c. Back in less security conscious times,
Microsoft used to provide an example of this type of thing in the DDK,
with the significant exception that the sample allocated it’s own buffer
before mapping it. In any case, the example is no longer shipped, but I
imagine you can find it (it’s called something like MemMap). Below is
an outline of the basic steps, working on the assumption that you
already have a physical address (which I think is correct):
Open a handle to \Device\PhysicalMemory:
RtlInitUnicodeString(& deviceName, “\Device\PhysicalMemory”);
InitializeObjectAttributes(& attributes, & deviceName,
OBJ_CASE_INSENSITIVE, 0, 0);
ZwOpenSection(& handle, SECTION_ALL_ATTRIBUTES, & attributes);
ObReferenceObjectByHandle(handle, SECTION_ALL_ACCESS, NULL, KernelMode,
& section, NULL);
if (numberOfBytesToMap)
{
ZwMapViewOfSection(handle, (HANDLE) -1, & virtualAddress, 0,
numberOfBytesToMap, & sectionBase, & numberOfBytesToMap, ViewShare, 0,
PAGE_READWRITE | PAGE_NOCACHE);
}
virtualAddress += physicalAddress.LowPart - sectionBase.LowPart;
ZwClose(handle);
It’s been a while since I’ve done this, but this is the jist of it.
One issue that you may have to beware of is whether or not the physical
memory that you are attempting to map is already mapped to another
virtual address range (in any context) with different caching
attributes. Doing so on Win2K (I think; it may be XP) or later will
fail; on earlier versions, it may cause corruption of the TLB. There is
no easy or documented way to determining if this is the case or not.
I hope this helps.
MM
>> xxxxx@acm.org 2006-05-27 08:09 >>>
This is an incredibly dangerous idea, since it blows security out of
the
water. What happens if the device has DMA or an interrupt, the user
app
will be able to crash the OS anytime it wants. While there are a few
devices where mapping a large memory region from PCI space to user
space is
justified, it is rare.
Tell us why you need such an unsecure and broken architecture, and
maybe we
will help.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply
“Arif Golde” wrote in message
news:xxxxx@ntdev…
> Hi everybody,
> I would want to write a memory mapper driver. This driver should be
able
> to find the physical base address from the configuration register of
a PCI
> device. After this it should be able to read and write to register’s
at an
> offset to this. The user should only need to provide the Subsystem
vendor
> ID and Subsystem device ID. The driver enumerates the PCI bus and
finds
> the device.
>
> CM_PARTIAL_RESOURCE_DESCRIPTOR p_mem_res ; // i get by iterating
though
> the CM_RESOURCE_LIST
> if( p_res->Type == CmResourceTypeMemory )
>
> _p_reg_base = (BYTE)MmMapIoSpace( p_mem_res->u.Memory.Start,
> p_mem_res->u.Memory.Length,
> MmNonCached );
>
> now this would give me a virtual base address in kernel space. How
would a
> user mode application able to address it. Honestly I don’t understand
the
> concept of kernel memory mapping and MDL’s?
> Can somebody patiently answer this.
>
> Also would this work with PCIe?
>
> Thanks
> Arif
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it’s
FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer