ladybird/Ports/gdb/patches/0001-gdb-Disable-xmalloc-for-alternate_signal_stack-for-s.patch
Brian Gianforcaro f01e1d0c17 Ports/gdb: Add descriptions to all gdb patches and remove dead code
Before working on the gdb port some more, I wanted to get these patches
cleaned up to have a good base to build upon.
2022-02-20 11:49:41 +01:00

83 lines
2 KiB
Diff

From 32bfc7a161e6bf10decbf29b31c7b547cf250d3a Mon Sep 17 00:00:00 2001
From: Brian Gianforcaro <b.gianfo@gmail.com>
Date: Sat, 19 Feb 2022 19:46:06 -0800
Subject: [PATCH 1/4] gdb: Disable xmalloc for alternate_signal_stack for
serenity
---
gdbsupport/alt-stack.h | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
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
};
--
2.32.0