public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexey Lapshin <alexey.lapshin@espressif.com>
To: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>
Cc: Alexey Gerenkov <alexey.gerenkov@espressif.com>,
	Anton Maklakov <anton.maklakov@espressif.com>,
	Ivan Grokhotkov <ivan@espressif.com>
Subject: [PATCH] libstdc++: Configurable exception emergency pool size
Date: Wed, 12 Oct 2022 19:29:54 +0000	[thread overview]
Message-ID: <019f1d36fd8e730634ae4a764b2c56b6eb59b673.camel@espressif.com> (raw)

From 8b27091310d2857880d8733a05813ca92a5a3e6f Mon Sep 17 00:00:00 2001
From: Alexey Gerenkov <alexey@espressif.com>
Date: Thu, 16 Nov 2017 15:06:35 +0300
Subject: [PATCH] libstdc++: Configurable exception emergency pool size

---
 libstdc++-v3/libsupc++/eh_alloc.cc | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-
v3/libsupc++/eh_alloc.cc
index 68f319869f9..6503041c20a 100644
--- a/libstdc++-v3/libsupc++/eh_alloc.cc
+++ b/libstdc++-v3/libsupc++/eh_alloc.cc
@@ -50,12 +50,13 @@ extern "C" void *memset (void *, int, std::size_t);
 
 using namespace __cxxabiv1;
 
-// ??? How to control these parameters.
-
 // Guess from the size of basic types how large a buffer is
reasonable.
 // Note that the basic c++ exception header has 13 pointers and 2
ints,
 // so on a system with PSImode pointers we're talking about 56 bytes
 // just for overhead.
+// To fix this:
+// Implement C function __cxx_eh_arena_size_get() in your codebase
which
+// returns size (size_t) for buffer to allocate.
 
 #if INT_MAX == 32767
 # define EMERGENCY_OBJ_SIZE	128
@@ -73,6 +74,12 @@ using namespace __cxxabiv1;
 # define EMERGENCY_OBJ_COUNT	4
 #endif
 
+extern "C" __attribute__((weak)) size_t __cxx_eh_arena_size_get(void)
+{
+  return EMERGENCY_OBJ_SIZE * EMERGENCY_OBJ_COUNT
+         + EMERGENCY_OBJ_COUNT * sizeof (__cxa_dependent_exception);
+}
+
 namespace __gnu_cxx
 {
   void __freeres();
@@ -116,11 +123,8 @@ namespace
 
   pool::pool()
     {
-      // Allocate the arena - we could add a GLIBCXX_EH_ARENA_SIZE
environment
-      // to make this tunable.
-      arena_size = (EMERGENCY_OBJ_SIZE * EMERGENCY_OBJ_COUNT
-		    + EMERGENCY_OBJ_COUNT * sizeof
(__cxa_dependent_exception));
-      arena = (char *)malloc (arena_size);
+      arena_size = __cxx_eh_arena_size_get();
+      arena = arena_size ? (char *)malloc (arena_size) : NULL;
       if (!arena)
 	{
 	  // If the allocation failed go without an emergency pool.
-- 
2.34.1


             reply	other threads:[~2022-10-12 19:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 19:29 Alexey Lapshin [this message]
2022-10-12 20:48 ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=019f1d36fd8e730634ae4a764b2c56b6eb59b673.camel@espressif.com \
    --to=alexey.lapshin@espressif.com \
    --cc=alexey.gerenkov@espressif.com \
    --cc=anton.maklakov@espressif.com \
    --cc=ivan@espressif.com \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).