Merge "Check for mprotect result" into main am: 0b2996f144 am: fd88338ed7 am: bb9ceed708 am: 4917ef4f28 am: 9bfc89f9c3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2654229
Change-Id: I1915a75b97ad2fe24d61cc5c28c54b38f924a332
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index b46c6cf..75226d3 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -137,7 +137,10 @@
// Make the stack read-write, and store its address in the register we're using as the shadow
// stack pointer. This is deliberately the only place where the address is stored.
char* scs = scs_aligned_guard_region + scs_offset;
- mprotect(scs, SCS_SIZE, PROT_READ | PROT_WRITE);
+ if (mprotect(scs, SCS_SIZE, PROT_READ | PROT_WRITE) == -1) {
+ async_safe_fatal("failed to mprotect() on shadow stack %p %d error %s", scs, SCS_SIZE,
+ strerror(errno));
+ }
#if defined(__aarch64__)
__asm__ __volatile__("mov x18, %0" ::"r"(scs));
#elif defined(__riscv)