public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Configurable exception emergency pool size
@ 2022-10-12 19:29 Alexey Lapshin
  2022-10-12 20:48 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Lapshin @ 2022-10-12 19:29 UTC (permalink / raw)
  To: libstdc++; +Cc: Alexey Gerenkov, Anton Maklakov, Ivan Grokhotkov

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-12 20:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 19:29 [PATCH] libstdc++: Configurable exception emergency pool size Alexey Lapshin
2022-10-12 20:48 ` Jonathan Wakely

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).