Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1K8gYj-0000Gh-9Q for mharc-grub-devel@gnu.org; Tue, 17 Jun 2008 15:09:37 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K8gYh-0000GZ-GR for grub-devel@gnu.org; Tue, 17 Jun 2008 15:09:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K8gYf-0000GB-Rm for grub-devel@gnu.org; Tue, 17 Jun 2008 15:09:35 -0400 Received: from [199.232.76.173] (port=34573 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K8gYf-0000G8-Lt for grub-devel@gnu.org; Tue, 17 Jun 2008 15:09:33 -0400 Received: from yx-out-1718.google.com ([74.125.44.154]:65024) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K8gYf-0005MU-9K for grub-devel@gnu.org; Tue, 17 Jun 2008 15:09:33 -0400 Received: by yx-out-1718.google.com with SMTP id 34so671172yxf.66 for ; Tue, 17 Jun 2008 12:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:mime-version:subject:date:references :x-mailer; bh=sh+uGIXzhaHUZmKKN9m7ovAIYA5dTCq4RRECpBoucZc=; b=wwOIH7rgJ6FnXR1J6hEiNfrW/R+dSLpZ6A9DK+WXZxLWYRaaE6dUiIy9Bf9HHidYw2 cXtEIpsODfwQHJJXNPkEPayFvRLER8WrmhrZwmNT5x0lBKT9wws/if8RTKlB5TFzvsfQ 4PFu78GUrCOdVZIMkrTmDnVASLdrpjteNEe2M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type:mime-version:subject :date:references:x-mailer; b=ukuP3pt2BBDONk5qYd3E/d/edRyGc0V9ALR1qNYzHGjFJUA0q70jlES8Qzlsl+WE8t QWyNqPLVG3/w7yGwkXy8UC1D2DVdK7kPuNLnToU64bIMxjQ76IFDGos9hkVXxGolW1Fs YQDbUlma9exQIBo8eywAT56w0FUSoa/x3zFRM= Received: by 10.150.52.2 with SMTP id z2mr13429373ybz.43.1213729771615; Tue, 17 Jun 2008 12:09:31 -0700 (PDT) Received: from ?172.29.0.147? ( [131.193.17.26]) by mx.google.com with ESMTPS id u6sm2988336pyb.0.2008.06.17.12.09.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 17 Jun 2008 12:09:30 -0700 (PDT) Message-Id: <4655B5DB-11BD-4A0D-9398-ABBD96A2F2CC@gmail.com> From: "Andrei E. Warkentin" To: The development of GRUB 2 In-Reply-To: <4857F2D3.1080703@dholloway.com> Content-Type: multipart/alternative; boundary=Apple-Mail-2--800632223 Mime-Version: 1.0 (Apple Message framework v919.2) Date: Tue, 17 Jun 2008 14:09:28 -0500 References: <200806170307.m5H37DjU073382@shoebox.dholloway.com> <48576165.1000002@dholloway.com> <48577CA8.5000604@dholloway.com> <4857F2D3.1080703@dholloway.com> X-Mailer: Apple Mail (2.919.2) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: grub EFI "too little memory" X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jun 2008 19:09:36 -0000 --Apple-Mail-2--800632223 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit > > Exactly on target. Then we need a more robust and permanent > solution I think right? > > How about asking with 0 sized buffer first knowing it will fail then > asking with a rounded-up buffer the 2nd time. > I can coded it, but I can't check it in of course. > > http://www.uefi.org/specs/ You shouldn't assume memory map size (in fact, it can change during the runtime if you use AllocatePool/FreePool/AllocatePages/FreePages), and should be something like... UINTN currentMemoryMapSize = 0; UINTN expectedMemoryMapSize = 0; EFI_MEMORY_DESCRIPTOR *memoryMap = NULL; UINTN mapKey; UINTN descriptorSize; UINT32 descriptorVersion; EFI_STATUS status = EFI_BUFFER_TOO_SMALL; while(status == EFI_BUFFER_TOO_SMALL) { status = gBS->GetMemoryMap(&expectedMemoryMapSize, &memoryMap, &mapKey, &descriptorSize, &descriptorVersion); if(status != EFI_BUFFER_TOO_SMALL) { break; } // May have allocated already... if(currentMemorySize) { status = gBS->FreePool(memoryMap); if(EFI_ERROR(status)) { break; } } // As per spec, allocate more than requested to handle growth of memory map due to allocation). expectedMemorySize = expectedMemorySize * 2; status = gBS->AllocatePool(EfiLoaderData, expectedMemoryMapSize, (VOID**) &memoryMap); currentMemoryMapSize = expectedMemoryMapSize; if(EFI_ERROR(status)) { break; } // Make sure we retry to get the memory map. status = EFI_BUFFER_TOO_SMALL; } if(EFI_ERROR(status) || currentMemoryMapSize == 0) { // No memory map, assorted errors.... } // Loop over the memoryMapSize array using descriptorSize (_NOT_ sizeof(EFI_MEMORY_DESCRIPTOR)), as that could break for future EFI versions where the descriptor size might increase with expansion). // Free pool. > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel --Apple-Mail-2--800632223 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable

Exactly on target.  Then we need a more robust = and permanent solution I think right?

How about asking with 0 = sized buffer first knowing it will fail then asking with a rounded-up = buffer the 2nd time.
I can coded it, but I can't check it in of = course.




You shouldn't assume memory map size (in fact, it can = change during the runtime if you use = AllocatePool/FreePool/AllocatePages/FreePages), and should be something = like...

UINTN currentMemoryMapSize =3D = 0;
UINTN expectedMemoryMapSize =3D = 0;
EFI_MEMORY_DESCRIPTOR *memoryMap =3D NULL;
UINTN = mapKey;
UINTN descriptorSize;
UINT32 = descriptorVersion;
EFI_STATUS status =3D = EFI_BUFFER_TOO_SMALL;
while(status =3D=3D = EFI_BUFFER_TOO_SMALL)
{
 status =3D = gBS->GetMemoryMap(&expectedMemoryMapSize, &memoryMap, = &mapKey, &descriptorSize, = &descriptorVersion);
if(status !=3D =  EFI_BUFFER_TOO_SMALL)
{
= break;
}

// May = have allocated already...
= if(currentMemorySize)
{
= status =3D gBS->FreePool(memoryMap);
= if(EFI_ERROR(status))
{
= break;
}
= }

// As per spec, allocate more = than requested to handle growth of memory map due to = allocation).
expectedMemorySize = =3D expectedMemorySize * 2;
status =3D = gBS->AllocatePool(EfiLoaderData, expectedMemoryMapSize, (VOID**) = &memoryMap);
currentMemoryMapSize =3D = expectedMemoryMapSize;
= if(EFI_ERROR(status))
{
= break;
}

// Make = sure we retry to get the memory map.
status =3D = EFI_BUFFER_TOO_SMALL;
}
if(EFI_ERROR(status) || = currentMemoryMapSize =3D=3D = 0)
{

// No memory map, assorted = errors....
}

// Loop over the = memoryMapSize array using descriptorSize (_NOT_ sizeof(EFI_MEMORY_DESCRIPTOR)), as that = could break for future EFI versions where the descriptor size might = increase with expansion).

// Free = pool. 






_______________________________________________
G= rub-devel mailing list
Grub-devel@gnu.org
http://lists.= gnu.org/mailman/listinfo/grub-devel

= --Apple-Mail-2--800632223--