mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 01:22:51 -06:00
fix allocation to ensure that top is properly aligned from the beginning
This commit is contained in:
@@ -153,8 +153,6 @@ typedef struct mchunk mbin;
|
|||||||
|
|
||||||
#define MIN_CHUNK_SIZE (offsetof(mchunk, fd_nextsize))
|
#define MIN_CHUNK_SIZE (offsetof(mchunk, fd_nextsize))
|
||||||
|
|
||||||
#define MALLOC_ALIGN_MASK (2*sizeof(size_t) - 1)
|
|
||||||
|
|
||||||
/* The smallest size we can malloc is an aligned minimal chunk */
|
/* The smallest size we can malloc is an aligned minimal chunk */
|
||||||
#define MINSIZE \
|
#define MINSIZE \
|
||||||
(unsigned long)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK))
|
(unsigned long)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK))
|
||||||
@@ -356,10 +354,12 @@ DB::init_state(size_t size)
|
|||||||
ms->fastbins[i] = 0;
|
ms->fastbins[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mchunk* top_chunk =
|
size_t sz = (sizeof(*ms) + sizeof(size_t));
|
||||||
mem2chunk(((char*) ms) + sizeof(*ms) + sizeof(size_t));
|
sz = (sz & ~MALLOC_ALIGN_MASK) + MALLOC_ALIGN_MASK + 1;
|
||||||
|
|
||||||
|
mchunk* top_chunk = mem2chunk(((char*) ms) + sz);
|
||||||
ms->top = ofs(ms,top_chunk);
|
ms->top = ofs(ms,top_chunk);
|
||||||
set_head(top_chunk, (size - sizeof(*ms)) | PREV_INUSE);
|
set_head(top_chunk, (size - (sz - sizeof(size_t))) | PREV_INUSE);
|
||||||
|
|
||||||
ms->last_remainder = 0;
|
ms->last_remainder = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef DB_H
|
#ifndef DB_H
|
||||||
#define DB_H
|
#define DB_H
|
||||||
|
|
||||||
|
#define MALLOC_ALIGN_MASK (2*sizeof(size_t) - 1)
|
||||||
|
|
||||||
class DB;
|
class DB;
|
||||||
|
|
||||||
extern PGF_INTERNAL_DECL __thread unsigned char* current_base __attribute__((tls_model("initial-exec")));
|
extern PGF_INTERNAL_DECL __thread unsigned char* current_base __attribute__((tls_model("initial-exec")));
|
||||||
@@ -39,18 +41,18 @@ public:
|
|||||||
|
|
||||||
static
|
static
|
||||||
variant tagged(ref<A> ref) {
|
variant tagged(ref<A> ref) {
|
||||||
assert(A::tag < 2*sizeof(size_t));
|
assert(A::tag < MALLOC_ALIGN_MASK + 1);
|
||||||
return (ref.offset | A::tag);
|
return (ref.offset | A::tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
ref<A> untagged(variant v) {
|
ref<A> untagged(variant v) {
|
||||||
return (v & ~(2*sizeof(size_t) - 1));
|
return (v & ~MALLOC_ALIGN_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
uint8_t get_tag(variant v) {
|
uint8_t get_tag(variant v) {
|
||||||
return (v & (2*sizeof(size_t) - 1));
|
return (v & MALLOC_ALIGN_MASK);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user