From 6e329183265d0da22799dcc5d9bf6547b7856b01 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sat, 9 Mar 2024 11:40:05 -0500 Subject: [PATCH] mempool: init_func can return an error Signed-off-by: Mathieu Desnoyers Change-Id: I212fd5a6ec6ae7580a28068de4ee88d7955da9d0 --- include/rseq/mempool.h | 7 +++++-- src/rseq-mempool.c | 12 +++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/rseq/mempool.h b/include/rseq/mempool.h index 1b3c944..1cad761 100644 --- a/include/rseq/mempool.h +++ b/include/rseq/mempool.h @@ -404,7 +404,10 @@ int rseq_mempool_attr_set_mmap(struct rseq_mempool_attr *attr, * rseq_mempool_attr_set_init: Set pool attribute structure memory init functions. * * The @init_func callback used to initialized memory after allocation - * for the pool. + * for the pool. The @init_func callback must return 0 on success, -1 on + * error with errno set. If @init_func returns failure, the allocation + * of the pool memory fails, which either causes the pool creation to + * fail or memory allocation to fail (for extensible memory pools). * * The @init_priv argument is a private data pointer passed to the * @init_func callback. @@ -412,7 +415,7 @@ int rseq_mempool_attr_set_mmap(struct rseq_mempool_attr *attr, * Returns 0 on success, -1 with errno=EINVAL if arguments are invalid. */ int rseq_mempool_attr_set_init(struct rseq_mempool_attr *attr, - void (*init_func)(void *priv, void *addr, size_t len, int cpu), + int (*init_func)(void *priv, void *addr, size_t len, int cpu), void *init_priv); /* diff --git a/src/rseq-mempool.c b/src/rseq-mempool.c index c53b16e..5823ae5 100644 --- a/src/rseq-mempool.c +++ b/src/rseq-mempool.c @@ -76,7 +76,7 @@ struct rseq_mempool_attr { void *mmap_priv; bool init_set; - void (*init_func)(void *priv, void *addr, size_t len, int cpu); + int (*init_func)(void *priv, void *addr, size_t len, int cpu); void *init_priv; bool robust_set; @@ -468,9 +468,11 @@ struct rseq_mempool_range *rseq_mempool_range_create(struct rseq_mempool *pool) int cpu; for (cpu = 0; cpu < pool->attr.max_nr_cpus; cpu++) { - pool->attr.init_func(pool->attr.init_priv, - base + (pool->attr.stride * cpu), - pool->attr.stride, cpu); + if (pool->attr.init_func(pool->attr.init_priv, + base + (pool->attr.stride * cpu), + pool->attr.stride, cpu)) { + goto error_alloc; + } } } return range; @@ -824,7 +826,7 @@ int rseq_mempool_attr_set_mmap(struct rseq_mempool_attr *attr, } int rseq_mempool_attr_set_init(struct rseq_mempool_attr *attr, - void (*init_func)(void *priv, void *addr, size_t len, int cpu), + int (*init_func)(void *priv, void *addr, size_t len, int cpu), void *init_priv) { if (!attr) { -- 2.34.1