xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame^] | 1 | /* Copyright (C) 1994-2016 Free Software Foundation, Inc. |
| 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 |
| 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. |
| 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 |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 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/>. */ |
| 17 | |
| 18 | #include <mach.h> |
| 19 | #include <hurd/threadvar.h> |
| 20 | |
| 21 | #define GETPORT \ |
| 22 | mach_port_t *portloc = \ |
| 23 | (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY) |
| 24 | #define reply_port (*(use_threadvar ? portloc : &global_reply_port)) |
| 25 | |
| 26 | static int use_threadvar; |
| 27 | static mach_port_t global_reply_port; |
| 28 | |
| 29 | /* These functions are called by MiG-generated code. */ |
| 30 | |
| 31 | /* Called by MiG to get a reply port. */ |
| 32 | mach_port_t |
| 33 | __mig_get_reply_port (void) |
| 34 | { |
| 35 | GETPORT; |
| 36 | |
| 37 | if (reply_port == MACH_PORT_NULL) |
| 38 | reply_port = __mach_reply_port (); |
| 39 | |
| 40 | return reply_port; |
| 41 | } |
| 42 | weak_alias (__mig_get_reply_port, mig_get_reply_port) |
| 43 | |
| 44 | /* Called by MiG to deallocate the reply port. */ |
| 45 | void |
| 46 | __mig_dealloc_reply_port (mach_port_t arg) |
| 47 | { |
| 48 | mach_port_t port; |
| 49 | |
| 50 | GETPORT; |
| 51 | |
| 52 | port = reply_port; |
| 53 | reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */ |
| 54 | |
| 55 | if (MACH_PORT_VALID (port)) |
| 56 | __mach_port_mod_refs (__mach_task_self (), port, |
| 57 | MACH_PORT_RIGHT_RECEIVE, -1); |
| 58 | } |
| 59 | weak_alias (__mig_dealloc_reply_port, mig_dealloc_reply_port) |
| 60 | |
| 61 | /* Called by mig interfaces when done with a port. Used to provide the |
| 62 | same interface as needed when a custom allocator is used. */ |
| 63 | void |
| 64 | __mig_put_reply_port(mach_port_t port) |
| 65 | { |
| 66 | /* Do nothing. */ |
| 67 | } |
| 68 | weak_alias (__mig_put_reply_port, mig_put_reply_port) |
| 69 | |
| 70 | /* Called at startup with STACK == NULL. When per-thread variables are set |
| 71 | up, this is called again with STACK set to the new stack being switched |
| 72 | to, where per-thread variables should be set up. */ |
| 73 | void |
| 74 | __mig_init (void *stack) |
| 75 | { |
| 76 | use_threadvar = stack != 0; |
| 77 | |
| 78 | if (use_threadvar) |
| 79 | { |
| 80 | /* Recycle the reply port used before multithreading was enabled. */ |
| 81 | mach_port_t *portloc = (mach_port_t *) |
| 82 | __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack); |
| 83 | *portloc = global_reply_port; |
| 84 | global_reply_port = MACH_PORT_NULL; |
| 85 | } |
| 86 | } |
| 87 | weak_alias (__mig_init, mig_init) |