diff --git a/src/Common/ThreadStatus.cpp b/src/Common/ThreadStatus.cpp index 18f24553d5e..76b0a6797df 100644 --- a/src/Common/ThreadStatus.cpp +++ b/src/Common/ThreadStatus.cpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -43,10 +44,15 @@ namespace struct ThreadStack { ThreadStack() - : data(aligned_alloc(4096, size)) - {} + : data(aligned_alloc(getPageSize(), size)) + { + /// Add a guard page + /// (and since the stack grows downward, we need to protect the first page). + mprotect(data, getPageSize(), PROT_NONE); + } ~ThreadStack() { + mprotect(data, getPageSize(), PROT_WRITE|PROT_READ); free(data); }