xref: /NextBSD/lib/libmach/mach/mig_support.c (revision 33da5adc555b3bc29986eeadca03829e4ad06b1e)
1 /*
2  * Copyright 1991-1998 by Open Software Foundation, Inc.
3  *              All Rights Reserved
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both the copyright notice and this permission notice appear in
9  * supporting documentation.
10  *
11  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  * FOR A PARTICULAR PURPOSE.
14  *
15  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 /*
22  * Mach Operating System
23  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
24  * All Rights Reserved.
25  *
26  * Permission to use, copy, modify and distribute this software and its
27  * documentation is hereby granted, provided that both the copyright
28  * notice and this permission notice appear in all copies of the
29  * software, derivative works or modified versions, and any portions
30  * thereof, and that both notices appear in supporting documentation.
31  *
32  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
33  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
34  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
35  *
36  * Carnegie Mellon requests users of this software to return to
37  *
38  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
39  *  School of Computer Science
40  *  Carnegie Mellon University
41  *  Pittsburgh PA 15213-3890
42  *
43  * any improvements or extensions that they make and grant Carnegie Mellon
44  * the rights to redistribute these changes.
45  */
46 /*
47  * MkLinux
48  */
49 /*
50  *  Abstract:
51  *	Routines to set and deallocate the mig reply port.
52  *	They are called from mig generated interfaces.
53  *
54  */
55 
56 #include <mach/mach.h>
57 #include <mach/mach_traps.h>
58 #include "externs.h"
59 
60 static mach_port_t	mig_reply_port = MACH_PORT_NULL;
61 
62 /*****************************************************
63  *  Called by mach_init. This is necessary after
64  *  a fork to get rid of bogus port number.
65  ****************************************************/
66 
67 void
mig_init(void * arg __unused)68 mig_init(void * arg __unused)
69 {
70 	mig_reply_port = MACH_PORT_NULL;
71 }
72 
73 /********************************************************
74  *  Called by mig interfaces whenever they  need a reply port.
75  *  Used to provide the same interface as multi-threaded tasks need.
76  ********************************************************/
77 
78 mach_port_t
mig_get_reply_port()79 mig_get_reply_port()
80 {
81 	if (mig_reply_port == MACH_PORT_NULL)
82 		mig_reply_port = mach_reply_port();
83 
84 	return mig_reply_port;
85 }
86 
87 /*************************************************************
88  *  Called by mig interfaces after a timeout on the port.
89  *  Could be called by user.
90  ***********************************************************/
91 
92 void
mig_dealloc_reply_port(mach_port_t reply_port __unused)93 mig_dealloc_reply_port(
94 	mach_port_t	reply_port __unused)
95 {
96 	mach_port_t port;
97 
98 	port = mig_reply_port;
99 	mig_reply_port = MACH_PORT_NULL;
100 
101 	(void) mach_port_mod_refs(mach_task_self(), port,
102 				  MACH_PORT_RIGHT_RECEIVE, -1);
103 }
104 
105 /*************************************************************
106  *  Called by mig interfaces after each RPC.
107  *  Could be called by user.
108  ***********************************************************/
109 
110 void
mig_put_reply_port(mach_port_t reply_port __unused)111 mig_put_reply_port(
112 	mach_port_t	reply_port __unused)
113 {
114 }
115