Commit Graph

189 Commits

Author SHA1 Message Date
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
c2679188ad Fix the build on Windows. 2019-04-30 09:38:35 +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
22d33ebf99 Add another checker.
Use nullptr where appropriate.
2019-04-29 15:00:25 +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
e6325e5cd2 Add a clang-tidy config file.
Small set of checks for now, we can add to this over time.
2019-04-29 11:30:23 +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
70e2fcf26f Fix 32bit build 2019-04-29 11:02:47 +01:00
Matthew Parkinson
5030fff9bd Missing include from test. 2019-04-29 11:02:47 +01:00
Matthew Parkinson
f1a26db8e5 Missing externs 2019-04-29 11:02:47 +01:00
Matthew Parkinson
37afe9d079 Clang format 2019-04-29 11:02:47 +01:00
Matthew Parkinson
f88bcdbf58 Made alloc_chunk typed
Alloc_chunk now allocates and calls the constructor.
2019-04-29 11:02:47 +01:00
Matthew Parkinson
2d831920ea Factored casting in external pointer calculation 2019-04-29 11:02:47 +01:00
Matthew Parkinson
a8618b0892 Use uintptr_t in signature for pagemap
We don't follow the pointers passed into the pagemap directly, but
instead use them to calculate indexs into the pagemap.  Use uintptr_t
means it is easier to perform address arithmetic, and not have casts
back to void* everywhere.
2019-04-29 11:02:47 +01:00
Matthew Parkinson
47428a096c Removing some casts and uses of void* 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
David Chisnall
30ad9722a7 Merge pull request #35 from Microsoft/shared_allocator_cmake_support
Shared allocator cmake support
2019-04-12 13:04:41 +01:00
Roy Schuster
29e4bdd29d Splitting EXPOSE_EXTERNAL_ALLOCATOR_API to EXPOSE_EXTERNAL_PAGEMAP and EXPOSE_EXTERNAL_RESERVE. Only the shim can be affected by passing the new pre-processor definitions to cmake. 2019-04-12 12:32:37 +01:00
Roy Schuster
81030a554f EOL conversion for clang-format 2019-04-12 10:43:55 +01:00
Roy Schuster
eb2b8a0c80 Checking for redefinition of SNMALLOC_EXPOSE_PAGEMAP, since it can now be a cmake argument 2019-04-12 10:10:58 +01:00
Roy Schuster
ebc1dab1cf Passing the EXPOSE_SHARED_ALLOCATOR argument to cmake will now expose the external allocator and pagemap sharing API 2019-04-12 09:51:52 +01:00
David Chisnall
8e5f96686a Merge pull request #34 from Microsoft/pagemap_access_refactor
Pagemap access refactor
2019-04-12 08:59:22 +01:00
David Chisnall
ca804c1815 [NFC] clang-format 2019-04-11 17:36:14 +01:00
David Chisnall
7f057f308f Fix inverted logic in the type check. 2019-04-11 17:31:44 +01:00
David Chisnall
5c1abffdda Fix missing const. 2019-04-11 17:25:53 +01:00
David Chisnall
9b3641df91 Address Matt's review comments. 2019-04-11 17:08:16 +01:00
David Chisnall
785766b129 Move constants into the right file.
Document them while we're moving them.
2019-04-11 16:57:12 +01:00
David Chisnall
cd8ba18191 Delete some dead code that's difficult to use correctly. 2019-04-11 16:55:05 +01:00
David Chisnall
9d24f7e24f Fix callers of renamed function. 2019-04-11 10:42:50 +01:00
David Chisnall
a64cc5562f Remove indirection in the common case.
Rather than unconditionally storing a pointer to the pagemap and
initialising this with a global, we now provide a choice of three
compile-time options for how the pagemap should be accessed.
2019-04-11 10:33:52 +01:00
David Chisnall
29b45c3345 Rename the pagemap accessor to be noun-verb. 2019-04-11 10:33:36 +01:00
David Chisnall
29aa8ef67e Give up on new making CI support recent clang-format.
Revert to 6.0 and use that locally to insert an extra blank line to make
CI happy...
2019-04-10 13:25:43 +01:00
David Chisnall
c673926d15 Add missing const.
No idea why this only raised an error with cl.exe, it was wrong on all
platforms.
2019-04-10 13:13:09 +01:00
David Chisnall
6f19d4e1e7 Bump the clang-format version to 7.
6 inserts some whitespace that 7 doesn't.
2019-04-10 13:09:55 +01:00
David Chisnall
ad0a22e571 Add missing doc comments. 2019-04-10 12:49:02 +01:00
David Chisnall
2442dc4f3f [NFI] clang-format 2019-04-10 12:43:04 +01:00
David Chisnall
d0fefb8641 Don't always refer to the global pagemap.
If you're creating a new allocator and the pagemap comes from a library
that exports the pagemap accessor function but not the pagemap symbol,
you need to be able to replace this.
2019-04-10 11:57:02 +01:00
David Chisnall
607573bb28 Add missing #pragma once to pal_consts.h
If you're defining a new PAL then you need to include this file twice.
2019-04-10 11:56:07 +01:00
David Chisnall
a93f43fd2f Add some type safety to other pagemap accesses.
Introduce a descriptor for the pagemap config and check that the source
descriptor is compatible with the destination type.
2019-04-09 15:52:38 +01:00
rschust
51fbdf3a44 ZeroMem should not be a part of pal_consts.h 2019-04-09 13:56:22 +01:00
rschust
71900ef947 Created pal_consts.h. New exported functions are now prefixed with "snmalloc_". 2019-04-09 13:56:22 +01:00
rschust
f0d18760fe Exporting the global pagemap and the default memory provider's reserve function in order to support shared allocators 2019-04-09 13:56:22 +01:00