d8307d
commit 2a764c6ee848dfe92cb2921ed3b14085f15d9e79
d8307d
Author: Florian Weimer <fweimer@redhat.com>
d8307d
Date:   Thu Oct 31 13:23:06 2019 +0100
d8307d
d8307d
    Enhance _dl_catch_exception to allow disabling exception handling
d8307d
    
d8307d
    In some cases, it is necessary to introduce noexcept regions
d8307d
    where raised dynamic loader exceptions (e.g., from lazy binding)
d8307d
    are fatal, despite being nested in a code region with an active
d8307d
    exception handler.  This change enhances _dl_catch_exception with
d8307d
    to provide such a capability.  The existing function is reused,
d8307d
    so that it is not necessary to introduce yet another function with
d8307d
    a similar purpose.
d8307d
    
d8307d
    Change-Id: Iec1bf642ff95a349fdde8040e9baf851ac7b8904
d8307d
d8307d
diff --git a/elf/dl-error-skeleton.c b/elf/dl-error-skeleton.c
d8307d
index d5f418ab1848f0c4..9cb002ccfed2c7b4 100644
d8307d
--- a/elf/dl-error-skeleton.c
d8307d
+++ b/elf/dl-error-skeleton.c
d8307d
@@ -173,6 +173,18 @@ int
d8307d
 _dl_catch_exception (struct dl_exception *exception,
d8307d
 		     void (*operate) (void *), void *args)
d8307d
 {
d8307d
+  /* If exception is NULL, temporarily disable exception handling.
d8307d
+     Exceptions during operate (args) are fatal.  */
d8307d
+  if (exception == NULL)
d8307d
+    {
d8307d
+      struct catch *const old = catch_hook;
d8307d
+      catch_hook = NULL;
d8307d
+      operate (args);
d8307d
+      /* If we get here, the operation was successful.  */
d8307d
+      catch_hook = old;
d8307d
+      return 0;
d8307d
+    }
d8307d
+
d8307d
   /* We need not handle `receiver' since setting a `catch' is handled
d8307d
      before it.  */
d8307d
 
d8307d
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
d8307d
index 95dc87519b80e0ec..cc2484033fe0d902 100644
d8307d
--- a/sysdeps/generic/ldsodefs.h
d8307d
+++ b/sysdeps/generic/ldsodefs.h
d8307d
@@ -852,7 +852,9 @@ libc_hidden_proto (_dl_catch_error)
d8307d
 
d8307d
 /* Call OPERATE (ARGS).  If no error occurs, set *EXCEPTION to zero.
d8307d
    Otherwise, store a copy of the raised exception in *EXCEPTION,
d8307d
-   which has to be freed by _dl_exception_free.  */
d8307d
+   which has to be freed by _dl_exception_free.  As a special case, if
d8307d
+   EXCEPTION is null, call OPERATE (ARGS) with exception handling
d8307d
+   disabled (so that exceptions are fatal).  */
d8307d
 int _dl_catch_exception (struct dl_exception *exception,
d8307d
 			 void (*operate) (void *), void *args);
d8307d
 libc_hidden_proto (_dl_catch_exception)