-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathpal_freebsd.h
More file actions
73 lines (66 loc) · 2.49 KB
/
Copy pathpal_freebsd.h
File metadata and controls
73 lines (66 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#if defined(__FreeBSD__) && !defined(_KERNEL)
# include "pal_bsd_aligned.h"
// On CHERI platforms, we need to know the value of CHERI_PERM_CHERIABI_VMMAP.
// This pollutes the global namespace a little, sadly, but I think only with
// symbols that begin with CHERI_, which is as close to namespaces as C offers.
# if defined(__CHERI_PURE_CAPABILITY__)
# include <cheri/cherireg.h>
# endif
namespace snmalloc
{
/**
* FreeBSD-specific platform abstraction layer.
*
* This adds FreeBSD-specific aligned allocation to the generic BSD
* implementation.
*/
class PALFreeBSD : public PALBSD_Aligned<PALFreeBSD>
{
public:
/**
* Bitmap of PalFeatures flags indicating the optional features that this
* PAL supports.
*
* The FreeBSD PAL does not currently add any features beyond those of a
* generic BSD with support for arbitrary alignment from `mmap`. This
* field is declared explicitly to remind anyone modifying this class to
* add new features that they should add any required feature flags.
*/
static constexpr uint64_t pal_features = PALBSD_Aligned::pal_features;
/**
* FreeBSD uses atypically small address spaces on its 64 bit RISC machines.
* Problematically, these are so small that if we used the default
* address_bits (48), we'd try to allocate the whole AS (or larger!) for the
* Pagemap itself!
*/
static constexpr size_t address_bits = (Aal::bits == 32) ?
Aal::address_bits :
(Aal::aal_name == RISCV ? 38 : Aal::address_bits);
// TODO, if we ever backport to MIPS, this should yield 39 there.
# if defined(__CHERI_PURE_CAPABILITY__)
static_assert(
aal_supports<StrictProvenance>,
"CHERI purecap support requires StrictProvenance AAL");
/**
* On CheriBSD, exporting a pointer means stripping it of the authority to
* manage the address space it references by clearing the CHERIABI_VMMAP
* permission bit.
*/
template<typename T, SNMALLOC_CONCEPT(capptr::ConceptBound) B>
static SNMALLOC_FAST_PATH CapPtr<T, capptr::user_address_control_type<B>>
capptr_to_user_address_control(CapPtr<T, B> p)
{
return CapPtr<T, capptr::user_address_control_type<B>>(
__builtin_cheri_perms_and(
p.unsafe_ptr(),
~static_cast<unsigned int>(CHERI_PERM_CHERIABI_VMMAP)));
}
# endif
static void nodump(void* p, size_t size) noexcept
{
madvise(p, size, MADV_NOCORE);
}
};
} // namespace snmalloc
#endif