1 /* $NetBSD: kern_time_60.c,v 1.3 2020/01/29 15:47:51 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2013, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
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 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: kern_time_60.c,v 1.3 2020/01/29 15:47:51 ad Exp $");
33
34 #if defined(_KERNEL_OPT)
35 #include "opt_compat_netbsd.h"
36 #endif
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/lwp.h>
41 #include <sys/time.h>
42 #include <sys/syscall.h>
43 #include <sys/syscallvar.h>
44 #include <sys/syscallargs.h>
45
46 #include <compat/common/compat_util.h>
47 #include <compat/common/compat_mod.h>
48
49 static const struct syscall_package compat_60_syscalls[] = {
50 { SYS_compat_60__lwp_park, 0, (sy_call_t *)compat_60_sys__lwp_park },
51 { 0, 0, NULL }
52 };
53
54 int
compat_60_sys__lwp_park(struct lwp * l,const struct compat_60_sys__lwp_park_args * uap,register_t * retval)55 compat_60_sys__lwp_park(struct lwp *l,
56 const struct compat_60_sys__lwp_park_args *uap, register_t *retval)
57 {
58 /* {
59 syscallarg(const struct timespec *) ts;
60 syscallarg(lwpid_t) unpark;
61 syscallarg(const void *) hint;
62 syscallarg(const void *) unparkhint;
63 } */
64
65 int error;
66 struct timespec ts, *tsp;
67
68 if (SCARG(uap, ts) == NULL)
69 tsp = NULL;
70 else {
71 error = copyin(SCARG(uap, ts), &ts, sizeof(ts));
72 if (error != 0)
73 return error;
74 tsp = &ts;
75 }
76
77 if (SCARG(uap, unpark) != 0) {
78 error = lwp_unpark(&SCARG(uap, unpark), 1);
79 if (error != 0)
80 return error;
81 }
82
83 return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp);
84 }
85
86 int
kern_time_60_init(void)87 kern_time_60_init(void)
88 {
89
90 return syscall_establish(NULL, compat_60_syscalls);
91 }
92
93 int
kern_time_60_fini(void)94 kern_time_60_fini(void)
95 {
96
97 return syscall_disestablish(NULL, compat_60_syscalls);
98 }
99