summaryrefslogtreecommitdiff
path: root/lib/libutils/isoc/bget_malloc.c
diff options
context:
space:
mode:
authorJens Wiklander <jens.wiklander@linaro.org>2020-12-28 21:52:33 +0100
committerJérôme Forissier <jerome@forissier.org>2021-01-05 15:21:06 +0100
commitcc5981b239d3f1d1ef4cffa3d8cdd407c4c7ef79 (patch)
tree36b32bb0e710cca72b92071414db29063caf4f7a /lib/libutils/isoc/bget_malloc.c
parent27e8d08d664b80a632eac1065d4904f85220bd75 (diff)
libutil: add alignment parameter to bget
Adds alignment parameter to bget(), bgetz() and bgetr(). If alignment is larger then 0 the returned buffer is guaranteed to have an address which is a multiple of this value. The algorithm is basically unchanged, in the way that the memory is still allocated from the end of a free memory block. The difference is in the core implementation in bget() where now alignment of the returned memory is taken into account. If only allocating with the minimum alignment the memory blocks are expected to be allocated in the same pattern. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'lib/libutils/isoc/bget_malloc.c')
-rw-r--r--lib/libutils/isoc/bget_malloc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libutils/isoc/bget_malloc.c b/lib/libutils/isoc/bget_malloc.c
index 12a72c9c..ae804957 100644
--- a/lib/libutils/isoc/bget_malloc.c
+++ b/lib/libutils/isoc/bget_malloc.c
@@ -371,7 +371,7 @@ static void *raw_malloc(size_t hdr_size, size_t ftr_size, size_t pl_size,
if (!s)
s++;
- ptr = bget(s, &ctx->poolset);
+ ptr = bget(0, s, &ctx->poolset);
out:
raw_malloc_return_hook(ptr, pl_size, ctx);
@@ -406,7 +406,7 @@ static void *raw_calloc(size_t hdr_size, size_t ftr_size, size_t pl_nmemb,
if (!s)
s++;
- ptr = bgetz(s, &ctx->poolset);
+ ptr = bgetz(0, s, &ctx->poolset);
out:
raw_malloc_return_hook(ptr, pl_nmemb * pl_size, ctx);
@@ -431,7 +431,7 @@ static void *raw_realloc(void *ptr, size_t hdr_size, size_t ftr_size,
if (!s)
s++;
- p = bgetr(ptr, s, &ctx->poolset);
+ p = bgetr(ptr, 0, s, &ctx->poolset);
out:
raw_malloc_return_hook(p, pl_size, ctx);
@@ -452,7 +452,7 @@ static __maybe_unused bufsize bget_buf_size(void *buf)
struct bdhead *bd;
bd = BDH(((char *)buf) - sizeof(struct bdhead));
- osize = bd->tsize - sizeof(struct bdhead);
+ osize = bd->tsize - sizeof(struct bdhead) - bd->offs;
} else
#endif
osize -= sizeof(struct bhead);