[review] Enhance _dl_catch_exception to allow disabling exception handling

Message ID gerrit.1572549639000.Iec1bf642ff95a349fdde8040e9baf851ac7b8904@gnutoolchain-gerrit.osci.io
State Superseded
Headers

Commit Message

Simon Marchi (Code Review) Oct. 31, 2019, 7:20 p.m. UTC
  Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/466
......................................................................

Enhance _dl_catch_exception to allow disabling exception handling

In some cases, it is necessary to introduce noexcept regions
where raised dynamic loader exceptions (e.g., from lazy binding)
are fatal, despite being nested in a code region with an active
exception handler.  This change enhances _dl_catch_exception with
to provide such a capability.  The existing function is reused,
so that it is not necessary to introduce yet another function with
a similar purpose.

Change-Id: Iec1bf642ff95a349fdde8040e9baf851ac7b8904
---
M elf/dl-error-skeleton.c
M sysdeps/generic/ldsodefs.h
2 files changed, 15 insertions(+), 1 deletion(-)
  

Comments

Simon Marchi (Code Review) Nov. 13, 2019, 12:57 p.m. UTC | #1
Florian Weimer has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/466
......................................................................


Patch Set 2:

This change is ready for review.
  
Simon Marchi (Code Review) Nov. 15, 2019, 10:21 p.m. UTC | #2
Carlos O'Donell has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/466
......................................................................


Patch Set 3: Code-Review+2

Looks good to me. Extends the existing API.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
  

Patch

diff --git a/elf/dl-error-skeleton.c b/elf/dl-error-skeleton.c
index a261af6..7caf28f 100644
--- a/elf/dl-error-skeleton.c
+++ b/elf/dl-error-skeleton.c
@@ -173,6 +173,18 @@ 
 _dl_catch_exception (struct dl_exception *exception,
 		     void (*operate) (void *), void *args)
 {
+  /* If exception is NULL, temporarily disable exception handling.
+     Exceptions during operate (args) are fatal.  */
+  if (exception == NULL)
+    {
+      struct catch *const old = catch_hook;
+      catch_hook = NULL;
+      operate (args);
+      /* If we get here, the operation was successful.  */
+      catch_hook = old;
+      return 0;
+    }
+
   /* We need not handle `receiver' since setting a `catch' is handled
      before it.  */
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 85b7936..ed0aed7 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -867,7 +867,9 @@ 
 
 /* Call OPERATE (ARGS).  If no error occurs, set *EXCEPTION to zero.
    Otherwise, store a copy of the raised exception in *EXCEPTION,
-   which has to be freed by _dl_exception_free.  */
+   which has to be freed by _dl_exception_free.  As a special case, if
+   EXCEPTION is null, call OPERATE (ARGS) with exception handling
+   disabled (so that exceptions are fatal).  */
 int _dl_catch_exception (struct dl_exception *exception,
 			 void (*operate) (void *), void *args);
 libc_hidden_proto (_dl_catch_exception)