mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-11-03 17:26:32 +01:00
Merge 5deea96fe1 into e371736b17
This commit is contained in:
commit
665581a41e
1 changed files with 14 additions and 1 deletions
15
h_malloc.c
15
h_malloc.c
|
|
@ -20,6 +20,13 @@
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wundef"
|
||||||
|
#if __x86_64__
|
||||||
|
#include "immintrin.h"
|
||||||
|
#endif
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
#ifdef USE_PKEY
|
#ifdef USE_PKEY
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -405,8 +412,14 @@ static size_t get_free_slot(struct random_state *rng, size_t slots, const struct
|
||||||
// randomize start location for linear search (uniform random choice is too slow)
|
// randomize start location for linear search (uniform random choice is too slow)
|
||||||
size_t random_index = get_random_u16_uniform(rng, slots);
|
size_t random_index = get_random_u16_uniform(rng, slots);
|
||||||
size_t first_bitmap = random_index / U64_WIDTH;
|
size_t first_bitmap = random_index / U64_WIDTH;
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wundef"
|
||||||
|
#if __x86_64__ && ((__GNU__ && __BMI2__ ) || (__clang__ && __BMI2INTRIN_H_))
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
u64 random_split = ~(~0UL << _pext_u64(random_index, 8));
|
||||||
|
#else
|
||||||
u64 random_split = ~(~0UL << (random_index - first_bitmap * U64_WIDTH));
|
u64 random_split = ~(~0UL << (random_index - first_bitmap * U64_WIDTH));
|
||||||
|
#endif
|
||||||
size_t i = first_bitmap;
|
size_t i = first_bitmap;
|
||||||
u64 masked = metadata->bitmap[i];
|
u64 masked = metadata->bitmap[i];
|
||||||
masked |= random_split;
|
masked |= random_split;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue