1 /* Copyright (C) 1991-2024 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 <https://www.gnu.org/licenses/>. */
23 #include <lock-intern.h> /* For `struct mutex'. */
26 #include <mach/setup-thread.h>
27 #include <mach/thread_switch.h>
28 #include <mach/mig_support.h>
29 #include <mach/vm_param.h>
33 #include <hurd/signal.h>
35 #include "hurdfault.h"
36 #include "hurdmalloc.h" /* XXX */
37 #include "../locale/localeinfo.h"
39 #include <libc-diag.h>
41 const char *_hurdsig_getenv (const char *);
43 struct mutex _hurd_siglock
;
46 /* Port that receives signals and other miscellaneous messages. */
47 mach_port_t _hurd_msgport
;
49 /* Thread listening on it. */
50 thread_t _hurd_msgport_thread
;
52 /* These are set up by _hurdsig_init. */
53 unsigned long int __hurd_sigthread_stack_base
;
54 unsigned long int __hurd_sigthread_stack_end
;
56 /* Linked-list of per-thread signal state. */
57 struct hurd_sigstate
*_hurd_sigstates
;
59 /* Sigstate for the task-global signals. */
60 struct hurd_sigstate
*_hurd_global_sigstate
;
62 /* Timeout for RPC's after interrupt_operation. */
63 mach_msg_timeout_t _hurd_interrupted_rpc_timeout
= 60000;
66 default_sigaction (struct sigaction actions
[NSIG
])
70 __sigemptyset (&actions
[0].sa_mask
);
71 actions
[0].sa_flags
= SA_RESTART
;
72 actions
[0].sa_handler
= SIG_DFL
;
74 for (signo
= 1; signo
< NSIG
; ++signo
)
75 actions
[signo
] = actions
[0];
78 struct hurd_sigstate
*
79 _hurd_thread_sigstate (thread_t thread
)
81 struct hurd_sigstate
*ss
;
82 __mutex_lock (&_hurd_siglock
);
83 for (ss
= _hurd_sigstates
; ss
!= NULL
; ss
= ss
->next
)
84 if (ss
->thread
== thread
)
88 ss
= malloc (sizeof (*ss
));
90 __libc_fatal ("hurd: Can't allocate sigstate\n");
91 __spin_lock_init (&ss
->critical_section_lock
);
92 __spin_lock_init (&ss
->lock
);
95 /* Initialize default state. */
96 __sigemptyset (&ss
->blocked
);
97 __sigemptyset (&ss
->pending
);
98 memset (&ss
->sigaltstack
, 0, sizeof (ss
->sigaltstack
));
99 ss
->sigaltstack
.ss_flags
|= SS_DISABLE
;
100 ss
->preemptors
= NULL
;
101 ss
->suspended
= MACH_PORT_NULL
;
102 ss
->intr_port
= MACH_PORT_NULL
;
104 ss
->active_resources
= NULL
;
106 ss
->cancel_hook
= NULL
;
108 if (thread
== MACH_PORT_NULL
)
110 /* Process-wide sigstate, use the system defaults. */
111 default_sigaction (ss
->actions
);
113 /* The global sigstate is not added to the _hurd_sigstates list.
114 It is created with _hurd_thread_sigstate (MACH_PORT_NULL)
115 but should be accessed through _hurd_global_sigstate. */
121 /* Use the global actions as a default for new threads. */
122 struct hurd_sigstate
*s
= _hurd_global_sigstate
;
125 __spin_lock (&s
->lock
);
126 memcpy (ss
->actions
, s
->actions
, sizeof (s
->actions
));
127 __spin_unlock (&s
->lock
);
130 default_sigaction (ss
->actions
);
132 ss
->next
= _hurd_sigstates
;
133 _hurd_sigstates
= ss
;
135 err
= __mach_port_mod_refs (__mach_task_self (), thread
,
136 MACH_PORT_RIGHT_SEND
, 1);
138 __libc_fatal ("hurd: Can't add reference on Mach thread\n");
141 __mutex_unlock (&_hurd_siglock
);
144 libc_hidden_def (_hurd_thread_sigstate
)
146 /* Destroy a sigstate structure. Called by libpthread just before the
147 * corresponding thread is terminated. */
149 _hurd_sigstate_delete (thread_t thread
)
151 struct hurd_sigstate
**ssp
, *ss
;
153 __mutex_lock (&_hurd_siglock
);
154 for (ssp
= &_hurd_sigstates
; *ssp
; ssp
= &(*ssp
)->next
)
155 if ((*ssp
)->thread
== thread
)
162 __mutex_unlock (&_hurd_siglock
);
165 if (ss
->thread
!= MACH_PORT_NULL
)
166 __mach_port_deallocate (__mach_task_self (), ss
->thread
);
172 /* Make SS a global receiver, with pthread signal semantics. */
174 _hurd_sigstate_set_global_rcv (struct hurd_sigstate
*ss
)
176 assert (ss
->thread
!= MACH_PORT_NULL
);
177 ss
->actions
[0].sa_handler
= SIG_IGN
;
179 libc_hidden_def (_hurd_sigstate_set_global_rcv
)
181 /* Check whether SS is a global receiver. */
183 sigstate_is_global_rcv (const struct hurd_sigstate
*ss
)
185 return (_hurd_global_sigstate
!= NULL
)
186 && (ss
->actions
[0].sa_handler
== SIG_IGN
);
188 libc_hidden_def (_hurd_sigstate_delete
)
190 /* Lock/unlock a hurd_sigstate structure. If the accessors below require
191 it, the global sigstate will be locked as well. */
193 _hurd_sigstate_lock (struct hurd_sigstate
*ss
)
195 if (sigstate_is_global_rcv (ss
))
196 __spin_lock (&_hurd_global_sigstate
->lock
);
197 __spin_lock (&ss
->lock
);
199 libc_hidden_def (_hurd_sigstate_lock
)
202 _hurd_sigstate_unlock (struct hurd_sigstate
*ss
)
204 __spin_unlock (&ss
->lock
);
205 if (sigstate_is_global_rcv (ss
))
206 __spin_unlock (&_hurd_global_sigstate
->lock
);
208 libc_hidden_def (_hurd_sigstate_unlock
)
210 /* Retrieve a thread's full set of pending signals, including the global
211 ones if appropriate. SS must be locked. */
213 _hurd_sigstate_pending (const struct hurd_sigstate
*ss
)
215 sigset_t pending
= ss
->pending
;
216 if (sigstate_is_global_rcv (ss
))
217 __sigorset (&pending
, &pending
, &_hurd_global_sigstate
->pending
);
220 libc_hidden_def (_hurd_sigstate_pending
)
222 /* Clear a pending signal and return the associated detailed
223 signal information. SS must be locked, and must have signal SIGNO
224 pending, either directly or through the global sigstate. */
225 static struct hurd_signal_detail
226 sigstate_clear_pending (struct hurd_sigstate
*ss
, int signo
)
228 if (sigstate_is_global_rcv (ss
)
229 && __sigismember (&_hurd_global_sigstate
->pending
, signo
))
231 __sigdelset (&_hurd_global_sigstate
->pending
, signo
);
232 return _hurd_global_sigstate
->pending_data
[signo
];
235 assert (__sigismember (&ss
->pending
, signo
));
236 __sigdelset (&ss
->pending
, signo
);
237 return ss
->pending_data
[signo
];
240 /* Retrieve a thread's action vector. SS must be locked. */
242 _hurd_sigstate_actions (struct hurd_sigstate
*ss
)
244 if (sigstate_is_global_rcv (ss
))
245 return _hurd_global_sigstate
->actions
;
251 /* Signal delivery itself is on this page. */
254 #include <hurd/crash.h>
255 #include <hurd/resource.h>
256 #include <hurd/paths.h>
259 #include <sys/wait.h>
260 #include <thread_state.h>
261 #include <hurd/msg_server.h>
262 #include <hurd/msg_reply.h> /* For __msg_sig_post_reply. */
263 #include <hurd/interrupt.h>
267 /* Call the crash dump server to mummify us before we die.
268 Returns nonzero if a core file was written. */
270 write_corefile (int signo
, const struct hurd_signal_detail
*detail
)
273 mach_port_t coreserver
;
274 file_t file
, coredir
;
277 /* Don't bother locking since we just read the one word. */
278 rlim_t corelimit
= _hurd_rlimits
[RLIMIT_CORE
].rlim_cur
;
281 /* No core dumping, thank you very much. Note that this makes
282 `ulimit -c 0' prevent crash-suspension too, which is probably
283 what the user wanted. */
287 When we have a protocol to make the server return an error
288 for RLIMIT_FSIZE, then tell the corefile fs server the RLIMIT_CORE
289 value in place of the RLIMIT_FSIZE value. */
291 /* First get a port to the core dumping server. */
292 coreserver
= MACH_PORT_NULL
;
293 name
= _hurdsig_getenv ("CRASHSERVER");
295 coreserver
= __file_name_lookup (name
, 0, 0);
296 if (coreserver
== MACH_PORT_NULL
)
297 coreserver
= __file_name_lookup (_SERVERS_CRASH
, 0, 0);
298 if (coreserver
== MACH_PORT_NULL
)
301 /* Get a port to the directory where the new core file will reside. */
302 file
= MACH_PORT_NULL
;
303 name
= _hurdsig_getenv ("COREFILE");
306 coredir
= __file_name_split (name
, (char **) &name
);
307 if (coredir
!= MACH_PORT_NULL
)
308 /* Create the new file, but don't link it into the directory yet. */
309 __dir_mkfile (coredir
, O_WRONLY
|O_CREAT
,
310 0600 & ~_hurd_umask
, /* XXX ? */
313 /* Call the core dumping server to write the core file. */
314 err
= __crash_dump_task (coreserver
,
317 signo
, detail
->code
, detail
->error
,
318 detail
->exc
, detail
->exc_code
, detail
->exc_subcode
,
319 _hurd_ports
[INIT_PORT_CTTYID
].port
,
320 MACH_MSG_TYPE_COPY_SEND
);
321 __mach_port_deallocate (__mach_task_self (), coreserver
);
323 if (! err
&& file
!= MACH_PORT_NULL
)
324 /* The core dump into FILE succeeded, so now link it into the
326 err
= __dir_link (coredir
, file
, name
, 1);
327 __mach_port_deallocate (__mach_task_self (), file
);
328 __mach_port_deallocate (__mach_task_self (), coredir
);
329 return !err
&& file
!= MACH_PORT_NULL
;
333 /* The lowest-numbered thread state flavor value is 1,
334 so we use bit 0 in machine_thread_all_state.set to
335 record whether we have done thread_abort. */
336 #define THREAD_ABORTED 1
338 /* SS->thread is suspended. Abort the thread and get its basic state. */
340 abort_thread (struct hurd_sigstate
*ss
, struct machine_thread_all_state
*state
,
341 void (*reply
) (void))
343 assert (ss
->thread
!= MACH_PORT_NULL
);
345 if (!(state
->set
& THREAD_ABORTED
))
347 error_t err
= __thread_abort (ss
->thread
);
349 /* Clear all thread state flavor set bits, because thread_abort may
350 have changed the state. */
351 state
->set
= THREAD_ABORTED
;
357 machine_get_basic_state (ss
->thread
, state
);
360 /* Find the location of the MiG reply port cell in use by the thread whose
361 state is described by THREAD_STATE. If SIGTHREAD is nonzero, make sure
362 that this location can be set without faulting, or else return NULL. */
365 interrupted_reply_port_location (thread_t thread
,
366 struct machine_thread_all_state
*thread_state
,
369 mach_port_t
*portloc
= &THREAD_TCB(thread
, thread_state
)->reply_port
;
371 if (sigthread
&& _hurdsig_catch_memory_fault (portloc
))
372 /* Faulted trying to read the TCB. */
375 DIAG_PUSH_NEEDS_COMMENT
;
376 /* GCC 6 and before seem to be confused by the setjmp call inside
377 _hurdsig_catch_memory_fault and think that we may be returning a second
378 time to here with portloc uninitialized (but we never do). */
379 DIAG_IGNORE_NEEDS_COMMENT (6, "-Wmaybe-uninitialized");
380 /* Fault now if this pointer is bogus. */
381 *(volatile mach_port_t
*) portloc
= *portloc
;
382 DIAG_POP_NEEDS_COMMENT
;
385 _hurdsig_end_catch_fault ();
390 #include <hurd/sigpreempt.h>
391 #include <intr-msg.h>
393 /* Timeout on interrupt_operation calls. */
394 mach_msg_timeout_t _hurdsig_interrupt_timeout
= 1000;
396 /* SS->thread is suspended.
398 Abort any interruptible RPC operation the thread is doing.
400 This uses only the constant member SS->thread and the unlocked, atomically
401 set member SS->intr_port, so no locking is needed.
403 If successfully sent an interrupt_operation and therefore the thread should
404 wait for its pending RPC to return (possibly EINTR) before taking the
405 incoming signal, returns the reply port to be received on. Otherwise
406 returns MACH_PORT_NULL.
408 SIGNO is used to find the applicable SA_RESTART bit. If SIGNO is zero,
409 the RPC fails with EINTR instead of restarting (thread_cancel).
411 *STATE_CHANGE is set nonzero if STATE->basic was modified and should
412 be applied back to the thread if it might ever run again, else zero. */
415 _hurdsig_abort_rpcs (struct hurd_sigstate
*ss
, int signo
, int sigthread
,
416 struct machine_thread_all_state
*state
, int *state_change
,
417 void (*reply
) (void))
419 extern const void _hurd_intr_rpc_msg_about_to attribute_hidden
;
420 extern const void _hurd_intr_rpc_msg_setup_done attribute_hidden
;
421 extern const void _hurd_intr_rpc_msg_in_trap attribute_hidden
;
422 mach_port_t rcv_port
= MACH_PORT_NULL
;
423 mach_port_t intr_port
;
427 intr_port
= ss
->intr_port
;
428 if (intr_port
== MACH_PORT_NULL
)
429 /* No interruption needs done. */
430 return MACH_PORT_NULL
;
432 /* Abort the thread's kernel context, so any pending message send or
433 receive completes immediately or aborts. */
434 abort_thread (ss
, state
, reply
);
436 if (state
->basic
.PC
>= (uintptr_t) &_hurd_intr_rpc_msg_about_to
437 && state
->basic
.PC
< (uintptr_t) &_hurd_intr_rpc_msg_in_trap
)
439 /* The thread is about to do the RPC, but hasn't yet entered
440 mach_msg. Importantly, it may have already checked ss->cancel for
441 the last time before doing the RPC, so setting that is not enough
442 to make it not enter mach_msg. Instead, mutate the thread's state
443 so it knows not to try the RPC.
445 If the thread is past _hurd_intr_rpc_msg_setup_done, just make it
446 jump to after the trap, since we know it's safe to do so. Otherwise,
447 we know that the thread is yet to check for the MACH_SEND_INTERRUPTED
448 value we set below, and will skip the trap by itself. */
449 if (state
->basic
.PC
>= (uintptr_t) &_hurd_intr_rpc_msg_setup_done
)
450 MACHINE_THREAD_STATE_SET_PC (&state
->basic
,
451 &_hurd_intr_rpc_msg_in_trap
);
452 state
->basic
.SYSRETURN
= MACH_SEND_INTERRUPTED
;
455 else if (state
->basic
.PC
== (uintptr_t) &_hurd_intr_rpc_msg_in_trap
456 /* The thread was blocked in the system call. After thread_abort,
457 the return value register indicates what state the RPC was in
459 && state
->basic
.SYSRETURN
== MACH_RCV_INTERRUPTED
)
461 /* The RPC request message was sent and the thread was waiting for the
462 reply message; now the message receive has been aborted, so the
463 mach_msg call will return MACH_RCV_INTERRUPTED. We must tell the
464 server to interrupt the pending operation. The thread must wait for
465 the reply message before running the signal handler (to guarantee that
466 the operation has finished being interrupted), so our nonzero return
467 tells the trampoline code to finish the message receive operation
468 before running the handler. */
470 mach_port_t
*reply
= interrupted_reply_port_location (ss
->thread
,
473 error_t err
= __interrupt_operation (intr_port
,
474 _hurdsig_interrupt_timeout
);
480 /* The interrupt didn't work.
481 Destroy the receive right the thread is blocked on, and
482 replace it with a dead name to keep the name from reuse until
483 the therad is done with it. To do this atomically, first
484 insert a send right, and then destroy the receive right,
485 turning the send right into a dead name. */
486 err
= __mach_port_insert_right (__mach_task_self (),
488 MACH_MSG_TYPE_MAKE_SEND
);
490 err
= __mach_port_mod_refs (__mach_task_self (), *reply
,
491 MACH_PORT_RIGHT_RECEIVE
, -1);
495 /* The system call return value register now contains
496 MACH_RCV_INTERRUPTED; when mach_msg resumes, it will retry the
497 call. Since we have just destroyed the receive right, the retry
498 will fail with MACH_RCV_INVALID_NAME. Instead, just change the
499 return value here to EINTR so mach_msg will not retry and the
500 EINTR error code will propagate up. */
501 state
->basic
.SYSRETURN
= EINTR
;
507 /* All threads whose RPCs were interrupted by the interrupt_operation
508 call above will retry their RPCs unless we clear SS->intr_port. So we
509 clear it for the thread taking a signal when SA_RESTART is clear, so
510 that its call returns EINTR. */
511 if (! signo
|| !(_hurd_sigstate_actions (ss
) [signo
].sa_flags
& SA_RESTART
))
512 ss
->intr_port
= MACH_PORT_NULL
;
519 /* Abort the RPCs being run by all threads but this one;
520 all other threads should be suspended. If LIVE is nonzero, those
521 threads may run again, so they should be adjusted as necessary to be
522 happy when resumed. STATE is clobbered as a scratch area; its initial
523 contents are ignored, and its contents on return are not useful. */
526 abort_all_rpcs (int signo
, struct machine_thread_all_state
*state
, int live
)
528 /* We can just loop over the sigstates. Any thread doing something
529 interruptible must have one. We needn't bother locking because all
530 other threads are stopped. */
532 struct hurd_sigstate
*ss
;
534 mach_port_t
*reply_ports
;
536 /* First loop over the sigstates to count them.
537 We need to know how big a vector we will need for REPLY_PORTS. */
539 for (ss
= _hurd_sigstates
; ss
!= NULL
; ss
= ss
->next
)
542 reply_ports
= alloca (nthreads
* sizeof *reply_ports
);
545 for (ss
= _hurd_sigstates
; ss
!= NULL
; ss
= ss
->next
, ++nthreads
)
546 if (ss
->thread
== _hurd_msgport_thread
)
547 reply_ports
[nthreads
] = MACH_PORT_NULL
;
551 state
->set
= 0; /* Reset scratch area. */
553 /* Abort any operation in progress with interrupt_operation.
554 Record the reply port the thread is waiting on.
555 We will wait for all the replies below. */
556 reply_ports
[nthreads
] = _hurdsig_abort_rpcs (ss
, signo
, 1,
557 state
, &state_changed
,
561 if (reply_ports
[nthreads
] != MACH_PORT_NULL
)
563 /* We will wait for the reply to this RPC below, so the
564 thread must issue a new RPC rather than waiting for the
565 reply to the one it sent. */
566 state
->basic
.SYSRETURN
= EINTR
;
570 /* Aborting the RPC needed to change this thread's state,
571 and it might ever run again. So write back its state. */
572 __thread_set_state (ss
->thread
, MACHINE_THREAD_STATE_FLAVOR
,
573 (natural_t
*) &state
->basic
,
574 MACHINE_THREAD_STATE_COUNT
);
578 /* Wait for replies from all the successfully interrupted RPCs. */
579 while (nthreads
-- > 0)
580 if (reply_ports
[nthreads
] != MACH_PORT_NULL
)
583 mach_msg_header_t head
;
584 err
= __mach_msg (&head
, MACH_RCV_MSG
|MACH_RCV_TIMEOUT
, 0, sizeof head
,
585 reply_ports
[nthreads
],
586 _hurd_interrupted_rpc_timeout
, MACH_PORT_NULL
);
589 case MACH_RCV_TIMED_OUT
:
590 case MACH_RCV_TOO_LARGE
:
599 /* Wake up any sigsuspend or pselect call that is blocking SS->thread. SS must
602 wake_sigsuspend (struct hurd_sigstate
*ss
)
605 mach_msg_header_t msg
;
607 if (ss
->suspended
== MACH_PORT_NULL
)
610 /* There is a sigsuspend waiting. Tell it to wake up. */
611 msg
.msgh_bits
= MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND
, 0);
612 msg
.msgh_remote_port
= ss
->suspended
;
613 msg
.msgh_local_port
= MACH_PORT_NULL
;
614 /* These values do not matter. */
615 msg
.msgh_id
= 8675309; /* Jenny, Jenny. */
616 ss
->suspended
= MACH_PORT_NULL
;
617 err
= __mach_msg (&msg
, MACH_SEND_MSG
, sizeof msg
, 0,
618 MACH_PORT_NULL
, MACH_MSG_TIMEOUT_NONE
,
623 struct hurd_signal_preemptor
*_hurdsig_preemptors
= 0;
624 sigset_t _hurdsig_preempted_set
;
626 /* XXX temporary to deal with spelling fix */
627 weak_alias (_hurdsig_preemptors
, _hurdsig_preempters
)
629 /* Mask of stop signals. */
630 #define STOPSIGS (__sigmask (SIGTTIN) | __sigmask (SIGTTOU) \
631 | __sigmask (SIGSTOP) | __sigmask (SIGTSTP))
633 /* Actual delivery of a single signal. Called with SS unlocked. When
634 the signal is delivered, return SS, locked (or, if SS was originally
635 _hurd_global_sigstate, the sigstate of the actual thread the signal
636 was delivered to). If the signal is being traced, return NULL with
638 static struct hurd_sigstate
*
639 post_signal (struct hurd_sigstate
*ss
,
640 int signo
, struct hurd_signal_detail
*detail
,
641 int untraced
, void (*reply
) (void))
643 struct machine_thread_all_state thread_state
;
644 enum { stop
, ignore
, core
, term
, handle
} act
;
647 /* sigaction for preemptors */
648 struct sigaction preempt_sigaction
= {
649 .sa_flags
= SA_RESTART
652 struct sigaction
*action
;
654 /* Mark the signal as pending. */
655 void mark_pending (void)
657 __sigaddset (&ss
->pending
, signo
);
658 /* Save the details to be given to the handler when SIGNO is
660 ss
->pending_data
[signo
] = *detail
;
663 /* Suspend the process with SIGNO. */
666 /* Stop all other threads and mark ourselves stopped. */
669 /* Hold the siglock while stopping other threads to be
670 sure it is not held by another thread afterwards. */
671 __mutex_lock (&_hurd_siglock
);
672 __proc_dostop (port
, _hurd_msgport_thread
);
673 __mutex_unlock (&_hurd_siglock
);
674 abort_all_rpcs (signo
, &thread_state
, 1);
676 __proc_mark_stop (port
, signo
, detail
->code
);
680 /* Resume the process after a suspension. */
683 /* Resume the process from being stopped. */
685 mach_msg_type_number_t nthreads
, i
;
691 /* Tell the proc server we are continuing. */
692 __USEPORT (PROC
, __proc_mark_cont (port
));
693 /* Fetch ports to all our threads and resume them. */
694 err
= __task_threads (__mach_task_self (), &threads
, &nthreads
);
696 for (i
= 0; i
< nthreads
; ++i
)
698 if (act
== handle
&& threads
[i
] == ss
->thread
)
700 /* The thread that will run the handler is kept suspended. */
703 else if (threads
[i
] != _hurd_msgport_thread
)
705 err
= __thread_resume (threads
[i
]);
708 err
= __mach_port_deallocate (__mach_task_self (),
712 __vm_deallocate (__mach_task_self (),
713 (vm_address_t
) threads
,
714 nthreads
* sizeof *threads
);
719 sighandler_t handler
;
725 /* This is PTRACE_CONTINUE. */
730 /* This call is just to check for pending signals. */
731 _hurd_sigstate_lock (ss
);
735 thread_state
.set
= 0; /* We know nothing. */
737 _hurd_sigstate_lock (ss
);
739 /* If this is a global signal, try to find a thread ready to accept
740 it right away. This is especially important for untraced signals,
741 since going through the global pending mask would de-untrace them. */
742 if (ss
->thread
== MACH_PORT_NULL
)
744 struct hurd_sigstate
*rss
;
746 __mutex_lock (&_hurd_siglock
);
747 for (rss
= _hurd_sigstates
; rss
!= NULL
; rss
= rss
->next
)
749 if (! sigstate_is_global_rcv (rss
))
752 /* The global sigstate is already locked. */
753 __spin_lock (&rss
->lock
);
754 if (! __sigismember (&rss
->blocked
, signo
))
759 __spin_unlock (&rss
->lock
);
761 __mutex_unlock (&_hurd_siglock
);
764 /* We want the preemptors to be able to update the blocking mask
765 without affecting the delivery of this signal, so we save the
766 current value to test against later. */
767 sigset_t blocked
= ss
->blocked
;
769 /* Check for a preempted signal. Preempted signals can arrive during
770 critical sections. */
772 inline sighandler_t
try_preemptor (struct hurd_signal_preemptor
*pe
)
773 { /* PE cannot be null. */
776 if (HURD_PREEMPT_SIGNAL_P (pe
, signo
, detail
->exc_subcode
))
780 sighandler_t handler
= (*pe
->preemptor
) (pe
, ss
,
782 if (handler
!= SIG_ERR
)
793 handler
= ss
->preemptors
? try_preemptor (ss
->preemptors
) : SIG_ERR
;
795 /* If no thread-specific preemptor, check for a global one. */
796 if (handler
== SIG_ERR
&& __sigismember (&_hurdsig_preempted_set
, signo
))
798 __mutex_lock (&_hurd_siglock
);
799 handler
= try_preemptor (_hurdsig_preemptors
);
800 __mutex_unlock (&_hurd_siglock
);
806 if (handler
== SIG_IGN
)
807 /* Ignore the signal altogether. */
809 else if (handler
!= SIG_ERR
)
811 /* Run the preemption-provided handler. */
812 action
= &preempt_sigaction
;
817 /* No preemption. Do normal handling. */
819 action
= & _hurd_sigstate_actions (ss
) [signo
];
821 if (!untraced
&& __sigismember (&_hurdsig_traced
, signo
))
823 /* We are being traced. Stop to tell the debugger of the signal. */
825 /* Already stopped. Mark the signal as pending;
826 when resumed, we will notice it and stop again. */
830 _hurd_sigstate_unlock (ss
);
835 handler
= action
->sa_handler
;
837 if (handler
== SIG_DFL
)
838 /* Figure out the default action for this signal. */
842 /* A sig_post msg with SIGNO==0 is sent to
843 tell us to check for pending signals. */
875 if (_hurd_pgrp
== _hurd_pid
)
877 /* We are the process group leader. Since there is no
878 user-specified handler for SIGINFO, we use a default one
879 which prints something interesting. We use the normal
880 handler mechanism instead of just doing it here to avoid
881 the signal thread faulting or blocking in this
882 potentially hairy operation. */
884 handler
= _hurd_siginfo_handler
;
894 else if (handler
== SIG_IGN
)
899 if (__sigmask (signo
) & STOPSIGS
)
900 /* Stop signals clear a pending SIGCONT even if they
901 are handled or ignored (but not if preempted). */
902 __sigdelset (&ss
->pending
, SIGCONT
);
905 if (signo
== SIGCONT
)
906 /* Even if handled or ignored (but not preempted), SIGCONT clears
907 stop signals and resumes the process. */
908 ss
->pending
&= ~STOPSIGS
;
910 if (_hurd_stopped
&& act
!= stop
&& (untraced
|| signo
== SIGCONT
))
915 if (_hurd_orphaned
&& act
== stop
916 && (__sigmask (signo
) & (__sigmask (SIGTTIN
) | __sigmask (SIGTTOU
)
917 | __sigmask (SIGTSTP
))))
919 /* If we would ordinarily stop for a job control signal, but we are
920 orphaned so no one would ever notice and continue us again, we just
921 quietly die, alone and in the dark. */
922 detail
->code
= signo
;
927 /* Handle receipt of a blocked signal, or any signal while stopped. */
928 if (__sigismember (&blocked
, signo
) || (signo
!= SIGKILL
&& _hurd_stopped
))
934 /* Perform the chosen action for the signal. */
940 /* We are already stopped, but receiving an untraced stop
941 signal. Instead of resuming and suspending again, just
942 notify the proc server of the new stop signal. */
943 error_t err
= __USEPORT (PROC
, __proc_mark_stop
944 (port
, signo
, detail
->code
));
948 /* Suspend the process. */
954 /* Blocking or ignoring a machine exception is fatal.
955 Otherwise we could just spin on the faulting instruction. */
958 /* Nobody cares about this signal. If there was a call to resume
959 above in SIGCONT processing and we've left a thread suspended,
960 now's the time to set it going. */
963 assert (ss
->thread
!= MACH_PORT_NULL
);
964 err
= __thread_resume (ss
->thread
);
971 /* We got a fault setting up the stack frame for the handler.
972 Nothing to do but die; BSD gets SIGILL in this case. */
973 detail
->code
= signo
; /* XXX ? */
980 case term
: /* Time to die. */
981 case core
: /* And leave a rotting corpse. */
982 /* Have the proc server stop all other threads in our task. */
983 err
= __USEPORT (PROC
, __proc_dostop (port
, _hurd_msgport_thread
));
985 /* No more user instructions will be executed.
986 The signal can now be considered delivered. */
988 /* Abort all server operations now in progress. */
989 abort_all_rpcs (signo
, &thread_state
, 0);
992 int status
= W_EXITCODE (0, signo
);
993 /* Do a core dump if desired. Only set the wait status bit saying we
994 in fact dumped core if the operation was actually successful. */
995 if (act
== core
&& write_corefile (signo
, detail
))
997 /* Tell proc how we died and then stick the saber in the gut. */
1003 /* Call a handler for this signal. */
1005 struct sigcontext
*scp
, ocontext
;
1006 int wait_for_reply
, state_changed
;
1008 assert (ss
->thread
!= MACH_PORT_NULL
);
1010 /* Stop the thread and abort its pending RPC operations. */
1013 err
= __thread_suspend (ss
->thread
);
1014 assert_perror (err
);
1017 /* Abort the thread's kernel context, so any pending message send
1018 or receive completes immediately or aborts. If an interruptible
1019 RPC is in progress, abort_rpcs will do this. But we must always
1020 do it before fetching the thread's state, because
1021 thread_get_state is never kosher before thread_abort. */
1022 abort_thread (ss
, &thread_state
, NULL
);
1026 /* We have a previous sigcontext that sigreturn was about
1027 to restore when another signal arrived. */
1031 if (_hurdsig_catch_memory_fault (ss
->context
))
1033 /* We faulted reading the thread's stack. Forget that
1034 context and pretend it wasn't there. It almost
1035 certainly crash if this handler returns, but that's it's
1041 /* Copy the context from the thread's stack before
1042 we start diddling the stack to set up the handler. */
1043 ocontext
= *ss
->context
;
1044 ss
->context
= &ocontext
;
1046 _hurdsig_end_catch_fault ();
1048 if (! machine_get_basic_state (ss
->thread
, &thread_state
))
1050 loc
= interrupted_reply_port_location (ss
->thread
,
1052 if (loc
&& *loc
!= MACH_PORT_NULL
)
1053 /* This is the reply port for the context which called
1054 sigreturn. Since we are abandoning that context entirely
1055 and restoring SS->context instead, destroy this port. */
1056 __mach_port_destroy (__mach_task_self (), *loc
);
1058 /* The thread was in sigreturn, not in any interruptible RPC. */
1061 assert (! __spin_lock_locked (&ss
->critical_section_lock
));
1065 int crit
= __spin_lock_locked (&ss
->critical_section_lock
);
1068 = (_hurdsig_abort_rpcs (ss
,
1069 /* In a critical section, any RPC
1070 should be cancelled instead of
1071 restarted, regardless of
1072 SA_RESTART, so the entire
1073 "atomic" operation can be aborted
1075 crit
? 0 : signo
, 1,
1076 &thread_state
, &state_changed
,
1082 /* The thread is in a critical section. Mark the signal as
1083 pending. When it finishes the critical section, it will
1084 check for pending signals. */
1087 /* Some cases of interrupting an RPC must change the
1088 thread state to back out the call. Normally this
1089 change is rolled into the warping to the handler and
1090 sigreturn, but we are not running the handler now
1091 because the thread is in a critical section. Instead,
1092 mutate the thread right away for the RPC interruption
1093 and resume it; the RPC will return early so the
1094 critical section can end soon. */
1095 __thread_set_state (ss
->thread
, MACHINE_THREAD_STATE_FLAVOR
,
1096 (natural_t
*) &thread_state
.basic
,
1097 MACHINE_THREAD_STATE_COUNT
);
1099 ss
->intr_port
= MACH_PORT_NULL
;
1100 __thread_resume (ss
->thread
);
1105 /* Call the machine-dependent function to set the thread up
1106 to run the signal handler, and preserve its old context. */
1107 scp
= _hurd_setup_sighandler (ss
, action
, handler
, signo
, detail
,
1108 wait_for_reply
, &thread_state
);
1112 /* Set the machine-independent parts of the signal context. */
1115 /* Fetch the thread variable for the MiG reply port,
1116 and set it to MACH_PORT_NULL. */
1117 mach_port_t
*loc
= interrupted_reply_port_location (ss
->thread
,
1122 scp
->sc_reply_port
= *loc
;
1123 *loc
= MACH_PORT_NULL
;
1126 scp
->sc_reply_port
= MACH_PORT_NULL
;
1128 /* Save the intr_port in use by the interrupted code,
1129 and clear the cell before running the trampoline. */
1130 scp
->sc_intr_port
= ss
->intr_port
;
1131 ss
->intr_port
= MACH_PORT_NULL
;
1135 /* After the handler runs we will restore to the state in
1136 SS->context, not the state of the thread now. So restore
1137 that context's reply port and intr port. */
1139 scp
->sc_reply_port
= ss
->context
->sc_reply_port
;
1140 scp
->sc_intr_port
= ss
->context
->sc_intr_port
;
1146 /* Backdoor extra argument to signal handler. */
1147 scp
->sc_error
= detail
->error
;
1149 /* Block requested signals while running the handler. */
1150 scp
->sc_mask
= ss
->blocked
;
1151 __sigorset (&ss
->blocked
, &ss
->blocked
, &action
->sa_mask
);
1153 /* Also block SIGNO unless we're asked not to. */
1154 if (! (action
->sa_flags
& (SA_RESETHAND
| SA_NODEFER
)))
1155 __sigaddset (&ss
->blocked
, signo
);
1157 /* Reset to SIG_DFL if requested. SIGILL and SIGTRAP cannot
1158 be automatically reset when delivered; the system silently
1159 enforces this restriction. */
1160 if (action
->sa_flags
& SA_RESETHAND
1161 && signo
!= SIGILL
&& signo
!= SIGTRAP
)
1162 action
->sa_handler
= SIG_DFL
;
1164 /* Any sigsuspend call must return after the handler does. */
1165 wake_sigsuspend (ss
);
1167 /* Start the thread running the handler (or possibly waiting for an
1168 RPC reply before running the handler). */
1169 err
= __thread_set_state (ss
->thread
, MACHINE_THREAD_STATE_FLAVOR
,
1170 (natural_t
*) &thread_state
.basic
,
1171 MACHINE_THREAD_STATE_COUNT
);
1172 assert_perror (err
);
1173 err
= __thread_resume (ss
->thread
);
1174 assert_perror (err
);
1175 thread_state
.set
= 0; /* Everything we know is now wrong. */
1183 /* Return the set of pending signals in SS which should be delivered. */
1185 pending_signals (struct hurd_sigstate
*ss
)
1187 /* We don't worry about any pending signals if we are stopped, nor if
1188 SS is in a critical section. We are guaranteed to get a sig_post
1189 message before any of them become deliverable: either the SIGCONT
1190 signal, or a sig_post with SIGNO==0 as an explicit poll when the
1191 thread finishes its critical section. */
1192 if (_hurd_stopped
|| __spin_lock_locked (&ss
->critical_section_lock
))
1195 return _hurd_sigstate_pending (ss
) & ~ss
->blocked
;
1198 /* Post the specified pending signals in SS and return 1. If one of
1199 them is traced, abort immediately and return 0. SS must be locked on
1200 entry and will be unlocked in all cases. */
1202 post_pending (struct hurd_sigstate
*ss
, sigset_t pending
, void (*reply
) (void))
1205 struct hurd_signal_detail detail
;
1207 /* Make sure SS corresponds to an actual thread, since we assume it won't
1208 change in post_signal. */
1209 assert (ss
->thread
!= MACH_PORT_NULL
);
1211 for (signo
= 1; signo
< NSIG
; ++signo
)
1212 if (__sigismember (&pending
, signo
))
1214 detail
= sigstate_clear_pending (ss
, signo
);
1215 _hurd_sigstate_unlock (ss
);
1217 /* Will reacquire the lock, except if the signal is traced. */
1218 if (! post_signal (ss
, signo
, &detail
, 0, reply
))
1222 /* No more signals pending; SS->lock is still locked. */
1223 _hurd_sigstate_unlock (ss
);
1228 /* Post all the pending signals of all threads and return 1. If a traced
1229 signal is encountered, abort immediately and return 0. */
1231 post_all_pending_signals (void (*reply
) (void))
1233 struct hurd_sigstate
*ss
;
1234 sigset_t pending
= 0;
1238 __mutex_lock (&_hurd_siglock
);
1239 for (ss
= _hurd_sigstates
; ss
!= NULL
; ss
= ss
->next
)
1241 _hurd_sigstate_lock (ss
);
1243 pending
= pending_signals (ss
);
1245 /* post_pending() below will unlock SS. */
1248 _hurd_sigstate_unlock (ss
);
1250 __mutex_unlock (&_hurd_siglock
);
1254 if (! post_pending (ss
, pending
, reply
))
1259 /* Deliver a signal. SS is not locked. */
1261 _hurd_internal_post_signal (struct hurd_sigstate
*ss
,
1262 int signo
, struct hurd_signal_detail
*detail
,
1263 mach_port_t reply_port
,
1264 mach_msg_type_name_t reply_port_type
,
1267 /* Reply to this sig_post message. */
1268 __typeof (__msg_sig_post_reply
) *reply_rpc
1269 = (untraced
? __msg_sig_post_untraced_reply
: __msg_sig_post_reply
);
1273 if (reply_port
== MACH_PORT_NULL
)
1275 err
= (*reply_rpc
) (reply_port
, reply_port_type
, 0);
1276 reply_port
= MACH_PORT_NULL
;
1277 if (err
!= MACH_SEND_INVALID_DEST
) /* Ignore dead reply port. */
1278 assert_perror (err
);
1281 ss
= post_signal (ss
, signo
, detail
, untraced
, reply
);
1285 /* The signal was neither fatal nor traced. We still hold SS->lock. */
1286 if (signo
!= 0 && ss
->thread
!= MACH_PORT_NULL
)
1288 /* The signal has either been ignored or is now being handled. We can
1289 consider it delivered and reply to the killer. */
1292 /* Post any pending signals for this thread. */
1293 if (! post_pending (ss
, pending_signals (ss
), reply
))
1298 /* If this was a process-wide signal or a poll request, we need
1299 to check for pending signals for all threads. */
1300 _hurd_sigstate_unlock (ss
);
1301 if (! post_all_pending_signals (reply
))
1304 /* All pending signals delivered to all threads.
1305 Now we can send the reply message even for signal 0. */
1310 /* Decide whether REFPORT enables the sender to send us a SIGNO signal.
1311 Returns zero if so, otherwise the error code to return to the sender. */
1314 signal_allowed (int signo
, mach_port_t refport
)
1316 if (signo
< 0 || signo
>= NSIG
)
1319 if (refport
== __mach_task_self ())
1320 /* Can send any signal. */
1323 /* Avoid needing to check for this below. */
1324 if (refport
== MACH_PORT_NULL
)
1337 /* Job control signals can be sent by the controlling terminal. */
1338 if (__USEPORT (CTTYID
, port
== refport
))
1344 /* A continue signal can be sent by anyone in the session. */
1345 mach_port_t sessport
;
1346 if (! __USEPORT (PROC
, __proc_getsidport (port
, &sessport
)))
1348 __mach_port_deallocate (__mach_task_self (), sessport
);
1349 if (refport
== sessport
)
1358 /* Any io object a file descriptor refers to might send us
1359 one of these signals using its async ID port for REFPORT.
1361 This is pretty wide open; it is not unlikely that some random
1362 process can at least open for reading something we have open,
1363 get its async ID port, and send us a spurious SIGIO or SIGURG
1364 signal. But BSD is actually wider open than that!--you can set
1365 the owner of an io object to any process or process group
1366 whatsoever and send them gratuitous signals.
1368 Someday we could implement some reasonable scheme for
1369 authorizing SIGIO and SIGURG signals properly. */
1372 int lucky
= 0; /* True if we find a match for REFPORT. */
1373 __mutex_lock (&_hurd_dtable_lock
);
1374 for (d
= 0; !lucky
&& (unsigned) d
< (unsigned) _hurd_dtablesize
; ++d
)
1376 struct hurd_userlink ulink
;
1378 mach_port_t asyncid
;
1379 if (_hurd_dtable
[d
] == NULL
)
1381 port
= _hurd_port_get (&_hurd_dtable
[d
]->port
, &ulink
);
1382 if (! __io_get_icky_async_id (port
, &asyncid
))
1384 if (refport
== asyncid
)
1385 /* Break out of the loop on the next iteration. */
1387 __mach_port_deallocate (__mach_task_self (), asyncid
);
1389 _hurd_port_free (&_hurd_dtable
[d
]->port
, &ulink
, port
);
1391 __mutex_unlock (&_hurd_dtable_lock
);
1392 /* If we found a lucky winner, we've set D to -1 in the loop. */
1398 /* If this signal is legit, we have done `goto win' by now.
1399 When we return the error, mig deallocates REFPORT. */
1403 /* Deallocate the REFPORT send right; we are done with it. */
1404 __mach_port_deallocate (__mach_task_self (), refport
);
1409 /* Implement the sig_post RPC from <hurd/msg.defs>;
1410 sent when someone wants us to get a signal. */
1412 _S_msg_sig_post (mach_port_t me
,
1413 mach_port_t reply_port
, mach_msg_type_name_t reply_port_type
,
1414 int signo
, natural_t sigcode
,
1415 mach_port_t refport
)
1418 struct hurd_signal_detail d
;
1420 if (err
= signal_allowed (signo
, refport
))
1423 d
.code
= d
.exc_subcode
= sigcode
;
1426 /* Post the signal to a global receiver thread (or mark it pending in
1427 the global sigstate). This will reply when the signal can be
1428 considered delivered. */
1429 _hurd_internal_post_signal (_hurd_global_sigstate
,
1430 signo
, &d
, reply_port
, reply_port_type
,
1431 0); /* Stop if traced. */
1433 return MIG_NO_REPLY
; /* Already replied. */
1436 /* Implement the sig_post_untraced RPC from <hurd/msg.defs>;
1437 sent when the debugger wants us to really get a signal
1438 even if we are traced. */
1440 _S_msg_sig_post_untraced (mach_port_t me
,
1441 mach_port_t reply_port
,
1442 mach_msg_type_name_t reply_port_type
,
1443 int signo
, natural_t sigcode
,
1444 mach_port_t refport
)
1447 struct hurd_signal_detail d
;
1449 if (err
= signal_allowed (signo
, refport
))
1452 d
.code
= d
.exc_subcode
= sigcode
;
1455 /* Post the signal to the designated signal-receiving thread. This will
1456 reply when the signal can be considered delivered. */
1457 _hurd_internal_post_signal (_hurd_global_sigstate
,
1458 signo
, &d
, reply_port
, reply_port_type
,
1459 1); /* Untraced flag. */
1461 return MIG_NO_REPLY
; /* Already replied. */
1464 extern void __mig_init (void *);
1466 #include <mach/task_special_ports.h>
1468 /* Initialize the message port, _hurd_global_sigstate, and start the
1472 _hurdsig_init (const int *intarray
, size_t intarraysize
)
1475 vm_size_t stacksize
;
1476 struct hurd_sigstate
*ss
;
1478 __mutex_init (&_hurd_siglock
);
1480 err
= __mach_port_allocate (__mach_task_self (),
1481 MACH_PORT_RIGHT_RECEIVE
,
1483 assert_perror (err
);
1485 /* Make a send right to the signal port. */
1486 err
= __mach_port_insert_right (__mach_task_self (),
1489 MACH_MSG_TYPE_MAKE_SEND
);
1490 assert_perror (err
);
1492 /* Initialize the global signal state. */
1493 _hurd_global_sigstate
= _hurd_thread_sigstate (MACH_PORT_NULL
);
1495 /* We block all signals, and let actual threads pull them from the
1497 __sigfillset(& _hurd_global_sigstate
->blocked
);
1499 /* Initialize the main thread's signal state. */
1500 ss
= _hurd_self_sigstate ();
1502 /* Mark it as a process-wide signal receiver. Threads in this set use
1503 the common action vector in _hurd_global_sigstate. */
1504 _hurd_sigstate_set_global_rcv (ss
);
1506 /* Copy inherited signal settings from our parent (or pre-exec process
1508 if (intarraysize
> INIT_SIGMASK
)
1509 ss
->blocked
= intarray
[INIT_SIGMASK
];
1510 if (intarraysize
> INIT_SIGPENDING
)
1511 _hurd_global_sigstate
->pending
= intarray
[INIT_SIGPENDING
];
1512 if (intarraysize
> INIT_SIGIGN
&& intarray
[INIT_SIGIGN
] != 0)
1515 for (signo
= 1; signo
< NSIG
; ++signo
)
1516 if (intarray
[INIT_SIGIGN
] & __sigmask(signo
))
1517 _hurd_global_sigstate
->actions
[signo
].sa_handler
= SIG_IGN
;
1520 /* Start the signal thread listening on the message port. */
1522 #pragma weak __pthread_create
1523 if (!__pthread_create
)
1525 err
= __thread_create (__mach_task_self (), &_hurd_msgport_thread
);
1526 assert_perror (err
);
1528 stacksize
= __vm_page_size
* 8; /* Small stack for signal thread. */
1529 err
= __mach_setup_thread_call (__mach_task_self (),
1530 _hurd_msgport_thread
,
1531 _hurd_msgport_receive
,
1532 (vm_address_t
*) &__hurd_sigthread_stack_base
,
1534 assert_perror (err
);
1535 err
= __mach_setup_tls (_hurd_msgport_thread
);
1536 assert_perror (err
);
1538 __hurd_sigthread_stack_end
= __hurd_sigthread_stack_base
+ stacksize
;
1540 /* Reinitialize the MiG support routines so they will use a per-thread
1541 variable for the cached reply port. */
1542 __mig_init ((void *) __hurd_sigthread_stack_base
);
1544 err
= __thread_resume (_hurd_msgport_thread
);
1545 assert_perror (err
);
1550 pthread_attr_t attr
;
1554 /* When pthread is being used, we need to make the signal thread a
1555 proper pthread. Otherwise it cannot use mutex_lock et al, which
1556 will be the pthread versions. Various of the message port RPC
1557 handlers need to take locks, so we need to be able to call into
1558 pthread code and meet its assumptions about how our thread and
1559 its stack are arranged. Since pthread puts it there anyway,
1560 we'll let the signal thread's per-thread variables be found as for
1561 any normal pthread, and just leave the magic __hurd_sigthread_*
1562 values all zero so they'll be ignored. */
1564 #pragma weak __pthread_detach
1565 #pragma weak __pthread_getattr_np
1566 #pragma weak __pthread_attr_getstack
1567 __pthread_create(&thread
, NULL
, &_hurd_msgport_receive
, NULL
);
1569 /* Record signal thread stack layout for fork() */
1570 __pthread_getattr_np (thread
, &attr
);
1571 __pthread_attr_getstack (&attr
, &addr
, &size
);
1572 __hurd_sigthread_stack_base
= (uintptr_t) addr
;
1573 __hurd_sigthread_stack_end
= __hurd_sigthread_stack_base
+ size
;
1575 __pthread_detach(thread
);
1577 /* XXX We need the thread port for the signal thread further on
1578 in this thread (see hurdfault.c:_hurdsigfault_init).
1579 Therefore we block until _hurd_msgport_thread is initialized
1580 by the newly created thread. This really shouldn't be
1581 necessary; we should be able to fetch the thread port for a
1582 pthread from here. */
1583 while (_hurd_msgport_thread
== 0)
1587 /* Receive exceptions on the signal port. */
1588 #ifdef TASK_EXCEPTION_PORT
1589 __task_set_special_port (__mach_task_self (),
1590 TASK_EXCEPTION_PORT
, _hurd_msgport
);
1591 #elif defined (EXC_MASK_ALL)
1592 __task_set_exception_ports (__mach_task_self (),
1593 EXC_MASK_ALL
& ~(EXC_MASK_SYSCALL
1594 | EXC_MASK_MACH_SYSCALL
1595 | EXC_MASK_RPC_ALERT
),
1597 EXCEPTION_DEFAULT
, MACHINE_THREAD_STATE
);
1599 # error task_set_exception_port?
1602 /* Sanity check. Any pending, unblocked signals should have been
1603 taken by our predecessor incarnation (i.e. parent or pre-exec state)
1604 before packing up our init ints. This assert is last (not above)
1605 so that signal handling is all set up to handle the abort. */
1606 assert ((ss
->pending
&~ ss
->blocked
) == 0);
1609 /* Reauthenticate with the proc server. */
1612 reauth_proc (mach_port_t
new)
1614 mach_port_t ref
, ignore
;
1616 ref
= __mach_reply_port ();
1617 if (! HURD_PORT_USE (&_hurd_ports
[INIT_PORT_PROC
],
1618 __proc_reauthenticate (port
, ref
,
1619 MACH_MSG_TYPE_MAKE_SEND
)
1620 || __auth_user_authenticate (new, ref
,
1621 MACH_MSG_TYPE_MAKE_SEND
,
1623 && ignore
!= MACH_PORT_NULL
)
1624 __mach_port_deallocate (__mach_task_self (), ignore
);
1625 __mach_port_destroy (__mach_task_self (), ref
);
1627 /* Set the owner of the process here too. */
1628 __mutex_lock (&_hurd_id
.lock
);
1629 if (!_hurd_check_ids ())
1630 HURD_PORT_USE (&_hurd_ports
[INIT_PORT_PROC
],
1631 __proc_setowner (port
,
1633 ? _hurd_id
.gen
.uids
[0] : 0),
1634 !_hurd_id
.gen
.nuids
));
1635 __mutex_unlock (&_hurd_id
.lock
);
1637 (void) &reauth_proc
; /* Silence compiler warning. */
1639 text_set_element (_hurd_reauth_hook
, reauth_proc
);
1641 /* Like `getenv', but safe for the signal thread to run.
1642 If the environment is trashed, this will just return NULL. */
1645 _hurdsig_getenv (const char *variable
)
1647 if (__libc_enable_secure
)
1650 if (_hurdsig_catch_memory_fault (__environ
))
1651 /* We bombed in getenv. */
1655 const size_t len
= strlen (variable
);
1657 char *volatile *ep
= __environ
;
1660 const char *p
= *ep
;
1661 _hurdsig_fault_preemptor
.first
= (long int) p
;
1662 _hurdsig_fault_preemptor
.last
= VM_MAX_ADDRESS
;
1663 if (! strncmp (p
, variable
, len
) && p
[len
] == '=')
1667 valuelen
= strlen (p
);
1668 _hurdsig_fault_preemptor
.last
= (long int) (p
+ valuelen
);
1669 value
= malloc (++valuelen
);
1671 memcpy (value
, p
, valuelen
);
1674 _hurdsig_fault_preemptor
.first
= (long int) ++ep
;
1675 _hurdsig_fault_preemptor
.last
= (long int) (ep
+ 1);
1677 _hurdsig_end_catch_fault ();