How to allocate physically contiguous memory in user mode on windows 7

Discussion in 'alt.windows7.general' started by rsyed, Mar 12, 2012.

  1. rsyed

    rsyed Guest

    Hello

    I want to allocate non paged physically contiguous memory in system memory i
    "user mode". Can any one suggest me the API through which we ca
    achieve this, or the way we can achieve this

    FYI
    I know that we can achieve this in kernel mode using the AP
    "MmAllocateContiguousMemory"

    Regards
    Rahim.
     
    rsyed, Mar 12, 2012
    #1
    1. Advertisements

  2. rsyed

    Paul Guest

    Re: How to allocate physically contiguous memory in user mode onwindows 7

    rsyed wrote:
    > Hello,
    >
    > I want to allocate non paged physically contiguous memory in system memory in
    > "user mode". Can any one suggest me the API through which we can
    > achieve this, or the way we can achieve this.
    >
    > FYI,
    > I know that we can achieve this in kernel mode using the API
    > "MmAllocateContiguousMemory".
    >
    > Regards,
    > Rahim.


    In user space (ring 3), there is no such requirement. User space
    uses virtual addresses, and the physical memory referenced by
    a virtual address, doesn't have to be contiguous. Only a driver
    writer would care to make the PA addresses contiguous (and only
    for the benefit of some dumb DMA circuits). Ordinary program
    writers, are "insulated" from hardware, and only care that the
    virtual addresses are contiguous. In this example, my program
    gets what looks like four contiguous storage locations, even though
    there in two different areas of physical memory.

    CPU --> VA TLB PA
    0x01 0x23
    0x02 0x24
    0x03 0x58
    0x04 0x59

    You don't write drivers in user space. You write them in
    kernel space (ring 0) and in there, the MmAllocateContiguousMemory
    can help you define contiguous addresses, for hardware which
    lacks scatter/gather DMA support. Perhaps something like
    the AGP GART, would have been an example of an area needing
    something like MmAllocateContiguousMemory.

    PA <--- DMA hardware, PCI bus
    0x23 (for architectures where the peripherals
    0x24 chips don't have access to a mapper or TLB.)
    0x25
    0x26 A few processors now, have an IOMMU, to add
    the ability to do translations here. But
    since not all processors have an IOMMU, it's
    not a feature the OS can rely on. Having an
    IOMMU, avoids the need for bounce buffers.

    HTH,
    Paul
     
    Paul, Mar 12, 2012
    #2
    1. Advertisements

  3. rsyed

    rsyed Guest

    Paul wrote on 03/12/2012 13:39 ET
    > rsyed wrote
    >> Hello
    >>
    >> I want to allocate non paged physically contiguous memory in system memory i
    >> "user mode". Can any one suggest me the API through which we ca
    >> achieve this, or the way we can achieve this
    >>
    >> FYI
    >> I know that we can achieve this in kernel mode using the AP
    >> "MmAllocateContiguousMemory"
    >>
    >> Regards
    >> Rahim
    >>
    >>
    >>

    > In user space (ring 3), there is no such requirement. User spac
    > uses virtual addresses, and the physical memory referenced b
    > a virtual address, doesn't have to be contiguous. Only a drive
    > writer would care to make the PA addresses contiguous (and onl
    > for the benefit of some dumb DMA circuits). Ordinary progra
    > writers, are "insulated" from hardware, and only care that th
    > virtual addresses are contiguous. In this example, my progra
    > gets what looks like four contiguous storage locations, even thoug
    > there in two different areas of physical memory
    >
    > CPU --> VA TLB P
    > 0x01 0x2
    > 0x02 0x2
    > 0x03 0x5
    > 0x04 0x5
    >
    > You don't write drivers in user space. You write them i
    > kernel space (ring 0) and in there, the MmAllocateContiguousMemor
    > can help you define contiguous addresses, for hardware whic
    > lacks scatter/gather DMA support. Perhaps something lik
    > the AGP GART, would have been an example of an area needin
    > something like MmAllocateContiguousMemory
    >
    > PA < DMA hardware, PCI bu
    > 0x23 (for architectures where the peripheral
    > 0x24 chips don't have access to a mapper or TLB.
    > 0x2
    > 0x26 A few processors now, have an IOMMU, to ad
    > the ability to do translations here. Bu
    > since not all processors have an IOMMU, it'
    > not a feature the OS can rely on. Having a
    > IOMMU, avoids the need for bounce buffers
    >
    > HTH
    > Pau
    >

    &ldquo;We have a requirement to allocate a pinned memory(non swappabl
    physica
    page memory) in user mode of windows 7, can someone suggest how this can b
    achieved in user mode, which are the windows API&rsquo;s available &rdquo;
    Little explanation and Links to the documents would be helpful

    Regards
    Rahim.
     
    rsyed, Mar 13, 2012
    #3
  4. rsyed

    Paul Guest

    Re: How to allocate physically contiguous memory in user mode onwindows 7

    rsyed wrote:
    > Paul wrote on 03/12/2012 13:39 ET :
    >> rsyed wrote:
    >>> Hello,
    >>>
    >>> I want to allocate non paged physically contiguous memory in system memory in
    >>> "user mode". Can any one suggest me the API through which we can
    >>> achieve this, or the way we can achieve this.
    >>>
    >>> FYI,
    >>> I know that we can achieve this in kernel mode using the API
    >>> "MmAllocateContiguousMemory".
    >>>
    >>> Regards,
    >>> Rahim.



    > We have a requirement to allocate a pinned memory(non swappable physical
    > page memory) in user mode of windows 7, can someone suggest how this can be
    > achieved in user mode, which are the windows API's available.
    > Little explanation and Links to the documents would be helpful.
    >
    > Regards,
    > Rahim.


    http://blogs.technet.com/b/markrussinovich/archive/2008/11/17/3155406.aspx

    Keyword is virtualalloc.

    *******

    This answer doesn't seem to be right. The problem is, the virtual memory system
    consists of the amount of physical memory in the system, plus the paging file.
    Virtualalloc, by the nature of its name, would not be distinguishing between
    those kinds of memory.

    My guess is, a slightly different means will be needed.

    http://www.windows-api.com/microsoft/Win32-Kernel/30356420/nonpaged-memory-in-user-space.aspx

    "VirtualAlloc can let you do this if you have the correct privilege enabled."

    *******

    This thread has a few suggestions.

    http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/cf9d17da-c29f-4183-8db6-4df5e7a4d924

    This one makes more sense. "AllocateUserPhysicalPages". That acquires physical
    memory, but without virtual addresses being allocated for them. They still need
    a virtual mapping, before being used.

    http://msdn.microsoft.com/en-us/library/aa366528(VS.85).aspx

    There is a code example here, linked from the previous page.

    http://msdn.microsoft.com/en-us/library/aa366531(v=vs.85).aspx

    Article on AWE Extensions.

    http://msdn.microsoft.com/en-us/library/aa366527(v=vs.85).aspx

    AWE relies on PAE mode, which is enabled on WinXP SP2 or SP3 as far
    as I know. And probably on later OSes. Even if a machine has less
    than 4GB of memory installed, PAE would still be enabled, because
    on WinXP it is used for NX protection (No Execute). NX prevents
    certain kinds of malware attacks.

    http://en.wikipedia.org/wiki/Address_Windowing_Extensions

    *******

    So it can be done, but it isn't the simplest thing in the world.
    As the user space program needs the privilege granted for
    that function (SeLockMemoryPrivilege).

    There is a claim here, that 7ZIP is setting that privilege :)
    And it requires a reboot, to take effect. That implies to me,
    that if you had access to the source code of 7ZIP, you might
    find a worked example of such a memory allocation.

    http://sourceforge.net/projects/sevenzip/forums/forum/45797/topic/4609502

    And another example here for setting SeLockMemoryPrivilege.

    http://www.tek-tips.com/viewthread.cfm?qid=1020893

    I'm not a software programmer. You should consult a Windows
    programming group, for the language you intend to use,
    for a real answer.

    Just a guess,
    Paul
     
    Paul, Mar 13, 2012
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. mtheriault

    How to move User profile directory c:\User\Profile

    mtheriault, Oct 9, 2009, in forum: General Discussion
    Replies:
    8
    Views:
    17,672
    mtheriault
    Nov 20, 2009
  2. Andrew

    SOLVED video memory - reserved memory

    Andrew, Mar 8, 2010, in forum: Hardware
    Replies:
    3
    Views:
    3,399
    Veedaz
    Mar 9, 2010
  3. BWS
    Replies:
    15
    Views:
    7,745
    Fire cat
    Oct 24, 2010
  4. Ophelia
    Replies:
    27
    Views:
    4,566
    Ophelia
    Jul 30, 2010
  5. Dany

    small memory dump or kernel memory dump?

    Dany, Aug 31, 2011, in forum: alt.windows7.general
    Replies:
    21
    Views:
    12,781
    Stephen Wolstenholme
    Sep 2, 2011
  6. William Palazzo
    Replies:
    0
    Views:
    1,505
    William Palazzo
    Aug 17, 2016
  7. itayzargof2
    Replies:
    0
    Views:
    806
    itayzargof2
    Nov 8, 2016
  8. Pontiac1933

    Windows 7 Pro on Windows 7 Home Computer

    Pontiac1933, Nov 16, 2016, in forum: Software
    Replies:
    1
    Views:
    1,090
    TrainableMan
    Nov 17, 2016
Loading...