diff --git a/include/common/memory.h b/include/common/memory.h index 2b7121b42..d52fb6265 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -33,6 +33,7 @@ #else #define MEM_F_SHARED 0 #endif +#define MEM_F_EXACT 0x2 /* reserve an extra void* at the end of a pool for linking */ #ifdef DEBUG_MEMORY_POOLS diff --git a/src/memory.c b/src/memory.c index 036f78607..53ab4890a 100644 --- a/src/memory.c +++ b/src/memory.c @@ -24,7 +24,9 @@ int mem_poison_byte = -1; /* Try to find an existing shared pool with the same characteristics and * returns it, otherwise creates this one. NULL is returned if no memory - * is available for a new creation. + * is available for a new creation. Two flags are supported : + * - MEM_F_SHARED to indicate that the pool may be shared with other users + * - MEM_F_EXACT to indicate that the size must not be rounded up */ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) { @@ -41,8 +43,10 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags) * so that the visible parts outside are not affected. */ - align = 16; - size = ((size + POOL_EXTRA + align - 1) & -align) - POOL_EXTRA; + if (!(flags & MEM_F_EXACT)) { + align = 16; + size = ((size + POOL_EXTRA + align - 1) & -align) - POOL_EXTRA; + } start = &pools; pool = NULL;