update from main archive 961116
[glibc/history.git] / hurd / catch-exc.c
blobe3186eb0cdb6c90d0d86cbcc7820f5e433e9fd58
1 /* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <mach/exc_server.h>
20 #include <hurd/signal.h>
22 /* Called by the microkernel when a thread gets an exception. */
24 kern_return_t
25 _S_catch_exception_raise (mach_port_t port,
26 thread_t thread,
27 task_t task,
28 int exception,
29 int code,
30 int subcode)
32 struct hurd_sigstate *ss;
33 int signo;
34 struct hurd_signal_detail d;
36 if (task != __mach_task_self ())
37 /* The sender wasn't the kernel. */
38 return EPERM;
40 d.exc = exception;
41 d.exc_code = code;
42 d.exc_subcode = subcode;
44 /* Call the machine-dependent function to translate the Mach exception
45 codes into a signal number and subcode. */
46 _hurd_exception2signal (&d, &signo);
48 /* Find the sigstate structure for the faulting thread. */
49 __mutex_lock (&_hurd_siglock);
50 for (ss = _hurd_sigstates; ss != NULL; ss = ss->next)
51 if (ss->thread == thread)
52 break;
53 __mutex_unlock (&_hurd_siglock);
54 if (ss == NULL)
55 ss = _hurd_thread_sigstate (thread); /* Allocate a fresh one. */
57 if (__spin_lock_locked (&ss->lock))
59 /* Loser. The thread faulted with its sigstate lock held. Its
60 sigstate data is now suspect. So we reset the parts of it which
61 could cause trouble for the signal thread. Anything else
62 clobbered therein will just hose this user thread, but it's
63 faulting already.
65 This is almost certainly a library bug: unless random memory
66 clobberation caused the sigstate lock to gratuitously appear held,
67 no code should do anything that can fault while holding the
68 sigstate lock. */
70 __spin_unlock (&ss->critical_section_lock);
71 ss->context = NULL;
72 __spin_unlock (&ss->lock);
75 /* Post the signal. */
76 _hurd_internal_post_signal (ss, signo, &d,
77 MACH_PORT_NULL, MACH_MSG_TYPE_PORT_SEND,
78 0);
80 return KERN_SUCCESS;