summaryrefslogtreecommitdiff
path: root/Ports
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-12-16 19:20:45 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-12-29 03:17:41 -0800
commit9f2e8683de43bde183e7c617c5822900bd42e68d (patch)
treed3ebe6818d93d55af3f8752d53fe76006c0c99ea /Ports
parentbd3bbd032949642ab113058e6372de40af7f0b2c (diff)
downloadserenity-9f2e8683de43bde183e7c617c5822900bd42e68d.zip
Ports/gdb: Use mmap instead of malloc for sigaltstack()
Stack regions can't be made volatile, which makes it impossible for malloc to manage memory that's used for `sigaltstack()`. Let's use mmap instead. Co-authored-by: Idan Horowitz <idan.horowitz@gmail.com>
Diffstat (limited to 'Ports')
-rw-r--r--Ports/gdb/patches/alt-stack-no-malloc.patch70
1 files changed, 70 insertions, 0 deletions
diff --git a/Ports/gdb/patches/alt-stack-no-malloc.patch b/Ports/gdb/patches/alt-stack-no-malloc.patch
new file mode 100644
index 0000000000..974d1db061
--- /dev/null
+++ b/Ports/gdb/patches/alt-stack-no-malloc.patch
@@ -0,0 +1,70 @@
+diff --git a/gdbsupport/alt-stack.h b/gdbsupport/alt-stack.h
+index 056ea41..b638533 100644
+--- a/gdbsupport/alt-stack.h
++++ b/gdbsupport/alt-stack.h
+@@ -20,7 +20,9 @@
+ #ifndef GDBSUPPORT_ALT_STACK_H
+ #define GDBSUPPORT_ALT_STACK_H
+
++#include "common-defs.h"
+ #include <signal.h>
++#include <sys/mman.h>
+
+ namespace gdb
+ {
+@@ -36,31 +38,44 @@ class alternate_signal_stack
+ public:
+ alternate_signal_stack ()
+ {
++ // We can't use xmalloc here on Serenity, because stack regions
++ // do not play well with how malloc manages its memory.
+ #ifdef HAVE_SIGALTSTACK
+- m_stack.reset ((char *) xmalloc (SIGSTKSZ));
+-
+- stack_t stack;
+- stack.ss_sp = m_stack.get ();
+- stack.ss_size = SIGSTKSZ;
+- stack.ss_flags = 0;
+-
+- sigaltstack (&stack, &m_old_stack);
++ void *ptr = mmap (nullptr, SIGSTKSZ, PROT_READ | PROT_WRITE,
++ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
++ if (ptr == MAP_FAILED)
++ {
++ warning ("could not mmap alternate signal stack");
++ }
++ else
++ {
++ m_stack = ptr;
++ stack_t stack;
++ stack.ss_sp = m_stack;
++ stack.ss_size = SIGSTKSZ;
++ stack.ss_flags = 0;
++
++ sigaltstack (&stack, &m_old_stack);
++ }
+ #endif
+ }
+
+ ~alternate_signal_stack ()
+ {
+ #ifdef HAVE_SIGALTSTACK
+- sigaltstack (&m_old_stack, nullptr);
++ if (m_stack != nullptr)
++ {
++ sigaltstack (&m_old_stack, nullptr);
++ munmap (m_stack, SIGSTKSZ);
++ }
+ #endif
+ }
+
+ DISABLE_COPY_AND_ASSIGN (alternate_signal_stack);
+
+ private:
+-
+ #ifdef HAVE_SIGALTSTACK
+- gdb::unique_xmalloc_ptr<char> m_stack;
++ void *m_stack{ nullptr };
+ stack_t m_old_stack;
+ #endif
+ };