aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/oslib-posix.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index fbd0dc8c57..c1bee2a581 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -596,6 +596,7 @@ pid_t qemu_fork(Error **errp)
void *qemu_alloc_stack(size_t *sz)
{
void *ptr, *guardpage;
+ int flags;
#ifdef CONFIG_DEBUG_STACK_USAGE
void *ptr2;
#endif
@@ -610,8 +611,18 @@ void *qemu_alloc_stack(size_t *sz)
/* allocate one extra page for the guard page */
*sz += pagesz;
- ptr = mmap(NULL, *sz, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ flags = MAP_PRIVATE | MAP_ANONYMOUS;
+#if defined(MAP_STACK) && defined(__OpenBSD__)
+ /* Only enable MAP_STACK on OpenBSD. Other OS's such as
+ * Linux/FreeBSD/NetBSD have a flag with the same name
+ * but have differing functionality. OpenBSD will SEGV
+ * if it spots execution with a stack pointer pointing
+ * at memory that was not allocated with MAP_STACK.
+ */
+ flags |= MAP_STACK;
+#endif
+
+ ptr = mmap(NULL, *sz, PROT_READ | PROT_WRITE, flags, -1, 0);
if (ptr == MAP_FAILED) {
perror("failed to allocate memory for stack");
abort();