mirror of
https://github.com/chromium/crashpad.git
synced 2025-01-14 01:08:01 +08:00
Add guard pages to test stacks
Bug: b:340659332 Change-Id: I4c2c82a1868d7a4f4a062a4e7a64258deedfb794 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5542248 Reviewed-by: Mark Mentovai <mark@chromium.org> Commit-Queue: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
aef8303371
commit
0e043ccf70
@ -52,6 +52,7 @@
|
|||||||
#include "util/misc/address_sanitizer.h"
|
#include "util/misc/address_sanitizer.h"
|
||||||
#include "util/misc/from_pointer_cast.h"
|
#include "util/misc/from_pointer_cast.h"
|
||||||
#include "util/misc/memory_sanitizer.h"
|
#include "util/misc/memory_sanitizer.h"
|
||||||
|
#include "util/posix/scoped_mmap.h"
|
||||||
#include "util/synchronization/semaphore.h"
|
#include "util/synchronization/semaphore.h"
|
||||||
|
|
||||||
#if BUILDFLAG(IS_ANDROID)
|
#if BUILDFLAG(IS_ANDROID)
|
||||||
@ -180,14 +181,21 @@ class TestThreadPool {
|
|||||||
<< ErrnoMessage("pthread_attr_init");
|
<< ErrnoMessage("pthread_attr_init");
|
||||||
|
|
||||||
if (stack_size > 0) {
|
if (stack_size > 0) {
|
||||||
void* stack_ptr;
|
const size_t page_size = getpagesize();
|
||||||
errno = posix_memalign(&stack_ptr, getpagesize(), stack_size);
|
DCHECK_EQ(stack_size % page_size, 0u);
|
||||||
ASSERT_EQ(errno, 0) << ErrnoMessage("posix_memalign");
|
size_t stack_alloc_size = 2 * page_size + stack_size;
|
||||||
|
|
||||||
thread->stack.reset(reinterpret_cast<char*>(stack_ptr));
|
ASSERT_TRUE(thread->stack.ResetMmap(nullptr,
|
||||||
|
stack_alloc_size,
|
||||||
|
PROT_NONE,
|
||||||
|
MAP_PRIVATE | MAP_ANONYMOUS,
|
||||||
|
-1,
|
||||||
|
0));
|
||||||
|
char* stack_ptr = thread->stack.addr_as<char*>() + page_size;
|
||||||
|
ASSERT_EQ(mprotect(stack_ptr, stack_size, PROT_READ | PROT_WRITE), 0)
|
||||||
|
<< "mprotect";
|
||||||
|
|
||||||
ASSERT_EQ(pthread_attr_setstack(&attr, thread->stack.get(), stack_size),
|
ASSERT_EQ(pthread_attr_setstack(&attr, stack_ptr, stack_size), 0)
|
||||||
0)
|
|
||||||
<< ErrnoMessage("pthread_attr_setstack");
|
<< ErrnoMessage("pthread_attr_setstack");
|
||||||
thread->expectation.max_stack_size = stack_size;
|
thread->expectation.max_stack_size = stack_size;
|
||||||
}
|
}
|
||||||
@ -238,7 +246,7 @@ class TestThreadPool {
|
|||||||
|
|
||||||
pthread_t pthread;
|
pthread_t pthread;
|
||||||
ThreadExpectation expectation;
|
ThreadExpectation expectation;
|
||||||
std::unique_ptr<char[], base::FreeDeleter> stack;
|
ScopedMmap stack;
|
||||||
Semaphore ready_semaphore;
|
Semaphore ready_semaphore;
|
||||||
Semaphore exit_semaphore;
|
Semaphore exit_semaphore;
|
||||||
pid_t tid;
|
pid_t tid;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user