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