[CRIU] [PATCH 1/2] rst-malloc: return aligned pointers to sizeof(void *) (v4)

Andrew Vagin avagin at virtuozzo.com
Fri Feb 5 10:08:28 PST 2016


On Fri, Feb 05, 2016 at 08:34:43PM +0300, Andrey Vagin wrote:
> From: Andrew Vagin <avagin at virtuozzo.com>
> 
> Stas found that if we don't align a pointer,
> futex and atomic operations can fail.
> 
> v2: don't hard-code the size of void *
> v3: add a function to allocate memory without gaps with
>     a privious slice. It's used to allocate arrays.
> v4: don't change rst_mem_cpos
>

Pls, ignore this one too. It's Friday

> Cc: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
> Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
> ---
>  include/rst-malloc.h |  1 +
>  rst-malloc.c         | 23 ++++++++++++++++++++++-
>  2 files changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/include/rst-malloc.h b/include/rst-malloc.h
> index 8c48f27..f205622 100644
> --- a/include/rst-malloc.h
> +++ b/include/rst-malloc.h
> @@ -58,6 +58,7 @@ extern void *rst_mem_remap_ptr(unsigned long pos, int type);
>   * last object can be freed (pop-ed from buffer).
>   */
>  extern void *rst_mem_alloc(unsigned long size, int type);
> +extern void *rst_mem_alloc_cont(unsigned long size, int type);
>  extern void rst_mem_free_last(int type);
>  /*
>   * Routines to remap SHREMAP and PRIVATE into restorer address space
> diff --git a/rst-malloc.c b/rst-malloc.c
> index 14e0b41..7685430 100644
> --- a/rst-malloc.c
> +++ b/rst-malloc.c
> @@ -128,6 +128,9 @@ unsigned long rst_mem_cpos(int type)
>  {
>  	struct rst_mem_type_s *t = &rst_mems[type];
>  	BUG_ON(!t->remapable || !t->enabled);
> +
> +	t->free_mem = (void *) round_up((unsigned long)t->free_mem, sizeof(void *));
> +
>  	return t->free_mem - t->buf;
>  }
>  
> @@ -138,7 +141,7 @@ void *rst_mem_remap_ptr(unsigned long pos, int type)
>  	return t->buf + pos;
>  }
>  
> -void *rst_mem_alloc(unsigned long size, int type)
> +static void *__rst_mem_alloc(unsigned long size, int type)
>  {
>  	struct rst_mem_type_s *t = &rst_mems[type];
>  	void *ret;
> @@ -158,6 +161,24 @@ void *rst_mem_alloc(unsigned long size, int type)
>  	return ret;
>  }
>  
> +void *rst_mem_alloc(unsigned long size, int type)
> +{
> +	struct rst_mem_type_s *t = &rst_mems[type];
> +
> +	t->free_mem = (void *) round_up((unsigned long)t->free_mem, sizeof(void *));
> +
> +	return __rst_mem_alloc(size, type);
> +}
> +
> +/* Allocate memory without gaps with a previous slice */
> +void *rst_mem_alloc_cont(unsigned long size, int type)
> +{
> +	struct rst_mem_type_s *t = &rst_mems[type];
> +	BUG_ON(!t->remapable);
> +
> +	return __rst_mem_alloc(size, type);
> +}
> +
>  void rst_mem_free_last(int type)
>  {
>  	struct rst_mem_type_s *t = &rst_mems[type];
> -- 
> 2.4.3
> 


More information about the CRIU mailing list