Commit Graph

52 Commits

Author SHA1 Message Date
David Chisnall
0b2b4d68a2 Revert "Add type confusion protection to the default memory provider."
This reverts commit d56201e28d.
2019-09-12 17:16:48 +01:00
David Chisnall
d56201e28d Add type confusion protection to the default memory provider. 2019-08-13 17:30:37 +01:00
David Chisnall
6dbe24da2e [NFC] Replace HEADER_GLOBAL with inline (C++17).
HEADER_GLOBAL was using non-standard attributes to achieve what C++17
now permits with a keyword.  Use the standard formulation.

Update the README to note that gcc is still not recommended, but because
of its poor codegen for 128-bit atomic compare and exchange, rather than
because it doesn't support the attribute used for HEADER_GLOBAL.
2019-08-13 17:30:37 +01:00
Matthew Parkinson
280c2ae25c Refactor ThreadAlloc
Made common code between the Libc and C++ based releasing of allocators
part of a parent class, which each implementation subclasses.
2019-07-15 17:49:40 +01:00
David Chisnall
d83828c537 [NFC] Appease clang-tidy. 2019-07-10 11:22:24 +01:00
David Chisnall
7eabea01d6 Add an Architecture Abstraction Layer.
Currently, we support one architecture, but this provides a layer for
adding other architectures without adding more nested `#ifdef`s.

Fixes #42
2019-07-10 10:42:59 +01:00
David Chisnall
e594377b8a Pull out the #defines from bits. 2019-07-09 13:16:45 +01:00
Matthew Parkinson
d1db6d07ad Use a queue of slabs for free lists
This commit changes the strategy for finding a free list from
a stack to a queue.  This tends to avoid the slow path considerably more.
It has some memory overheads.

TOOD:  We should move the bump allocation data out of the metaslab and
into the allocator.  At the moment, the slab contains the bump allocation
data, we should move this into the allocator, as it only ever has one slab
it is bump allocating from per sizeclass.
2019-07-05 17:04:55 +01:00
Matthew Parkinson
54879fbb4a Make GCC happy with inline 2019-07-02 15:38:28 +01:00
Matthew Parkinson
b74116e209 Fixes 2019-07-02 14:58:13 +01:00
Matthew Parkinson
eb4e28e8d0 CR Feedback
Removed stub from message queue, and use an actual allocation.
2019-07-02 14:08:05 +01:00
Matthew Parkinson
fdcbcf7016 Add prefetch to mpscq. 2019-07-02 14:07:42 +01:00
Matthew Parkinson
d4e94d9c49 Minor changes to mpscq fast path. 2019-07-02 14:07:13 +01:00
Matthew Parkinson
621b7e6b9a Clang format. 2019-07-02 10:51:18 +01:00
Matthew Parkinson
3c7d122dea Add macro for ASSUME and FAST_PATH/SLOW_PATH
Fixes GCC warning that was incorrect using an ASSUME.

Made fast path and slow path Macros so we can add additional attributes.
2019-07-01 14:35:36 +01:00
Matthew Parkinson
830b06a616 Add a couple of likely annotations. 2019-07-01 14:24:03 +01:00
Matthew Parkinson
b8bcfc0798 Made the statistics print atexit
Fixed some statistics and made them automatically print atexit.
2019-05-16 11:43:44 +01:00
Matthew Parkinson
48416e3241 CR Feedback 2019-05-14 21:16:11 +01:00
Matthew Parkinson
b484619f20 Added branch predictor hint. 2019-05-14 21:16:11 +01:00
Matthew Parkinson
3c7582f717 Remove two unused functions. 2019-05-10 15:12:26 +01:00
Matthew Parkinson
8fcedfc290 Fix the GCC build (#40)
* Make it compile with GCC.  
* Add GCC to CI.
* Add warning to documentation about using GCC.
2019-05-05 19:58:37 +01:00
David Chisnall
840e00b430 Fix sign warning. 2019-04-30 14:08:41 +01:00
David Chisnall
8bd136c224 Remove all instances of static_cast<size_t>(1).
In preparation for removing magic numbers, simplify code that is
computing masks with a single bit set.
2019-04-30 11:50:32 +01:00
David Chisnall
91f2310215 More checks.
Use using instead of typedef.
2019-04-30 09:46:01 +01:00
David Chisnall
5c197e4ae4 [NFC] More checks, comments on end of namespace braces. 2019-04-30 09:46:01 +01:00
David Chisnall
49ece8f4e1 Enable the static analyser from clang-tidy.
Fix a false positive.  The loops in the pagemap accessor are too
complicated for the static analyser to check, so it doesn't spot that a
non-null return is impossible.
2019-04-30 09:46:01 +01:00
David Chisnall
d06e539732 Add more checks.
Add missing parentheses in UNUSED (shouldn't matter, but keeps a checker
that may catch real bugs elsewhere happy).
2019-04-30 09:46:01 +01:00
David Chisnall
b5bc09ced3 Add some more checkers.
Change the result of `operator=` on `Mod` to return `Mod&`.  In this
example:

```c++
Mod<4, int> a;
int b = (a = 8);
```

The value of `b` will now be 0, not 8, and will equal the value of `a`.
Hopefully this is less confusing to users of this class.
2019-04-29 15:14:43 +01:00
David Chisnall
c3c71afa57 Move pagemap to using InvalidPointer.
Replace a constant `uintptr_t` value of 1 that was repeatedly cast to a
pointer with an `InvalidPointer<1>`.
2019-04-29 13:46:57 +01:00
David Chisnall
28fac4d700 Fix the remaining clang-tidy warnings.
This introduces a new `address_t` type and two new casts: `pointer_cast`
and `address_cast` for casting between an `address_t` and a pointer.
These should make it easier to audit the codebase for casts between
pointers and integers.  In particular, the remaining `reinterpret_cast`s
and `pointer_cast`s should be the only places where we could perform
invalid pointer arithmetic.

Also adds a `pointer_offset` helper that adds an offset (in bytes) to a
pointer, preserving its original type.  This is a sufficiently common
pattern that it seemed worthwhile to centralise it.
2019-04-29 13:37:05 +01:00
David Chisnall
4bafca9be7 [NFC] Automatic fixes from clang-tidy. 2019-04-29 11:33:07 +01:00
David Chisnall
365571b2b8 Add an explicit invalid pointer type.
This is a generalisation of `std::nullptr_t` that allows non-0 values of
pointer-sized-but-not-a-pointer thing.  `DLList` now takes an
`InvalidPointer`, `nullptr_t`, or some other compatible class as a
sentinel value instead of a `uintptr_t`.
2019-04-29 11:22:40 +01:00
Matthew Parkinson
4a0299ec77 Clang format 2019-04-29 11:02:47 +01:00
Matthew Parkinson
f1835813bd uintptr_max instead of -1/~0 2019-04-29 11:02:47 +01:00
Matthew Parkinson
c471e1a271 CR 2019-04-29 11:02:47 +01:00
Matthew Parkinson
8eb6e36966 Add comment about min/max. 2019-04-29 11:02:47 +01:00
Matthew Parkinson
37afe9d079 Clang format 2019-04-29 11:02:47 +01:00
Matthew Parkinson
2c613b4f8a Factored casts out of DLL/mpmcstack/mpscq.
Nicer use of decltype to constrain instances.

Made a terminator method, to factor out casts.
2019-04-29 11:02:47 +01:00
Matthew Parkinson
4faf9f3bee Use fewer header files
Removing some includes to reduce the code that is dragged in.
2019-04-29 11:02:47 +01:00
Matthew Parkinson
9940fbd363 Fixed typo. 2019-02-19 15:44:23 +00:00
Matthew Parkinson
d588e8ecb1 Updated to match documentation. 2019-02-19 15:00:55 +00:00
Matthew Parkinson
ccccd686fb Merge pull request #16 from Microsoft/Sizeclass
Simplified sizeclass calculations and added tests.
2019-02-19 13:07:08 +00:00
Matthew Parkinson
c02077a06a Bug fix in umul code for 32-bit Win 2019-02-15 14:36:47 +00:00
Matthew Parkinson
e004641cec Added to comment. 2019-02-11 14:47:12 +00:00
Matthew Parkinson
9981bad9b5 clang format 2019-02-11 14:47:12 +00:00
Matthew Parkinson
1272078487 Simplified size class calculation
The rounding code can be integrated directly into the sizeclass code,
which means, the code paths can be simplified slightly.

The special case for zero mantissa bits is not required, as the compiler
generates the same code from the more complex path due to
eliminating dead code after folding the constant zero through.
2019-02-11 14:47:12 +00:00
Matthew Parkinson
d5fb7150a3 Clang format 2019-01-24 11:39:19 +00:00
Matthew Parkinson
294efe8e03 Hardening access to meta data
Introduce a wrapper that ensure various fields of meta data, represent
valid indexes into the the address space, and not beyond the current
slab/superslab.
2019-01-24 11:39:18 +00:00
Matthew Parkinson
745a2a53d1 Clang format 2019-01-22 17:18:54 +00:00
Matthew Parkinson
bb5027b454 Harden sizeclass table
If a sizeclass in the metadata is corrupted, then this can be used to
force an index beyond the end of these tables. This extends the tables
to the next power of two, and uses a mask on the index, so they are
always either a valid piece of data, or zero.
2019-01-22 11:19:57 +00:00