mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-12-24 04:12:22 -05:00
add initial guard slabs implementation
This commit is contained in:
parent
cc1e79fdba
commit
1be74ec40d
2 changed files with 9 additions and 4 deletions
9
malloc.c
9
malloc.c
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
static_assert(sizeof(void *) == 8, "64-bit only");
|
||||
|
||||
static const bool guard_slabs = true;
|
||||
|
||||
// either sizeof(uint64_t) or 0
|
||||
static const size_t canary_size = sizeof(uint64_t);
|
||||
|
||||
|
|
@ -140,9 +142,9 @@ static size_t get_metadata_max(size_t slab_size) {
|
|||
}
|
||||
|
||||
static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_size, bool non_zero_size) {
|
||||
if (unlikely(c->metadata_count == c->metadata_allocated)) {
|
||||
if (unlikely(c->metadata_count >= c->metadata_allocated)) {
|
||||
size_t metadata_max = get_metadata_max(slab_size);
|
||||
if (c->metadata_count == metadata_max) {
|
||||
if (c->metadata_count >= metadata_max) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -162,6 +164,9 @@ static struct slab_metadata *alloc_metadata(struct size_class *c, size_t slab_si
|
|||
return NULL;
|
||||
}
|
||||
c->metadata_count++;
|
||||
if (guard_slabs) {
|
||||
c->metadata_count++;
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue