Commit 7458b054 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

rst-malloc: return aligned pointers to sizeof(void *) (v4)

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

Cc: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent b09356f4
......@@ -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
......
......@@ -138,7 +138,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 +158,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];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment