Commit Graph

431 Commits

Author SHA1 Message Date
David CARLIER
c6197cb5f2 Illumos systems/Solaris support. (#226)
MAP_NORESERVE flag usage for memory over commit permitted only
 in the mmap context.
2020-07-08 15:35:28 +01:00
David Chisnall
5199556263 Reduce code duplication. (#220)
* Reduce code duplication.

The Apple and Haiku PALs both had *almost* identical code to the POSIX
PAL, differing only in some small argument variables.  This is fragile
and easy to accidentally get out of sync.  For example, the changes to
`reserve_at_least` involved copying identical code into multiple PALs
and it's easy to accidentally miss one.

This change introduces two optional fields on POSIX-derived PALs:

 - `default_mmap_flags` allows a PAL to provide additional `MAP_*`
   flags to all `mmap` calls.
 - `anonymous_memory_fd` allows the PAL to override the default file
   descriptor used for memory mappings.

If a PAL does not provide these, default values are used.

Fixes #219
2020-06-30 13:33:50 +01:00
David CARLIER
4a3102fedb Haiku support proposal. (#218)
* Haiku support proposal.
Basic PAL implementation.
This platform does not support TLS modes.

* MAP_NORESERVE usage
2020-06-30 11:01:49 +01:00
Matthew Parkinson
94a2ba4eda Revert "fixes for mingw (#215)" (#216)
This reverts commit 8f6b8db4ed.
2020-06-23 09:40:06 +01:00
Schrodinger ZHU Yifan
8f6b8db4ed fixes for mingw (#215)
* fix mingw

* fix mingw malloc test
2020-06-23 07:05:06 +01:00
Matthew Parkinson
e16f2aff6f Add AddressSpaceManager (#214)
This change brings in a new approach to managing address space.
It wraps the Pal with a power of two reservation system, that
guarantees all returned blocks are naturally aligned to their size. It
either lets the Pal perform aligned requests, or over allocates and
splits into power of two blocks.
2020-06-22 12:36:40 +01:00
Matthew Parkinson
e393ac882f New configuration of slab sizes for OE. 2020-06-18 13:09:06 +01:00
Matthew Parkinson
26949de089 New PAL for open enclave
This changes the implementation of the open enclacve pal to support
aligned allocations.  This reduces the amount of memory required for
the initial reservation as the large allocator doesn't have to
overallocate to get alignment.
2020-06-18 13:09:06 +01:00
Theo Butler
61afa77898 Fix sizeclass rounding error 2020-06-08 07:55:32 +01:00
Matthew Parkinson
333190a27d Add some default initialisers. (#207)
* Add some default initialisers.
2020-05-29 17:12:00 +01:00
Anand Krishnamoorthi
c7736a2def OpenEnclave PAL: Store enclave heap base/end in inline variables. (#201)
PALOpenEnclave object is lazily constructed. I couldn't
figure out a straight-forward way to pass the heap bounds to
the constructor of PALOpenEnclave object.
As an alternative, store the bounds in inline static variables of
the PALOpenEnclave class and set them via static setup_initial_range
function.

- two_alloc_types/alloc1.cc
  Define oe_allocator_init to forward base, end values to
  PALOpenEnclave::setup_inital_range
- two_alloc_types/main.cc
  Use oe_allocator_init function to set up heap range.

- fixed_region/fixed_region.cc
  Initialize heap range via call to PALOpenEnclave::setup_inital_range.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2020-05-28 19:04:33 +01:00
Matthew Parkinson
2c9ab3096d Fix includes for the OE Pal.
The Pal should include address.h, this was masked as other Pals included
it, but are only included for simulating OE scenarios, rather than
the actual build for OE.
2020-05-27 13:42:32 +01:00
Matthew Parkinson
de0ab1dbe0 Remove iostream from ARM aal.
The ARM AAL was including `<iostream>`, this is unnecessary, and only
`<cstddef>` should be required for `size_t`.
2020-05-26 11:16:43 +01:00
Nathaniel Filardo
37766588de Linux PowerPC port 2020-05-23 15:42:10 +00:00
Nathaniel Filardo
44e9abe888 Move OS_PAGE_SIZE to PAL 2020-05-23 15:42:10 +00:00
Nathaniel Filardo
b2ee1902dc AAL: add AalName and smallest_page_size 2020-05-23 15:42:10 +00:00
Nathaniel Filardo
3d3b048776 mediumslab: stop assuming page-alignedness of objects
With large pages (e.g. the 64K that Debian defaults to for ppc64), this
is a bit much to ask.  It's only not true for the bottom few medium size
classes, tho', as all sizes above 256K are multiples of 64K with the
current two mantissa bits size schedule.
2020-05-23 15:42:10 +00:00
Matthew Parkinson
87dfd41553 Improve code quality for alloc_size (#196)
* Improve code quality for alloc_size

* Made error noreturn.

* Update docs.

* Move annoation
2020-05-23 16:16:12 +01:00
Matthew Parkinson
fbbc2ddb76 Merge pull request #191 from nwf/aal-address_t
Allow the AAL to define address_t
2020-05-23 08:26:29 +01:00
Matthew Parkinson
97e695bedc Merge pull request #193 from nwf/aal-strict-provenance
Introduce AAL StrictProvenance flag, factor CDLList
2020-05-21 17:09:54 +01:00
Amaury Chamayou
8dad07f692 Make up for the lack of intrinsic headers in Open Enclave (#195) 2020-05-21 17:04:12 +01:00
Nathaniel Filardo
12111ae7d3 ds/cdllist: factor out next to base classes
Choose between implementations based on aal's requirement of strict
provenance.
2020-05-21 12:43:38 +00:00
Nathaniel Filardo
4b7ee7808b AAL: new StrictProvenance feature flag 2020-05-21 12:43:38 +00:00
Nathaniel Filardo
a1704a82e1 ds/dllist: sentinels are always addresses 2020-05-20 14:36:06 +00:00
Nathaniel Filardo
7e4d6916e0 ds/address::is_aligned_block: don't cast to size_t
Now that address_t is always a scalar, there's no reason to cast to
size_t.
2020-05-20 14:36:06 +00:00
Nathaniel Filardo
7b296a91fa Let the AAL define address_t. 2020-05-20 14:36:06 +00:00
Matthew Parkinson
8d6823b3ed Merge pull request #190 from mjp41/error_message
Add error message for failure during init.
2020-05-20 10:40:59 +01:00
Matthew Parkinson
958de73f5b Merge pull request #188 from nwf/ptr-not-addr
Use pointers, not addresses, in more places
2020-05-19 20:34:29 +01:00
Nathaniel Filardo
3f32f37e60 Eliminate pointer_cast()
Since we anticipate address_t not carrying provenance on CHERI, but
rather being vaddr_t there, it doesn't make sense to offer conversion
back to a provenance-carrying pointer.

Thankfully, there is not much to be done here: the uses were few and
could be replaced with the vocabulary of other pointer operations in
ds/address.h
2020-05-19 14:53:55 +00:00
Nathaniel Filardo
79ad6630d3 alloc: eliminate external_pointer/address distinction
Just always work with pointers using the functions defined in
ds/address.h.  This more obviously preserves provenance through the
chain of reasoning.  Note that there is still risk of malloc() being
used as an amplification oracle on CHERI, but there's no additional risk
from this change.

Rename the external_address into external_pointer.
2020-05-19 14:53:55 +00:00
Matthew Parkinson
185781ef52 Add error message for failure during init! 2020-05-19 10:21:00 +01:00
SchrodingerZhu
497f9d9386 add static library (#189)
* add static library

* leave static library on by default

* fix 1mib layout

* code reviews
2020-05-19 06:46:40 +01:00
Nathaniel Wesley Filardo
6dae830ea0 Use cmake to find backtrace() (#187)
On FreeBSD, this notably requires the use of -lexecinfo, as backtrace()
is not available in -lc.  Rather than testing in C, test in cmake.
2020-05-16 12:45:51 +01:00
Nathaniel Wesley Filardo
ce47fdecfc test/contention: acquire+release contention[].exchange (#184)
It is important, in test_tasks_f, that the store of the size to the
allocated block be made visible to other processors before the store of
the pointer itself.  Otherwise, other cores are justified in reading
junk.

This manifests on PowerPC as tripping the "Deallocating with incorrect
size supplied" assertion in alloc.h:/check_size because the value read
from the allocated block may not be a size but rather an internal queue
pointer, which is implausibly large, as sizes go.
2020-05-13 14:32:28 +01:00
Matthew Parkinson
4347701d33 Fix sized delete of nullptr (#181)
* Fix sized delete of nullptr

The core snmalloc code assumes if you know the size, then it is not
nullptr. However, the C++ delete operator can be called with nullptr.

This change checks for that case.
2020-05-07 15:02:48 +01:00
Matthew Parkinson
a9cfc3a2b4 Various minor changes to aid compiling with std14 (#182)
These changes make the code compile in clang10 with -std14.
2020-05-07 15:02:31 +01:00
Matthew Parkinson
c899ee7ab2 Large alloc fix (#178)
* Improved malloc style tests

Added comprehensive testing of realloc, and other minor improvements
to reporting errors.

* Fix realloc resizing for large sizeclasses.

The rounding by sizeclass was incorrect for large allocation.  This fixes
that.

* Ensure alloc_size is committed

There is an awkward interaction between alloc_size and
committing only what is requested.  If the user assumes
everything up to alloc_size is available, then we need to
either store the more precise size for alloc_size to return
or commit the whole 2^n range, so that alloc_size stays simple.

This changes to just make the whole range committed.
In the future, we might want to store a more precise size, so
that the allocation can be sized more precisely.

* Reduce size of objects.
2020-05-07 06:31:37 +01:00
Matthew Parkinson
0180ee9a4d Add cfree to overrides. (#179) 2020-05-06 13:55:48 +01:00
SchrodingerZhu
a43773c5b7 add android support (#171)
* adjust for android

* update docs

* add const qualifier to `alloc_size`

* check const qualifier in cmake
2020-04-18 07:58:13 +01:00
Paul Liétar
0f5cc165e8 Don't require 16-byte CAS on x86. (#173)
* Don't require 16-byte CAS on x86.

We only need to CAS 2 pointers, which is always possible on x86.

* Fix the way the Image variable is referenced.

* Replace failOnStderr by `set -eo pipefail` on Linux.

The x86 image doesn't have clangformat, which causes cmake to print a
warning on the stderr. Exit codes should be enough to detect failure.

* Use x86 images from snmallocciteam.

* clang-format
2020-04-16 07:33:02 +01:00
Matthew Parkinson
60005c809a Fix to page alignment for size of commit. 2020-04-14 12:12:51 +01:00
Matthew Parkinson
d135786ad5 Test case for large non-pagealigned calloc size. 2020-04-14 12:11:04 +01:00
Matthew Parkinson
d4fccfa4ab Fix callbacks
This change does two things
* correctly passes the template parameters into the callbacks fixing
  correct zeroing of memory.
* By making the callbacks more specific it removes the warnings that GCC
was generating.
2020-04-14 11:39:00 +01:00
Matthew Parkinson
070aa9467d First calloc test. 2020-04-14 11:39:00 +01:00
Matthew Parkinson
fe8b8a0891 Improved assume defines. 2020-04-13 08:33:52 +01:00
Matthew Parkinson
cf9c2eb9d9 Addressing OE linking issues when built with GCC (#167)
* Use C++17 inline statics

This leads to better codegen in GCC, and fixes some linking issues in OE.

* Detect GCC and OE combination and fall-back to lock based ABA.

* clangformat
2020-04-10 13:49:39 +01:00
Paul Liétar
6f697e06ef Add missing closing > 2020-04-10 12:54:09 +02:00
Paul Liétar
1ccb808a18 Fix clang-tidy warning and CR comments. 2020-04-10 12:36:36 +02:00
Paul Liétar
794a5912c7 Replace uses of std::function by function_ref. 2020-04-09 15:47:11 +02:00
Paul Liétar
89523a96bd Add back the peek methods to ABA. (#165)
These are used by the Verona runtime.
2020-04-09 14:13:57 +01:00