1*d1c42b4fSad /* $NetBSD: kern_time_60.c,v 1.3 2020/01/29 15:47:51 ad Exp $ */
2ab470567Schristos
3ab470567Schristos /*-
4*d1c42b4fSad * Copyright (c) 2013, 2020 The NetBSD Foundation, Inc.
5ab470567Schristos * All rights reserved.
6ab470567Schristos *
7ab470567Schristos * This code is derived from software contributed to The NetBSD Foundation
8ab470567Schristos * by Christos Zoulas.
9ab470567Schristos *
10ab470567Schristos * Redistribution and use in source and binary forms, with or without
11ab470567Schristos * modification, are permitted provided that the following conditions
12ab470567Schristos * are met:
13ab470567Schristos * 1. Redistributions of source code must retain the above copyright
14ab470567Schristos * notice, this list of conditions and the following disclaimer.
15ab470567Schristos * 2. Redistributions in binary form must reproduce the above copyright
16ab470567Schristos * notice, this list of conditions and the following disclaimer in the
17ab470567Schristos * documentation and/or other materials provided with the distribution.
18ab470567Schristos *
19ab470567Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ab470567Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ab470567Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ab470567Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ab470567Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ab470567Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ab470567Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ab470567Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ab470567Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ab470567Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ab470567Schristos * POSSIBILITY OF SUCH DAMAGE.
30ab470567Schristos */
31ab470567Schristos #include <sys/cdefs.h>
32*d1c42b4fSad __KERNEL_RCSID(0, "$NetBSD: kern_time_60.c,v 1.3 2020/01/29 15:47:51 ad Exp $");
33d91f98a8Spgoyette
34d91f98a8Spgoyette #if defined(_KERNEL_OPT)
35d91f98a8Spgoyette #include "opt_compat_netbsd.h"
36d91f98a8Spgoyette #endif
37ab470567Schristos
38ab470567Schristos #include <sys/param.h>
39ab470567Schristos #include <sys/systm.h>
40ab470567Schristos #include <sys/lwp.h>
41ab470567Schristos #include <sys/time.h>
42d91f98a8Spgoyette #include <sys/syscall.h>
43d91f98a8Spgoyette #include <sys/syscallvar.h>
44ab470567Schristos #include <sys/syscallargs.h>
45ab470567Schristos
46ab470567Schristos #include <compat/common/compat_util.h>
47ab470567Schristos #include <compat/common/compat_mod.h>
48ab470567Schristos
49d91f98a8Spgoyette static const struct syscall_package compat_60_syscalls[] = {
50d91f98a8Spgoyette { SYS_compat_60__lwp_park, 0, (sy_call_t *)compat_60_sys__lwp_park },
51d91f98a8Spgoyette { 0, 0, NULL }
52d91f98a8Spgoyette };
53d91f98a8Spgoyette
54ab470567Schristos int
compat_60_sys__lwp_park(struct lwp * l,const struct compat_60_sys__lwp_park_args * uap,register_t * retval)55ab470567Schristos compat_60_sys__lwp_park(struct lwp *l,
56ab470567Schristos const struct compat_60_sys__lwp_park_args *uap, register_t *retval)
57ab470567Schristos {
58ab470567Schristos /* {
59ab470567Schristos syscallarg(const struct timespec *) ts;
60ab470567Schristos syscallarg(lwpid_t) unpark;
61ab470567Schristos syscallarg(const void *) hint;
62ab470567Schristos syscallarg(const void *) unparkhint;
63ab470567Schristos } */
64ab470567Schristos
65ab470567Schristos int error;
66ab470567Schristos struct timespec ts, *tsp;
67ab470567Schristos
68ab470567Schristos if (SCARG(uap, ts) == NULL)
69ab470567Schristos tsp = NULL;
70ab470567Schristos else {
71ab470567Schristos error = copyin(SCARG(uap, ts), &ts, sizeof(ts));
72ab470567Schristos if (error != 0)
73ab470567Schristos return error;
74ab470567Schristos tsp = &ts;
75ab470567Schristos }
76ab470567Schristos
77ab470567Schristos if (SCARG(uap, unpark) != 0) {
78*d1c42b4fSad error = lwp_unpark(&SCARG(uap, unpark), 1);
79ab470567Schristos if (error != 0)
80ab470567Schristos return error;
81ab470567Schristos }
82ab470567Schristos
83*d1c42b4fSad return lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, tsp);
84ab470567Schristos }
85d91f98a8Spgoyette
86d91f98a8Spgoyette int
kern_time_60_init(void)87d91f98a8Spgoyette kern_time_60_init(void)
88d91f98a8Spgoyette {
89d91f98a8Spgoyette
90d91f98a8Spgoyette return syscall_establish(NULL, compat_60_syscalls);
91d91f98a8Spgoyette }
92d91f98a8Spgoyette
93d91f98a8Spgoyette int
kern_time_60_fini(void)94d91f98a8Spgoyette kern_time_60_fini(void)
95d91f98a8Spgoyette {
96d91f98a8Spgoyette
97d91f98a8Spgoyette return syscall_disestablish(NULL, compat_60_syscalls);
98d91f98a8Spgoyette }
99