From owner-svn-src-all@FreeBSD.ORG Thu Sep 18 08:36:48 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C28A9CAB; Thu, 18 Sep 2014 08:36:48 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ABF4AF7A; Thu, 18 Sep 2014 08:36:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8I8amh2096924; Thu, 18 Sep 2014 08:36:48 GMT (envelope-from bz@FreeBSD.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8I8akZG096906; Thu, 18 Sep 2014 08:36:46 GMT (envelope-from bz@FreeBSD.org) Message-Id: <201409180836.s8I8akZG096906@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bz set sender to bz@FreeBSD.org using -f From: "Bjoern A. Zeeb" Date: Thu, 18 Sep 2014 08:36:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271743 - in head/sys: amd64/linux32 compat/linux conf i386/linux modules/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Sep 2014 08:36:48 -0000 Author: bz Date: Thu Sep 18 08:36:45 2014 New Revision: 271743 URL: http://svnweb.freebsd.org/changeset/base/271743 Log: 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 Added: head/sys/compat/linux/linux_timer.c (contents, props changed) head/sys/compat/linux/linux_timer.h (contents, props changed) Modified: head/sys/amd64/linux32/linux.h head/sys/amd64/linux32/linux32_dummy.c head/sys/amd64/linux32/syscalls.master head/sys/conf/files.amd64 head/sys/conf/files.i386 head/sys/conf/files.pc98 head/sys/i386/linux/linux.h head/sys/i386/linux/linux_machdep.c head/sys/i386/linux/syscalls.master head/sys/modules/linux/Makefile Modified: head/sys/amd64/linux32/linux.h ============================================================================== --- head/sys/amd64/linux32/linux.h Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/amd64/linux32/linux.h Thu Sep 18 08:36:45 2014 (r271743) @@ -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. */ Modified: head/sys/amd64/linux32/linux32_dummy.c ============================================================================== --- head/sys/amd64/linux32/linux32_dummy.c Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/amd64/linux32/linux32_dummy.c Thu Sep 18 08:36:45 2014 (r271743) @@ -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); Modified: head/sys/amd64/linux32/syscalls.master ============================================================================== --- head/sys/amd64/linux32/syscalls.master Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/amd64/linux32/syscalls.master Thu Sep 18 08:36:45 2014 (r271743) @@ -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); } Added: head/sys/compat/linux/linux_timer.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/compat/linux/linux_timer.c Thu Sep 18 08:36:45 2014 (r271743) @@ -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 +__FBSDID("$FreeBSD$"); + +#include "opt_compat.h" + +#include +#include +#include +#include +#include +#include +#include + +#ifdef COMPAT_LINUX32 +#include +#include +#else +#include +#include +#endif +#include + +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)); +} + Added: head/sys/compat/linux/linux_timer.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/compat/linux/linux_timer.h Thu Sep 18 08:36:45 2014 (r271743) @@ -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 */ Modified: head/sys/conf/files.amd64 ============================================================================== --- head/sys/conf/files.amd64 Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/conf/files.amd64 Thu Sep 18 08:36:45 2014 (r271743) @@ -477,6 +477,7 @@ compat/linux/linux_socket.c optional com 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 Modified: head/sys/conf/files.i386 ============================================================================== --- head/sys/conf/files.i386 Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/conf/files.i386 Thu Sep 18 08:36:45 2014 (r271743) @@ -83,6 +83,7 @@ compat/linux/linux_socket.c optional com 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 Modified: head/sys/conf/files.pc98 ============================================================================== --- head/sys/conf/files.pc98 Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/conf/files.pc98 Thu Sep 18 08:36:45 2014 (r271743) @@ -55,6 +55,7 @@ compat/linux/linux_socket.c optional com 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 Modified: head/sys/i386/linux/linux.h ============================================================================== --- head/sys/i386/linux/linux.h Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/i386/linux/linux.h Thu Sep 18 08:36:45 2014 (r271743) @@ -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. */ Modified: head/sys/i386/linux/linux_machdep.c ============================================================================== --- head/sys/i386/linux/linux_machdep.c Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/i386/linux/linux_machdep.c Thu Sep 18 08:36:45 2014 (r271743) @@ -980,37 +980,6 @@ linux_get_thread_area(struct thread *td, 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) Modified: head/sys/i386/linux/syscalls.master ============================================================================== --- head/sys/i386/linux/syscalls.master Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/i386/linux/syscalls.master Thu Sep 18 08:36:45 2014 (r271743) @@ -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); } Modified: head/sys/modules/linux/Makefile ============================================================================== --- head/sys/modules/linux/Makefile Thu Sep 18 06:47:48 2014 (r271742) +++ head/sys/modules/linux/Makefile Thu Sep 18 08:36:45 2014 (r271743) @@ -13,6 +13,7 @@ SRCS= linux_fork.c linux${SFX}_dummy.c l 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