x86-64: Use fxsave/xsave/xsavec in _dl_runtime_resolve [BZ #21265]
[glibc.git] / hurd / catch-exc.c
blob1a4fa95c9fbccb4174d05ef027bf68541f3e9dc6
1 /* Copyright (C) 1994-2017 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <mach/exc_server.h>
19 #include <hurd/signal.h>
20 #include <assert.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 #ifdef EXC_MASK_ALL /* New interface flavor. */
29 exception_type_t exception,
30 exception_data_t code,
31 mach_msg_type_number_t codeCnt
32 #else /* Vanilla Mach 3.0 interface. */
33 integer_t exception,
34 integer_t code, integer_t subcode
35 #endif
38 struct hurd_sigstate *ss;
39 int signo;
40 struct hurd_signal_detail d;
42 if (task != __mach_task_self ())
43 /* The sender wasn't the kernel. */
44 return EPERM;
46 d.exc = exception;
47 #ifdef EXC_MASK_ALL
48 assert (codeCnt >= 2);
49 d.exc_code = code[0];
50 d.exc_subcode = code[1];
51 #else
52 d.exc_code = code;
53 d.exc_subcode = subcode;
54 #endif
56 /* Call the machine-dependent function to translate the Mach exception
57 codes into a signal number and subcode. */
58 _hurd_exception2signal (&d, &signo);
60 /* Find the sigstate structure for the faulting thread. */
61 __mutex_lock (&_hurd_siglock);
62 for (ss = _hurd_sigstates; ss != NULL; ss = ss->next)
63 if (ss->thread == thread)
64 break;
65 __mutex_unlock (&_hurd_siglock);
66 if (ss == NULL)
67 ss = _hurd_thread_sigstate (thread); /* Allocate a fresh one. */
69 if (__spin_lock_locked (&ss->lock))
71 /* Loser. The thread faulted with its sigstate lock held. Its
72 sigstate data is now suspect. So we reset the parts of it which
73 could cause trouble for the signal thread. Anything else
74 clobbered therein will just hose this user thread, but it's
75 faulting already.
77 This is almost certainly a library bug: unless random memory
78 clobberation caused the sigstate lock to gratuitously appear held,
79 no code should do anything that can fault while holding the
80 sigstate lock. */
82 __spin_unlock (&ss->critical_section_lock);
83 ss->context = NULL;
84 __spin_unlock (&ss->lock);
87 /* Post the signal. */
88 _hurd_internal_post_signal (ss, signo, &d,
89 MACH_PORT_NULL, MACH_MSG_TYPE_PORT_SEND,
90 0);
92 return KERN_SUCCESS;
95 #ifdef EXC_MASK_ALL
96 /* XXX New interface flavor has additional RPCs that we could be using
97 instead. These RPCs roll a thread_get_state/thread_set_state into
98 the message, so the signal thread ought to use these to save some calls.
100 kern_return_t
101 _S_catch_exception_raise_state (mach_port_t port,
102 exception_type_t exception,
103 exception_data_t code,
104 mach_msg_type_number_t codeCnt,
105 int *flavor,
106 thread_state_t old_state,
107 mach_msg_type_number_t old_stateCnt,
108 thread_state_t new_state,
109 mach_msg_type_number_t *new_stateCnt)
111 abort ();
112 return KERN_FAILURE;
115 kern_return_t
116 _S_catch_exception_raise_state_identity (mach_port_t exception_port,
117 thread_t thread,
118 task_t task,
119 exception_type_t exception,
120 exception_data_t code,
121 mach_msg_type_number_t codeCnt,
122 int *flavor,
123 thread_state_t old_state,
124 mach_msg_type_number_t old_stateCnt,
125 thread_state_t new_state,
126 mach_msg_type_number_t *new_stateCnt)
128 abort ();
129 return KERN_FAILURE;
131 #endif