Skip to content

Commit 7900cb8

Browse files
committed
Prevent internal errno setting escaping to the client.
1 parent 06df9dd commit 7900cb8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/snmalloc/pal/pal_linux.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ namespace snmalloc
127127

128128
static void notify_not_using(void* p, size_t size) noexcept
129129
{
130+
KeepErrno k;
130131
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
131132

132133
// Fill memory so that when we switch the pages back on we don't make
@@ -147,6 +148,7 @@ namespace snmalloc
147148
*/
148149
static void notify_do_dump(void* p, size_t size) noexcept
149150
{
151+
KeepErrno k;
150152
madvise(p, size, MADV_DODUMP);
151153
}
152154

@@ -155,11 +157,13 @@ namespace snmalloc
155157
*/
156158
static void notify_do_not_dump(void* p, size_t size) noexcept
157159
{
160+
KeepErrno k;
158161
madvise(p, size, MADV_DONTDUMP);
159162
}
160163

161164
static uint64_t get_entropy64()
162165
{
166+
KeepErrno k;
163167
// TODO: If the system call fails then the POSIX PAL calls libc
164168
// functions that can require malloc, which may result in deadlock.
165169

@@ -249,7 +253,7 @@ namespace snmalloc
249253
template<class T>
250254
static void wait_on_address(stl::Atomic<T>& addr, T expected)
251255
{
252-
int backup = errno;
256+
KeepErrno k;
253257
static_assert(
254258
sizeof(T) == sizeof(WaitingWord) && alignof(T) == alignof(WaitingWord),
255259
"T must be the same size and alignment as WaitingWord");
@@ -273,12 +277,12 @@ namespace snmalloc
273277
syscall(
274278
SYS_futex, &addr, FUTEX_WAIT_PRIVATE, expected, nullptr, nullptr, 0);
275279
}
276-
errno = backup;
277280
}
278281

279282
template<class T>
280283
static void notify_one_on_address(stl::Atomic<T>& addr)
281284
{
285+
KeepErrno k;
282286
static_assert(
283287
sizeof(T) == sizeof(WaitingWord) && alignof(T) == alignof(WaitingWord),
284288
"T must be the same size and alignment as WaitingWord");
@@ -288,6 +292,7 @@ namespace snmalloc
288292
template<class T>
289293
static void notify_all_on_address(stl::Atomic<T>& addr)
290294
{
295+
KeepErrno k;
291296
static_assert(
292297
sizeof(T) == sizeof(WaitingWord) && alignof(T) == alignof(WaitingWord),
293298
"T must be the same size and alignment as WaitingWord");

0 commit comments

Comments
 (0)