about summary refs log tree commit diff
path: root/hurd/catch-signal.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-01-04 10:00:22 +0000
committerRoland McGrath <roland@gnu.org>1996-01-04 10:00:22 +0000
commitfb8e70d6dd3a9c3a0e0d2713b5be3cbc9d7a6409 (patch)
treed465aa6b6c500395145dc09bc4ea448392cf1a6a /hurd/catch-signal.c
parent67f27f3a02d623331a56cddee2a56c34b3b13bd9 (diff)
downloadglibc-fb8e70d6dd3a9c3a0e0d2713b5be3cbc9d7a6409.tar.gz
glibc-fb8e70d6dd3a9c3a0e0d2713b5be3cbc9d7a6409.tar.xz
glibc-fb8e70d6dd3a9c3a0e0d2713b5be3cbc9d7a6409.zip
Wed Jan 3 20:23:42 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu> cvs/libc-960104
	* hurd/catch-signal.c: New file.

	* hurd/intr-msg.c: When restarting RPC, fetch a new reply port.

	* hurd/hurdsig.c: Use new hurdfault.h interface.
	(abort_all_rpcs): Mutate return value to EINTR in threads whose
	replies we will wait for.

	* hurd/hurdkill.c (_hurd_sig_post): When doing pgrp, make sure we
	do ourselves last.

Wed Jan  3 19:17:10 1996  Miles Bader  <miles@gnu.ai.mit.edu>

	* sysdeps/mach/hurd/access.c (__access): Put the uid/gid arguments
	to auth_makeauth() in the right order.

Wed Jan  3 17:19:04 1996  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>

	* sysdeps/generic/strsep.c: Rewritten.

	* sysdeps/mach/hurd/fork.c: Use a different workaround for the
 	suspended page fault deadlock kernel bug: thread_abort our signal
 	thread first thing after proc_dostop.

	* sysdeps/mach/hurd/setgid.c: Rewrote gid frobnication to
	recognize rootness properly.

	* hurd/hurdsig.c: Use new signal preemption interface.
Diffstat (limited to 'hurd/catch-signal.c')
-rw-r--r--hurd/catch-signal.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/hurd/catch-signal.c b/hurd/catch-signal.c
new file mode 100644
index 0000000000..3e8ee6c7e2
--- /dev/null
+++ b/hurd/catch-signal.c
@@ -0,0 +1,87 @@
+/* Convenience function to catch expected signals during an operation.
+Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <hurd/signal.h>
+#include <hurd/sigpreempt.h>
+#include <string.h>
+#include <assert.h>
+
+error_t
+hurd_catch_signal (sigset_t sigset,
+		   unsigned long int first, unsigned long int last,
+		   error_t (*operate) (struct hurd_signal_preempter *),
+		   sighandler_t handler)
+{
+  jmp_buf buf;
+  void throw (int signo, long int sigcode, struct sigcontext *scp)
+    { longjmp (buf, scp->sc_error ?: EGRATUITOUS); }
+
+  struct hurd_signal_preempter preempter =
+    {
+      sigset, first, last,
+      NULL, handler == SIG_ERR ? (sighandler_t) &throw : handler,
+    };
+
+  struct hurd_sigstate *const ss = _hurd_self_sigstate ();
+  error_t error;
+
+  if (handler == SIG_ERR)
+    /* Not our handler; don't bother saving state.  */
+    error = 0;
+  else
+    /* This returns again with nonzero value when we preempt a signal.  */
+    error = setjmp (buf);
+
+  if (error == 0)
+    {
+      /* Install a signal preempter for the thread.  */
+      __spin_lock (&ss->lock);
+      preempter.next = ss->preempters;
+      ss->preempters = &preempter;
+      __spin_unlock (&ss->lock);
+
+      /* Try the operation that might crash.  */
+      (*operate) (&preempter);
+    }
+
+  /* Either FUNCTION completed happily and ERROR is still zero, or it hit
+     an expected signal and `throw' made setjmp return the signal error
+     code in ERROR.  Now we can remove the preempter and return.  */
+
+  __spin_lock (&ss->lock);
+  assert (ss->preempters == &preempter);
+  ss->preempters = preempter.next;
+  __spin_unlock (&ss->lock);
+
+  return error;
+}
+
+
+error_t
+hurd_safe_memset (void *dest, int byte, size_t nbytes)
+{
+  error_t operate (struct hurd_signal_preempter *preempter)
+    {
+      memset (dest, byte, nbytes);
+      return 0;
+    }
+  return hurd_catch_signal (sigmask (SIGBUS) | sigmask (SIGSEGV),
+			    (vm_address_t) dest, (vm_address_t) dest + nbytes,
+			    &operate, SIG_ERR);
+}