On Sep 5, 2013, at 12:41 PM, Fernando Ferraz <[email protected]> wrote:
> Hi,
>
> I've created a function that fills a linked list containing blocks of 1024kB
> and a pointer to the next node.
>
> my struct is something like this:
>
> typedef struct _Buffer {
> UINT64 Len; //By default 1024*1024
> UINT64 *InitialAddress; //Pointer to the the 1024K buffer
> struct _Buffer *Next; //Pointer to the next buffer container
> } Buffer;
>
>
> I started allocating a pointer to my struct called Buffer (I expect it
> consumes about 24 Bytes on a X86_64 architecture).
>
>
> Status = EfiBootServices->AllocatePool(EfiBootServicesData,
> sizeof(Buffer),
> (VOID**) &FirstNode);
>
>
> Then I allocated a new pointer containing about 1024KB and I was expecting
> something like a contiguous address in relation to my previous allocated
> struct.
>
>
> Status = EfiBootServices->AllocatePool(EfiBootServicesData,
> SIZE_ONE_MB,
> (VOID**) &InitAddress);
>
>
> But what I found was a address pointing to a different region in memory (eg.
> struct address = 0x6B563598, 1024K buffer address = 0x6A51E018 or address =
> 0x6B1A7C98, 1024K buffer address = 0x507018 in forward nodes) which is not
> contiguous.
>
> There is a especific algorithm on UDK for memory allocation or it is
> something that each manufacturer decides what to use? There is some
> documentation that I can read to understand this behavior?
>
Why do you expect memory allocations to be contiguous? This is not guaranteed
any place in the UEFI spec. Depending on implementation specifics seems like a
bad plan for portability.
If you look in
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdeModulePkg/Core/Dxe/Mem/Pool.c
you will notice that the Pool allocations contain a POOL_HEAD and a POOL_TAIL
structures that wrap the buffer returned to the caller. There is also a scheme
to reuse previously freed buffers of a similar size. So there is no way you
will ever get contiguous memory ranges allocated. Not to mention these
structures and schemes could change at anytime.
Why not just ask for what you want:
#include <Library/MemoryAllocationLib.>
...
FirstNode = AllocatePool (sizeof (Buffer) + SIZE_ONE_MB);
if (FirstNode != NULL) {
FirstNode->InitialAddress = (UINT64 *)(FirstNode + 1);
}
Thanks,
Andrew Fish
>
>
> Thank you,
> Fernando
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel