Re: [Edk2 Dev] Why did the allocate aligned pool services get removed from the MemoryAllocationLib.h?

Subject: Re: [Edk2 Dev] Why did the allocate aligned pool services get removed from the MemoryAllocationLib.h?

From: "Andrew J. Fish" <afish@apple.com>

To: dev@edk2.tianocore.org

Date: 2009-06-02 20:11:12

Mike,

Thanks for the explanation. It looks like the following code in  
partition driver assumes an allocated buffer does all the alignment  
required by IoAlign.  Seems like  a bug.

It would probably be good to have BlockIo protocol for testing that  
requires some crazy alignment to help catch these issues via a test.


BOOLEAN
PartitionRestoreGptTable (
   IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,
   IN  EFI_DISK_IO_PROTOCOL        *DiskIo,
   IN  EFI_PARTITION_TABLE_HEADER  *PartHeader
   )
{
   EFI_STATUS                  Status;
   UINTN                       BlockSize;
   EFI_PARTITION_TABLE_HEADER  *PartHdr;
   EFI_LBA                     PEntryLBA;
   UINT8                       *Ptr;

   PartHdr   = NULL;
   Ptr       = NULL;

   BlockSize = BlockIo->Media->BlockSize;

   PartHdr   = AllocateZeroPool (BlockSize);

   if (PartHdr == NULL) {
     DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));
     return FALSE;
   }

   PEntryLBA = (PartHeader->MyLBA == PRIMARY_PART_HEADER_LBA) ? \
                              (PartHeader->LastUsableLBA + 1) : \
                              (PRIMARY_PART_HEADER_LBA + 1);

   CopyMem (PartHdr, PartHeader, sizeof (EFI_PARTITION_TABLE_HEADER));

   PartHdr->MyLBA              = PartHeader->AlternateLBA;
   PartHdr->AlternateLBA       = PartHeader->MyLBA;
   PartHdr->PartitionEntryLBA  = PEntryLBA;
   PartitionSetCrc ((EFI_TABLE_HEADER *) PartHdr);

   Status = BlockIo->WriteBlocks (BlockIo, BlockIo->Media->MediaId,  
PartHdr->MyLBA, BlockSize, PartHdr);
   if (EFI_ERROR (Status)) {
     goto Done;
   }



Andrew Fish





On Jun 1, 2009, at 6:42 PM, Mike Kinney wrote:

> Andrew,
>
> They were removed because misuse of these APIs would cause  
> unexpected failures.
>
> For example, a buffer allocated with AllocateAlignedPool() would be  
> implemented on top of AllocatePool(), but would over allocate the  
> size of the buffer to guarantee that a pointer could be returned  
> within the allocated buffer that was at the required alignment.   
> This means the address returned may not actually be the first byte  
> in the allocate pool buffer.
>
> If a FreePool() was called by accident, instead of  
> FreeAlignedPool(), then the system would ASSERT() from the pool  
> allocation services in the DXE Core because the pool head signature  
> mat not match.  These unexpected failures were confusing and  
> difficult to root cause.
>
> Since the need for aligned buffer is fairly rare, we decided to  
> retire the aligned pool functions.  The aligned page allocation  
> services are still present.  These aligned page services may not be  
> as efficient on the use of system memory as the aligned pool  
> services, but they are functional, and do not have the unexpected  
> failures.
>
> If you have used AllocateAlignedPool() services in the past, I  
> recommend you update that code to use the AllocateAlignedPages()  
> services.
>
> Best regards,
>
> Mike
>
>
> -----Original Message-----
> From: Andrew J. Fish [mailto:afish@apple.com]
> Sent: Monday, June 01, 2009 6:16 PM
> To: dev@edk2.tianocore.org
> Subject: [Edk2 Dev] Why did the allocate aligned pool services get  
> removed from the MemoryAllocationLib.h?
>
> Why did the allocate aligned pool services get removed for the
> MemoryAllocationLib?
>
>
> Andrew Fish
>
> ------------------------------------------------------
> https://edk2.tianocore.org/ds/viewMessage.do?dsForumId=135&dsMessageId=43430
>
> To unsubscribe from this discussion, please e-mail [unsubscribeURL]
>
> ------------------------------------------------------
> https://edk2.tianocore.org/ds/viewMessage.do?dsForumId=135&dsMessageId=43431
>
> To unsubscribe from this discussion, please e-mail [unsubscribeURL]

------------------------------------------------------
https://edk2.tianocore.org/ds/viewMessage.do?dsForumId=135&dsMessageId=43496

To unsubscribe from this discussion, please e-mail [unsubscribeURL]