Back to index

glibc  2.9
mig-reply.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994,1995,1996,1997,2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <mach.h>
00020 #include <hurd/threadvar.h>
00021 
00022 #define GETPORT \
00023   mach_port_t *portloc = \
00024     (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY)
00025 #define reply_port (*(use_threadvar ? portloc : &global_reply_port))
00026 
00027 static int use_threadvar;
00028 static mach_port_t global_reply_port;
00029 
00030 /* These functions are called by MiG-generated code.  */
00031 
00032 /* Called by MiG to get a reply port.  */
00033 mach_port_t
00034 __mig_get_reply_port (void)
00035 {
00036   GETPORT;
00037 
00038   if (reply_port == MACH_PORT_NULL)
00039     reply_port = __mach_reply_port ();
00040 
00041   return reply_port;
00042 }
00043 weak_alias (__mig_get_reply_port, mig_get_reply_port)
00044 
00045 /* Called by MiG to deallocate the reply port.  */
00046 void
00047 __mig_dealloc_reply_port (mach_port_t arg)
00048 {
00049   mach_port_t port;
00050 
00051   GETPORT;
00052 
00053   port = reply_port;
00054   reply_port = MACH_PORT_NULL;     /* So the mod_refs RPC won't use it.  */
00055 
00056   if (MACH_PORT_VALID (port))
00057     __mach_port_mod_refs (__mach_task_self (), port,
00058                        MACH_PORT_RIGHT_RECEIVE, -1);
00059 }
00060 weak_alias (__mig_dealloc_reply_port, mig_dealloc_reply_port)
00061 
00062 /* Called by mig interfaces when done with a port.  Used to provide the
00063    same interface as needed when a custom allocator is used.  */
00064 void
00065 __mig_put_reply_port(mach_port_t port)
00066 {
00067   /* Do nothing.  */
00068 }
00069 weak_alias (__mig_put_reply_port, mig_put_reply_port)
00070 
00071 /* Called at startup with STACK == NULL.  When per-thread variables are set
00072    up, this is called again with STACK set to the new stack being switched
00073    to, where per-thread variables should be set up.  */
00074 void
00075 __mig_init (void *stack)
00076 {
00077   use_threadvar = stack != 0;
00078 
00079   if (use_threadvar)
00080     {
00081       /* Recycle the reply port used before multithreading was enabled.  */
00082       mach_port_t *portloc = (mach_port_t *)
00083        __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack);
00084       *portloc = global_reply_port;
00085       global_reply_port = MACH_PORT_NULL;
00086     }
00087 }
00088 weak_alias (__mig_init, mig_init)