[OpenBIOS] [PATCH 2/5] Introduce ofmem_malloc_align() function for arbitrary alignment.
Blue Swirl
blauwirbel at gmail.com
Tue Dec 21 22:02:27 CET 2010
On Tue, Dec 21, 2010 at 10:38 AM, Mark Cave-Ayland
<mark.cave-ayland at siriusit.co.uk> wrote:
> Rework ofmem_malloc() so that it takes a second parameter specifying the alignment for the allocation and rename it to
> ofmem_malloc_align(). Then create ofmem_malloc() as a simple wrapper function onto ofmem_malloc_align() using a default
> alignment of CONFIG_OFMEM_MALLOC_ALIGN.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
> ---
> openbios-devel/include/libopenbios/ofmem.h | 1 +
> openbios-devel/libopenbios/ofmem_common.c | 11 ++++++++---
> 2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/openbios-devel/include/libopenbios/ofmem.h b/openbios-devel/include/libopenbios/ofmem.h
> index 6472008..72247d9 100644
> --- a/openbios-devel/include/libopenbios/ofmem.h
> +++ b/openbios-devel/include/libopenbios/ofmem.h
> @@ -76,6 +76,7 @@ extern int ofmem_map_page_range( phys_addr_t phys, ucell virt, ucell size,
> ucell mode );
>
> /* malloc interface */
> +extern void* ofmem_malloc_align( size_t size, int alignment );
The standard function with this signature would be posix_memalign(),
so how about ofmem_memalign() or even ofmem_posix_memalign()?
'extern' isn't useful for function prototypes.
> extern void* ofmem_malloc( size_t size );
> extern void ofmem_free( void *ptr );
> extern void* ofmem_realloc( void *ptr, size_t size );
> diff --git a/openbios-devel/libopenbios/ofmem_common.c b/openbios-devel/libopenbios/ofmem_common.c
> index a4e199c..e892260 100644
> --- a/openbios-devel/libopenbios/ofmem_common.c
> +++ b/openbios-devel/libopenbios/ofmem_common.c
> @@ -86,7 +86,7 @@ print_trans( void )
> /* OF private allocations */
> /************************************************************************/
>
> -void* ofmem_malloc( size_t size )
> +void* ofmem_malloc_align( size_t size, int alignment )
> {
> ofmem_t *ofmem = ofmem_arch_get_private();
> alloc_desc_t *d, **pp;
> @@ -99,7 +99,7 @@ void* ofmem_malloc( size_t size )
> if( !ofmem->next_malloc )
> ofmem->next_malloc = (char*)ofmem_arch_get_malloc_base();
>
> - size = ALIGN_SIZE(size + sizeof(alloc_desc_t), CONFIG_OFMEM_MALLOC_ALIGN);
> + size = ALIGN_SIZE(size + sizeof(alloc_desc_t), alignment);
>
> /* look in the freelist */
> for( pp=&ofmem->mfree; *pp && (**pp).size < size; pp = &(**pp).next ) {
> @@ -115,7 +115,7 @@ void* ofmem_malloc( size_t size )
>
> top = ofmem_arch_get_heap_top();
>
> - ret = (char *)ALIGN_PTR((uintptr_t)ofmem->next_malloc + sizeof(alloc_desc_t), CONFIG_OFMEM_MALLOC_ALIGN);
> + ret = (char *)ALIGN_PTR((uintptr_t)ofmem->next_malloc + sizeof(alloc_desc_t), alignment);
> if( pointer2cell((void *)ret) + size > top ) {
> printk("out of malloc memory (%x)!\n", size );
> return NULL;
> @@ -132,6 +132,11 @@ void* ofmem_malloc( size_t size )
> return (void *)ret;
> }
>
> +void* ofmem_malloc( size_t size )
> +{
> + return ofmem_malloc_align( size, CONFIG_OFMEM_MALLOC_ALIGN );
> +}
> +
> void ofmem_free( void *ptr )
> {
> ofmem_t *ofmem = ofmem_arch_get_private();
> --
> 1.7.1
>
>
> --
> OpenBIOS http://openbios.org/
> Mailinglist: http://lists.openbios.org/mailman/listinfo
> Free your System - May the Forth be with you
>
More information about the OpenBIOS
mailing list