]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/hurd/mig-reply.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / mach / hurd / mig-reply.c
CommitLineData
d4697bc9 1/* Copyright (C) 1994-2014 Free Software Foundation, Inc.
478b92f0
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.
478b92f0
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.
478b92f0 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
28f540f4
RM
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)
bf3534a5 24#define reply_port (*(use_threadvar ? portloc : &global_reply_port))
28f540f4
RM
25
26static int use_threadvar;
27static 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. */
32mach_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}
42weak_alias (__mig_get_reply_port, mig_get_reply_port)
43
44/* Called by MiG to deallocate the reply port. */
45void
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. */
aa0e1b59
MB
54
55 if (MACH_PORT_VALID (port))
56 __mach_port_mod_refs (__mach_task_self (), port,
57 MACH_PORT_RIGHT_RECEIVE, -1);
28f540f4
RM
58}
59weak_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. */
63void
64__mig_put_reply_port(mach_port_t port)
65{
66 /* Do nothing. */
67}
68weak_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. */
73void
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}
87weak_alias (__mig_init, mig_init)