/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center; by Matthias Scheler.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* FreeBSD compatibility module. Try to deal with scheduler related syscalls.
*/
int
freebsd_sys_yield(struct lwp *l, const void *v, register_t *retval)
{
yield();
return 0;
}
/*
* XXX: Needs adjustment to do a proper conversion.
*/
static int
sched_freebsd2native(int freebsd_policy,
const struct freebsd_sched_param *freebsd_params, int *native_policy,
struct sched_param *native_params)
{
int p;
switch (freebsd_policy) {
case FREEBSD_SCHED_OTHER:
p = SCHED_OTHER;
break;
case FREEBSD_SCHED_FIFO:
p = SCHED_FIFO;
break;
case FREEBSD_SCHED_RR:
p = SCHED_RR;
break;
default:
return EINVAL;
}
if (native_policy != NULL)
*native_policy = p;
if (freebsd_params != NULL && native_params != NULL) {
/* XXX: Needs adjustment to do a proper conversion. */
native_params->sched_priority = freebsd_params->sched_priority;
}
return 0;
}
static int
sched_native2freebsd(int native_policy, const struct sched_param *native_params,
int *freebsd_policy, struct freebsd_sched_param *freebsd_params)
{
int p;
switch (native_policy) {
case SCHED_OTHER:
p = FREEBSD_SCHED_OTHER;
break;
case SCHED_FIFO:
p = FREEBSD_SCHED_FIFO;
break;
case SCHED_RR:
p = FREEBSD_SCHED_RR;
break;
default:
return EINVAL;
}
if (freebsd_policy != NULL)
*freebsd_policy = p;
if (native_params != NULL && freebsd_params != NULL) {
/* XXX: Needs adjustment to do a proper conversion. */
memset(freebsd_params, 0, sizeof(*freebsd_params));
freebsd_params->sched_priority = native_params->sched_priority;
}
error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
if (error)
goto out;
/* We need the current policy in FreeBSD terms. */
error = do_sched_getparam(SCARG(uap, pid), 0, &policy, NULL);
if (error)
goto out;
error = sched_native2freebsd(policy, NULL, &policy, NULL);
if (error)
goto out;
error = sched_freebsd2native(policy, &lp, &policy, &sp);
if (error)
goto out;