Daniel Micay
4ee12e64e0
configuration for guard region sizes
2018-10-06 15:17:55 -04:00
Daniel Micay
d18b05eaf4
avoid redundant checks for large realloc
2018-10-06 13:31:16 -04:00
Daniel Micay
eb7ced7781
implement in-place growth of large allocations
2018-10-06 13:24:22 -04:00
Daniel Micay
3dc49f8f73
slightly improve sized deallocation error messages
2018-10-05 01:06:12 -04:00
Daniel Micay
dcd969ae04
use a consistent style for fixed-size int types
...
The stdint.h types don't cover 128-bit integers and the underscore makes
them ill suited to usage in function suffixes. Instead, use the common
naming style in the Linux kernel and elsewhere including the ChaCha8
implementation included here.
2018-10-04 15:17:11 -04:00
Daniel Micay
642eed81c0
allow using larger guards on large allocations
2018-10-04 02:58:24 -04:00
Daniel Micay
5811bd184c
avoid unnecessary preprocessor use for canary mask
2018-10-03 17:17:20 -04:00
Daniel Micay
b24569b6ca
zero leading byte of canaries
2018-10-03 17:09:57 -04:00
Daniel Micay
cf449b3df4
add sized deallocation support
2018-09-19 13:05:12 -04:00
Daniel Micay
82314f4471
make get_size_info straightforward for zero size
2018-09-11 14:51:36 -04:00
Daniel Micay
7a404ddbf2
optimize size calculation for 16 byte spaced sizes
2018-09-11 14:46:44 -04:00
Daniel Micay
2d6ad18aa4
make function naming a bit more consistent
2018-09-11 14:18:13 -04:00
Daniel Micay
684291bf6a
avoid overhead of init check for slab deallocation
2018-09-11 14:13:43 -04:00
Daniel Micay
ef098fea06
simplify init function
2018-09-11 14:12:27 -04:00
Daniel Micay
61684925e8
fix overly naive slab allocation alignment support
2018-09-10 19:01:11 -04:00
Daniel Micay
9a1acce5eb
optimize calloc when zero on free is disabled
2018-09-07 16:33:28 -04:00
Daniel Micay
7ae7abedea
mark more unlikely code paths
2018-09-07 02:53:15 -04:00
Daniel Micay
49af83a817
wrap mutex type to enable future optimization
2018-09-07 01:13:08 -04:00
Daniel Micay
fc2473e7ee
add configuration for canaries
2018-09-07 00:35:08 -04:00
Daniel Micay
96c538d90f
add configuration for zero on free
2018-09-07 00:33:51 -04:00
Daniel Micay
ba3a8b0058
add slot randomization to configuration header
2018-09-07 00:25:02 -04:00
Daniel Micay
bed303a76f
remove unnecessary else branch
2018-09-07 00:22:51 -04:00
Daniel Micay
d398384b90
add header for configuration
2018-09-07 00:17:31 -04:00
Daniel Micay
99d68238d2
implement slab allocation write-after-free check
2018-09-07 00:00:32 -04:00
Daniel Micay
684e63a878
handle pthread_atfork calling into malloc
...
This results in compatibility with the malloc replacement support added
in musl 1.1.20.
2018-09-06 19:48:00 -04:00
Daniel Micay
1be74ec40d
add initial guard slabs implementation
2018-09-06 18:55:24 -04:00
Daniel Micay
cc1e79fdba
abstract metadata allocation to allow guard slabs
2018-09-06 18:45:41 -04:00
Daniel Micay
d8e18e0011
aligned_alloc is now the same as BSD memalign
...
The resolution to DR 460 (which is explicitly included in C17) removed
the requirement for the size to be a multiple of the alignment.
2018-09-06 16:30:22 -04:00
Daniel Micay
0d3c2e1988
no need for a dedicated init rng
2018-09-06 16:02:25 -04:00
Daniel Micay
8624201f06
refresh canary value when allocating free slabs
2018-09-06 15:07:01 -04:00
Daniel Micay
a875951e82
fix build with musl
2018-09-06 14:35:08 -04:00
Daniel Micay
e891b40588
implement Android malloc_disable/malloc_enable API
2018-09-06 14:17:23 -04:00
Daniel Micay
3a532b17dc
implement in-place shrinking for large allocations
2018-09-05 07:37:26 -04:00
Daniel Micay
645209dcbf
remove unnecessary debugging code
2018-09-05 03:42:05 -04:00
Daniel Micay
9ddd53d56c
implement initial slab allocation canaries
2018-09-04 09:29:35 -04:00
Daniel Micay
1a7b8079d0
reuse is_init when possible
2018-09-02 19:58:57 -04:00
Daniel Micay
7733047c7b
trigger early initialization in a conservative way
2018-09-02 19:52:12 -04:00
Daniel Micay
7e088dc870
add stubs for Android extensions
2018-09-02 05:08:45 -04:00
Daniel Micay
e4648192c0
split out code for managing page spans
2018-09-02 02:03:39 -04:00
Daniel Micay
e93d039214
only use reserved memory for regions hash table
2018-09-01 10:23:06 -04:00
Daniel Micay
c3a4829d77
remove unnecessary special case from realloc
2018-09-01 02:42:33 -04:00
Daniel Micay
f441dfe2e3
align size class metadata to cacheline size
2018-08-31 23:10:26 -04:00
Daniel Micay
fad10ce943
use FIFO queue for free slabs
2018-08-31 22:55:49 -04:00
Daniel Micay
3f80895822
ignore pad argument to malloc_trim per glibc
...
The pad argument is only used by the main arena for sbrk in glibc, with
every other page size gap purged with MADV_DONTNEED. It makes more sense
to simply treat it as an ignored legacy parameter rather than trying to
come up with a sensible way to use it for keeping cached free slabs.
2018-08-30 09:36:46 -04:00
Daniel Micay
1ea997b887
add missing headers to malloc.h
2018-08-30 08:48:43 -04:00
Daniel Micay
2b0f7aa985
use a consistent name for size class integer index
2018-08-30 07:13:28 -04:00
Daniel Micay
0f5f2bf6c9
add basic initial heuristic for freeing slabs
2018-08-30 06:56:00 -04:00
Daniel Micay
456dfe4154
add support for purging and protecting empty slabs
2018-08-30 05:59:44 -04:00
Daniel Micay
bb176e09bc
remove useless code in the empty_slabs path
2018-08-30 05:45:03 -04:00
Daniel Micay
29df2429c2
empty_slabs will remain a singly-linked list
2018-08-30 05:27:51 -04:00
Daniel Micay
f94068ea63
rename free_slabs to empty_slabs
2018-08-30 04:55:39 -04:00
Daniel Micay
b6d4af872f
move libdivide.h to third_party/libdivide.h
2018-08-30 03:03:19 -04:00
Daniel Micay
6f9de3e667
add inline hint to get_size_info
2018-08-29 15:13:53 -04:00
Daniel Micay
e85c69a0a4
fix builds with prefix
2018-08-29 15:07:36 -04:00
Daniel Micay
becadc57a5
get rid of unused MIN_ALIGN definition
2018-08-29 14:18:45 -04:00
Daniel Micay
2684a98eab
add initial malloc_object_size extensions
2018-08-29 14:18:42 -04:00
Daniel Micay
0e2f3d1015
sanity check page size at runtime
2018-08-29 11:00:18 -04:00
Daniel Micay
d779d41721
wrap more memory mapping implementation details
2018-08-29 10:57:42 -04:00
Daniel Micay
1cb28531a8
add wrapper for mremap with sanity check
2018-08-29 10:43:54 -04:00
Daniel Micay
5bc6820c24
rely on mmap rounding to page size when possible
2018-08-29 03:25:00 -04:00
Daniel Micay
58d929c0f0
split out low-level memory mapping wrappers
2018-08-29 00:53:38 -04:00
Daniel Micay
8b42e8c3d6
make sure errno is always set on failure
2018-08-28 22:49:11 -04:00
Daniel Micay
66aa98dbd9
sanity-check mmap errno on failure too
2018-08-28 22:41:18 -04:00
Daniel Micay
705b6a4f8d
make non-out-of-memory mprotect errors fatal
2018-08-28 22:22:57 -04:00
Daniel Micay
19c46d16f1
check pthread_atfork return value
2018-08-28 21:31:20 -04:00
Daniel Micay
803811a6ac
add support for using mremap
2018-08-28 10:44:04 -04:00
Daniel Micay
718bf82f96
add inline hints for slab_allocate and slab_free
2018-08-27 09:29:30 -04:00
Daniel Micay
33f862ec19
add inline hints for init and enforce_init
2018-08-27 09:29:27 -04:00
Daniel Micay
67b9608ccf
avoid duplicated init code calculating slab size
2018-08-27 09:22:04 -04:00
Daniel Micay
c7b24f63f1
use libdivide for substantially faster division
2018-08-27 07:07:48 -04:00
Daniel Micay
63b0c39343
reorder size_class struct for better performance
2018-08-27 05:21:58 -04:00
Daniel Micay
14ca7d7c3f
randomize large allocation guard size
2018-08-26 04:46:12 -04:00
Daniel Micay
a13a45a17d
hold regions_lock in alloc_aligned
2018-08-26 04:37:43 -04:00
Daniel Micay
2b7c9362bb
consume fewer random bytes for slab randomization
2018-08-25 18:32:44 -04:00
Daniel Micay
c5d76179a5
improve interaction of slot rand with slot mask
2018-08-25 18:04:55 -04:00
Daniel Micay
173dd6e7a5
randomize slot selection for empty slabs too
2018-08-25 18:02:13 -04:00
Daniel Micay
c335c43dd7
simplify slab out-of-memory error handling
2018-08-25 16:41:07 -04:00
Daniel Micay
7bcfa3f08b
tune slab metadata allocation
2018-08-25 15:46:22 -04:00
Daniel Micay
4777ee0c85
special case division for page size slabs
2018-08-25 15:21:50 -04:00
Daniel Micay
ec78add6ab
define ffzl utility function
2018-08-25 03:14:07 -04:00
Daniel Micay
f08d4d31db
randomize slab slot choice
2018-08-25 03:02:39 -04:00
Daniel Micay
965c3202b4
finish implementation of zero byte size class
2018-08-25 02:48:47 -04:00
Daniel Micay
f97a0ef8b1
use a more appropriate type for masked bitmaps
2018-08-25 01:09:15 -04:00
Daniel Micay
f3c8502509
add CSPRNGs for regions and slabs
2018-08-25 00:25:33 -04:00
Daniel Micay
805bdc6087
add an extra sanity check for unallocated metadata
2018-08-24 05:22:38 -04:00
Daniel Micay
2d168b0516
check for double free slightly earlier
2018-08-24 04:51:52 -04:00
Daniel Micay
97b693d862
stop treating guard size as a constant
2018-08-24 04:07:46 -04:00
Daniel Micay
83dabbd8fa
fix handling of random bases for class regions
2018-08-24 03:52:01 -04:00
Daniel Micay
0d51459dc9
add a special memory protected 0 byte size class
2018-08-24 03:24:23 -04:00
Daniel Micay
7a86b67778
add unaligned free check for small allocations
2018-08-24 02:55:53 -04:00
Daniel Micay
2aee424b7b
fix inconsistent whitespace
2018-08-24 02:09:20 -04:00
Daniel Micay
a874a61099
adjust slot count for 12288 byte size class
2018-08-23 18:00:13 -04:00
Daniel Micay
127f110126
adjust slot count for 10240 byte size class
2018-08-23 17:56:17 -04:00
Daniel Micay
c59c97c65b
adjust slot count for 48 byte size class
2018-08-23 17:53:10 -04:00
Daniel Micay
56e4c7e042
adjust slot count for 224 byte size class
2018-08-23 17:42:51 -04:00
Daniel Micay
4aa0fab4f4
avoid deadlocks after forking threaded processes
2018-08-23 17:22:12 -04:00
Daniel Micay
70d61b6662
initial commit
2018-08-23 15:42:41 -04:00