1 /* $NetBSD: mach_host.c,v 1.29 2005/12/11 12:20:20 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.29 2005/12/11 12:20:20 christos Exp $");
41
42 #include <sys/types.h>
43 #include <sys/malloc.h>
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/systm.h>
47 #include <sys/signal.h>
48 #include <sys/proc.h>
49
50 #include <uvm/uvm_extern.h>
51 #include <uvm/uvm_param.h>
52
53 #include <compat/mach/mach_types.h>
54 #include <compat/mach/mach_host.h>
55 #include <compat/mach/mach_port.h>
56 #include <compat/mach/mach_clock.h>
57 #include <compat/mach/mach_errno.h>
58 #include <compat/mach/mach_services.h>
59
60 int
61 mach_host_info(args)
62 struct mach_trap_args *args;
63 {
64 mach_host_info_request_t *req = args->smsg;
65 mach_host_info_reply_t *rep = args->rmsg;
66 size_t *msglen = args->rsize;
67 mach_host_info_reply_simple_t *reps;
68
69 *msglen = sizeof(*rep);
70 mach_set_header(rep, req, *msglen);
71
72 switch(req->req_flavor) {
73 case MACH_HOST_BASIC_INFO: {
74 struct mach_host_basic_info *info
75 = (struct mach_host_basic_info *)&rep->rep_data[0];
76
77 rep->rep_msgh.msgh_size = sizeof(*reps)
78 - sizeof(rep->rep_trailer) + sizeof(*info);
79 rep->rep_count = sizeof(*info) / sizeof(mach_integer_t);
80 mach_host_basic_info(info);
81 break;
82 }
83
84 case MACH_HOST_PRIORITY_INFO: {
85 struct mach_host_priority_info *info
86 = (struct mach_host_priority_info *)&rep->rep_data[0];
87
88 rep->rep_msgh.msgh_size = sizeof(*reps)
89 - sizeof(rep->rep_trailer) + sizeof(*info);
90 rep->rep_count = sizeof(*info) / sizeof(mach_integer_t);
91 mach_host_priority_info(info);
92 break;
93 }
94
95 case MACH_HOST_SEMAPHORE_TRAPS:
96 case MACH_HOST_MACH_MSG_TRAP:
97 reps = (mach_host_info_reply_simple_t *)rep;
98 reps->rep_msgh.msgh_size =
99 sizeof(*reps) - sizeof(reps->rep_trailer);
100 *msglen = sizeof(*reps);
101 break;
102
103 case MACH_HOST_SCHED_INFO: {
104 struct mach_host_sched_info *info
105 = (struct mach_host_sched_info *)&rep->rep_data[0];
106
107 rep->rep_msgh.msgh_size = sizeof(*reps)
108 - sizeof(rep->rep_trailer) + sizeof(*info);
109 rep->rep_count = sizeof(*info) / sizeof(mach_integer_t);
110
111 info->min_timeout = 1000 / hz; /* XXX timout in ms */
112 info->min_quantum = 1000 / hz; /* quantum in ms */
113
114 break;
115 }
116
117 case MACH_HOST_RESOURCE_SIZES:
118 uprintf("mach_host_info() Unimplemented host_info flavor %d\n",
119 req->req_flavor);
120 default:
121 uprintf("Unknown host_info flavor %d\n", req->req_flavor);
122 rep->rep_retval = native_to_mach_errno[EINVAL];
123 break;
124 }
125
126 mach_set_trailer(rep, *msglen);
127
128 return 0;
129 }
130
131
132 int
133 mach_host_page_size(args)
134 struct mach_trap_args *args;
135 {
136 mach_host_page_size_request_t *req = args->smsg;
137 mach_host_page_size_reply_t *rep = args->rmsg;
138 size_t *msglen = args->rsize;
139
140 *msglen = sizeof(*rep);
141 mach_set_header(rep, req, *msglen);
142
143 rep->rep_page_size = PAGE_SIZE;
144
145 mach_set_trailer(rep, *msglen);
146
147 return 0;
148 }
149
150 int
151 mach_host_get_clock_service(args)
152 struct mach_trap_args *args;
153 {
154 mach_host_get_clock_service_request_t *req = args->smsg;
155 mach_host_get_clock_service_reply_t *rep = args->rmsg;
156 size_t *msglen = args->rsize;
157 struct lwp *l = args->l;
158 struct mach_right *mr;
159
160 mr = mach_right_get(mach_clock_port, l, MACH_PORT_TYPE_SEND, 0);
161
162 *msglen = sizeof(*rep);
163 mach_set_header(rep, req, *msglen);
164 mach_add_port_desc(rep, mr->mr_name);
165 mach_set_trailer(rep, *msglen);
166
167 return 0;
168 }
169
170 void
171 mach_host_priority_info(info)
172 struct mach_host_priority_info *info;
173 {
174 /* XXX One day, try to fill this correctly */
175 info->kernel_priority = 0x50;
176 info->system_priority = 0x50;
177 info->server_priority = 0x40;
178 info->user_priority = 0x1f;
179 info->depress_priority = 0x00;
180 info->idle_priority = 0x00;
181 info->minimum_priority = 0x00;
182 info->maximum_priority = 0x4f;
183
184 return;
185 }
186
187 int
188 mach_host_get_io_master(args)
189 struct mach_trap_args *args;
190 {
191 mach_host_get_io_master_request_t *req = args->smsg;
192 mach_host_get_io_master_reply_t *rep = args->rmsg;
193 size_t *msglen = args->rsize;
194 struct lwp *l = args->l;
195 struct mach_right *mr;
196
197 mr = mach_right_get(mach_io_master_port, l, MACH_PORT_TYPE_SEND, 0);
198
199 *msglen = sizeof(*rep);
200 mach_set_header(rep, req, *msglen);
201 mach_add_port_desc(rep, mr->mr_name);
202 mach_set_trailer(rep, *msglen);
203
204 return 0;
205 }
206
207 int
208 mach_processor_set_default(args)
209 struct mach_trap_args *args;
210 {
211 mach_processor_set_default_request_t *req = args->smsg;
212 mach_processor_set_default_reply_t *rep = args->rmsg;
213 size_t *msglen = args->rsize;
214 struct lwp *l = args->l;
215 struct mach_right *mr;
216 struct mach_port *mp;
217
218 mp = mach_port_get();
219 mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
220
221 *msglen = sizeof(*rep);
222 mach_set_header(rep, req, *msglen);
223 mach_add_port_desc(rep, mr->mr_name);
224 mach_set_trailer(rep, *msglen);
225
226 return 0;
227 }
228
229 int
230 mach_host_processor_set_priv(args)
231 struct mach_trap_args *args;
232 {
233 mach_host_processor_set_priv_request_t *req = args->smsg;
234 mach_host_processor_set_priv_reply_t *rep = args->rmsg;
235 size_t *msglen = args->rsize;
236 struct lwp *l = args->l;
237 mach_port_t mn;
238 struct mach_right *mr;
239 struct mach_right *smr;
240 struct mach_port *smp;
241
242 mn = req->req_set.name;
243 if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
244 return mach_msg_error(args, EINVAL);
245
246 smp = mach_port_get();
247 smr = mach_right_get(smp, l, MACH_PORT_TYPE_SEND, 0);
248
249 *msglen = sizeof(*rep);
250 mach_set_header(rep, req, *msglen);
251 mach_add_port_desc(rep, smr->mr_name);
252 mach_set_trailer(rep, *msglen);
253
254 return 0;
255 }
Cache object: 68f19e178fbe558dfa49874b9322eccd
|