summaryrefslogtreecommitdiff
path: root/ipc/mach_rpc.c
blob: 7f5b2eb2832d68e3e3a24ac20a9f5a2c288f3a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* 
 * Copyright (c) 1994 The University of Utah and
 * the Computer Systems Laboratory (CSL).  All rights reserved.
 *
 * Permission to use, copy, modify and distribute this software is hereby
 * granted provided that (1) source code retains these copyright, permission,
 * and disclaimer notices, and (2) redistributions including binaries
 * reproduce the notices in supporting documentation, and (3) all advertising
 * materials mentioning features or use of this software display the following
 * acknowledgement: ``This product includes software developed by the
 * Computer Systems Laboratory at the University of Utah.''
 *
 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
 * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
 * improvements that they make and grant CSL redistribution rights.
 *
 */

#ifdef MIGRATING_THREADS

#include <kern/printf.h>
#include <mach/kern_return.h>
#include <mach/port.h>
#include <mach/rpc.h>
#include <mach/notify.h>
#include <mach/mach_param.h>
#include <mach/vm_param.h>
#include <mach/vm_prot.h>
#include <kern/task.h>
#include <kern/act.h>
#include <vm/vm_map.h>
#include <vm/vm_kern.h>
#include <vm/vm_user.h>
#include <ipc/ipc_entry.h>
#include <ipc/ipc_space.h>
#include <ipc/ipc_object.h>
#include <ipc/ipc_notify.h>
#include <ipc/ipc_port.h>
#include <ipc/ipc_pset.h>
#include <ipc/ipc_right.h>

#undef DEBUG_MPRC

/*
 * XXX need to identify if one endpoint of an RPC is the kernel to
 * ensure proper port name translation (or lack of).  This is bogus.
 */
#define ISKERNELACT(act)	((act)->task == kernel_task)

/*
 * Copy the indicated port from the task associated with the source
 * activation into the task associated with the destination activation.
 *
 * XXX on errors we should probably clear the portp to avoid leaking
 * info to the other side.
 */
kern_return_t
mach_port_rpc_copy(portp, sact, dact)
	struct rpc_port_desc *portp;
	struct Act *sact, *dact;
{
	ipc_space_t sspace, dspace;
	mach_msg_type_name_t tname;
	ipc_object_t iname;
	kern_return_t kr;

#ifdef DEBUG_MPRC
	printf("m_p_rpc_copy(portp=%x/%x, sact=%x, dact=%x): ",
	       portp->name, portp->msgt_name, sact, dact);
#endif
	sspace = sact->task->itk_space;
	dspace = dact->task->itk_space;
	if (sspace == IS_NULL || dspace == IS_NULL) {
#ifdef DEBUG_MPRC
		printf("bogus src (%x) or dst (%x) space\n", sspace, dspace);
#endif
		return KERN_INVALID_TASK;
	}

	if (!MACH_MSG_TYPE_PORT_ANY(portp->msgt_name)) {
#ifdef DEBUG_MPRC
		printf("invalid port type\n");
#endif
		return KERN_INVALID_VALUE;
	}

	if (ISKERNELACT(sact)) {
		iname = (ipc_object_t) portp->name;
		ipc_object_copyin_from_kernel(iname, portp->msgt_name);
		kr = KERN_SUCCESS;
	} else {
		kr = ipc_object_copyin(sspace, portp->name, portp->msgt_name,
				       &iname);
	}
	if (kr != KERN_SUCCESS) {
#ifdef DEBUG_MPRC
		printf("copyin returned %x\n", kr);
#endif
		return kr;
	}

	tname = ipc_object_copyin_type(portp->msgt_name);
	if (!IO_VALID(iname)) {
		portp->name = (mach_port_t) iname;
		portp->msgt_name = tname;
#ifdef DEBUG_MPRC
		printf("iport %x invalid\n", iname);
#endif
		return KERN_SUCCESS;
	}

	if (ISKERNELACT(dact)) {
		portp->name = (mach_port_t) iname;
		kr = KERN_SUCCESS;
	} else {
		kr = ipc_object_copyout(dspace, iname, tname, TRUE,
					&portp->name);
	}
	if (kr != KERN_SUCCESS) {
		ipc_object_destroy(iname, tname);

		if (kr == KERN_INVALID_CAPABILITY)
			portp->name = MACH_PORT_DEAD;
		else {
			portp->name = MACH_PORT_NULL;
#ifdef DEBUG_MPRC
			printf("copyout iport %x returned %x\n", iname);
#endif
			return kr;
		}
	}

	portp->msgt_name = tname;
#ifdef DEBUG_MPRC
	printf("portp=%x/%x, iname=%x\n", portp->name, portp->msgt_name, iname);
#endif
	return KERN_SUCCESS;
}

kern_return_t
mach_port_rpc_sig(space, name, buffer, buflen)
{
	return KERN_FAILURE;
}

#endif /* MIGRATING_THREADS */