Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 1b36291

Browse files
committed
__init_shadow_call_stack: explicitly check for mmap() failures.
Also reword the comments slightly for clarity, and explicitly say PROT_NONE rather than 0, also for clarity. Change-Id: If2e40016f1c632723ef103a636d3b0a93dd9a30f
1 parent 4c5fe98 commit 1b36291

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libc/bionic/pthread_create.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,15 @@ static void __init_alternate_signal_stack(pthread_internal_t* thread) {
118118

119119
static void __init_shadow_call_stack(pthread_internal_t* thread __unused) {
120120
#if defined(__aarch64__) || defined(__riscv)
121-
// Allocate the stack and the guard region.
121+
// Allocate the shadow call stack and its guard region.
122122
char* scs_guard_region = reinterpret_cast<char*>(
123-
mmap(nullptr, SCS_GUARD_REGION_SIZE, 0, MAP_PRIVATE | MAP_ANON, -1, 0));
123+
mmap(nullptr, SCS_GUARD_REGION_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0));
124+
if (scs_guard_region == MAP_FAILED) {
125+
async_safe_fatal("failed to allocate shadow stack: %m");
126+
}
124127
thread->shadow_call_stack_guard_region = scs_guard_region;
125128

126-
// The address is aligned to SCS_SIZE so that we only need to store the lower log2(SCS_SIZE) bits
129+
// Align the address to SCS_SIZE so that we only need to store the lower log2(SCS_SIZE) bits
127130
// in jmp_buf. See the SCS commentary in pthread_internal.h for more detail.
128131
char* scs_aligned_guard_region =
129132
reinterpret_cast<char*>(align_up(reinterpret_cast<uintptr_t>(scs_guard_region), SCS_SIZE));

0 commit comments

Comments
 (0)