Kernel malloc/realloc?

Discussion in 'Windows Vista Drivers' started by Bogdan Bejan, Feb 4, 2004.

  1. Bogdan Bejan

    Alex Guest

    Do you even know the diffrence between a RTL function and a System API
    function?

    As it's been sed before, pointing to RTL source code to understand how
    **SYSTEM** APIs work is stupid.

    Sorry, if it's ofensive, but this is what it is

    MSDN Library April 2003:
    GlobalAlloc:
    GMEM_MOVEABLE:
    "Allocates movable memory. Memory blocks are never moved in physical memory,
    but they can be moved within the default heap."

    **"never moved in physical memory"**
     
    Alex, Feb 15, 2004
    #41
    1. Advertisements

  2. No, stupid is calling functions belonging to Win32, 'SYSTEM'. Windows
    NT has a kernel that has several possible environments above it and one
    of them is Win32. There is or was a POSIX environment. They also had a
    OS/2 environment at one time because the OS/2 Brief would run under NT4.
    The use of the GlobalAlloc function is not even recommended since the
    overhead is high. So how does a function in kernel32.dll even belong in
    the 'Development Device Drivers' newsgroup? The first question was
    about allocating and reallocating memory under Windows 2000+.

     
    David J. Craig, Feb 15, 2004
    #42
    1. Advertisements

  3. This comment is a remnant of Windows 3.1 standard mode. And even then the
    words about physical memory were wrong (these were related to GMEM_FIXED).

    Win32 API makes no guarantees about memory physical address.

     
    Alexander Grigoriev, Feb 15, 2004
    #43
  4. Bogdan Bejan

    Alex Guest

    I'm getting really bored, really fast, Whatever, I know that...
    And since you seem to support the look into RTL sources, learn kernel
    programming, please share with the rest of the forum what you learn after
    you look at those surces...

     
    Alex, Feb 15, 2004
    #44
  5. Bogdan Bejan

    Alex Guest

    No, it can't guarantees that the memory is not moved in physical, because as
    somone pointed early, if you allocate 1 byte it is possible that the rest of
    the 4k page be ussed by some one else, so if you grow the 1 byte to 1K then
    it has to move the first 1 byte in a new free physical page...
    ....but...
    If you alloc 4K then you grow the buffer, no coppy will be made, this is my
    belief, this is how it should be done

    Also, optimal, when allocating fractions of pages, when you grow a
    allocation unit inside a 4K page, you have to look at the sizes, you can
    ether copy the buffer being resized, or you can copy the rest of the 4k in
    another physical page. If it is implemented like this it will be quite fast.

    Besides, growable buffers are ussualy needed for streams, and low data rate
    streams like HTTP over TCP/IP put a verry low strain on the whole resize
    concept

    Even better, on application side, you can allways allocate multiples of 4K
    ( if you know you don't waste space like this)

     
    Alex, Feb 15, 2004
    #45
  6. In Win32, both GlobalAlloc and LocalAlloc are mapped to HeapAlloc.

    --
    Maxim Shatskih, Windows DDK MVP
    StorageCraft Corporation

    http://www.storagecraft.com

     
    Maxim S. Shatskih, Feb 15, 2004
    #46
  7. Bogdan Bejan

    Tim Roberts Guest

    Which debugger? The addresses above 80000000 are in kernel space. A
    user-mode debugger won't find them.

    I KNOW it's true in NT/2K/XP. I made sure by using a kernel debugger
    before I posted the comment.
    It was as of 2.4, at C0000000. I don't know about 2.6, but I'd be
    surprised if things had changed.
     
    Tim Roberts, Feb 17, 2004
    #47
  8. Bogdan Bejan

    Tim Roberts Guest

    You don't want to get into a war of credentials here.

    Look, bozo, you are the one who said:
    YOU related this thread to user-mode reallocation. I answered your
    question with a concrete, verifiable reference. If you have somehow
    developed the idea that insulting the people who are trying to help you is
    the right way to get them to continue that help, then you are sadly
    mistaken.
    Wrong. The key algorithms for most system-based functions were established
    and refined decades ago. It is extremely unlikely that the API
    implementation of a memory-related function will vary significantly from
    the RTL implementation of that same function.
    As David pointed out, this comment is a leftover from the 16-bit days and
    no longer applies in Win32 code.

    Did you perform any actual experiments to see if what you describe is even
    possible? Consider this program:

    C:\tmp>type x.c

    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>

    int main()
    {
    HANDLE heap = GetProcessHeap();
    void* pv1[4];
    int i;

    for( i = 0; i < 4; i++ )
    {
    pv1 = HeapAlloc( heap, 0, 16 );
    printf( "%08x\n", pv1 );
    }
    for( i = 0; i < 4; i++ )
    HeapFree( heap, 0, pv1 );

    return 0;
    }


    C:\tmp>cl x.c
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
    Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

    x.c
    Microsoft (R) Incremental Linker Version 6.00.8168
    Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

    /out:x.exe
    x.obj

    C:\tmp>x
    00132f48
    00132f60
    00132f78
    00132f90

    C:\tmp>

    The system API HeapAlloc has allocated those addresses within the same
    page. You cannot alter the paging of one of those objects without screwing
    up the others.
     
    Tim Roberts, Feb 17, 2004
    #48
  9. Bogdan Bejan

    Alex Guest

    The weord "kernel" in the thread title should make it quite clear what this
    is about..
    If i point to functions like GloballAlloc, is because some people took the
    idea of acctualy reallocating a memory buffer without copy close to
    blasfemy, while it is quite possible in "user mode" but was not verry clear
    how to do it in "kernel mode"
    You answer nothing, you pointed to the C++ Run Tim Library source code, and
    that is...well...stupid
    How can i learn how to realloc a memory buffer in "kernel" mode by looking
    at that?

    Fine, don't post anymore...whatver
    There is no algorithm in the RTL, the RTL is just a wrapper over some
    windows API
    Did you acctually look at this misterious RTL code? Well, i did (for reasons
    unrelated to this thread) and it maps to the user mode HeapXXX windows API,
    Same as GloballAlloc, as Max pointed out...
    Really? this whole memory management is more of a x86 thing then a OS
    dependent, the OS part is only the specific API to work with the memory, If
    you ask me

    screwing

    Ok, fine... but another experiment is in order

    In user mode, allocate a 1 page memory block, then keep resizing it in
    multiples of 1 page
    After each reallocation get the VA returned
    Pass the VA to a kernel mode driver, find out the physical adress for the VA
    Print the physical adress
     
    Alex, Feb 17, 2004
    #49
  10. Well folks, in a given heads-up as to whom to trust when answering
    questions, I'd vote for Tim. Alex is proving himself to be nothing but an
    ass with a broken keyboard and a busted spell checker. Oh ... and of course
    he always has to have the last say ... so I'm going to let him have it, and
    let him throw his little tantrum totally ignored.

    Gary

     
    Gary G. Little, Feb 17, 2004
    #50
  11. I'm afraid it's WinIce artifact (or caused by DisablePagingExecutive flag
    set by WinIce).

    I see it on a Win2K system with WinIce.

    WinDbg connected to a kernel debugger on another system doesn't show such
    mapping.
     
    Alexander Grigoriev, Feb 18, 2004
    #51
    1. Advertisements

Ask a Question

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.