Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / mach / hurd / mig-reply.c
blob540b7bd51103eb7b15bb9e4f52a7a6de8f9a20c1
1 /* Copyright (C) 1994-2014 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.h>
19 #include <hurd/threadvar.h>
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))
26 static int use_threadvar;
27 static mach_port_t global_reply_port;
29 /* These functions are called by MiG-generated code. */
31 /* Called by MiG to get a reply port. */
32 mach_port_t
33 __mig_get_reply_port (void)
35 GETPORT;
37 if (reply_port == MACH_PORT_NULL)
38 reply_port = __mach_reply_port ();
40 return reply_port;
42 weak_alias (__mig_get_reply_port, mig_get_reply_port)
44 /* Called by MiG to deallocate the reply port. */
45 void
46 __mig_dealloc_reply_port (mach_port_t arg)
48 mach_port_t port;
50 GETPORT;
52 port = reply_port;
53 reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */
55 if (MACH_PORT_VALID (port))
56 __mach_port_mod_refs (__mach_task_self (), port,
57 MACH_PORT_RIGHT_RECEIVE, -1);
59 weak_alias (__mig_dealloc_reply_port, mig_dealloc_reply_port)
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)
66 /* Do nothing. */
68 weak_alias (__mig_put_reply_port, mig_put_reply_port)
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)
76 use_threadvar = stack != 0;
78 if (use_threadvar)
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;
87 weak_alias (__mig_init, mig_init)