lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Demux messages sent on the signal port. |
| 2 | Copyright (C) 1991-2015 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <hurd.h> |
| 20 | #include <hurd/signal.h> |
| 21 | #include <stddef.h> |
| 22 | |
| 23 | struct demux |
| 24 | { |
| 25 | struct demux *next; |
| 26 | boolean_t (*demux) (mach_msg_header_t *inp, |
| 27 | mach_msg_header_t *outp); |
| 28 | }; |
| 29 | |
| 30 | struct demux *_hurd_msgport_demuxers = NULL; |
| 31 | |
| 32 | extern boolean_t __msg_server (mach_msg_header_t *inp, |
| 33 | mach_msg_header_t *outp); |
| 34 | |
| 35 | static boolean_t |
| 36 | msgport_server (mach_msg_header_t *inp, |
| 37 | mach_msg_header_t *outp) |
| 38 | { |
| 39 | extern boolean_t _S_msg_server (mach_msg_header_t *inp, |
| 40 | mach_msg_header_t *outp); |
| 41 | extern boolean_t _S_exc_server (mach_msg_header_t *inp, |
| 42 | mach_msg_header_t *outp); |
| 43 | struct demux *d; |
| 44 | |
| 45 | for (d = _hurd_msgport_demuxers; d != NULL; d = d->next) |
| 46 | if ((*d->demux) (inp, outp)) |
| 47 | return 1; |
| 48 | |
| 49 | return (_S_exc_server (inp, outp) || |
| 50 | _S_msg_server (inp, outp)); |
| 51 | } |
| 52 | |
| 53 | /* This is the code that the signal thread runs. */ |
| 54 | void |
| 55 | _hurd_msgport_receive (void) |
| 56 | { |
| 57 | /* Get our own sigstate cached so we never again have to take a lock to |
| 58 | fetch it. There is much code in hurdsig.c that operates with some |
| 59 | sigstate lock held, which will deadlock with _hurd_thread_sigstate. |
| 60 | |
| 61 | Furthermore, in the cthreads case this is the convenient spot |
| 62 | to initialize _hurd_msgport_thread (see hurdsig.c:_hurdsig_init). */ |
| 63 | |
| 64 | _hurd_msgport_thread = _hurd_self_sigstate ()->thread; |
| 65 | |
| 66 | while (1) |
| 67 | (void) __mach_msg_server (msgport_server, __vm_page_size, _hurd_msgport); |
| 68 | } |