Implement most of timer_{create,settime,gettime,getoverrun,delete}
for amd64/linux32. Fix the entirely bogus (untested) version from r161310 for i386/linux using the same shared code in compat/linux. It is unclear to me if we could support more clock mappings but the current set allows me to successfully run commercial 32bit linux software under linuxolator on amd64. Reviewed by: jhb Differential Revision: D784 MFC after: 3 days Sponsored by: DARPA, AFRL
This commit is contained in:
parent
5d99eb5926
commit
0a041f3b47
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=271743
@ -61,6 +61,11 @@ MALLOC_DECLARE(M_LINUX);
|
||||
#define PTRIN(v) (void *)(uintptr_t)(v)
|
||||
#define PTROUT(v) (l_uintptr_t)(uintptr_t)(v)
|
||||
|
||||
#define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
|
||||
#define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
|
||||
#define PTRIN_CP(src,dst,fld) \
|
||||
do { (dst).fld = PTRIN((src).fld); } while (0)
|
||||
|
||||
/*
|
||||
* Provide a separate set of types for the Linux types.
|
||||
*/
|
||||
|
@ -73,11 +73,6 @@ DUMMY(epoll_create);
|
||||
DUMMY(epoll_ctl);
|
||||
DUMMY(epoll_wait);
|
||||
DUMMY(remap_file_pages);
|
||||
DUMMY(timer_create);
|
||||
DUMMY(timer_settime);
|
||||
DUMMY(timer_gettime);
|
||||
DUMMY(timer_getoverrun);
|
||||
DUMMY(timer_delete);
|
||||
DUMMY(fstatfs64);
|
||||
DUMMY(mbind);
|
||||
DUMMY(get_mempolicy);
|
||||
|
@ -435,11 +435,13 @@
|
||||
256 AUE_NULL STD { int linux_epoll_wait(void); }
|
||||
257 AUE_NULL STD { int linux_remap_file_pages(void); }
|
||||
258 AUE_NULL STD { int linux_set_tid_address(int *tidptr); }
|
||||
259 AUE_NULL STD { int linux_timer_create(void); }
|
||||
260 AUE_NULL STD { int linux_timer_settime(void); }
|
||||
261 AUE_NULL STD { int linux_timer_gettime(void); }
|
||||
262 AUE_NULL STD { int linux_timer_getoverrun(void); }
|
||||
263 AUE_NULL STD { int linux_timer_delete(void); }
|
||||
259 AUE_NULL STD { int linux_timer_create(clockid_t clock_id, \
|
||||
struct sigevent *evp, l_timer_t *timerid); }
|
||||
260 AUE_NULL STD { int linux_timer_settime(l_timer_t timerid, l_int flags, \
|
||||
const struct itimerspec *new, struct itimerspec *old); }
|
||||
261 AUE_NULL STD { int linux_timer_gettime(l_timer_t timerid, struct itimerspec *setting); }
|
||||
262 AUE_NULL STD { int linux_timer_getoverrun(l_timer_t timerid); }
|
||||
263 AUE_NULL STD { int linux_timer_delete(l_timer_t timerid); }
|
||||
264 AUE_CLOCK_SETTIME STD { int linux_clock_settime(clockid_t which, struct l_timespec *tp); }
|
||||
265 AUE_NULL STD { int linux_clock_gettime(clockid_t which, struct l_timespec *tp); }
|
||||
266 AUE_NULL STD { int linux_clock_getres(clockid_t which, struct l_timespec *tp); }
|
||||
|
182
sys/compat/linux/linux_timer.c
Normal file
182
sys/compat/linux/linux_timer.c
Normal file
@ -0,0 +1,182 @@
|
||||
/*-
|
||||
* Copyright (c) 2014 Bjoern A. Zeeb
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by SRI International and the University of
|
||||
* Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249
|
||||
* ("MRC2"), as part of the DARPA MRC research programme.
|
||||
*
|
||||
* 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 AUTHOR 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 AUTHOR 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.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_compat.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/syscallsubr.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef COMPAT_LINUX32
|
||||
#include <machine/../linux32/linux.h>
|
||||
#include <machine/../linux32/linux32_proto.h>
|
||||
#else
|
||||
#include <machine/../linux/linux.h>
|
||||
#include <machine/../linux/linux_proto.h>
|
||||
#endif
|
||||
#include <compat/linux/linux_timer.h>
|
||||
|
||||
static int
|
||||
linux_convert_l_clockid(clockid_t *clock_id)
|
||||
{
|
||||
|
||||
switch (*clock_id) {
|
||||
case LINUX_CLOCK_REALTIME:
|
||||
*clock_id = CLOCK_REALTIME;
|
||||
break;
|
||||
case LINUX_CLOCK_MONOTONIC:
|
||||
*clock_id = CLOCK_MONOTONIC;
|
||||
break;
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
linux_convert_l_sigevent(struct l_sigevent *l_sig, struct sigevent *sig)
|
||||
{
|
||||
|
||||
CP(*l_sig, *sig, sigev_notify);
|
||||
switch (l_sig->sigev_notify) {
|
||||
case L_SIGEV_SIGNAL:
|
||||
sig->sigev_notify = SIGEV_SIGNAL;
|
||||
CP(*l_sig, *sig, sigev_signo);
|
||||
PTRIN_CP(*l_sig, *sig, sigev_value.sival_ptr);
|
||||
break;
|
||||
case L_SIGEV_NONE:
|
||||
sig->sigev_notify = SIGEV_NONE;
|
||||
break;
|
||||
case L_SIGEV_THREAD:
|
||||
#if 0
|
||||
/* Seems to not be used anywhere (anymore)? */
|
||||
sig->sigev_notify = SIGEV_THREAD;
|
||||
return (ENOSYS);
|
||||
#else
|
||||
return (EINVAL);
|
||||
#endif
|
||||
case L_SIGEV_THREAD_ID:
|
||||
sig->sigev_notify = SIGEV_THREAD_ID;
|
||||
CP2(*l_sig, *sig, _l_sigev_un._tid, sigev_notify_thread_id);
|
||||
CP(*l_sig, *sig, sigev_signo);
|
||||
PTRIN_CP(*l_sig, *sig, sigev_value.sival_ptr);
|
||||
break;
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_create(struct thread *td, struct linux_timer_create_args *uap)
|
||||
{
|
||||
struct l_sigevent l_ev;
|
||||
struct sigevent ev, *evp;
|
||||
int error, id;
|
||||
|
||||
if (uap->evp == NULL) {
|
||||
evp = NULL;
|
||||
} else {
|
||||
error = copyin(uap->evp, &l_ev, sizeof(l_ev));
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = linux_convert_l_sigevent(&l_ev, &ev);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
evp = &ev;
|
||||
}
|
||||
error = linux_convert_l_clockid(&uap->clock_id);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
|
||||
if (error == 0) {
|
||||
error = copyout(&id, uap->timerid, sizeof(int));
|
||||
if (error != 0)
|
||||
kern_ktimer_delete(td, id);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_settime(struct thread *td, struct linux_timer_settime_args *uap)
|
||||
{
|
||||
struct l_itimerspec l_val, l_oval;
|
||||
struct itimerspec val, oval, *ovalp;
|
||||
int error;
|
||||
|
||||
error = copyin(uap->new, &l_val, sizeof(l_val));
|
||||
if (error != 0)
|
||||
return (error);
|
||||
ITS_CP(l_val, val);
|
||||
ovalp = uap->old != NULL ? &oval : NULL;
|
||||
error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
|
||||
if (error == 0 && uap->old != NULL) {
|
||||
ITS_CP(oval, l_oval);
|
||||
error = copyout(&l_oval, uap->old, sizeof(l_oval));
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_gettime(struct thread *td, struct linux_timer_gettime_args *uap)
|
||||
{
|
||||
struct l_itimerspec l_val;
|
||||
struct itimerspec val;
|
||||
int error;
|
||||
|
||||
error = kern_ktimer_gettime(td, uap->timerid, &val);
|
||||
if (error == 0) {
|
||||
ITS_CP(val, l_val);
|
||||
error = copyout(&l_val, uap->setting, sizeof(l_val));
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_getoverrun(struct thread *td, struct linux_timer_getoverrun_args *uap)
|
||||
{
|
||||
|
||||
return (kern_ktimer_getoverrun(td, uap->timerid));
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_delete(struct thread *td, struct linux_timer_delete_args *uap)
|
||||
{
|
||||
|
||||
return (kern_ktimer_delete(td, uap->timerid));
|
||||
}
|
||||
|
97
sys/compat/linux/linux_timer.h
Normal file
97
sys/compat/linux/linux_timer.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*-
|
||||
* Copyright (c) 2014 Bjoern A. Zeeb
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by SRI International and the University of
|
||||
* Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249
|
||||
* ("MRC2"), as part of the DARPA MRC research programme.
|
||||
*
|
||||
* 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 AUTHOR 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 AUTHOR 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$
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_TIMER_H
|
||||
#define _LINUX_TIMER_H
|
||||
|
||||
#ifndef __LINUX_ARCH_SIGEV_PREAMBLE_SIZE
|
||||
#define __LINUX_ARCH_SIGEV_PREAMBLE_SIZE \
|
||||
(sizeof(l_int) * 2 + sizeof(l_sigval_t))
|
||||
#endif
|
||||
|
||||
#define LINUX_SIGEV_MAX_SIZE 64
|
||||
#define LINUX_SIGEV_PAD_SIZE \
|
||||
((LINUX_SIGEV_MAX_SIZE - __LINUX_ARCH_SIGEV_PREAMBLE_SIZE) / \
|
||||
sizeof(l_int))
|
||||
|
||||
#define LINUX_CLOCK_REALTIME 0
|
||||
#define LINUX_CLOCK_MONOTONIC 1
|
||||
#define LINUX_CLOCK_PROCESS_CPUTIME_ID 2
|
||||
#define LINUX_CLOCK_THREAD_CPUTIME_ID 3
|
||||
#define LINUX_CLOCK_MONOTONIC_RAW 4
|
||||
#define LINUX_CLOCK_REALTIME_COARSE 5
|
||||
#define LINUX_CLOCK_MONOTONIC_COARSE 6
|
||||
#define LINUX_CLOCK_BOOTTIME 7
|
||||
#define LINUX_CLOCK_REALTIME_ALARM 8
|
||||
#define LINUX_CLOCK_BOOTTIME_ALARM 9
|
||||
#define LINUX_CLOCK_SGI_CYCLE 10
|
||||
#define LINUX_CLOCK_TAI 11
|
||||
|
||||
#define L_SIGEV_SIGNAL 0
|
||||
#define L_SIGEV_NONE 1
|
||||
#define L_SIGEV_THREAD 2
|
||||
#define L_SIGEV_THREAD_ID 4
|
||||
|
||||
#define TS_CP(src,dst,fld) do { \
|
||||
CP((src).fld,(dst).fld,tv_sec); \
|
||||
CP((src).fld,(dst).fld,tv_nsec); \
|
||||
} while (0)
|
||||
|
||||
#define ITS_CP(src, dst) do { \
|
||||
TS_CP((src), (dst), it_interval); \
|
||||
TS_CP((src), (dst), it_value); \
|
||||
} while (0)
|
||||
|
||||
struct l_sigevent {
|
||||
l_sigval_t sigev_value;
|
||||
l_int sigev_signo;
|
||||
l_int sigev_notify;
|
||||
union {
|
||||
l_int _pad[LINUX_SIGEV_PAD_SIZE];
|
||||
l_int _tid;
|
||||
struct {
|
||||
l_uintptr_t _function;
|
||||
l_uintptr_t _attribute;
|
||||
} _l_sigev_thread;
|
||||
} _l_sigev_un;
|
||||
}
|
||||
#if defined(__amd64__) && defined(COMPAT_LINUX32)
|
||||
__packed
|
||||
#endif
|
||||
;
|
||||
|
||||
struct l_itimerspec {
|
||||
struct l_timespec it_interval;
|
||||
struct l_timespec it_value;
|
||||
};
|
||||
|
||||
#endif /* _LINUX_TIMER_H */
|
@ -477,6 +477,7 @@ compat/linux/linux_socket.c optional compat_linux32
|
||||
compat/linux/linux_stats.c optional compat_linux32
|
||||
compat/linux/linux_sysctl.c optional compat_linux32
|
||||
compat/linux/linux_time.c optional compat_linux32
|
||||
compat/linux/linux_timer.c optional compat_linux32
|
||||
compat/linux/linux_uid16.c optional compat_linux32
|
||||
compat/linux/linux_util.c optional compat_linux32
|
||||
dev/amr/amr_linux.c optional compat_linux32 amr
|
||||
|
@ -83,6 +83,7 @@ compat/linux/linux_socket.c optional compat_linux
|
||||
compat/linux/linux_stats.c optional compat_linux
|
||||
compat/linux/linux_sysctl.c optional compat_linux
|
||||
compat/linux/linux_time.c optional compat_linux
|
||||
compat/linux/linux_timer.c optional compat_linux
|
||||
compat/linux/linux_uid16.c optional compat_linux
|
||||
compat/linux/linux_util.c optional compat_linux
|
||||
compat/ndis/kern_ndis.c optional ndisapi pci
|
||||
|
@ -55,6 +55,7 @@ compat/linux/linux_socket.c optional compat_linux
|
||||
compat/linux/linux_stats.c optional compat_linux
|
||||
compat/linux/linux_sysctl.c optional compat_linux
|
||||
compat/linux/linux_time.c optional compat_linux
|
||||
compat/linux/linux_timer.c optional compat_linux
|
||||
compat/linux/linux_uid16.c optional compat_linux
|
||||
compat/linux/linux_util.c optional compat_linux
|
||||
compat/svr4/imgact_svr4.c optional compat_svr4
|
||||
|
@ -54,6 +54,11 @@ MALLOC_DECLARE(M_LINUX);
|
||||
#define PTRIN(v) (void *)(v)
|
||||
#define PTROUT(v) (l_uintptr_t)(v)
|
||||
|
||||
#define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
|
||||
#define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
|
||||
#define PTRIN_CP(src,dst,fld) \
|
||||
do { (dst).fld = PTRIN((src).fld); } while (0)
|
||||
|
||||
/*
|
||||
* Provide a separate set of types for the Linux types.
|
||||
*/
|
||||
|
@ -980,37 +980,6 @@ linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* copied from kern/kern_time.c */
|
||||
int
|
||||
linux_timer_create(struct thread *td, struct linux_timer_create_args *args)
|
||||
{
|
||||
return sys_ktimer_create(td, (struct ktimer_create_args *) args);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_settime(struct thread *td, struct linux_timer_settime_args *args)
|
||||
{
|
||||
return sys_ktimer_settime(td, (struct ktimer_settime_args *) args);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_gettime(struct thread *td, struct linux_timer_gettime_args *args)
|
||||
{
|
||||
return sys_ktimer_gettime(td, (struct ktimer_gettime_args *) args);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_getoverrun(struct thread *td, struct linux_timer_getoverrun_args *args)
|
||||
{
|
||||
return sys_ktimer_getoverrun(td, (struct ktimer_getoverrun_args *) args);
|
||||
}
|
||||
|
||||
int
|
||||
linux_timer_delete(struct thread *td, struct linux_timer_delete_args *args)
|
||||
{
|
||||
return sys_ktimer_delete(td, (struct ktimer_delete_args *) args);
|
||||
}
|
||||
|
||||
/* XXX: this wont work with module - convert it */
|
||||
int
|
||||
linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
|
||||
|
@ -439,7 +439,7 @@
|
||||
258 AUE_NULL STD { int linux_set_tid_address(int *tidptr); }
|
||||
259 AUE_NULL STD { int linux_timer_create(clockid_t clock_id, \
|
||||
struct sigevent *evp, l_timer_t *timerid); }
|
||||
260 AUE_NULL STD { int linux_timer_settime(l_timer_t timerid, \
|
||||
260 AUE_NULL STD { int linux_timer_settime(l_timer_t timerid, l_int flags, \
|
||||
const struct itimerspec *new, struct itimerspec *old); }
|
||||
261 AUE_NULL STD { int linux_timer_gettime(l_timer_t timerid, struct itimerspec *setting); }
|
||||
262 AUE_NULL STD { int linux_timer_getoverrun(l_timer_t timerid); }
|
||||
|
@ -13,6 +13,7 @@ SRCS= linux_fork.c linux${SFX}_dummy.c linux_emul.c linux_file.c \
|
||||
linux${SFX}_machdep.c linux_mib.c linux_misc.c linux_signal.c \
|
||||
linux_socket.c linux_stats.c linux_sysctl.c linux${SFX}_sysent.c \
|
||||
linux${SFX}_sysvec.c linux_uid16.c linux_util.c linux_time.c \
|
||||
linux_timer.c \
|
||||
opt_inet6.h opt_compat.h opt_posix.h opt_usb.h vnode_if.h \
|
||||
device_if.h bus_if.h assym.s
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user