(_dl_sysdep_start_cleanup): New function.
[glibc/history.git] / hurd / catch-exc.c
blob72e06db1d38d0fcdcfe1e149a01ec8ee1ee37ac0
1 /* Copyright (C) 1994, 1995 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 int signo, error;
33 long int sigcode;
34 struct hurd_sigstate *ss;
36 if (task != __mach_task_self ())
37 /* The sender wasn't the kernel. */
38 return EPERM;
40 /* Call the machine-dependent function to translate the Mach exception
41 codes into a signal number and subcode. */
42 _hurd_exception2signal (exception, code, subcode,
43 &signo, &sigcode, &error);
45 /* Find the sigstate structure for the faulting thread. */
46 __mutex_lock (&_hurd_siglock);
47 for (ss = _hurd_sigstates; ss != NULL; ss = ss->next)
48 if (ss->thread == thread)
49 break;
50 __mutex_unlock (&_hurd_siglock);
51 if (ss == NULL)
52 ss = _hurd_thread_sigstate (thread); /* Allocate a fresh one. */
54 if (__spin_lock_locked (&ss->lock))
56 /* Loser. The thread faulted with its sigstate lock held. Its
57 sigstate data is now suspect. So we reset the parts of it which
58 could cause trouble for the signal thread. Anything else
59 clobbered therein will just hose this user thread, but it's
60 faulting already.
62 This is almost certainly a library bug: unless random memory
63 clobberation caused the sigstate lock to gratuitously appear held,
64 no code should do anything that can fault while holding the
65 sigstate lock. */
67 ss->critical_section = 0;
68 ss->context = NULL;
69 __spin_unlock (&ss->lock);
72 /* Post the signal. */
73 _hurd_internal_post_signal (ss, signo, sigcode, error,
74 MACH_PORT_NULL, MACH_MSG_TYPE_PORT_SEND,
75 0);
77 return KERN_SUCCESS;