]>
Commit | Line | Data |
---|---|---|
dff8da6b | 1 | /* Copyright (C) 1994-2024 Free Software Foundation, Inc. |
c84142e8 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
c84142e8 UD |
8 | |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
c84142e8 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
17 | |
18 | #include <mach/exc_server.h> | |
19 | #include <hurd/signal.h> | |
21297437 | 20 | #include <assert.h> |
28f540f4 RM |
21 | |
22 | /* Called by the microkernel when a thread gets an exception. */ | |
23 | ||
24 | kern_return_t | |
25 | _S_catch_exception_raise (mach_port_t port, | |
26 | thread_t thread, | |
27 | task_t task, | |
f22a77e1 RM |
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. */ | |
14906e37 | 33 | integer_t exception, |
d8ee5d61 | 34 | integer_t code, long_integer_t subcode |
f22a77e1 RM |
35 | #endif |
36 | ) | |
28f540f4 | 37 | { |
cb9cae96 | 38 | error_t err; |
28f540f4 | 39 | struct hurd_sigstate *ss; |
0e3426bb RM |
40 | int signo; |
41 | struct hurd_signal_detail d; | |
28f540f4 RM |
42 | |
43 | if (task != __mach_task_self ()) | |
44 | /* The sender wasn't the kernel. */ | |
45 | return EPERM; | |
46 | ||
0e3426bb | 47 | d.exc = exception; |
f22a77e1 RM |
48 | #ifdef EXC_MASK_ALL |
49 | assert (codeCnt >= 2); | |
50 | d.exc_code = code[0]; | |
51 | d.exc_subcode = code[1]; | |
52 | #else | |
0e3426bb RM |
53 | d.exc_code = code; |
54 | d.exc_subcode = subcode; | |
f22a77e1 | 55 | #endif |
0e3426bb | 56 | |
28f540f4 RM |
57 | /* Call the machine-dependent function to translate the Mach exception |
58 | codes into a signal number and subcode. */ | |
0e3426bb | 59 | _hurd_exception2signal (&d, &signo); |
28f540f4 RM |
60 | |
61 | /* Find the sigstate structure for the faulting thread. */ | |
45000f12 | 62 | ss = _hurd_thread_sigstate (thread); |
28f540f4 RM |
63 | |
64 | if (__spin_lock_locked (&ss->lock)) | |
65 | { | |
66 | /* Loser. The thread faulted with its sigstate lock held. Its | |
67 | sigstate data is now suspect. So we reset the parts of it which | |
68 | could cause trouble for the signal thread. Anything else | |
69 | clobbered therein will just hose this user thread, but it's | |
70 | faulting already. | |
71 | ||
72 | This is almost certainly a library bug: unless random memory | |
73 | clobberation caused the sigstate lock to gratuitously appear held, | |
74 | no code should do anything that can fault while holding the | |
75 | sigstate lock. */ | |
76 | ||
8f0c527e | 77 | __spin_unlock (&ss->critical_section_lock); |
28f540f4 RM |
78 | ss->context = NULL; |
79 | __spin_unlock (&ss->lock); | |
80 | } | |
81 | ||
82 | /* Post the signal. */ | |
0e3426bb | 83 | _hurd_internal_post_signal (ss, signo, &d, |
28f540f4 RM |
84 | MACH_PORT_NULL, MACH_MSG_TYPE_PORT_SEND, |
85 | 0); | |
86 | ||
cb9cae96 SB |
87 | err = __mach_port_deallocate (__mach_task_self (), task); |
88 | assert_perror (err); | |
89 | err = __mach_port_deallocate (__mach_task_self (), thread); | |
90 | assert_perror (err); | |
91 | ||
28f540f4 RM |
92 | return KERN_SUCCESS; |
93 | } | |
f22a77e1 RM |
94 | |
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. | |
99 | */ | |
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) | |
110 | { | |
111 | abort (); | |
112 | return KERN_FAILURE; | |
113 | } | |
114 | ||
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) | |
127 | { | |
128 | abort (); | |
129 | return KERN_FAILURE; | |
130 | } | |
131 | #endif |