Skip to content

Commit bf3c99d

Browse files
nwf-msrmjp41
authored andcommitted
fully-static PALs
1 parent cb1694f commit bf3c99d

File tree

10 files changed

+38
-41
lines changed

10 files changed

+38
-41
lines changed

src/pal/pal_bsd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace snmalloc
3131
* operating system to replace the pages with CoW copies of a zero page at
3232
* any point between the call and the next write to that page.
3333
*/
34-
void notify_not_using(void* p, size_t size) noexcept
34+
static void notify_not_using(void* p, size_t size) noexcept
3535
{
3636
SNMALLOC_ASSERT(is_aligned_block<OS::page_size>(p, size));
3737
madvise(p, size, MADV_FREE);

src/pal/pal_bsd_aligned.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace snmalloc
2929
* Reserve memory at a specific alignment.
3030
*/
3131
template<bool committed>
32-
void* reserve_aligned(size_t size) noexcept
32+
static void* reserve_aligned(size_t size) noexcept
3333
{
3434
// Alignment must be a power of 2.
3535
SNMALLOC_ASSERT(size == bits::next_pow2(size));

src/pal/pal_concept.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,17 @@ namespace snmalloc
3535
* PALs expose a basic library of memory operations.
3636
*/
3737
template<typename PAL>
38-
concept ConceptPAL_memops = requires(PAL p, void* vp, size_t sz)
38+
concept ConceptPAL_memops = requires(void* vp, size_t sz)
3939
{
40-
{ p.notify_not_using(vp, sz) } noexcept -> ConceptSame<void>;
40+
{ PAL::notify_not_using(vp, sz) } noexcept -> ConceptSame<void>;
4141

42-
/* For reasons unknown, these seem to tickle some bug in MSVC */
43-
# if !defined(_MSC_VER)
44-
{ p.template notify_using<NoZero>(vp, sz) } noexcept
42+
{ PAL::template notify_using<NoZero>(vp, sz) } noexcept
4543
-> ConceptSame<void>;
46-
{ p.template notify_using<YesZero>(vp, sz) } noexcept
44+
{ PAL::template notify_using<YesZero>(vp, sz) } noexcept
4745
-> ConceptSame<void>;
48-
# endif
4946

50-
{ p.template zero<false>(vp, sz) } noexcept -> ConceptSame<void>;
51-
{ p.template zero<true>(vp, sz) } noexcept -> ConceptSame<void>;
47+
{ PAL::template zero<false>(vp, sz) } noexcept -> ConceptSame<void>;
48+
{ PAL::template zero<true>(vp, sz) } noexcept -> ConceptSame<void>;
5249
};
5350

5451
/**
@@ -57,29 +54,29 @@ namespace snmalloc
5754
template<typename PAL>
5855
concept ConceptPAL_reserve_at_least = requires(PAL p, void* vp, size_t sz)
5956
{
60-
{ p.reserve_at_least(sz) } noexcept
57+
{ PAL::reserve_at_least(sz) } noexcept
6158
-> ConceptSame<std::pair<void*, size_t>>;
6259
};
6360

6461
/**
6562
* Some PALs expose a richer allocator which understands aligned allocations
6663
*/
6764
template<typename PAL>
68-
concept ConceptPAL_reserve_aligned = requires(PAL p, size_t sz)
65+
concept ConceptPAL_reserve_aligned = requires(size_t sz)
6966
{
70-
{ p.template reserve_aligned<false>(sz) } noexcept -> ConceptSame<void*>;
71-
{ p.template reserve_aligned<true>(sz) } noexcept -> ConceptSame<void*>;
67+
{ PAL::template reserve_aligned<true>(sz) } noexcept -> ConceptSame<void*>;
68+
{ PAL::template reserve_aligned<false>(sz) } noexcept
69+
-> ConceptSame<void*>;
7270
};
7371

7472
/**
7573
* Some PALs can provide memory pressure callbacks.
7674
*/
7775
template<typename PAL>
78-
concept ConceptPAL_mem_low_notify =
79-
requires(PAL p, PalNotificationObject* pno)
76+
concept ConceptPAL_mem_low_notify = requires(PalNotificationObject* pno)
8077
{
81-
{ p.expensive_low_memory_check() } -> ConceptSame<bool>;
82-
{ p.register_for_low_memory_callback(pno) } -> ConceptSame<void>;
78+
{ PAL::expensive_low_memory_check() } -> ConceptSame<bool>;
79+
{ PAL::register_for_low_memory_callback(pno) } -> ConceptSame<void>;
8380
};
8481

8582
/**

src/pal/pal_freebsd_kernel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ namespace snmalloc
3434
}
3535

3636
/// Notify platform that we will not be using these pages
37-
void notify_not_using(void* p, size_t size)
37+
static void notify_not_using(void* p, size_t size)
3838
{
3939
vm_offset_t addr = get_vm_offset(p);
4040
kmem_unback(kernel_object, addr, size);
4141
}
4242

4343
/// Notify platform that we will be using these pages
4444
template<ZeroMem zero_mem>
45-
void notify_using(void* p, size_t size)
45+
static void notify_using(void* p, size_t size)
4646
{
4747
vm_offset_t addr = get_vm_offset(p);
4848
int flags = M_WAITOK | ((zero_mem == YesZero) ? M_ZERO : 0);
@@ -54,13 +54,13 @@ namespace snmalloc
5454

5555
/// OS specific function for zeroing memory
5656
template<bool page_aligned = false>
57-
void zero(void* p, size_t size)
57+
static void zero(void* p, size_t size)
5858
{
5959
::bzero(p, size);
6060
}
6161

6262
template<bool committed>
63-
void* reserve_aligned(size_t size) noexcept
63+
static void* reserve_aligned(size_t size) noexcept
6464
{
6565
SNMALLOC_ASSERT(size == bits::next_pow2(size));
6666
SNMALLOC_ASSERT(size >= minimum_alloc_size);

src/pal/pal_haiku.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace snmalloc
3131
* Notify platform that we will not be needing these pages.
3232
* Haiku does not provide madvise call per say only the posix equivalent.
3333
*/
34-
void notify_not_using(void* p, size_t size) noexcept
34+
static void notify_not_using(void* p, size_t size) noexcept
3535
{
3636
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
3737
posix_madvise(p, size, POSIX_MADV_DONTNEED);

src/pal/pal_linux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace snmalloc
3737
* clear the underlying memory range.
3838
*/
3939
template<bool page_aligned = false>
40-
void zero(void* p, size_t size) noexcept
40+
static void zero(void* p, size_t size) noexcept
4141
{
4242
// QEMU does not seem to be giving the desired behaviour for
4343
// MADV_DONTNEED. switch back to memset only for QEMU.

src/pal/pal_open_enclave.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace snmalloc
6262
}
6363

6464
template<bool page_aligned = false>
65-
void zero(void* p, size_t size) noexcept
65+
static void zero(void* p, size_t size) noexcept
6666
{
6767
oe_memset_s(p, size, 0, size);
6868
}

src/pal/pal_plain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace snmalloc
1111
{
1212
public:
1313
// Notify platform that we will not be using these pages
14-
void notify_not_using(void*, size_t) noexcept {}
14+
static void notify_not_using(void*, size_t) noexcept {}
1515

1616
// Notify platform that we will not be using these pages
1717
template<ZeroMem zero_mem>
18-
void notify_using(void* p, size_t size) noexcept
18+
static void notify_using(void* p, size_t size) noexcept
1919
{
2020
if constexpr (zero_mem == YesZero)
2121
{

src/pal/pal_posix.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace snmalloc
131131
* high memory pressure conditions, though on Linux this seems to impose
132132
* too much of a performance penalty.
133133
*/
134-
void notify_not_using(void* p, size_t size) noexcept
134+
static void notify_not_using(void* p, size_t size) noexcept
135135
{
136136
SNMALLOC_ASSERT(is_aligned_block<OS::page_size>(p, size));
137137
#ifdef USE_POSIX_COMMIT_CHECKS
@@ -150,7 +150,7 @@ namespace snmalloc
150150
* function.
151151
*/
152152
template<ZeroMem zero_mem>
153-
void notify_using(void* p, size_t size) noexcept
153+
static void notify_using(void* p, size_t size) noexcept
154154
{
155155
SNMALLOC_ASSERT(
156156
is_aligned_block<OS::page_size>(p, size) || (zero_mem == NoZero));
@@ -163,7 +163,7 @@ namespace snmalloc
163163
#endif
164164

165165
if constexpr (zero_mem == YesZero)
166-
static_cast<OS*>(this)->template zero<true>(p, size);
166+
zero<true>(p, size);
167167
}
168168

169169
/**
@@ -178,7 +178,7 @@ namespace snmalloc
178178
* calling bzero at some point.
179179
*/
180180
template<bool page_aligned = false>
181-
void zero(void* p, size_t size) noexcept
181+
static void zero(void* p, size_t size) noexcept
182182
{
183183
if (page_aligned || is_aligned_block<OS::page_size>(p, size))
184184
{
@@ -207,7 +207,7 @@ namespace snmalloc
207207
* POSIX does not define a portable interface for specifying alignment
208208
* greater than a page.
209209
*/
210-
std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
210+
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
211211
{
212212
SNMALLOC_ASSERT(size == bits::next_pow2(size));
213213

src/pal/pal_windows.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace snmalloc
6464
* Check whether the low memory state is still in effect. This is an
6565
* expensive operation and should not be on any fast paths.
6666
*/
67-
bool expensive_low_memory_check()
67+
static bool expensive_low_memory_check()
6868
{
6969
BOOL result;
7070
QueryMemoryResourceNotification(lowMemoryObject, &result);
@@ -113,7 +113,7 @@ namespace snmalloc
113113
}
114114

115115
/// Notify platform that we will not be using these pages
116-
void notify_not_using(void* p, size_t size) noexcept
116+
static void notify_not_using(void* p, size_t size) noexcept
117117
{
118118
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
119119

@@ -125,7 +125,7 @@ namespace snmalloc
125125

126126
/// Notify platform that we will be using these pages
127127
template<ZeroMem zero_mem>
128-
void notify_using(void* p, size_t size) noexcept
128+
static void notify_using(void* p, size_t size) noexcept
129129
{
130130
SNMALLOC_ASSERT(
131131
is_aligned_block<page_size>(p, size) || (zero_mem == NoZero));
@@ -138,7 +138,7 @@ namespace snmalloc
138138

139139
/// OS specific function for zeroing memory
140140
template<bool page_aligned = false>
141-
void zero(void* p, size_t size) noexcept
141+
static void zero(void* p, size_t size) noexcept
142142
{
143143
if (page_aligned || is_aligned_block<page_size>(p, size))
144144
{
@@ -151,13 +151,13 @@ namespace snmalloc
151151
}
152152

153153
# ifdef USE_SYSTEMATIC_TESTING
154-
size_t& systematic_bump_ptr()
154+
static size_t& systematic_bump_ptr()
155155
{
156156
static size_t bump_ptr = (size_t)0x4000'0000'0000;
157157
return bump_ptr;
158158
}
159159

160-
std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
160+
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
161161
{
162162
// Magic number for over-allocating chosen by the Pal
163163
// These should be further refined based on experiments.
@@ -183,7 +183,7 @@ namespace snmalloc
183183
}
184184
# elif defined(PLATFORM_HAS_VIRTUALALLOC2)
185185
template<bool committed>
186-
void* reserve_aligned(size_t size) noexcept
186+
static void* reserve_aligned(size_t size) noexcept
187187
{
188188
SNMALLOC_ASSERT(size == bits::next_pow2(size));
189189
SNMALLOC_ASSERT(size >= minimum_alloc_size);
@@ -213,7 +213,7 @@ namespace snmalloc
213213
return ret;
214214
}
215215
# else
216-
std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
216+
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
217217
{
218218
SNMALLOC_ASSERT(size == bits::next_pow2(size));
219219

0 commit comments

Comments
 (0)