unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [review] Enhance _dl_catch_exception to allow disabling exception handling
@ 2019-10-31 19:20 Florian Weimer (Code Review)
  2019-11-13 12:57 ` [review v2] " Florian Weimer (Code Review)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Florian Weimer (Code Review) @ 2019-10-31 19:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Florian Weimer

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



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)

-- 
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: Iec1bf642ff95a349fdde8040e9baf851ac7b8904
Gerrit-Change-Number: 466
Gerrit-PatchSet: 1
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-MessageType: newchange

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

* [review v2] Enhance _dl_catch_exception to allow disabling exception handling
  2019-10-31 19:20 [review] Enhance _dl_catch_exception to allow disabling exception handling Florian Weimer (Code Review)
@ 2019-11-13 12:57 ` Florian Weimer (Code Review)
  2019-11-15 22:21 ` [review v3] " Carlos O'Donell (Code Review)
  2019-11-16 15:30 ` [pushed] " Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Florian Weimer (Code Review) @ 2019-11-13 12:57 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

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.


-- 
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: Iec1bf642ff95a349fdde8040e9baf851ac7b8904
Gerrit-Change-Number: 466
Gerrit-PatchSet: 2
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-Reviewer: Florian Weimer <fweimer@redhat.com>
Gerrit-Comment-Date: Wed, 13 Nov 2019 12:57:17 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

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

* [review v3] Enhance _dl_catch_exception to allow disabling exception handling
  2019-10-31 19:20 [review] Enhance _dl_catch_exception to allow disabling exception handling Florian Weimer (Code Review)
  2019-11-13 12:57 ` [review v2] " Florian Weimer (Code Review)
@ 2019-11-15 22:21 ` Carlos O'Donell (Code Review)
  2019-11-16 15:30 ` [pushed] " Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Carlos O'Donell (Code Review) @ 2019-11-15 22:21 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

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>


-- 
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: Iec1bf642ff95a349fdde8040e9baf851ac7b8904
Gerrit-Change-Number: 466
Gerrit-PatchSet: 3
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-Reviewer: Carlos O'Donell <carlos@redhat.com>
Gerrit-Reviewer: Florian Weimer <fweimer@redhat.com>
Gerrit-Comment-Date: Fri, 15 Nov 2019 22:21:03 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

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

* [pushed] Enhance _dl_catch_exception to allow disabling exception handling
  2019-10-31 19:20 [review] Enhance _dl_catch_exception to allow disabling exception handling Florian Weimer (Code Review)
  2019-11-13 12:57 ` [review v2] " Florian Weimer (Code Review)
  2019-11-15 22:21 ` [review v3] " Carlos O'Donell (Code Review)
@ 2019-11-16 15:30 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-11-16 15:30 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha; +Cc: Carlos O'Donell

Sourceware to Gerrit sync has submitted this change.

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

Approvals:
  Carlos O'Donell: Looks good to me, approved


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 4d67c05..891049d 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -861,7 +861,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)

-- 
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: Iec1bf642ff95a349fdde8040e9baf851ac7b8904
Gerrit-Change-Number: 466
Gerrit-PatchSet: 4
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-Reviewer: Carlos O'Donell <carlos@redhat.com>
Gerrit-Reviewer: Florian Weimer <fweimer@redhat.com>
Gerrit-MessageType: merged

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

end of thread, other threads:[~2019-11-16 15:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 19:20 [review] Enhance _dl_catch_exception to allow disabling exception handling Florian Weimer (Code Review)
2019-11-13 12:57 ` [review v2] " Florian Weimer (Code Review)
2019-11-15 22:21 ` [review v3] " Carlos O'Donell (Code Review)
2019-11-16 15:30 ` [pushed] " Sourceware to Gerrit sync (Code Review)

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