-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHERI, take 2021.10 #402
CHERI, take 2021.10 #402
Changes from all commits
9bdc559
9775e1e
b4d80aa
583edc8
1e2f7ff
15b70be
83f150e
4bf01a4
83dc540
700e741
23ef47e
1472787
d3bd56c
1bb9324
eee45dd
ad3e4bb
535f6c3
ef7babd
12406b7
b481837
8dfbb44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include "../ds/defines.h" | ||
|
||
#include <stddef.h> | ||
|
||
namespace snmalloc | ||
{ | ||
/** | ||
* A mixin AAL that applies CHERI to a `Base` architecture. Gives | ||
* architectural teeth to the capptr_bound primitive. | ||
*/ | ||
template<typename Base> | ||
class AAL_CHERI : public Base | ||
nwf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public: | ||
/** | ||
* CHERI pointers are not integers and come with strict provenance | ||
* requirements. | ||
*/ | ||
static constexpr uint64_t aal_features = | ||
(Base::aal_features & ~IntegerPointers) | StrictProvenance; | ||
|
||
/** | ||
* On CHERI-aware compilers, ptraddr_t is an integral type that is wide | ||
* enough to hold any address that may be contained within a memory | ||
* capability. It does not carry provenance: it is not a capability, but | ||
* merely an address. | ||
*/ | ||
typedef ptraddr_t address_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks as if it comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correct place for ptraddr_t is <stddef.h>, CheriBSD also provides it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a fixed-with integer type would also be slightly wrong, as it's not necessarily the same type as ptraddr_t. On Darwin, uint64_t is unsigned long long but size_t is unsigned long, so ptraddr_t would likely also be unsigned long. |
||
|
||
template< | ||
typename T, | ||
SNMALLOC_CONCEPT(capptr::ConceptBound) BOut, | ||
SNMALLOC_CONCEPT(capptr::ConceptBound) BIn, | ||
typename U = T> | ||
static SNMALLOC_FAST_PATH CapPtr<T, BOut> | ||
capptr_bound(CapPtr<U, BIn> a, size_t size) noexcept | ||
{ | ||
static_assert( | ||
BIn::spatial > capptr::dimension::Spatial::Alloc, | ||
"Refusing to re-bound Spatial::Alloc CapPtr"); | ||
static_assert( | ||
capptr::is_spatial_refinement<BIn, BOut>(), | ||
"capptr_bound must preserve non-spatial CapPtr dimensions"); | ||
SNMALLOC_ASSERT(__builtin_cheri_tag_get(a.unsafe_ptr())); | ||
|
||
void* pb = __builtin_cheri_bounds_set_exact(a.unsafe_ptr(), size); | ||
return CapPtr<T, BOut>(static_cast<T*>(pb)); | ||
} | ||
}; | ||
} // namespace snmalloc |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,6 @@ namespace snmalloc | |
X86, | ||
X86_SGX, | ||
Sparc, | ||
RISCV | ||
}; | ||
} // namespace snmalloc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
nwf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#if __riscv_xlen == 64 | ||
# define SNMALLOC_VA_BITS_64 | ||
#elif __riscv_xlen == 32 | ||
# define SNMALLOC_VA_BITS_32 | ||
#endif | ||
|
||
namespace snmalloc | ||
{ | ||
/** | ||
* RISC-V architecture layer, phrased as generically as possible. Specific | ||
* implementations may need to adjust some of these. | ||
*/ | ||
class AAL_RISCV | ||
{ | ||
public: | ||
static constexpr uint64_t aal_features = IntegerPointers; | ||
|
||
static constexpr size_t smallest_page_size = 0x1000; | ||
|
||
static constexpr AalName aal_name = RISCV; | ||
|
||
static void inline pause() | ||
{ | ||
/* | ||
* The "Zihintpause" extension claims to be the right thing to do here, | ||
* and it is expected to be used in analogous places, e.g., Linux's | ||
* cpu_relax(), but... | ||
* | ||
* its specification is somewhat unusual, in that it talks about the rate | ||
* at which a HART's instructions retire rather than the rate at which | ||
* they are dispatched (Intel's PAUSE instruction explicitly promises | ||
* that it "de-pipelines" the spin-wait loop, for example) or anything | ||
* about memory semantics (Intel's PAUSE docs talk about a possible | ||
* memory order violation and pipeline flush upon loop exit). | ||
* | ||
* we don't yet have examples of what implementations have done. | ||
* | ||
* it's not yet understood by C frontends or assembler, meaning we'd have | ||
* to spell it out by hand, as | ||
* __asm__ volatile(".byte 0xF; .byte 0x0; .byte 0x0; .byte 0x1"); | ||
* | ||
* All told, we just leave this function empty for the moment. The good | ||
* news is that, if and when we do add a PAUSE, the instruction is encoded | ||
* by stealing some dead space of the FENCE instruction and so should be | ||
* available everywhere even if it doesn't do anything on a particular | ||
* microarchitecture. | ||
*/ | ||
} | ||
}; | ||
|
||
using AAL_Arch = AAL_RISCV; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires Clang 12, but I assume the variable will only be set when that requirement is met?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea; despite the generic name, AFAICT this file is used only in cross-build jobs, where we're already requiring
clang-13
.