From owner-freebsd-threads@FreeBSD.ORG Mon Jul 15 11:06:52 2013 Return-Path: Delivered-To: freebsd-threads@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 7582DF84 for ; Mon, 15 Jul 2013 11:06:52 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 69599FD5 for ; Mon, 15 Jul 2013 11:06:52 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6FB6qag084622 for ; Mon, 15 Jul 2013 11:06:52 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6FB6q0Y084620 for freebsd-threads@FreeBSD.org; Mon, 15 Jul 2013 11:06:52 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 15 Jul 2013 11:06:52 GMT Message-Id: <201307151106.r6FB6q0Y084620@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-threads@FreeBSD.org Subject: Current problem reports assigned to freebsd-threads@FreeBSD.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jul 2013 11:06:52 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o threa/180496 threads clock_gettime() does not return CPU-time for zombie pr o threa/179158 threads ruby19 segfaults during build on ppc64 o threa/168417 threads pthread_getcpuclockid() does not work to specification o threa/163512 threads libc defaults to single threaded o threa/160708 threads possible security problem with RLIMIT_VMEM o threa/150959 threads [libc] Stub pthread_once in libc should call _libc_onc o threa/148515 threads Memory / syslog strangeness in FreeBSD 8.x ( possible o threa/141721 threads rtprio(1): (id|rt)prio priority resets when new thread o threa/135673 threads databases/mysql50-server - MySQL query lock-ups on 7.2 o threa/128922 threads threads hang with xorg running o threa/122923 threads 'nice' does not prevent background process from steali o threa/121336 threads lang/neko threading ok on UP, broken on SMP (FreeBSD 7 o threa/116668 threads can no longer use jdk15 with libthr on -stable SMP o threa/115211 threads pthread_atfork misbehaves in initial thread o threa/110306 threads apache 2.0 segmentation violation when calling gethost o threa/103975 threads Implicit loading/unloading of libpthread.so may crash o threa/80992 threads abort() sometimes not caught by gdb depending on threa o threa/79683 threads svctcp_create() fails if multiple threads call at the s threa/30464 threads [patch] pthread mutex attributes -- pshared 19 problems total. From owner-freebsd-threads@FreeBSD.ORG Wed Jul 17 22:50:47 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 44BC3EC0 for ; Wed, 17 Jul 2013 22:50:47 +0000 (UTC) (envelope-from marcus@marcuscom.com) Received: from av-tac-rtp.cisco.com (av-tac-rtp.cisco.com [64.102.19.209]) by mx1.freebsd.org (Postfix) with ESMTP id F41EF119 for ; Wed, 17 Jul 2013 22:50:46 +0000 (UTC) X-TACSUNS: Virus Scanned Received: from chook.cisco.com (localhost.cisco.com [127.0.0.1]) by av-tac-rtp.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6HMeF3h029812 for ; Wed, 17 Jul 2013 18:40:15 -0400 (EDT) Received: from dhcp-10-150-54-149.cisco.com (dhcp-10-150-54-149.cisco.com [10.150.54.149]) by chook.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6HMeFC4026843; Wed, 17 Jul 2013 18:40:15 -0400 (EDT) Message-ID: <51E71D4F.5030502@marcuscom.com> Date: Wed, 17 Jul 2013 18:40:15 -0400 From: Joe Marcus Clarke User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: freebsd-threads@freebsd.org Subject: Mutexes and error checking Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Koop Mast X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jul 2013 22:50:47 -0000 It seems we might have a discrepancy between the way our pthread implementation works compared to Linux. If a mutex is set to NORMAL type and one goes to unlock it, EPERM is returned unless the current thread is the mutex owner. While this sounds perfectly sane, it appears Linux only returns EPERM if the mutex type is ERRORCHECK. We are seeing some problems in ported code because of this. As a suggestion, if people agree, would it be possible to emulate the behavior of Linux and only return EPERM if the mutex is of type ERRORCHECK or RECURSVIE? Joe -- PGP Key : http://www.marcuscom.com/pgp.asc From owner-freebsd-threads@FreeBSD.ORG Thu Jul 18 15:09:07 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 31C215B2 for ; Thu, 18 Jul 2013 15:09:07 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) by mx1.freebsd.org (Postfix) with ESMTP id EC2A435E for ; Thu, 18 Jul 2013 15:09:06 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.6/8.14.6/NETPLEX) with ESMTP id r6IF94vQ001389; Thu, 18 Jul 2013 11:09:05 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.1 (mail.netplex.net [204.213.176.9]); Thu, 18 Jul 2013 11:09:05 -0400 (EDT) Date: Thu, 18 Jul 2013 11:09:04 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Joe Marcus Clarke Subject: Re: Mutexes and error checking In-Reply-To: <51E71D4F.5030502@marcuscom.com> Message-ID: References: <51E71D4F.5030502@marcuscom.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 15:09:07 -0000 On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: > It seems we might have a discrepancy between the way our pthread > implementation works compared to Linux. If a mutex is set to NORMAL > type and one goes to unlock it, EPERM is returned unless the current > thread is the mutex owner. While this sounds perfectly sane, it appears > Linux only returns EPERM if the mutex type is ERRORCHECK. > > We are seeing some problems in ported code because of this. As a > suggestion, if people agree, would it be possible to emulate the > behavior of Linux and only return EPERM if the mutex is of type > ERRORCHECK or RECURSVIE? First, any software that does that is broken. Second, the POSIX spec seems to imply that an error is returned when a different thread tries to unlock an already locked mutex: http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm Is the mutex robust or not robust? If not robust (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex cannot be unlocked by any other thread than the owner. So, it would seem to be wrong to _not_ return an error when the mutex is not unlocked after pthread_mutex_unlock() returns. -- DE From owner-freebsd-threads@FreeBSD.ORG Thu Jul 18 15:13:36 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 7C198616 for ; Thu, 18 Jul 2013 15:13:36 +0000 (UTC) (envelope-from marcus@marcuscom.com) Received: from av-tac-rtp.cisco.com (av-tac-rtp.cisco.com [64.102.19.209]) by mx1.freebsd.org (Postfix) with ESMTP id 1C76E37E for ; Thu, 18 Jul 2013 15:13:35 +0000 (UTC) X-TACSUNS: Virus Scanned Received: from chook.cisco.com (localhost.cisco.com [127.0.0.1]) by av-tac-rtp.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6IFDYnB010665 for ; Thu, 18 Jul 2013 11:13:34 -0400 (EDT) Received: from dhcp-10-150-54-149.cisco.com (dhcp-10-150-54-149.cisco.com [10.150.54.149]) by chook.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6IFDVBW008377; Thu, 18 Jul 2013 11:13:31 -0400 (EDT) Message-ID: <51E8061B.60906@marcuscom.com> Date: Thu, 18 Jul 2013 11:13:31 -0400 From: Joe Marcus Clarke User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Daniel Eischen Subject: Re: Mutexes and error checking References: <51E71D4F.5030502@marcuscom.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 15:13:36 -0000 On 7/18/13 11:09 AM, Daniel Eischen wrote: > On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: > >> It seems we might have a discrepancy between the way our pthread >> implementation works compared to Linux. If a mutex is set to NORMAL >> type and one goes to unlock it, EPERM is returned unless the current >> thread is the mutex owner. While this sounds perfectly sane, it appears >> Linux only returns EPERM if the mutex type is ERRORCHECK. >> >> We are seeing some problems in ported code because of this. As a >> suggestion, if people agree, would it be possible to emulate the >> behavior of Linux and only return EPERM if the mutex is of type >> ERRORCHECK or RECURSVIE? > > First, any software that does that is broken. > > Second, the POSIX spec seems to imply that an error is returned > when a different thread tries to unlock an already locked mutex: > > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm > > > Is the mutex robust or not robust? If not robust > (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex > cannot be unlocked by any other thread than the owner. > So, it would seem to be wrong to _not_ return an > error when the mutex is not unlocked after > pthread_mutex_unlock() returns. > Don't get me wrong, I agree with you. This behavior should result in EPERM. However, my comment was more on the portability side to maintain parity with Linux in order to support the 3rd party code people wanting to run on FreeBSD. We can workaround it in some cases, but I was floating up to you guys to perhaps create a broader workaround. Joe -- PGP Key : http://www.marcuscom.com/pgp.asc From owner-freebsd-threads@FreeBSD.ORG Thu Jul 18 15:22:43 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id DA6D8916 for ; Thu, 18 Jul 2013 15:22:43 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) by mx1.freebsd.org (Postfix) with ESMTP id 630ED5EC for ; Thu, 18 Jul 2013 15:22:43 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.6/8.14.6/NETPLEX) with ESMTP id r6IFMgDK018150; Thu, 18 Jul 2013 11:22:42 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.1 (mail.netplex.net [204.213.176.9]); Thu, 18 Jul 2013 11:22:42 -0400 (EDT) Date: Thu, 18 Jul 2013 11:22:42 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Joe Marcus Clarke Subject: Re: Mutexes and error checking In-Reply-To: <51E8061B.60906@marcuscom.com> Message-ID: References: <51E71D4F.5030502@marcuscom.com> <51E8061B.60906@marcuscom.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 15:22:43 -0000 On Thu, 18 Jul 2013, Joe Marcus Clarke wrote: > On 7/18/13 11:09 AM, Daniel Eischen wrote: >> On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: >> >>> It seems we might have a discrepancy between the way our pthread >>> implementation works compared to Linux. If a mutex is set to NORMAL >>> type and one goes to unlock it, EPERM is returned unless the current >>> thread is the mutex owner. While this sounds perfectly sane, it appears >>> Linux only returns EPERM if the mutex type is ERRORCHECK. >>> >>> We are seeing some problems in ported code because of this. As a >>> suggestion, if people agree, would it be possible to emulate the >>> behavior of Linux and only return EPERM if the mutex is of type >>> ERRORCHECK or RECURSVIE? >> >> First, any software that does that is broken. >> >> Second, the POSIX spec seems to imply that an error is returned >> when a different thread tries to unlock an already locked mutex: >> >> >> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm >> >> >> Is the mutex robust or not robust? If not robust >> (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex >> cannot be unlocked by any other thread than the owner. >> So, it would seem to be wrong to _not_ return an >> error when the mutex is not unlocked after >> pthread_mutex_unlock() returns. >> > > Don't get me wrong, I agree with you. This behavior should result in > EPERM. However, my comment was more on the portability side to maintain > parity with Linux in order to support the 3rd party code people wanting > to run on FreeBSD. We can workaround it in some cases, but I was > floating up to you guys to perhaps create a broader workaround. If it is not a robust mutex, the behavior _is_ undefined, so I think Linux is allowed to return 0 (no error), just as FreeBSD is allowed to return an error. I will check Solaris 10 later to see what it does. How many cases of this are we seeing in ports? How hard is it to upstream portability fixes to them - are they usually willing to accept these types of fixes? -- DE From owner-freebsd-threads@FreeBSD.ORG Thu Jul 18 15:33:18 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7F035A76 for ; Thu, 18 Jul 2013 15:33:18 +0000 (UTC) (envelope-from marcus@marcuscom.com) Received: from av-tac-rtp.cisco.com (av-tac-rtp.cisco.com [64.102.19.209]) by mx1.freebsd.org (Postfix) with ESMTP id 2A4BC650 for ; Thu, 18 Jul 2013 15:33:17 +0000 (UTC) X-TACSUNS: Virus Scanned Received: from chook.cisco.com (localhost.cisco.com [127.0.0.1]) by av-tac-rtp.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6IFXHAj013386 for ; Thu, 18 Jul 2013 11:33:17 -0400 (EDT) Received: from dhcp-10-150-54-149.cisco.com (dhcp-10-150-54-149.cisco.com [10.150.54.149]) by chook.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6IFXGVU006103; Thu, 18 Jul 2013 11:33:16 -0400 (EDT) Message-ID: <51E80ABC.30809@marcuscom.com> Date: Thu, 18 Jul 2013 11:33:16 -0400 From: Joe Marcus Clarke User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Daniel Eischen Subject: Re: Mutexes and error checking References: <51E71D4F.5030502@marcuscom.com> <51E8061B.60906@marcuscom.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 15:33:18 -0000 On 7/18/13 11:22 AM, Daniel Eischen wrote: > On Thu, 18 Jul 2013, Joe Marcus Clarke wrote: > >> On 7/18/13 11:09 AM, Daniel Eischen wrote: >>> On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: >>> >>>> It seems we might have a discrepancy between the way our pthread >>>> implementation works compared to Linux. If a mutex is set to NORMAL >>>> type and one goes to unlock it, EPERM is returned unless the current >>>> thread is the mutex owner. While this sounds perfectly sane, it >>>> appears >>>> Linux only returns EPERM if the mutex type is ERRORCHECK. >>>> >>>> We are seeing some problems in ported code because of this. As a >>>> suggestion, if people agree, would it be possible to emulate the >>>> behavior of Linux and only return EPERM if the mutex is of type >>>> ERRORCHECK or RECURSVIE? >>> >>> First, any software that does that is broken. >>> >>> Second, the POSIX spec seems to imply that an error is returned >>> when a different thread tries to unlock an already locked mutex: >>> >>> >>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm >>> >>> >>> >>> Is the mutex robust or not robust? If not robust >>> (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex >>> cannot be unlocked by any other thread than the owner. >>> So, it would seem to be wrong to _not_ return an >>> error when the mutex is not unlocked after >>> pthread_mutex_unlock() returns. >>> >> >> Don't get me wrong, I agree with you. This behavior should result in >> EPERM. However, my comment was more on the portability side to maintain >> parity with Linux in order to support the 3rd party code people wanting >> to run on FreeBSD. We can workaround it in some cases, but I was >> floating up to you guys to perhaps create a broader workaround. > > If it is not a robust mutex, the behavior _is_ undefined, so I > think Linux is allowed to return 0 (no error), just as FreeBSD > is allowed to return an error. I will check Solaris 10 later > to see what it does. > > How many cases of this are we seeing in ports? How hard is > it to upstream portability fixes to them - are they usually > willing to accept these types of fixes? I'll let Koop chime in here on the count. I think the problem is it's not trivial to hunt down the offending app code. I am very certain the upstream authors would be very happy to receive our patches, though. Joe > -- PGP Key : http://www.marcuscom.com/pgp.asc From owner-freebsd-threads@FreeBSD.ORG Thu Jul 18 15:55:41 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E5F1F5E0; Thu, 18 Jul 2013 15:55:41 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) by mx1.freebsd.org (Postfix) with ESMTP id A267E7EC; Thu, 18 Jul 2013 15:55:41 +0000 (UTC) Received: from Julian-MBP3.local (ppp121-45-226-51.lns20.per1.internode.on.net [121.45.226.51]) (authenticated bits=0) by vps1.elischer.org (8.14.5/8.14.5) with ESMTP id r6IFtbkE065898 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 18 Jul 2013 08:55:39 -0700 (PDT) (envelope-from julian@freebsd.org) Message-ID: <51E80FF3.2080101@freebsd.org> Date: Thu, 18 Jul 2013 23:55:31 +0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Daniel Eischen Subject: Re: Mutexes and error checking References: <51E71D4F.5030502@marcuscom.com> <51E8061B.60906@marcuscom.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Joe Marcus Clarke , Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 15:55:42 -0000 On 7/18/13 11:22 PM, Daniel Eischen wrote: > On Thu, 18 Jul 2013, Joe Marcus Clarke wrote: > >> On 7/18/13 11:09 AM, Daniel Eischen wrote: >>> On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: >>> >>>> It seems we might have a discrepancy between the way our pthread >>>> implementation works compared to Linux. If a mutex is set to NORMAL >>>> type and one goes to unlock it, EPERM is returned unless the current >>>> thread is the mutex owner. While this sounds perfectly sane, it >>>> appears >>>> Linux only returns EPERM if the mutex type is ERRORCHECK. >>>> >>>> We are seeing some problems in ported code because of this. As a >>>> suggestion, if people agree, would it be possible to emulate the >>>> behavior of Linux and only return EPERM if the mutex is of type >>>> ERRORCHECK or RECURSVIE? >>> >>> First, any software that does that is broken. >>> >>> Second, the POSIX spec seems to imply that an error is returned >>> when a different thread tries to unlock an already locked mutex: >>> >>> >>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm >>> >>> >>> >>> Is the mutex robust or not robust? If not robust >>> (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex >>> cannot be unlocked by any other thread than the owner. >>> So, it would seem to be wrong to _not_ return an >>> error when the mutex is not unlocked after >>> pthread_mutex_unlock() returns. >>> >> >> Don't get me wrong, I agree with you. This behavior should result in >> EPERM. However, my comment was more on the portability side to >> maintain >> parity with Linux in order to support the 3rd party code people >> wanting >> to run on FreeBSD. We can workaround it in some cases, but I was >> floating up to you guys to perhaps create a broader workaround. > > If it is not a robust mutex, the behavior _is_ undefined, so I > think Linux is allowed to return 0 (no error), just as FreeBSD > is allowed to return an error. I will check Solaris 10 later > to see what it does. > > How many cases of this are we seeing in ports? How hard is > it to upstream portability fixes to them - are they usually > willing to accept these types of fixes? I think the answer would be to declare a new type of mutex that allows this ant document it as to only be used in broken linux code. don't know how much work it would be however. From owner-freebsd-threads@FreeBSD.ORG Thu Jul 18 18:52:36 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D2F69DE for ; Thu, 18 Jul 2013 18:52:36 +0000 (UTC) (envelope-from marcus@marcuscom.com) Received: from av-tac-rtp.cisco.com (av-tac-rtp.cisco.com [64.102.19.209]) by mx1.freebsd.org (Postfix) with ESMTP id 8A96EFE1 for ; Thu, 18 Jul 2013 18:52:36 +0000 (UTC) X-TACSUNS: Virus Scanned Received: from chook.cisco.com (localhost.cisco.com [127.0.0.1]) by av-tac-rtp.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6IIqYDo012052 for ; Thu, 18 Jul 2013 14:52:34 -0400 (EDT) Received: from dhcp-10-150-54-149.cisco.com (dhcp-10-150-54-149.cisco.com [10.150.54.149]) by chook.cisco.com (8.13.8+Sun/8.13.8) with ESMTP id r6IIqYjc007543; Thu, 18 Jul 2013 14:52:34 -0400 (EDT) Message-ID: <51E83972.9070902@marcuscom.com> Date: Thu, 18 Jul 2013 14:52:34 -0400 From: Joe Marcus Clarke User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Julian Elischer Subject: Re: Mutexes and error checking References: <51E71D4F.5030502@marcuscom.com> <51E8061B.60906@marcuscom.com> <51E80FF3.2080101@freebsd.org> In-Reply-To: <51E80FF3.2080101@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 18:52:37 -0000 On 7/18/13 11:55 AM, Julian Elischer wrote: > On 7/18/13 11:22 PM, Daniel Eischen wrote: >> On Thu, 18 Jul 2013, Joe Marcus Clarke wrote: >> >>> On 7/18/13 11:09 AM, Daniel Eischen wrote: >>>> On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: >>>> >>>>> It seems we might have a discrepancy between the way our pthread >>>>> implementation works compared to Linux. If a mutex is set to NORMAL >>>>> type and one goes to unlock it, EPERM is returned unless the current >>>>> thread is the mutex owner. While this sounds perfectly sane, it >>>>> appears >>>>> Linux only returns EPERM if the mutex type is ERRORCHECK. >>>>> >>>>> We are seeing some problems in ported code because of this. As a >>>>> suggestion, if people agree, would it be possible to emulate the >>>>> behavior of Linux and only return EPERM if the mutex is of type >>>>> ERRORCHECK or RECURSVIE? >>>> >>>> First, any software that does that is broken. >>>> >>>> Second, the POSIX spec seems to imply that an error is returned >>>> when a different thread tries to unlock an already locked mutex: >>>> >>>> >>>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm >>>> >>>> >>>> >>>> Is the mutex robust or not robust? If not robust >>>> (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex >>>> cannot be unlocked by any other thread than the owner. >>>> So, it would seem to be wrong to _not_ return an >>>> error when the mutex is not unlocked after >>>> pthread_mutex_unlock() returns. >>>> >>> >>> Don't get me wrong, I agree with you. This behavior should result in >>> EPERM. However, my comment was more on the portability side to maintain >>> parity with Linux in order to support the 3rd party code people wanting >>> to run on FreeBSD. We can workaround it in some cases, but I was >>> floating up to you guys to perhaps create a broader workaround. >> >> If it is not a robust mutex, the behavior _is_ undefined, so I >> think Linux is allowed to return 0 (no error), just as FreeBSD >> is allowed to return an error. I will check Solaris 10 later >> to see what it does. >> >> How many cases of this are we seeing in ports? How hard is >> it to upstream portability fixes to them - are they usually >> willing to accept these types of fixes? > > I think the answer would be to declare a new type of mutex that allows > this ant document it as to only be used in broken linux code. don't > know how much work it would be however. I think this would be as much/more work than trying to fix the problem in the software or adding band-aids to abstraction packages like GLib. If the consensus is we don't want to modify FreeBSD behavior, then we will hack GLib and fix things tactically as we see them. Joe > > > -- PGP Key : http://www.marcuscom.com/pgp.asc From owner-freebsd-threads@FreeBSD.ORG Fri Jul 19 02:36:29 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 564F4AEE for ; Fri, 19 Jul 2013 02:36:29 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) by mx1.freebsd.org (Postfix) with ESMTP id 048248F0 for ; Fri, 19 Jul 2013 02:36:28 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.6/8.14.6/NETPLEX) with ESMTP id r6J2aMhg034054; Thu, 18 Jul 2013 22:36:22 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.1 (mail.netplex.net [204.213.176.9]); Thu, 18 Jul 2013 22:36:22 -0400 (EDT) Date: Thu, 18 Jul 2013 22:36:22 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Joe Marcus Clarke Subject: Re: Mutexes and error checking In-Reply-To: Message-ID: References: <51E71D4F.5030502@marcuscom.com> <51E8061B.60906@marcuscom.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jul 2013 02:36:29 -0000 On Thu, 18 Jul 2013, Daniel Eischen wrote: > On Thu, 18 Jul 2013, Joe Marcus Clarke wrote: > >> On 7/18/13 11:09 AM, Daniel Eischen wrote: >>> On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: >>> >>>> It seems we might have a discrepancy between the way our pthread >>>> implementation works compared to Linux. If a mutex is set to NORMAL >>>> type and one goes to unlock it, EPERM is returned unless the current >>>> thread is the mutex owner. While this sounds perfectly sane, it appears >>>> Linux only returns EPERM if the mutex type is ERRORCHECK. >>>> >>>> We are seeing some problems in ported code because of this. As a >>>> suggestion, if people agree, would it be possible to emulate the >>>> behavior of Linux and only return EPERM if the mutex is of type >>>> ERRORCHECK or RECURSVIE? >>> >>> First, any software that does that is broken. >>> >>> Second, the POSIX spec seems to imply that an error is returned >>> when a different thread tries to unlock an already locked mutex: >>> >>> >>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm >>> >>> >>> Is the mutex robust or not robust? If not robust >>> (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex >>> cannot be unlocked by any other thread than the owner. >>> So, it would seem to be wrong to _not_ return an >>> error when the mutex is not unlocked after >>> pthread_mutex_unlock() returns. >>> >> >> Don't get me wrong, I agree with you. This behavior should result in >> EPERM. However, my comment was more on the portability side to maintain >> parity with Linux in order to support the 3rd party code people wanting >> to run on FreeBSD. We can workaround it in some cases, but I was >> floating up to you guys to perhaps create a broader workaround. > > If it is not a robust mutex, the behavior _is_ undefined, so I > think Linux is allowed to return 0 (no error), just as FreeBSD > is allowed to return an error. I will check Solaris 10 later > to see what it does. I tried Solaris 10. For an already locked PTHREAD_MUTEX_NORMAL mutex: pthread_mutex_lock() by owner returns EDEADLK pthread_mutex_lock() by non-owner results in deadlock For the above, I tested with and without the owning thread being dead/finished. The results were the same. I don't really agree with Linux's behavior here. Why even bother with mutexes at all? The only thing that I can think of, is that they are only returning 0 if the owning thread is dead or has finished. The source for the above test is here: http://people.freebsd.org/~deischen/mutex_test.c -- DE From owner-freebsd-threads@FreeBSD.ORG Fri Jul 19 05:55:48 2013 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C27B2FC2 for ; Fri, 19 Jul 2013 05:55:48 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) by mx1.freebsd.org (Postfix) with ESMTP id 6C1CB1A4 for ; Fri, 19 Jul 2013 05:55:48 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.6/8.14.6/NETPLEX) with ESMTP id r6J5tkNh020988; Fri, 19 Jul 2013 01:55:46 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.1 (mail.netplex.net [204.213.176.9]); Fri, 19 Jul 2013 01:55:47 -0400 (EDT) Date: Fri, 19 Jul 2013 01:55:46 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Joe Marcus Clarke Subject: Re: Mutexes and error checking In-Reply-To: Message-ID: References: <51E71D4F.5030502@marcuscom.com> <51E8061B.60906@marcuscom.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Koop Mast , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jul 2013 05:55:48 -0000 On Thu, 18 Jul 2013, Daniel Eischen wrote: > On Thu, 18 Jul 2013, Daniel Eischen wrote: > >> On Thu, 18 Jul 2013, Joe Marcus Clarke wrote: >> >>> On 7/18/13 11:09 AM, Daniel Eischen wrote: >>>> On Wed, 17 Jul 2013, Joe Marcus Clarke wrote: >>>> >>>>> It seems we might have a discrepancy between the way our pthread >>>>> implementation works compared to Linux. If a mutex is set to NORMAL >>>>> type and one goes to unlock it, EPERM is returned unless the current >>>>> thread is the mutex owner. While this sounds perfectly sane, it appears >>>>> Linux only returns EPERM if the mutex type is ERRORCHECK. >>>>> >>>>> We are seeing some problems in ported code because of this. As a >>>>> suggestion, if people agree, would it be possible to emulate the >>>>> behavior of Linux and only return EPERM if the mutex is of type >>>>> ERRORCHECK or RECURSVIE? >>>> >>>> First, any software that does that is broken. >>>> >>>> Second, the POSIX spec seems to imply that an error is returned >>>> when a different thread tries to unlock an already locked mutex: >>>> >>>> >>>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.htm >>>> >>>> >>>> Is the mutex robust or not robust? If not robust >>>> (PTHREAD_MUTEX_STALLED), then a PTHREAD_MUTEX_NORMAL mutex >>>> cannot be unlocked by any other thread than the owner. >>>> So, it would seem to be wrong to _not_ return an >>>> error when the mutex is not unlocked after >>>> pthread_mutex_unlock() returns. >>>> >>> >>> Don't get me wrong, I agree with you. This behavior should result in >>> EPERM. However, my comment was more on the portability side to maintain >>> parity with Linux in order to support the 3rd party code people wanting >>> to run on FreeBSD. We can workaround it in some cases, but I was >>> floating up to you guys to perhaps create a broader workaround. >> >> If it is not a robust mutex, the behavior _is_ undefined, so I >> think Linux is allowed to return 0 (no error), just as FreeBSD >> is allowed to return an error. I will check Solaris 10 later >> to see what it does. > > I tried Solaris 10. For an already locked PTHREAD_MUTEX_NORMAL > mutex: Ugh! I misread the problem when I tried to recreate it and test it on Solaris, so forget that last email. It seems Solaris behaves like Linux with PTHREAD_MUTEX_NORMAL and _unlocking_ mutexes owned by other threads (dead or not). Solaris only returns EPERM for PTHREAD_MUTEX_ERRORCHECK mutexes. Test program was updated: http://people.freebsd.org/~deischen/mutex_test.c -- DE From owner-freebsd-threads@FreeBSD.ORG Fri Jul 19 12:10:00 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D4944B86 for ; Fri, 19 Jul 2013 12:10:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id A2B3161F for ; Fri, 19 Jul 2013 12:10:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6JCA00h064413 for ; Fri, 19 Jul 2013 12:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6JCA07G064412; Fri, 19 Jul 2013 12:10:00 GMT (envelope-from gnats) Resent-Date: Fri, 19 Jul 2013 12:10:00 GMT Resent-Message-Id: <201307191210.r6JCA07G064412@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Petr Salinger Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 387C8A83 for ; Fri, 19 Jul 2013 12:09:21 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121]) by mx1.freebsd.org (Postfix) with ESMTP id 2B25160A for ; Fri, 19 Jul 2013 12:09:21 +0000 (UTC) Received: from oldred.freebsd.org ([127.0.1.6]) by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r6JC9Kn9001518 for ; Fri, 19 Jul 2013 12:09:20 GMT (envelope-from nobody@oldred.freebsd.org) Received: (from nobody@localhost) by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r6JC9KUQ001513; Fri, 19 Jul 2013 12:09:20 GMT (envelope-from nobody) Message-Id: <201307191209.r6JC9KUQ001513@oldred.freebsd.org> Date: Fri, 19 Jul 2013 12:09:20 GMT From: Petr Salinger To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jul 2013 12:10:00 -0000 >Number: 180652 >Category: threads >Synopsis: compat32 problem in clock_getcpuclockid2 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 19 12:10:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Petr Salinger >Release: HEAD >Organization: >Environment: GNU/kFreeBSD 10.0-0-amd64 >Description: The prototype is int clock_getcpuclockid2(id_t id, int which, clockid_t *clock_id); In the first argument so far only pid_t and lwpid_t sizes are passed. Accroding to sys/_types.h: typedef __int64_t __id_t; typedef __int32_t __lwpid_t; typedef __int32_t __pid_t; typedef __int32_t __clockid_t; There is no freebsd32_clock_getcpuclockid2 at all. The 64-bit argument is misplaced in compat32. >How-To-Repeat: >Fix: The PID/TID is encoded in lower 30 bits of clockid. I.e. whole id_t space cannot be used anyway. Please either change signature of syscall to int clock_getcpuclockid2(long id, int which, clockid_t *clock_id); or provide real freebsd32_clock_getcpuclockid2 (); >Release-Note: >Audit-Trail: >Unformatted: From owner-freebsd-threads@FreeBSD.ORG Fri Jul 19 17:00:01 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3A803A25 for ; Fri, 19 Jul 2013 17:00:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 2D112659 for ; Fri, 19 Jul 2013 17:00:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6JH00Ge071222 for ; Fri, 19 Jul 2013 17:00:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6JH00ST071221; Fri, 19 Jul 2013 17:00:00 GMT (envelope-from gnats) Date: Fri, 19 Jul 2013 17:00:00 GMT Message-Id: <201307191700.r6JH00ST071221@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Konstantin Belousov Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Konstantin Belousov List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jul 2013 17:00:01 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Konstantin Belousov To: Petr Salinger Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Fri, 19 Jul 2013 19:52:30 +0300 --dA3KA1Bq6vhZBZVs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 19, 2013 at 12:09:20PM +0000, Petr Salinger wrote: >=20 > >Number: 180652 > >Category: threads > >Synopsis: compat32 problem in clock_getcpuclockid2 > >Confidential: no > >Severity: non-critical > >Priority: low > >Responsible: freebsd-threads > >State: open > >Quarter: =20 > >Keywords: =20 > >Date-Required: > >Class: sw-bug > >Submitter-Id: current-users > >Arrival-Date: Fri Jul 19 12:10:00 UTC 2013 > >Closed-Date: > >Last-Modified: > >Originator: Petr Salinger > >Release: HEAD > >Organization: > >Environment: > GNU/kFreeBSD 10.0-0-amd64 > >Description: > The prototype is >=20 > int clock_getcpuclockid2(id_t id, int which, clockid_t *clock_id); >=20 > In the first argument so far only pid_t and lwpid_t sizes are passed. >=20 > Accroding to sys/_types.h: >=20 > typedef __int64_t __id_t; > typedef __int32_t __lwpid_t;=20 > typedef __int32_t __pid_t; > typedef __int32_t __clockid_t; >=20 > There is no freebsd32_clock_getcpuclockid2 at all. > The 64-bit argument is misplaced in compat32. >=20 >=20 > >How-To-Repeat: >=20 > >Fix: >=20 > The PID/TID is encoded in lower 30 bits of clockid. > I.e. whole id_t space cannot be used anyway. >=20 > Please either change signature of syscall to >=20 > int clock_getcpuclockid2(long id, int which, clockid_t *clock_id); >=20 > or provide real >=20 > freebsd32_clock_getcpuclockid2 (); The following worked for me. diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/f= reebsd32_misc.c index dd8d4f7..cfcd83b 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -2332,6 +2332,20 @@ freebsd32_clock_getres(struct thread *td, } =20 int +freebsd32_clock_getcpuclockid2(struct thread *td, + struct freebsd32_clock_getcpuclockid2_args *uap) +{ + clockid_t clk_id; + int error; + + error =3D kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id), + uap->which, &clk_id); + if (error =3D=3D 0) + error =3D copyout(&clk_id, uap->clock_id, sizeof(clockid_t)); + return (error); +} + +int freebsd32_thr_new(struct thread *td, struct freebsd32_thr_new_args *uap) { diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/sy= scalls.master index bcca754..6cb649f 100644 --- a/sys/compat/freebsd32/syscalls.master +++ b/sys/compat/freebsd32/syscalls.master @@ -457,8 +457,9 @@ 244 AUE_NULL UNIMPL nosys 245 AUE_NULL UNIMPL nosys 246 AUE_NULL UNIMPL nosys -247 AUE_NULL NOPROTO { int clock_getcpuclockid2(id_t id,\ - int which, clockid_t *clock_id); } +247 AUE_NULL STD { int freebsd32_clock_getcpuclockid2(\ + uint32_t id1, uint32_t id2,\ + int which, clockid_t *clock_id); } 248 AUE_NULL UNIMPL ntp_gettime 249 AUE_NULL UNIMPL nosys ; syscall numbers initially used in OpenBSD diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 9e0cc06..6b908a0 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -183,38 +183,46 @@ int sys_clock_getcpuclockid2(struct thread *td, struct clock_getcpuclockid2_ar= gs *uap) { clockid_t clk_id; + int error; + + error =3D kern_clock_getcpuclockid2(td, uap->id, uap->which, &clk_id); + if (error =3D=3D 0) + error =3D copyout(&clk_id, uap->clock_id, sizeof(clockid_t)); + return (error); +} + +int +kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t *clk_id) +{ struct proc *p; pid_t pid; lwpid_t tid; int error; =20 - switch(uap->which) { + switch (which) { case CPUCLOCK_WHICH_PID: - if (uap->id !=3D 0) { - p =3D pfind(uap->id); + if (id !=3D 0) { + p =3D pfind(id); if (p =3D=3D NULL) return (ESRCH); error =3D p_cansee(td, p); PROC_UNLOCK(p); - if (error) + if (error !=3D 0) return (error); - pid =3D uap->id; + pid =3D id; } else { pid =3D td->td_proc->p_pid; } - clk_id =3D MAKE_PROCESS_CPUCLOCK(pid); - break; + *clk_id =3D MAKE_PROCESS_CPUCLOCK(pid); + return (0); case CPUCLOCK_WHICH_TID: - if (uap->id =3D=3D 0) - tid =3D td->td_tid; - else - tid =3D uap->id; - clk_id =3D MAKE_THREAD_CPUCLOCK(tid); - break; + tid =3D id =3D=3D 0 ? td->td_tid : id; + *clk_id =3D MAKE_THREAD_CPUCLOCK(tid); + return (0); default: return (EINVAL); } - return (copyout(&clk_id, uap->clock_id, sizeof(clockid_t))); } =20 #ifndef _SYS_SYSPROTO_H_ diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 49e8be1..8901ff3 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -76,6 +76,8 @@ int kern_chmod(struct thread *td, char *path, enum uio_se= g pathseg, int mode); int kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int ui= d, int gid); +int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t clk_id); int kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts); int kern_clock_gettime(struct thread *td, clockid_t clock_id, --dA3KA1Bq6vhZBZVs Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJR6W7OAAoJEJDCuSvBvK1Bgk0P/jsLFXu7HfjYIYsechP8d+8U FNdFrJMhQOFEfeQljwp71eqOE8g6iC0faSPErs/qwEwOjUn4F+CwffrJstcnPiFb UPC7pZjP2S12Sd3G1spPdwkphqHIfNdIDWhUxUPclH53au/pcL8d3i5Nj/FpLrNy TVgWshgAtBS6/1teKBQsSAtUQR7wje4ZYuCvabfGCsKjANBmKElXvUy2hAoSZM86 B44dj821JkHsj0Kg9A1BtdZu44fPu99byAmKfhj2Shyg5KGGv2f1m+Urm5yT70th KwwPsBewrkmMYEydm7/QxqHMs8yY9CcA1PbWPI2rb2nmZQtamrKUo3AOLjtzo8G+ 0soisBIeOoEkVMNRMq41LGdgs5vbe2WdtUfLek1+ASjTvGGq8JwKgVjG5u4mC4l9 rvtti0Tc6jh8/dC3a71gv16zh+ehWYq0QD5mY87AlNx+xf4lu1rohuZQdpREni/i tnQyYTD0HLx7PS6NlP4ZLnDR2H8Qsr+8DMW8JMKaF4As2orbEsucQoEQEOy7kpOJ oKDUBQPCMsybnk64QQwDCPcZfJNxpw7egCzVYQZIzADTkWRvb4ut5hj/rzQonaVg ibdCW4A7HK1xxqIUolK+eXaGEfvXX/vJLqUn/dK1lB+XmTXZ6gHgytkk8LwaICaZ KryVDPEaF0MAaPylSmbS =/PlM -----END PGP SIGNATURE----- --dA3KA1Bq6vhZBZVs-- From owner-freebsd-threads@FreeBSD.ORG Fri Jul 19 20:00:02 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 6F896E62 for ; Fri, 19 Jul 2013 20:00:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 621B5E6E for ; Fri, 19 Jul 2013 20:00:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6JK01NG010226 for ; Fri, 19 Jul 2013 20:00:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6JK01fJ010225; Fri, 19 Jul 2013 20:00:01 GMT (envelope-from gnats) Date: Fri, 19 Jul 2013 20:00:01 GMT Message-Id: <201307192000.r6JK01fJ010225@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Petr Salinger Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Petr Salinger List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jul 2013 20:00:02 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Petr Salinger To: Konstantin Belousov Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Fri, 19 Jul 2013 21:58:00 +0200 (CEST) Test in progress, backported to 9.1, but with int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, clockid_t *clk_id); here: > --- a/sys/sys/syscallsubr.h > +++ b/sys/sys/syscallsubr.h > @@ -76,6 +76,8 @@ int kern_chmod(struct thread *td, char *path, enum uio_seg pathseg, > int mode); > int kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid, > int gid); > +int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, > + clockid_t clk_id); > int kern_clock_getres(struct thread *td, clockid_t clock_id, > struct timespec *ts); > int kern_clock_gettime(struct thread *td, clockid_t clock_id, Petr From owner-freebsd-threads@FreeBSD.ORG Sat Jul 20 13:30:02 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3B500BB1 for ; Sat, 20 Jul 2013 13:30:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 2E2F21CF for ; Sat, 20 Jul 2013 13:30:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6KDU1Mn043381 for ; Sat, 20 Jul 2013 13:30:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6KDU1IP043380; Sat, 20 Jul 2013 13:30:01 GMT (envelope-from gnats) Date: Sat, 20 Jul 2013 13:30:01 GMT Message-Id: <201307201330.r6KDU1IP043380@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Petr Salinger Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Petr Salinger List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jul 2013 13:30:02 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Petr Salinger To: Konstantin Belousov Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Sat, 20 Jul 2013 15:26:06 +0200 (CEST) With the above change to prototype in syscallsubr.h, it works fine. Tested on x86, backported to 9.1 kernel: 64 bit under 64 bit kernel, 32 bit under 64 bit kernel, 32 bit under 32 bit kernel. Many thanks. It looks like the only remaining missing part of compat32 interfaces (covered by our eglibc testsuite) is ktimer_*() family, used for http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_gettime.html Thanks again Petr From owner-freebsd-threads@FreeBSD.ORG Sat Jul 20 13:40:01 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6AB34E9C for ; Sat, 20 Jul 2013 13:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 4AFD722F for ; Sat, 20 Jul 2013 13:40:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6KDe1n5045087 for ; Sat, 20 Jul 2013 13:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6KDe18X045086; Sat, 20 Jul 2013 13:40:01 GMT (envelope-from gnats) Date: Sat, 20 Jul 2013 13:40:01 GMT Message-Id: <201307201340.r6KDe18X045086@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: dfilter@FreeBSD.ORG (dfilter service) Subject: Re: threads/180652: commit references a PR X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: dfilter service List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jul 2013 13:40:01 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: dfilter@FreeBSD.ORG (dfilter service) To: bug-followup@FreeBSD.org Cc: Subject: Re: threads/180652: commit references a PR Date: Sat, 20 Jul 2013 13:39:54 +0000 (UTC) Author: kib Date: Sat Jul 20 13:39:41 2013 New Revision: 253494 URL: http://svnweb.freebsd.org/changeset/base/253494 Log: id_t is 64bit, provide the compat32 wrapper for clock_getcpuclockid2(2). Reported and tested by: Petr Salinger PR: threads/180652 Sponsored by: The FreeBSD Foundation Modified: head/sys/compat/freebsd32/freebsd32_misc.c head/sys/compat/freebsd32/syscalls.master head/sys/kern/kern_time.c head/sys/sys/syscallsubr.h Modified: head/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- head/sys/compat/freebsd32/freebsd32_misc.c Sat Jul 20 13:14:59 2013 (r253493) +++ head/sys/compat/freebsd32/freebsd32_misc.c Sat Jul 20 13:39:41 2013 (r253494) @@ -2332,6 +2332,20 @@ freebsd32_clock_getres(struct thread *td } int +freebsd32_clock_getcpuclockid2(struct thread *td, + struct freebsd32_clock_getcpuclockid2_args *uap) +{ + clockid_t clk_id; + int error; + + error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id), + uap->which, &clk_id); + if (error == 0) + error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t)); + return (error); +} + +int freebsd32_thr_new(struct thread *td, struct freebsd32_thr_new_args *uap) { Modified: head/sys/compat/freebsd32/syscalls.master ============================================================================== --- head/sys/compat/freebsd32/syscalls.master Sat Jul 20 13:14:59 2013 (r253493) +++ head/sys/compat/freebsd32/syscalls.master Sat Jul 20 13:39:41 2013 (r253494) @@ -457,8 +457,9 @@ 244 AUE_NULL UNIMPL nosys 245 AUE_NULL UNIMPL nosys 246 AUE_NULL UNIMPL nosys -247 AUE_NULL NOPROTO { int clock_getcpuclockid2(id_t id,\ - int which, clockid_t *clock_id); } +247 AUE_NULL STD { int freebsd32_clock_getcpuclockid2(\ + uint32_t id1, uint32_t id2,\ + int which, clockid_t *clock_id); } 248 AUE_NULL UNIMPL ntp_gettime 249 AUE_NULL UNIMPL nosys ; syscall numbers initially used in OpenBSD Modified: head/sys/kern/kern_time.c ============================================================================== --- head/sys/kern/kern_time.c Sat Jul 20 13:14:59 2013 (r253493) +++ head/sys/kern/kern_time.c Sat Jul 20 13:39:41 2013 (r253494) @@ -183,38 +183,46 @@ int sys_clock_getcpuclockid2(struct thread *td, struct clock_getcpuclockid2_args *uap) { clockid_t clk_id; + int error; + + error = kern_clock_getcpuclockid2(td, uap->id, uap->which, &clk_id); + if (error == 0) + error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t)); + return (error); +} + +int +kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t *clk_id) +{ struct proc *p; pid_t pid; lwpid_t tid; int error; - switch(uap->which) { + switch (which) { case CPUCLOCK_WHICH_PID: - if (uap->id != 0) { - p = pfind(uap->id); + if (id != 0) { + p = pfind(id); if (p == NULL) return (ESRCH); error = p_cansee(td, p); PROC_UNLOCK(p); - if (error) + if (error != 0) return (error); - pid = uap->id; + pid = id; } else { pid = td->td_proc->p_pid; } - clk_id = MAKE_PROCESS_CPUCLOCK(pid); - break; + *clk_id = MAKE_PROCESS_CPUCLOCK(pid); + return (0); case CPUCLOCK_WHICH_TID: - if (uap->id == 0) - tid = td->td_tid; - else - tid = uap->id; - clk_id = MAKE_THREAD_CPUCLOCK(tid); - break; + tid = id == 0 ? td->td_tid : id; + *clk_id = MAKE_THREAD_CPUCLOCK(tid); + return (0); default: return (EINVAL); } - return (copyout(&clk_id, uap->clock_id, sizeof(clockid_t))); } #ifndef _SYS_SYSPROTO_H_ Modified: head/sys/sys/syscallsubr.h ============================================================================== --- head/sys/sys/syscallsubr.h Sat Jul 20 13:14:59 2013 (r253493) +++ head/sys/sys/syscallsubr.h Sat Jul 20 13:39:41 2013 (r253494) @@ -76,6 +76,8 @@ int kern_chmod(struct thread *td, char * int mode); int kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid, int gid); +int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t *clk_id); int kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts); int kern_clock_gettime(struct thread *td, clockid_t clock_id, _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" From owner-freebsd-threads@FreeBSD.ORG Sat Jul 20 14:40:01 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 6FF818B8 for ; Sat, 20 Jul 2013 14:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 519803E0 for ; Sat, 20 Jul 2013 14:40:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6KEe1t5056659 for ; Sat, 20 Jul 2013 14:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6KEe1YI056658; Sat, 20 Jul 2013 14:40:01 GMT (envelope-from gnats) Date: Sat, 20 Jul 2013 14:40:01 GMT Message-Id: <201307201440.r6KEe1YI056658@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Konstantin Belousov Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Konstantin Belousov List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jul 2013 14:40:01 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Konstantin Belousov To: Petr Salinger Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Sat, 20 Jul 2013 17:36:26 +0300 --ofoyOKZR33MYzbeX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 20, 2013 at 03:26:06PM +0200, Petr Salinger wrote: > It looks like the only remaining missing part of compat32 interfaces > (covered by our eglibc testsuite) is ktimer_*() family, used for > http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_gettime.h= tml Try this. Could you provide me with the isolated test case for timer_* functions ? commit 20bc0c0e4343307a4d24a1812c5cd546aa18b1da Author: Konstantin Belousov Date: Sat Jul 20 17:31:39 2013 +0300 Implement compat32 for ktimer_*. diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebs= d32.h index a95b0e5..9b04965 100644 --- a/sys/compat/freebsd32/freebsd32.h +++ b/sys/compat/freebsd32/freebsd32.h @@ -69,6 +69,15 @@ struct timespec32 { CP((src).fld,(dst).fld,tv_nsec); \ } while (0) =20 +struct itimerspec32 { + struct timespec32 it_interval; + struct timespec32 it_value; +}; +#define ITS_CP(src, dst) do { \ + TS_CP((src), (dst), it_interval); \ + TS_CP((src), (dst), it_value); \ +} while (0) + struct rusage32 { struct timeval32 ru_utime; struct timeval32 ru_stime; diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/f= reebsd32_misc.c index cfcd83b..4136ba9 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -2332,6 +2332,43 @@ freebsd32_clock_getres(struct thread *td, } =20 int +freebsd32_ktimer_settime(struct thread *td, + struct freebsd32_ktimer_settime_args *uap) +{ + struct itimerspec32 val32, oval32; + struct itimerspec val, oval, *ovalp; + int error; + + error =3D copyin(uap->value, &val32, sizeof(val32)); + if (error !=3D 0) + return (error); + ITS_CP(val32, val); + ovalp =3D uap->ovalue !=3D NULL ? &oval : NULL; + error =3D kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp); + if (error =3D=3D 0 && uap->ovalue !=3D NULL) { + ITS_CP(oval, oval32); + error =3D copyout(&oval32, uap->ovalue, sizeof(oval32)); + } + return (error); +} + +int +freebsd32_ktimer_gettime(struct thread *td, + struct freebsd32_ktimer_gettime_args *uap) +{ + struct itimerspec32 val32; + struct itimerspec val; + int error; + + error =3D kern_ktimer_gettime(td, uap->timerid, &val); + if (error =3D=3D 0) { + ITS_CP(val, val32); + error =3D copyout(&val32, uap->value, sizeof(val32)); + } + return (error); +} + +int freebsd32_clock_getcpuclockid2(struct thread *td, struct freebsd32_clock_getcpuclockid2_args *uap) { diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/sy= scalls.master index 6cb649f..6d3ea7c 100644 --- a/sys/compat/freebsd32/syscalls.master +++ b/sys/compat/freebsd32/syscalls.master @@ -441,11 +441,16 @@ const struct timespec32 *tp); } 234 AUE_NULL STD { int freebsd32_clock_getres(clockid_t clock_id, \ struct timespec32 *tp); } -235 AUE_NULL UNIMPL timer_create -236 AUE_NULL UNIMPL timer_delete -237 AUE_NULL UNIMPL timer_settime -238 AUE_NULL UNIMPL timer_gettime -239 AUE_NULL UNIMPL timer_getoverrun +235 AUE_NULL NOPROTO { int ktimer_create(clockid_t clock_id, \ + struct sigevent *evp, int *timerid); } +236 AUE_NULL NOPROTO { int ktimer_delete(int timerid); } +237 AUE_NULL STD { int freebsd32_ktimer_settime(int timerid,\ + int flags, \ + const struct itimerspec32 *value, \ + struct itimerspec32 *ovalue); } +238 AUE_NULL STD { int freebsd32_ktimer_gettime(int timerid,\ + struct itimerspec32 *value); } +239 AUE_NULL NOPROTO { int ktimer_getoverrun(int timerid); } 240 AUE_NULL STD { int freebsd32_nanosleep( \ const struct timespec32 *rqtp, \ struct timespec32 *rmtp); } diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 6b908a0..8703a11 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1271,35 +1271,40 @@ struct ktimer_settime_args { int sys_ktimer_settime(struct thread *td, struct ktimer_settime_args *uap) { - struct proc *p =3D td->td_proc; - struct itimer *it; struct itimerspec val, oval, *ovalp; int error; =20 error =3D copyin(uap->value, &val, sizeof(val)); if (error !=3D 0) return (error); -=09 - if (uap->ovalue !=3D NULL) - ovalp =3D &oval; - else - ovalp =3D NULL; + ovalp =3D uap->ovalue !=3D NULL ? &oval : NULL; + error =3D kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp); + if (error =3D=3D 0 && uap->ovalue !=3D NULL) + error =3D copyout(ovalp, uap->ovalue, sizeof(*ovalp)); + return (error); +} + +int +kern_ktimer_settime(struct thread *td, int timer_id, int flags, + struct itimerspec *val, struct itimerspec *oval) +{ + struct proc *p; + struct itimer *it; + int error; =20 + p =3D td->td_proc; PROC_LOCK(p); - if (uap->timerid < 3 || - (it =3D itimer_find(p, uap->timerid)) =3D=3D NULL) { + if (timer_id < 3 || (it =3D itimer_find(p, timer_id)) =3D=3D NULL) { PROC_UNLOCK(p); error =3D EINVAL; } else { PROC_UNLOCK(p); itimer_enter(it); - error =3D CLOCK_CALL(it->it_clockid, timer_settime, - (it, uap->flags, &val, ovalp)); + error =3D CLOCK_CALL(it->it_clockid, timer_settime, (it, + flags, val, oval)); itimer_leave(it); ITIMER_UNLOCK(it); } - if (error =3D=3D 0 && uap->ovalue !=3D NULL) - error =3D copyout(ovalp, uap->ovalue, sizeof(*ovalp)); return (error); } =20 @@ -1312,26 +1317,34 @@ struct ktimer_gettime_args { int sys_ktimer_gettime(struct thread *td, struct ktimer_gettime_args *uap) { - struct proc *p =3D td->td_proc; - struct itimer *it; struct itimerspec val; int error; =20 + error =3D kern_ktimer_gettime(td, uap->timerid, &val); + if (error =3D=3D 0) + error =3D copyout(&val, uap->value, sizeof(val)); + return (error); +} + +int +kern_ktimer_gettime(struct thread *td, int timer_id, struct itimerspec *va= l) +{ + struct proc *p; + struct itimer *it; + int error; + + p =3D td->td_proc; PROC_LOCK(p); - if (uap->timerid < 3 || - (it =3D itimer_find(p, uap->timerid)) =3D=3D NULL) { + if (timer_id < 3 || (it =3D itimer_find(p, timer_id)) =3D=3D NULL) { PROC_UNLOCK(p); error =3D EINVAL; } else { PROC_UNLOCK(p); itimer_enter(it); - error =3D CLOCK_CALL(it->it_clockid, timer_gettime, - (it, &val)); + error =3D CLOCK_CALL(it->it_clockid, timer_gettime, (it, val)); itimer_leave(it); ITIMER_UNLOCK(it); } - if (error =3D=3D 0) - error =3D copyout(&val, uap->value, sizeof(val)); return (error); } =20 diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 75278c3..4ed38b3 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -228,6 +228,10 @@ int kern_symlink(struct thread *td, char *path, char *= link, enum uio_seg segflg); int kern_symlinkat(struct thread *td, char *path1, int fd, char *path2, enum uio_seg segflg); +int kern_ktimer_settime(struct thread *td, int timer_id, int flags, + struct itimerspec *val, struct itimerspec *oval); +int kern_ktimer_gettime(struct thread *td, int timer_id, + struct itimerspec *val); int kern_thr_new(struct thread *td, struct thr_param *param); int kern_thr_suspend(struct thread *td, struct timespec *tsp); int kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, --ofoyOKZR33MYzbeX Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJR6qBqAAoJEJDCuSvBvK1BXIEP/2LMSizL9cYmu6TSo3dvTWqr ICOuzscpUHr1gJSOLVNimN6vdJVRbKPaWE4xW7QjxFYJYmkOfshuBW6kswstONXS Wctk8MmyICW1IhB48QFB3POGeo/qST1OQfXC9lNYcpsPmZT1B03zEKbJuZHDWUO7 MH7XLABc0+kR6aPIqhGQoEepn0okZLNvlbjG0rEBJ67SZjCMI6024pucn+J78I05 7vZOyTvWG8GRn9T/vCGsfKkkcYY6HnYwmEXTRhd5zR1HSufJIx2VCjuU6CRca1Uq o8x4IC7PXOtfMzXIZrbnVUJXnJR3wTHRAOJSdi+KM2aHhP6BRFY64v22ui5ITcBo yJ01k8aGQVn57WNh6rpnraYJ2gfJxyCxczSVBTk1y8eeNqRHli+56dUkvYld6+ZP mggoCmTuAPF7Dd9SmwtUuA18h98Nkf5BNyBbsCmAqAA0oT71vyPjc9ZVem5zUM5k tsorkrz/HyJWK5KiMFmdkD1l4cxJueIyb2e/QCMz3RraemfWPHaaO69FiERCVyeF Txuhq5bZEgaLxB1MdxWRpuR9Xhu5gesgJNH3gxARehaS1+P5oASc5/tSdq2tdH6x sMQ0rDhDMDuBfFO43HrXKDgHcmwfTEwmEIeCqiM+H1HCXIJ2w4DVWC+2MkHHR3Yt hf/ZkZtPbEU5LWwzeZDc =PNhX -----END PGP SIGNATURE----- --ofoyOKZR33MYzbeX-- From owner-freebsd-threads@FreeBSD.ORG Sat Jul 20 16:50:01 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A70ACBAE for ; Sat, 20 Jul 2013 16:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 97A77B27 for ; Sat, 20 Jul 2013 16:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6KGo03F082592 for ; Sat, 20 Jul 2013 16:50:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6KGo0xa082591; Sat, 20 Jul 2013 16:50:00 GMT (envelope-from gnats) Date: Sat, 20 Jul 2013 16:50:00 GMT Message-Id: <201307201650.r6KGo0xa082591@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Petr Salinger Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Petr Salinger List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jul 2013 16:50:01 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Petr Salinger To: Konstantin Belousov Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Sat, 20 Jul 2013 18:46:58 +0200 (CEST) >> It looks like the only remaining missing part of compat32 interfaces >> (covered by our eglibc testsuite) is ktimer_*() family, used for >> http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_gettime.html > > Try this. The sizeof(struct sigevent) used in int ktimer_create(clockid_t clock_id, struct sigevent *evp, int *timerid); is not the same in 32-bit and 64-bit arch. I doubt it will work correctly. > Could you provide me with the isolated test case for timer_* > functions ? They can be derived from http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=nptl/sysdeps/pthread/tst-timer.c;hb=HEAD and tst-timer[2-5].c from http://sourceware.org/git/?p=glibc.git;a=tree;f=rt Thanks for you work Petr From owner-freebsd-threads@FreeBSD.ORG Sat Jul 20 18:10:09 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 11741BD7 for ; Sat, 20 Jul 2013 18:10:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id E7D03E1C for ; Sat, 20 Jul 2013 18:10:08 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6KIA89D000435 for ; Sat, 20 Jul 2013 18:10:08 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6KIA8t2000431; Sat, 20 Jul 2013 18:10:08 GMT (envelope-from gnats) Date: Sat, 20 Jul 2013 18:10:08 GMT Message-Id: <201307201810.r6KIA8t2000431@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Konstantin Belousov Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Konstantin Belousov List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jul 2013 18:10:09 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Konstantin Belousov To: Petr Salinger Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Sat, 20 Jul 2013 21:03:23 +0300 --2NSZC26AJDpFITwK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 20, 2013 at 06:46:58PM +0200, Petr Salinger wrote: > >> It looks like the only remaining missing part of compat32 interfaces > >> (covered by our eglibc testsuite) is ktimer_*() family, used for > >> http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_gettim= e.html > > > > Try this. >=20 > The sizeof(struct sigevent) used in >=20 > int ktimer_create(clockid_t clock_id, struct sigevent *evp, int *timer= id); >=20 > is not the same in 32-bit and 64-bit arch. I doubt it will work correctly. This is fair. >=20 > > Could you provide me with the isolated test case for timer_* > > functions ? >=20 > They can be derived from >=20 > http://sourceware.org/git/?p=3Dglibc.git;a=3Dblob_plain;f=3Dnptl/sysdeps/= pthread/tst-timer.c;hb=3DHEAD >=20 > and tst-timer[2-5].c from >=20 > http://sourceware.org/git/?p=3Dglibc.git;a=3Dtree;f=3Drt And this is not. I only tested with adapted tst-timer2.c. I hope you would do the rest. diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebs= d32.h index a95b0e5..9b04965 100644 --- a/sys/compat/freebsd32/freebsd32.h +++ b/sys/compat/freebsd32/freebsd32.h @@ -69,6 +69,15 @@ struct timespec32 { CP((src).fld,(dst).fld,tv_nsec); \ } while (0) =20 +struct itimerspec32 { + struct timespec32 it_interval; + struct timespec32 it_value; +}; +#define ITS_CP(src, dst) do { \ + TS_CP((src), (dst), it_interval); \ + TS_CP((src), (dst), it_value); \ +} while (0) + struct rusage32 { struct timeval32 ru_utime; struct timeval32 ru_stime; diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/f= reebsd32_misc.c index cfcd83b..3d84941 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -2331,6 +2331,70 @@ freebsd32_clock_getres(struct thread *td, return (error); } =20 +int freebsd32_ktimer_create(struct thread *td, + struct freebsd32_ktimer_create_args *uap) +{ + struct sigevent32 ev32; + struct sigevent ev, *evp; + int error, id; + + if (uap->evp =3D=3D NULL) { + evp =3D NULL; + } else { + evp =3D &ev; + error =3D copyin(uap->evp, &ev32, sizeof(ev32)); + if (error !=3D 0) + return (error); + error =3D convert_sigevent32(&ev32, &ev); + if (error !=3D 0) + return (error); + } + error =3D kern_ktimer_create(td, uap->clock_id, &ev, &id, -1); + if (error =3D=3D 0) { + error =3D copyout(&id, uap->timerid, sizeof(int)); + if (error !=3D 0) + kern_ktimer_delete(td, id); + } + return (error); +} + +int +freebsd32_ktimer_settime(struct thread *td, + struct freebsd32_ktimer_settime_args *uap) +{ + struct itimerspec32 val32, oval32; + struct itimerspec val, oval, *ovalp; + int error; + + error =3D copyin(uap->value, &val32, sizeof(val32)); + if (error !=3D 0) + return (error); + ITS_CP(val32, val); + ovalp =3D uap->ovalue !=3D NULL ? &oval : NULL; + error =3D kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp); + if (error =3D=3D 0 && uap->ovalue !=3D NULL) { + ITS_CP(oval, oval32); + error =3D copyout(&oval32, uap->ovalue, sizeof(oval32)); + } + return (error); +} + +int +freebsd32_ktimer_gettime(struct thread *td, + struct freebsd32_ktimer_gettime_args *uap) +{ + struct itimerspec32 val32; + struct itimerspec val; + int error; + + error =3D kern_ktimer_gettime(td, uap->timerid, &val); + if (error =3D=3D 0) { + ITS_CP(val, val32); + error =3D copyout(&val32, uap->value, sizeof(val32)); + } + return (error); +} + int freebsd32_clock_getcpuclockid2(struct thread *td, struct freebsd32_clock_getcpuclockid2_args *uap) @@ -2912,3 +2976,28 @@ freebsd32_posix_fadvise(struct thread *td, return (kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len), uap->advice)); } + +int +convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig) +{ + + CP(*sig32, *sig, sigev_notify); + switch (sig->sigev_notify) { + case SIGEV_NONE: + break; + case SIGEV_THREAD_ID: + CP(*sig32, *sig, sigev_notify_thread_id); + /* FALLTHROUGH */ + case SIGEV_SIGNAL: + CP(*sig32, *sig, sigev_signo); + break; + case SIGEV_KEVENT: + CP(*sig32, *sig, sigev_notify_kqueue); + CP(*sig32, *sig, sigev_notify_kevent_flags); + PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr); + break; + default: + return (EINVAL); + } + return (0); +} diff --git a/sys/compat/freebsd32/freebsd32_signal.h b/sys/compat/freebsd32= /freebsd32_signal.h index d31a8ae..18899f8 100644 --- a/sys/compat/freebsd32/freebsd32_signal.h +++ b/sys/compat/freebsd32/freebsd32_signal.h @@ -97,6 +97,8 @@ struct sigevent32 { } _sigev_un; }; =20 +struct sigevent; +int convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig); void siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst); =20 #endif /* !_COMPAT_FREEBSD32_SIGNAL_H_ */ diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/sy= scalls.master index 6cb649f..daee72c 100644 --- a/sys/compat/freebsd32/syscalls.master +++ b/sys/compat/freebsd32/syscalls.master @@ -441,11 +441,17 @@ const struct timespec32 *tp); } 234 AUE_NULL STD { int freebsd32_clock_getres(clockid_t clock_id, \ struct timespec32 *tp); } -235 AUE_NULL UNIMPL timer_create -236 AUE_NULL UNIMPL timer_delete -237 AUE_NULL UNIMPL timer_settime -238 AUE_NULL UNIMPL timer_gettime -239 AUE_NULL UNIMPL timer_getoverrun +235 AUE_NULL STD { int freebsd32_ktimer_create(\ + clockid_t clock_id, \ + struct sigevent32 *evp, int *timerid); } +236 AUE_NULL NOPROTO { int ktimer_delete(int timerid); } +237 AUE_NULL STD { int freebsd32_ktimer_settime(int timerid,\ + int flags, \ + const struct itimerspec32 *value, \ + struct itimerspec32 *ovalue); } +238 AUE_NULL STD { int freebsd32_ktimer_gettime(int timerid,\ + struct itimerspec32 *value); } +239 AUE_NULL NOPROTO { int ktimer_getoverrun(int timerid); } 240 AUE_NULL STD { int freebsd32_nanosleep( \ const struct timespec32 *rqtp, \ struct timespec32 *rmtp); } @@ -476,7 +482,7 @@ struct aiocb32 *aiocbp); } 257 AUE_NULL NOSTD { int freebsd32_lio_listio(int mode, \ struct aiocb32 * const *acb_list, \ - int nent, struct sigevent *sig); } + int nent, struct sigevent32 *sig); } 258 AUE_NULL UNIMPL nosys 259 AUE_NULL UNIMPL nosys 260 AUE_NULL UNIMPL nosys @@ -825,8 +831,8 @@ const char *msg_ptr, size_t msg_len,\ unsigned msg_prio, \ const struct timespec32 *abs_timeout);} -461 AUE_NULL NOPROTO|NOSTD { int kmq_notify(int mqd, \ - const struct sigevent *sigev); } +461 AUE_NULL NOSTD { int freebsd32_kmq_notify(int mqd, \ + const struct sigevent32 *sigev); } 462 AUE_NULL NOPROTO|NOSTD { int kmq_unlink(const char *path); } 463 AUE_NULL NOPROTO { int abort2(const char *why, int nargs, void **args)= ; } 464 AUE_NULL NOPROTO { int thr_set_name(long id, const char *name); } diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 6b908a0..415188c 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -98,9 +98,6 @@ static int realtimer_settime(struct itimer *, int, static int realtimer_delete(struct itimer *); static void realtimer_clocktime(clockid_t, struct timespec *); static void realtimer_expire(void *); -static int kern_timer_create(struct thread *, clockid_t, - struct sigevent *, int *, int); -static int kern_timer_delete(struct thread *, int); =20 int register_posix_clock(int, struct kclock *); void itimer_fire(struct itimer *it); @@ -1078,20 +1075,18 @@ sys_ktimer_create(struct thread *td, struct ktimer_= create_args *uap) evp1 =3D &ev; } else evp1 =3D NULL; - - error =3D kern_timer_create(td, uap->clock_id, evp1, &id, -1); - + error =3D kern_ktimer_create(td, uap->clock_id, evp1, &id, -1); if (error =3D=3D 0) { error =3D copyout(&id, uap->timerid, sizeof(int)); if (error !=3D 0) - kern_timer_delete(td, id); + kern_ktimer_delete(td, id); } return (error); } =20 -static int -kern_timer_create(struct thread *td, clockid_t clock_id, - struct sigevent *evp, int *timerid, int preset_id) +int +kern_ktimer_create(struct thread *td, clockid_t clock_id, struct sigevent = *evp, + int *timerid, int preset_id) { struct proc *p =3D td->td_proc; struct itimer *it; @@ -1206,7 +1201,8 @@ struct ktimer_delete_args { int sys_ktimer_delete(struct thread *td, struct ktimer_delete_args *uap) { - return (kern_timer_delete(td, uap->timerid)); + + return (kern_ktimer_delete(td, uap->timerid)); } =20 static struct itimer * @@ -1228,8 +1224,8 @@ itimer_find(struct proc *p, int timerid) return (it); } =20 -static int -kern_timer_delete(struct thread *td, int timerid) +int +kern_ktimer_delete(struct thread *td, int timerid) { struct proc *p =3D td->td_proc; struct itimer *it; @@ -1271,35 +1267,40 @@ struct ktimer_settime_args { int sys_ktimer_settime(struct thread *td, struct ktimer_settime_args *uap) { - struct proc *p =3D td->td_proc; - struct itimer *it; struct itimerspec val, oval, *ovalp; int error; =20 error =3D copyin(uap->value, &val, sizeof(val)); if (error !=3D 0) return (error); -=09 - if (uap->ovalue !=3D NULL) - ovalp =3D &oval; - else - ovalp =3D NULL; + ovalp =3D uap->ovalue !=3D NULL ? &oval : NULL; + error =3D kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp); + if (error =3D=3D 0 && uap->ovalue !=3D NULL) + error =3D copyout(ovalp, uap->ovalue, sizeof(*ovalp)); + return (error); +} =20 +int +kern_ktimer_settime(struct thread *td, int timer_id, int flags, + struct itimerspec *val, struct itimerspec *oval) +{ + struct proc *p; + struct itimer *it; + int error; + + p =3D td->td_proc; PROC_LOCK(p); - if (uap->timerid < 3 || - (it =3D itimer_find(p, uap->timerid)) =3D=3D NULL) { + if (timer_id < 3 || (it =3D itimer_find(p, timer_id)) =3D=3D NULL) { PROC_UNLOCK(p); error =3D EINVAL; } else { PROC_UNLOCK(p); itimer_enter(it); - error =3D CLOCK_CALL(it->it_clockid, timer_settime, - (it, uap->flags, &val, ovalp)); + error =3D CLOCK_CALL(it->it_clockid, timer_settime, (it, + flags, val, oval)); itimer_leave(it); ITIMER_UNLOCK(it); } - if (error =3D=3D 0 && uap->ovalue !=3D NULL) - error =3D copyout(ovalp, uap->ovalue, sizeof(*ovalp)); return (error); } =20 @@ -1312,26 +1313,34 @@ struct ktimer_gettime_args { int sys_ktimer_gettime(struct thread *td, struct ktimer_gettime_args *uap) { - struct proc *p =3D td->td_proc; - struct itimer *it; struct itimerspec val; int error; =20 + error =3D kern_ktimer_gettime(td, uap->timerid, &val); + if (error =3D=3D 0) + error =3D copyout(&val, uap->value, sizeof(val)); + return (error); +} + +int +kern_ktimer_gettime(struct thread *td, int timer_id, struct itimerspec *va= l) +{ + struct proc *p; + struct itimer *it; + int error; + + p =3D td->td_proc; PROC_LOCK(p); - if (uap->timerid < 3 || - (it =3D itimer_find(p, uap->timerid)) =3D=3D NULL) { + if (timer_id < 3 || (it =3D itimer_find(p, timer_id)) =3D=3D NULL) { PROC_UNLOCK(p); error =3D EINVAL; } else { PROC_UNLOCK(p); itimer_enter(it); - error =3D CLOCK_CALL(it->it_clockid, timer_gettime, - (it, &val)); + error =3D CLOCK_CALL(it->it_clockid, timer_gettime, (it, val)); itimer_leave(it); ITIMER_UNLOCK(it); } - if (error =3D=3D 0) - error =3D copyout(&val, uap->value, sizeof(val)); return (error); } =20 @@ -1626,7 +1635,7 @@ itimers_event_hook_exit(void *arg, struct proc *p) panic("unhandled event"); for (; i < TIMER_MAX; ++i) { if ((it =3D its->its_timers[i]) !=3D NULL) - kern_timer_delete(curthread, i); + kern_ktimer_delete(curthread, i); } if (its->its_timers[0] =3D=3D NULL && its->its_timers[1] =3D=3D NULL && diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c index 73579d3..ae3f1a6 100644 --- a/sys/kern/uipc_mqueue.c +++ b/sys/kern/uipc_mqueue.c @@ -2235,10 +2235,9 @@ sys_kmq_timedsend(struct thread *td, struct kmq_time= dsend_args *uap) return (error); } =20 -int -sys_kmq_notify(struct thread *td, struct kmq_notify_args *uap) +static int +kern_kmq_notify(struct thread *td, int mqd, struct sigevent *sigev) { - struct sigevent ev; struct filedesc *fdp; struct proc *p; struct mqueue *mq; @@ -2246,34 +2245,31 @@ sys_kmq_notify(struct thread *td, struct kmq_notify= _args *uap) struct mqueue_notifier *nt, *newnt =3D NULL; int error; =20 - p =3D td->td_proc; - fdp =3D td->td_proc->p_fd; - if (uap->sigev) { - error =3D copyin(uap->sigev, &ev, sizeof(ev)); - if (error) - return (error); - if (ev.sigev_notify !=3D SIGEV_SIGNAL && - ev.sigev_notify !=3D SIGEV_THREAD_ID && - ev.sigev_notify !=3D SIGEV_NONE) + if (sigev !=3D NULL) { + if (sigev->sigev_notify !=3D SIGEV_SIGNAL && + sigev->sigev_notify !=3D SIGEV_THREAD_ID && + sigev->sigev_notify !=3D SIGEV_NONE) return (EINVAL); - if ((ev.sigev_notify =3D=3D SIGEV_SIGNAL || - ev.sigev_notify =3D=3D SIGEV_THREAD_ID) && - !_SIG_VALID(ev.sigev_signo)) + if ((sigev->sigev_notify =3D=3D SIGEV_SIGNAL || + sigev->sigev_notify =3D=3D SIGEV_THREAD_ID) && + !_SIG_VALID(sigev->sigev_signo)) return (EINVAL); } - error =3D getmq(td, uap->mqd, &fp, NULL, &mq); + p =3D td->td_proc; + fdp =3D td->td_proc->p_fd; + error =3D getmq(td, mqd, &fp, NULL, &mq); if (error) return (error); again: FILEDESC_SLOCK(fdp); - fp2 =3D fget_locked(fdp, uap->mqd); + fp2 =3D fget_locked(fdp, mqd); if (fp2 =3D=3D NULL) { FILEDESC_SUNLOCK(fdp); error =3D EBADF; goto out; } #ifdef CAPABILITIES - error =3D cap_check(cap_rights(fdp, uap->mqd), CAP_POLL_EVENT); + error =3D cap_check(cap_rights(fdp, mqd), CAP_POLL_EVENT); if (error) { FILEDESC_SUNLOCK(fdp); goto out; @@ -2286,12 +2282,12 @@ again: } mtx_lock(&mq->mq_mutex); FILEDESC_SUNLOCK(fdp); - if (uap->sigev !=3D NULL) { + if (sigev !=3D NULL) { if (mq->mq_notifier !=3D NULL) { error =3D EBUSY; } else { PROC_LOCK(p); - nt =3D notifier_search(p, uap->mqd); + nt =3D notifier_search(p, mqd); if (nt =3D=3D NULL) { if (newnt =3D=3D NULL) { PROC_UNLOCK(p); @@ -2314,10 +2310,10 @@ again: nt->nt_ksi.ksi_flags |=3D KSI_INS | KSI_EXT; nt->nt_ksi.ksi_code =3D SI_MESGQ; nt->nt_proc =3D p; - nt->nt_ksi.ksi_mqd =3D uap->mqd; + nt->nt_ksi.ksi_mqd =3D mqd; notifier_insert(p, nt); } - nt->nt_sigev =3D ev; + nt->nt_sigev =3D *sigev; mq->mq_notifier =3D nt; PROC_UNLOCK(p); /* @@ -2330,7 +2326,7 @@ again: mqueue_send_notification(mq); } } else { - notifier_remove(p, mq, uap->mqd); + notifier_remove(p, mq, mqd); } mtx_unlock(&mq->mq_mutex); =20 @@ -2341,6 +2337,20 @@ out: return (error); } =20 +int +sys_kmq_notify(struct thread *td, struct kmq_notify_args *uap) +{ + struct sigevent ev; + int error; + + if (uap->sigev !=3D NULL) { + error =3D copyin(uap->sigev, &ev, sizeof(ev)); + if (error !=3D 0) + return (error); + } + return (kern_kmq_notify(td, uap->mqd, &ev)); +} + static void mqueue_fdclose(struct thread *td, int fd, struct file *fp) { @@ -2637,6 +2647,7 @@ static struct syscall_helper_data mq_syscalls[] =3D { #ifdef COMPAT_FREEBSD32 #include #include +#include #include #include =20 @@ -2763,12 +2774,30 @@ freebsd32_kmq_timedreceive(struct thread *td, return (error); } =20 +int +freebsd32_kmq_notify(struct thread *td, struct freebsd32_kmq_notify_args *= uap) +{ + struct sigevent ev; + struct sigevent32 ev32; + int error; + + if (uap->sigev !=3D NULL) { + error =3D copyin(uap->sigev, &ev32, sizeof(ev32)); + if (error !=3D 0) + return (error); + error =3D convert_sigevent32(&ev32, &ev); + if (error !=3D 0) + return (error); + } + return (kern_kmq_notify(td, uap->mqd, &ev)); +} + static struct syscall_helper_data mq32_syscalls[] =3D { SYSCALL32_INIT_HELPER(freebsd32_kmq_open), SYSCALL32_INIT_HELPER(freebsd32_kmq_setattr), SYSCALL32_INIT_HELPER(freebsd32_kmq_timedsend), SYSCALL32_INIT_HELPER(freebsd32_kmq_timedreceive), - SYSCALL32_INIT_HELPER_COMPAT(kmq_notify), + SYSCALL32_INIT_HELPER(freebsd32_kmq_notify), SYSCALL32_INIT_HELPER_COMPAT(kmq_unlink), SYSCALL_INIT_LAST }; diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 5fb9341..862443c 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -2755,31 +2755,6 @@ aiocb32_copyin_old_sigevent(struct aiocb *ujob, stru= ct aiocb *kjob) } =20 static int -convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig) -{ - - CP(*sig32, *sig, sigev_notify); - switch (sig->sigev_notify) { - case SIGEV_NONE: - break; - case SIGEV_THREAD_ID: - CP(*sig32, *sig, sigev_notify_thread_id); - /* FALLTHROUGH */ - case SIGEV_SIGNAL: - CP(*sig32, *sig, sigev_signo); - break; - case SIGEV_KEVENT: - CP(*sig32, *sig, sigev_notify_kqueue); - CP(*sig32, *sig, sigev_notify_kevent_flags); - PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr); - break; - default: - return (EINVAL); - } - return (0); -} - -static int aiocb32_copyin(struct aiocb *ujob, struct aiocb *kjob) { struct aiocb32 job32; diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 75278c3..e18c735 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -228,6 +228,13 @@ int kern_symlink(struct thread *td, char *path, char *= link, enum uio_seg segflg); int kern_symlinkat(struct thread *td, char *path1, int fd, char *path2, enum uio_seg segflg); +int kern_ktimer_create(struct thread *td, clockid_t clock_id, + struct sigevent *evp, int *timerid, int preset_id); +int kern_ktimer_delete(struct thread *, int); +int kern_ktimer_settime(struct thread *td, int timer_id, int flags, + struct itimerspec *val, struct itimerspec *oval); +int kern_ktimer_gettime(struct thread *td, int timer_id, + struct itimerspec *val); int kern_thr_new(struct thread *td, struct thr_param *param); int kern_thr_suspend(struct thread *td, struct timespec *tsp); int kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, --2NSZC26AJDpFITwK Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJR6tDrAAoJEJDCuSvBvK1BvcYP/R6m82mifGFauZkLBjpKWQGp 25g/h6oDG4T3NOh3YUM6Uvi3/i2PubHgZYcjEX82BwFHZ5AHtdZ+E2RY3C7J0/jX ewKCGi5AqpNK/Akalzry9cs+4JbYXTxgiLtfxAs9ad2sBZtBqRSpotiMnEN+N1Jl SpDdjzAQB5DJVjxtCwl5rdX0SEOeyH/jToBjQon73P/ZJWe1g693w35KGD5+IRW0 ics0rx8R+OM2aeRwFNc0VJvHnrQ5vhZ/K5w7C+Omqp5KipvCMvvPN9pBQgByydsB HsHXYoQVgWjsYeHxDBwSL/bQOK65/UnlSkXARtYQOwHqIBIu2LRRubbIjBFquSIP dd1UcfJv8/GunmGmxD3Ho3qHvIdbtv/rrQZbP5GVihA6b4dWWsBj3XgA9DQb12Fa Tjti4siMdtAMaSqkcQ8iwCaarjfvtKCVtDkt5KL+POEpzAPQdCXhHwrs8rmagdY1 ty/5S59mew8GQKiFgemZXdb8L0GjCPWUUorv/6fsLtxcPx+ZkQmQyvKV/Omfmqgl uTzmqPt64l+jEjQN4uy+e3Dt201Dte+oSD+Rkm53sRN3xirrFNNkSXWJUEzVAbMh TS9d0tettcQzf7kYfHh7CY5x+prJ4RW9oyZbdCndRbuK6S/R+TJZZQ07b+hvz485 nzTR4BSm4h16TPgvaETC =1swq -----END PGP SIGNATURE----- --2NSZC26AJDpFITwK-- From owner-freebsd-threads@FreeBSD.ORG Sat Jul 20 20:10:02 2013 Return-Path: Delivered-To: freebsd-threads@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 2D86B36F for ; Sat, 20 Jul 2013 20:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 067DA215 for ; Sat, 20 Jul 2013 20:10:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6KKA1Kj024906 for ; Sat, 20 Jul 2013 20:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6KKA1Y7024905; Sat, 20 Jul 2013 20:10:01 GMT (envelope-from gnats) Date: Sat, 20 Jul 2013 20:10:01 GMT Message-Id: <201307202010.r6KKA1Y7024905@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org Cc: From: Petr Salinger Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Petr Salinger List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jul 2013 20:10:02 -0000 The following reply was made to PR threads/180652; it has been noted by GNATS. From: Petr Salinger To: Konstantin Belousov Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: threads/180652: compat32 problem in clock_getcpuclockid2 Date: Sat, 20 Jul 2013 22:08:45 +0200 (CEST) > I only tested with adapted tst-timer2.c. I hope you would do the rest. I tried. The tst-timer4.c timed out. I will look at it later. Petr