kern_time_50.c revision 1.33 1 1.33 pgoyette /* $NetBSD: kern_time_50.c,v 1.33 2019/01/27 02:08:39 pgoyette Exp $ */
2 1.2 christos
3 1.2 christos /*-
4 1.8 rmind * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 1.2 christos * All rights reserved.
6 1.2 christos *
7 1.2 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.2 christos * by Christos Zoulas.
9 1.2 christos *
10 1.2 christos * Redistribution and use in source and binary forms, with or without
11 1.2 christos * modification, are permitted provided that the following conditions
12 1.2 christos * are met:
13 1.2 christos * 1. Redistributions of source code must retain the above copyright
14 1.2 christos * notice, this list of conditions and the following disclaimer.
15 1.2 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 christos * notice, this list of conditions and the following disclaimer in the
17 1.2 christos * documentation and/or other materials provided with the distribution.
18 1.2 christos *
19 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 christos * POSSIBILITY OF SUCH DAMAGE.
30 1.2 christos */
31 1.2 christos #include <sys/cdefs.h>
32 1.33 pgoyette __KERNEL_RCSID(0, "$NetBSD: kern_time_50.c,v 1.33 2019/01/27 02:08:39 pgoyette Exp $");
33 1.2 christos
34 1.2 christos #ifdef _KERNEL_OPT
35 1.33 pgoyette #include "opt_compat_netbsd.h"
36 1.8 rmind #include "opt_aio.h"
37 1.2 christos #include "opt_ntp.h"
38 1.8 rmind #include "opt_mqueue.h"
39 1.2 christos #endif
40 1.2 christos
41 1.2 christos #include <sys/param.h>
42 1.22 apb #include <sys/conf.h>
43 1.2 christos #include <sys/systm.h>
44 1.2 christos #include <sys/namei.h>
45 1.2 christos #include <sys/filedesc.h>
46 1.2 christos #include <sys/kernel.h>
47 1.2 christos #include <sys/file.h>
48 1.2 christos #include <sys/stat.h>
49 1.2 christos #include <sys/socketvar.h>
50 1.2 christos #include <sys/vnode.h>
51 1.2 christos #include <sys/proc.h>
52 1.2 christos #include <sys/uio.h>
53 1.2 christos #include <sys/dirent.h>
54 1.2 christos #include <sys/kauth.h>
55 1.2 christos #include <sys/time.h>
56 1.2 christos #include <sys/timex.h>
57 1.21 apb #include <sys/clockctl.h>
58 1.2 christos #include <sys/aio.h>
59 1.2 christos #include <sys/poll.h>
60 1.33 pgoyette #include <sys/syscall.h>
61 1.2 christos #include <sys/syscallargs.h>
62 1.33 pgoyette #include <sys/syscallvar.h>
63 1.25 pgoyette #include <sys/sysctl.h>
64 1.2 christos #include <sys/resource.h>
65 1.33 pgoyette #include <sys/compat_stub.h>
66 1.2 christos
67 1.2 christos #include <compat/common/compat_util.h>
68 1.25 pgoyette #include <compat/common/compat_mod.h>
69 1.2 christos #include <compat/sys/time.h>
70 1.2 christos #include <compat/sys/timex.h>
71 1.2 christos #include <compat/sys/resource.h>
72 1.2 christos #include <compat/sys/clockctl.h>
73 1.2 christos
74 1.25 pgoyette struct timeval50 boottime50;
75 1.25 pgoyette
76 1.33 pgoyette static struct sysctllog *kern_time_50_clog = NULL;
77 1.33 pgoyette
78 1.33 pgoyette static const struct syscall_package kern_time_50_syscalls[] = {
79 1.33 pgoyette { SYS_compat_50_clock_gettime, 0,
80 1.33 pgoyette (sy_call_t *)compat_50_sys_clock_gettime },
81 1.33 pgoyette { SYS_compat_50_clock_settime, 0,
82 1.33 pgoyette (sy_call_t *)compat_50_sys_clock_settime },
83 1.33 pgoyette { SYS_compat_50_clock_getres, 0,
84 1.33 pgoyette (sy_call_t *)compat_50_sys_clock_getres},
85 1.33 pgoyette { SYS_compat_50_nanosleep, 0, (sy_call_t *)compat_50_sys_nanosleep },
86 1.33 pgoyette { SYS_compat_50_gettimeofday, 0,
87 1.33 pgoyette (sy_call_t *)compat_50_sys_gettimeofday },
88 1.33 pgoyette { SYS_compat_50_settimeofday, 0,
89 1.33 pgoyette (sy_call_t *)compat_50_sys_settimeofday },
90 1.33 pgoyette { SYS_compat_50_adjtime, 0, (sy_call_t *)compat_50_sys_adjtime },
91 1.33 pgoyette { SYS_compat_50_setitimer, 0, (sy_call_t *)compat_50_sys_setitimer },
92 1.33 pgoyette { SYS_compat_50_getitimer, 0, (sy_call_t *)compat_50_sys_getitimer },
93 1.33 pgoyette { SYS_compat_50_aio_suspend, 0,
94 1.33 pgoyette (sy_call_t *)compat_50_sys_aio_suspend },
95 1.33 pgoyette { SYS_compat_50_mq_timedsend, 0,
96 1.33 pgoyette (sy_call_t *)compat_50_sys_mq_timedsend },
97 1.33 pgoyette { SYS_compat_50_mq_timedreceive, 0,
98 1.33 pgoyette (sy_call_t *)compat_50_sys_mq_timedreceive },
99 1.33 pgoyette { SYS_compat_50_getrusage, 0, (sy_call_t *)compat_50_sys_getrusage },
100 1.33 pgoyette { SYS_compat_50_timer_settime, 0,
101 1.33 pgoyette (sy_call_t *)compat_50_sys_timer_settime },
102 1.33 pgoyette { SYS_compat_50_timer_gettime, 0,
103 1.33 pgoyette (sy_call_t *)compat_50_sys_timer_gettime },
104 1.33 pgoyette { SYS_compat_50___ntp_gettime30, 0,
105 1.33 pgoyette (sy_call_t *)compat_50_sys___ntp_gettime30 },
106 1.33 pgoyette { 0, 0, NULL }
107 1.33 pgoyette };
108 1.33 pgoyette
109 1.2 christos int
110 1.2 christos compat_50_sys_clock_gettime(struct lwp *l,
111 1.2 christos const struct compat_50_sys_clock_gettime_args *uap, register_t *retval)
112 1.2 christos {
113 1.2 christos /* {
114 1.2 christos syscallarg(clockid_t) clock_id;
115 1.2 christos syscallarg(struct timespec50 *) tp;
116 1.2 christos } */
117 1.15 njoly int error;
118 1.2 christos struct timespec ats;
119 1.2 christos struct timespec50 ats50;
120 1.2 christos
121 1.15 njoly error = clock_gettime1(SCARG(uap, clock_id), &ats);
122 1.15 njoly if (error != 0)
123 1.15 njoly return error;
124 1.15 njoly
125 1.2 christos timespec_to_timespec50(&ats, &ats50);
126 1.2 christos
127 1.2 christos return copyout(&ats50, SCARG(uap, tp), sizeof(ats50));
128 1.2 christos }
129 1.2 christos
130 1.2 christos /* ARGSUSED */
131 1.2 christos int
132 1.2 christos compat_50_sys_clock_settime(struct lwp *l,
133 1.2 christos const struct compat_50_sys_clock_settime_args *uap, register_t *retval)
134 1.2 christos {
135 1.2 christos /* {
136 1.2 christos syscallarg(clockid_t) clock_id;
137 1.2 christos syscallarg(const struct timespec50 *) tp;
138 1.2 christos } */
139 1.2 christos int error;
140 1.2 christos struct timespec ats;
141 1.2 christos struct timespec50 ats50;
142 1.2 christos
143 1.2 christos error = copyin(SCARG(uap, tp), &ats50, sizeof(ats50));
144 1.2 christos if (error)
145 1.2 christos return error;
146 1.2 christos timespec50_to_timespec(&ats50, &ats);
147 1.2 christos
148 1.2 christos return clock_settime1(l->l_proc, SCARG(uap, clock_id), &ats,
149 1.2 christos true);
150 1.2 christos }
151 1.2 christos
152 1.2 christos
153 1.2 christos int
154 1.2 christos compat_50_sys_clock_getres(struct lwp *l,
155 1.2 christos const struct compat_50_sys_clock_getres_args *uap, register_t *retval)
156 1.2 christos {
157 1.2 christos /* {
158 1.2 christos syscallarg(clockid_t) clock_id;
159 1.2 christos syscallarg(struct timespec50 *) tp;
160 1.2 christos } */
161 1.2 christos struct timespec50 ats50;
162 1.14 njoly struct timespec ats;
163 1.29 maxv int error;
164 1.2 christos
165 1.14 njoly error = clock_getres1(SCARG(uap, clock_id), &ats);
166 1.14 njoly if (error != 0)
167 1.14 njoly return error;
168 1.14 njoly
169 1.14 njoly if (SCARG(uap, tp)) {
170 1.14 njoly timespec_to_timespec50(&ats, &ats50);
171 1.14 njoly error = copyout(&ats50, SCARG(uap, tp), sizeof(ats50));
172 1.2 christos }
173 1.2 christos
174 1.2 christos return error;
175 1.2 christos }
176 1.2 christos
177 1.2 christos /* ARGSUSED */
178 1.2 christos int
179 1.2 christos compat_50_sys_nanosleep(struct lwp *l,
180 1.2 christos const struct compat_50_sys_nanosleep_args *uap, register_t *retval)
181 1.2 christos {
182 1.2 christos /* {
183 1.2 christos syscallarg(struct timespec50 *) rqtp;
184 1.2 christos syscallarg(struct timespec50 *) rmtp;
185 1.2 christos } */
186 1.2 christos struct timespec rmt, rqt;
187 1.2 christos struct timespec50 rmt50, rqt50;
188 1.2 christos int error, error1;
189 1.2 christos
190 1.2 christos error = copyin(SCARG(uap, rqtp), &rqt50, sizeof(rqt50));
191 1.2 christos if (error)
192 1.2 christos return error;
193 1.2 christos timespec50_to_timespec(&rqt50, &rqt);
194 1.2 christos
195 1.23 christos error = nanosleep1(l, CLOCK_MONOTONIC, 0, &rqt,
196 1.23 christos SCARG(uap, rmtp) ? &rmt : NULL);
197 1.2 christos if (SCARG(uap, rmtp) == NULL || (error != 0 && error != EINTR))
198 1.2 christos return error;
199 1.2 christos
200 1.2 christos timespec_to_timespec50(&rmt, &rmt50);
201 1.2 christos error1 = copyout(&rmt50, SCARG(uap, rmtp), sizeof(*SCARG(uap, rmtp)));
202 1.2 christos return error1 ? error1 : error;
203 1.2 christos }
204 1.2 christos
205 1.2 christos /* ARGSUSED */
206 1.2 christos int
207 1.2 christos compat_50_sys_gettimeofday(struct lwp *l,
208 1.2 christos const struct compat_50_sys_gettimeofday_args *uap, register_t *retval)
209 1.2 christos {
210 1.2 christos /* {
211 1.2 christos syscallarg(struct timeval50 *) tp;
212 1.2 christos syscallarg(void *) tzp; really "struct timezone *";
213 1.2 christos } */
214 1.2 christos struct timeval atv;
215 1.2 christos struct timeval50 atv50;
216 1.2 christos int error = 0;
217 1.2 christos struct timezone tzfake;
218 1.2 christos
219 1.2 christos if (SCARG(uap, tp)) {
220 1.2 christos microtime(&atv);
221 1.2 christos timeval_to_timeval50(&atv, &atv50);
222 1.2 christos error = copyout(&atv50, SCARG(uap, tp), sizeof(*SCARG(uap, tp)));
223 1.2 christos if (error)
224 1.2 christos return error;
225 1.2 christos }
226 1.2 christos if (SCARG(uap, tzp)) {
227 1.2 christos /*
228 1.2 christos * NetBSD has no kernel notion of time zone, so we just
229 1.2 christos * fake up a timezone struct and return it if demanded.
230 1.2 christos */
231 1.2 christos tzfake.tz_minuteswest = 0;
232 1.2 christos tzfake.tz_dsttime = 0;
233 1.2 christos error = copyout(&tzfake, SCARG(uap, tzp), sizeof(tzfake));
234 1.2 christos }
235 1.2 christos return error;
236 1.2 christos }
237 1.2 christos
238 1.2 christos /* ARGSUSED */
239 1.2 christos int
240 1.2 christos compat_50_sys_settimeofday(struct lwp *l,
241 1.2 christos const struct compat_50_sys_settimeofday_args *uap, register_t *retval)
242 1.2 christos {
243 1.2 christos /* {
244 1.2 christos syscallarg(const struct timeval50 *) tv;
245 1.2 christos syscallarg(const void *) tzp; really "const struct timezone *";
246 1.2 christos } */
247 1.2 christos struct timeval50 atv50;
248 1.2 christos struct timeval atv;
249 1.2 christos int error = copyin(SCARG(uap, tv), &atv50, sizeof(atv50));
250 1.2 christos if (error)
251 1.2 christos return error;
252 1.2 christos timeval50_to_timeval(&atv50, &atv);
253 1.2 christos return settimeofday1(&atv, false, SCARG(uap, tzp), l, true);
254 1.2 christos }
255 1.2 christos
256 1.2 christos /* ARGSUSED */
257 1.2 christos int
258 1.2 christos compat_50_sys_adjtime(struct lwp *l,
259 1.2 christos const struct compat_50_sys_adjtime_args *uap, register_t *retval)
260 1.2 christos {
261 1.2 christos /* {
262 1.2 christos syscallarg(const struct timeval50 *) delta;
263 1.2 christos syscallarg(struct timeval50 *) olddelta;
264 1.2 christos } */
265 1.2 christos int error;
266 1.2 christos struct timeval50 delta50, olddelta50;
267 1.2 christos struct timeval delta, olddelta;
268 1.2 christos
269 1.2 christos if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
270 1.2 christos KAUTH_REQ_SYSTEM_TIME_ADJTIME, NULL, NULL, NULL)) != 0)
271 1.2 christos return error;
272 1.2 christos
273 1.2 christos if (SCARG(uap, delta)) {
274 1.2 christos error = copyin(SCARG(uap, delta), &delta50,
275 1.2 christos sizeof(*SCARG(uap, delta)));
276 1.2 christos if (error)
277 1.2 christos return (error);
278 1.2 christos timeval50_to_timeval(&delta50, &delta);
279 1.2 christos }
280 1.2 christos adjtime1(SCARG(uap, delta) ? &delta : NULL,
281 1.2 christos SCARG(uap, olddelta) ? &olddelta : NULL, l->l_proc);
282 1.2 christos if (SCARG(uap, olddelta)) {
283 1.2 christos timeval_to_timeval50(&olddelta, &olddelta50);
284 1.2 christos error = copyout(&olddelta50, SCARG(uap, olddelta),
285 1.2 christos sizeof(*SCARG(uap, olddelta)));
286 1.2 christos }
287 1.2 christos return error;
288 1.2 christos }
289 1.2 christos
290 1.2 christos /* BSD routine to set/arm an interval timer. */
291 1.2 christos /* ARGSUSED */
292 1.2 christos int
293 1.2 christos compat_50_sys_getitimer(struct lwp *l,
294 1.2 christos const struct compat_50_sys_getitimer_args *uap, register_t *retval)
295 1.2 christos {
296 1.2 christos /* {
297 1.2 christos syscallarg(int) which;
298 1.2 christos syscallarg(struct itimerval50 *) itv;
299 1.2 christos } */
300 1.2 christos struct proc *p = l->l_proc;
301 1.2 christos struct itimerval aitv;
302 1.2 christos struct itimerval50 aitv50;
303 1.2 christos int error;
304 1.2 christos
305 1.2 christos error = dogetitimer(p, SCARG(uap, which), &aitv);
306 1.2 christos if (error)
307 1.2 christos return error;
308 1.2 christos itimerval_to_itimerval50(&aitv, &aitv50);
309 1.2 christos return copyout(&aitv50, SCARG(uap, itv), sizeof(*SCARG(uap, itv)));
310 1.2 christos }
311 1.2 christos
312 1.2 christos int
313 1.2 christos compat_50_sys_setitimer(struct lwp *l,
314 1.2 christos const struct compat_50_sys_setitimer_args *uap, register_t *retval)
315 1.2 christos {
316 1.2 christos /* {
317 1.2 christos syscallarg(int) which;
318 1.2 christos syscallarg(const struct itimerval50 *) itv;
319 1.2 christos syscallarg(struct itimerval50 *) oitv;
320 1.2 christos } */
321 1.2 christos struct proc *p = l->l_proc;
322 1.2 christos int which = SCARG(uap, which);
323 1.2 christos struct compat_50_sys_getitimer_args getargs;
324 1.2 christos const struct itimerval50 *itvp;
325 1.2 christos struct itimerval50 aitv50;
326 1.2 christos struct itimerval aitv;
327 1.2 christos int error;
328 1.2 christos
329 1.2 christos if ((u_int)which > ITIMER_PROF)
330 1.2 christos return (EINVAL);
331 1.2 christos itvp = SCARG(uap, itv);
332 1.2 christos if (itvp &&
333 1.31 christos (error = copyin(itvp, &aitv50, sizeof(aitv50))) != 0)
334 1.2 christos return (error);
335 1.2 christos itimerval50_to_itimerval(&aitv50, &aitv);
336 1.2 christos if (SCARG(uap, oitv) != NULL) {
337 1.2 christos SCARG(&getargs, which) = which;
338 1.2 christos SCARG(&getargs, itv) = SCARG(uap, oitv);
339 1.2 christos if ((error = compat_50_sys_getitimer(l, &getargs, retval)) != 0)
340 1.2 christos return (error);
341 1.2 christos }
342 1.2 christos if (itvp == 0)
343 1.2 christos return (0);
344 1.2 christos
345 1.2 christos return dosetitimer(p, which, &aitv);
346 1.2 christos }
347 1.2 christos
348 1.2 christos int
349 1.2 christos compat_50_sys_aio_suspend(struct lwp *l,
350 1.2 christos const struct compat_50_sys_aio_suspend_args *uap, register_t *retval)
351 1.2 christos {
352 1.2 christos /* {
353 1.2 christos syscallarg(const struct aiocb *const[]) list;
354 1.2 christos syscallarg(int) nent;
355 1.2 christos syscallarg(const struct timespec50 *) timeout;
356 1.2 christos } */
357 1.8 rmind #ifdef AIO
358 1.2 christos struct aiocb **list;
359 1.2 christos struct timespec ts;
360 1.2 christos struct timespec50 ts50;
361 1.2 christos int error, nent;
362 1.2 christos
363 1.2 christos nent = SCARG(uap, nent);
364 1.2 christos if (nent <= 0 || nent > aio_listio_max)
365 1.2 christos return EAGAIN;
366 1.2 christos
367 1.2 christos if (SCARG(uap, timeout)) {
368 1.2 christos /* Convert timespec to ticks */
369 1.2 christos error = copyin(SCARG(uap, timeout), &ts50,
370 1.2 christos sizeof(*SCARG(uap, timeout)));
371 1.2 christos if (error)
372 1.2 christos return error;
373 1.2 christos timespec50_to_timespec(&ts50, &ts);
374 1.2 christos }
375 1.10 yamt list = kmem_alloc(nent * sizeof(*list), KM_SLEEP);
376 1.10 yamt error = copyin(SCARG(uap, list), list, nent * sizeof(*list));
377 1.2 christos if (error)
378 1.2 christos goto out;
379 1.2 christos error = aio_suspend1(l, list, nent, SCARG(uap, timeout) ? &ts : NULL);
380 1.2 christos out:
381 1.10 yamt kmem_free(list, nent * sizeof(*list));
382 1.2 christos return error;
383 1.2 christos #else
384 1.2 christos return ENOSYS;
385 1.2 christos #endif
386 1.2 christos }
387 1.2 christos
388 1.2 christos int
389 1.2 christos compat_50_sys_mq_timedsend(struct lwp *l,
390 1.2 christos const struct compat_50_sys_mq_timedsend_args *uap, register_t *retval)
391 1.2 christos {
392 1.2 christos /* {
393 1.2 christos syscallarg(mqd_t) mqdes;
394 1.2 christos syscallarg(const char *) msg_ptr;
395 1.2 christos syscallarg(size_t) msg_len;
396 1.2 christos syscallarg(unsigned) msg_prio;
397 1.2 christos syscallarg(const struct timespec50 *) abs_timeout;
398 1.2 christos } */
399 1.8 rmind #ifdef MQUEUE
400 1.9 rmind struct timespec50 ts50;
401 1.9 rmind struct timespec ts, *tsp;
402 1.2 christos int error;
403 1.2 christos
404 1.2 christos /* Get and convert time value */
405 1.2 christos if (SCARG(uap, abs_timeout)) {
406 1.2 christos error = copyin(SCARG(uap, abs_timeout), &ts50, sizeof(ts50));
407 1.2 christos if (error)
408 1.2 christos return error;
409 1.2 christos timespec50_to_timespec(&ts50, &ts);
410 1.9 rmind tsp = &ts;
411 1.9 rmind } else {
412 1.9 rmind tsp = NULL;
413 1.9 rmind }
414 1.2 christos
415 1.9 rmind return mq_send1(SCARG(uap, mqdes), SCARG(uap, msg_ptr),
416 1.9 rmind SCARG(uap, msg_len), SCARG(uap, msg_prio), tsp);
417 1.8 rmind #else
418 1.8 rmind return ENOSYS;
419 1.8 rmind #endif
420 1.2 christos }
421 1.2 christos
422 1.2 christos int
423 1.2 christos compat_50_sys_mq_timedreceive(struct lwp *l,
424 1.2 christos const struct compat_50_sys_mq_timedreceive_args *uap, register_t *retval)
425 1.2 christos {
426 1.2 christos /* {
427 1.2 christos syscallarg(mqd_t) mqdes;
428 1.2 christos syscallarg(char *) msg_ptr;
429 1.2 christos syscallarg(size_t) msg_len;
430 1.2 christos syscallarg(unsigned *) msg_prio;
431 1.2 christos syscallarg(const struct timespec50 *) abs_timeout;
432 1.2 christos } */
433 1.8 rmind #ifdef MQUEUE
434 1.9 rmind struct timespec ts, *tsp;
435 1.9 rmind struct timespec50 ts50;
436 1.2 christos ssize_t mlen;
437 1.9 rmind int error;
438 1.2 christos
439 1.2 christos /* Get and convert time value */
440 1.2 christos if (SCARG(uap, abs_timeout)) {
441 1.2 christos error = copyin(SCARG(uap, abs_timeout), &ts50, sizeof(ts50));
442 1.2 christos if (error)
443 1.2 christos return error;
444 1.2 christos
445 1.2 christos timespec50_to_timespec(&ts50, &ts);
446 1.9 rmind tsp = &ts;
447 1.9 rmind } else {
448 1.9 rmind tsp = NULL;
449 1.9 rmind }
450 1.2 christos
451 1.9 rmind error = mq_recv1(SCARG(uap, mqdes), SCARG(uap, msg_ptr),
452 1.9 rmind SCARG(uap, msg_len), SCARG(uap, msg_prio), tsp, &mlen);
453 1.2 christos if (error == 0)
454 1.2 christos *retval = mlen;
455 1.2 christos
456 1.2 christos return error;
457 1.8 rmind #else
458 1.8 rmind return ENOSYS;
459 1.8 rmind #endif
460 1.2 christos }
461 1.2 christos
462 1.4 njoly void
463 1.2 christos rusage_to_rusage50(const struct rusage *ru, struct rusage50 *ru50)
464 1.2 christos {
465 1.2 christos (void)memcpy(&ru50->ru_first, &ru->ru_first,
466 1.3 njoly (char *)&ru50->ru_last - (char *)&ru50->ru_first +
467 1.3 njoly sizeof(ru50->ru_last));
468 1.2 christos ru50->ru_maxrss = ru->ru_maxrss;
469 1.2 christos timeval_to_timeval50(&ru->ru_utime, &ru50->ru_utime);
470 1.2 christos timeval_to_timeval50(&ru->ru_stime, &ru50->ru_stime);
471 1.2 christos }
472 1.2 christos
473 1.2 christos int
474 1.2 christos compat_50_sys_getrusage(struct lwp *l,
475 1.2 christos const struct compat_50_sys_getrusage_args *uap, register_t *retval)
476 1.2 christos {
477 1.2 christos /* {
478 1.2 christos syscallarg(int) who;
479 1.2 christos syscallarg(struct rusage50 *) rusage;
480 1.2 christos } */
481 1.24 njoly int error;
482 1.2 christos struct rusage ru;
483 1.2 christos struct rusage50 ru50;
484 1.2 christos struct proc *p = l->l_proc;
485 1.2 christos
486 1.24 njoly error = getrusage1(p, SCARG(uap, who), &ru);
487 1.24 njoly if (error != 0)
488 1.24 njoly return error;
489 1.2 christos
490 1.2 christos rusage_to_rusage50(&ru, &ru50);
491 1.2 christos return copyout(&ru50, SCARG(uap, rusage), sizeof(ru50));
492 1.2 christos }
493 1.2 christos
494 1.2 christos
495 1.2 christos /* Return the time remaining until a POSIX timer fires. */
496 1.2 christos int
497 1.2 christos compat_50_sys_timer_gettime(struct lwp *l,
498 1.2 christos const struct compat_50_sys_timer_gettime_args *uap, register_t *retval)
499 1.2 christos {
500 1.2 christos /* {
501 1.2 christos syscallarg(timer_t) timerid;
502 1.2 christos syscallarg(struct itimerspec50 *) value;
503 1.2 christos } */
504 1.2 christos struct itimerspec its;
505 1.2 christos struct itimerspec50 its50;
506 1.2 christos int error;
507 1.2 christos
508 1.2 christos if ((error = dotimer_gettime(SCARG(uap, timerid), l->l_proc,
509 1.2 christos &its)) != 0)
510 1.2 christos return error;
511 1.2 christos itimerspec_to_itimerspec50(&its, &its50);
512 1.2 christos
513 1.2 christos return copyout(&its50, SCARG(uap, value), sizeof(its50));
514 1.2 christos }
515 1.2 christos
516 1.2 christos /* Set and arm a POSIX realtime timer */
517 1.2 christos int
518 1.2 christos compat_50_sys_timer_settime(struct lwp *l,
519 1.2 christos const struct compat_50_sys_timer_settime_args *uap, register_t *retval)
520 1.2 christos {
521 1.2 christos /* {
522 1.2 christos syscallarg(timer_t) timerid;
523 1.2 christos syscallarg(int) flags;
524 1.2 christos syscallarg(const struct itimerspec50 *) value;
525 1.2 christos syscallarg(struct itimerspec50 *) ovalue;
526 1.2 christos } */
527 1.2 christos int error;
528 1.2 christos struct itimerspec value, ovalue, *ovp = NULL;
529 1.2 christos struct itimerspec50 value50, ovalue50;
530 1.2 christos
531 1.2 christos if ((error = copyin(SCARG(uap, value), &value50, sizeof(value50))) != 0)
532 1.2 christos return error;
533 1.2 christos
534 1.2 christos itimerspec50_to_itimerspec(&value50, &value);
535 1.2 christos if (SCARG(uap, ovalue))
536 1.2 christos ovp = &ovalue;
537 1.2 christos
538 1.2 christos if ((error = dotimer_settime(SCARG(uap, timerid), &value, ovp,
539 1.2 christos SCARG(uap, flags), l->l_proc)) != 0)
540 1.2 christos return error;
541 1.2 christos
542 1.2 christos if (ovp) {
543 1.2 christos itimerspec_to_itimerspec50(&ovalue, &ovalue50);
544 1.2 christos return copyout(&ovalue50, SCARG(uap, ovalue), sizeof(ovalue50));
545 1.2 christos }
546 1.2 christos return 0;
547 1.2 christos }
548 1.2 christos
549 1.2 christos /*
550 1.2 christos * ntp_gettime() - NTP user application interface
551 1.2 christos */
552 1.2 christos int
553 1.2 christos compat_50_sys___ntp_gettime30(struct lwp *l,
554 1.2 christos const struct compat_50_sys___ntp_gettime30_args *uap, register_t *retval)
555 1.2 christos {
556 1.33 pgoyette if (vec_ntp_gettime == NULL)
557 1.33 pgoyette return ENOSYS; /* No NTP available in kernel */
558 1.33 pgoyette
559 1.2 christos /* {
560 1.2 christos syscallarg(struct ntptimeval *) ntvp;
561 1.2 christos } */
562 1.2 christos struct ntptimeval ntv;
563 1.2 christos struct ntptimeval50 ntv50;
564 1.2 christos int error;
565 1.2 christos
566 1.2 christos if (SCARG(uap, ntvp)) {
567 1.33 pgoyette (*vec_ntp_gettime)(&ntv);
568 1.32 riastrad memset(&ntv50, 0, sizeof(ntv50));
569 1.2 christos timespec_to_timespec50(&ntv.time, &ntv50.time);
570 1.2 christos ntv50.maxerror = ntv.maxerror;
571 1.2 christos ntv50.esterror = ntv.esterror;
572 1.2 christos ntv50.tai = ntv.tai;
573 1.2 christos ntv50.time_state = ntv.time_state;
574 1.2 christos
575 1.2 christos error = copyout(&ntv50, SCARG(uap, ntvp), sizeof(ntv50));
576 1.2 christos if (error)
577 1.2 christos return error;
578 1.2 christos }
579 1.33 pgoyette *retval = (*vec_ntp_timestatus)();
580 1.2 christos return 0;
581 1.2 christos }
582 1.25 pgoyette
583 1.33 pgoyette static void
584 1.25 pgoyette compat_sysctl_time(struct sysctllog **clog)
585 1.25 pgoyette {
586 1.25 pgoyette struct timeval tv;
587 1.25 pgoyette
588 1.25 pgoyette TIMESPEC_TO_TIMEVAL(&tv, &boottime);
589 1.25 pgoyette timeval_to_timeval50(&tv, &boottime50);
590 1.25 pgoyette
591 1.25 pgoyette sysctl_createv(clog, 0, NULL, NULL,
592 1.25 pgoyette CTLFLAG_PERMANENT,
593 1.25 pgoyette CTLTYPE_STRUCT, "oboottime",
594 1.25 pgoyette SYSCTL_DESCR("System boot time"),
595 1.25 pgoyette NULL, 0, &boottime50, sizeof(boottime50),
596 1.25 pgoyette CTL_KERN, KERN_OBOOTTIME, CTL_EOL);
597 1.25 pgoyette }
598 1.33 pgoyette
599 1.33 pgoyette int
600 1.33 pgoyette kern_time_50_init(void)
601 1.33 pgoyette {
602 1.33 pgoyette int error;
603 1.33 pgoyette
604 1.33 pgoyette compat_sysctl_time(&kern_time_50_clog);
605 1.33 pgoyette
606 1.33 pgoyette error = syscall_establish(NULL, kern_time_50_syscalls);
607 1.33 pgoyette if (error != 0)
608 1.33 pgoyette sysctl_teardown(&kern_time_50_clog);
609 1.33 pgoyette
610 1.33 pgoyette return error;
611 1.33 pgoyette }
612 1.33 pgoyette
613 1.33 pgoyette int
614 1.33 pgoyette kern_time_50_fini(void)
615 1.33 pgoyette {
616 1.33 pgoyette int error;
617 1.33 pgoyette
618 1.33 pgoyette error = syscall_disestablish(NULL, kern_time_50_syscalls);
619 1.33 pgoyette if (error == 0)
620 1.33 pgoyette sysctl_teardown(&kern_time_50_clog);
621 1.33 pgoyette
622 1.33 pgoyette return error;
623 1.33 pgoyette }
624