From owner-freebsd-emulation@FreeBSD.ORG Sun Oct 12 13:47:56 2014 Return-Path: Delivered-To: freebsd-emulation@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7E2DB2A6 for ; Sun, 12 Oct 2014 13:47:56 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (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 6494AA2E for ; Sun, 12 Oct 2014 13:47:56 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.9/8.14.9) with ESMTP id s9CDlu9J064584 for ; Sun, 12 Oct 2014 13:47:56 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-emulation@FreeBSD.org Subject: [Bug 192842] [patch][linux] linux_ppoll syscall required by linux apps that use pulseaudio (on linux_base-f20) Date: Sun, 12 Oct 2014 13:47:56 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: mjg@FreeBSD.org X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-emulation@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Oct 2014 13:47:56 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192842 Mateusz Guzik changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mjg@FreeBSD.org --- Comment #6 from Mateusz Guzik --- +linux_ppoll(struct thread *td, struct linux_ppoll_args *pargs) +{ + struct l_timespec lts; + struct timeval tv, *tvp, tv0, tv1; + struct poll_args pa; + sigset_t usigmask, *usigmaskp; + l_sigset_t lsigmask; + int error, retval, mss, msns; error and retval? + + /* Get the time */ + if (pargs->timeout_ts != NULL) + { style + error = copyin(pargs->timeout_ts, <s, sizeof(lts)); + if (error != 0) + return (error); + + TIMESPEC_TO_TIMEVAL(&tv, <s); + if (itimerfix(&tv)) + return (EINVAL); + + /* Mark the time before the call */ + microtime(&tv0); + tvp = &tv; + } else + tvp = NULL; + + /* Get the sigmask */ + if (pargs->sigmask != NULL) { + error = copyin(pargs->sigmask, &lsigmask, sizeof(lsigmask)); + if (error) + return (error); + linux_to_bsd_sigset(&lsigmask, &usigmask); + usigmaskp = &usigmask; + } else + usigmaskp = NULL; + + /* Set the sigmask */ + error = kern_sigprocmask (td, SIG_SETMASK, usigmaskp, &td->td_oldsigmask, 0); + if (error) + return (error); + + pa.fds = pargs->fds; + pa.nfds = pargs->nfds; + + /* Linux's ppoll allows NULL timeout which is translated to FreeBSD's INFTIM (-1) */ + if (tvp==NULL) + pa.timeout = INFTIM; + else + { style + mss = tvp->tv_sec * 1000; + msns = tvp->tv_usec / 1000; + + /* + * Handling the multiplication and addition overflow. + * If it happens, assing pa.timeout the INT_MAX value + */ + if (mss/1000 == tvp->tv_sec) { + pa.timeout = mss + msns; + if ( pa.timeout < 0) + pa.timeout = INT_MAX; + } else + pa.timeout = INT_MAX; + } + + /* + * Ensure that the td_oldsigmask is restored by ast() + * when returns to user mode and that the TDP_OLDMASK + * is cleared + */ + td->td_pflags |= TDP_OLDMASK; + thread_lock(td); + td->td_flags |= TDF_ASTPENDING; + thread_unlock(td); Why was not this done immediately after kern_sigprocmask? Also, this would benefit from kern_ppoll helper. Given that pselect has similar code, maybe an additional helper should be introduced. + + /* call sys_poll */ + retval = sys_poll(td, &pa); + + if (retval == 0 && pargs->timeout_ts) { + if (td->td_retval[0]) { + /* + * Compute how much time was left of the timeout, + * by subtracting the current time and the time + * before we started the call, and subtracting + * that result from the user-supplied value. + */ + microtime(&tv1); + timevalsub(&tv1, &tv0); + timevalsub(&tv, &tv1); + if (tv.tv_sec < 0) + timevalclear(&tv); + } else + timevalclear(&tv); + + TIMEVAL_TO_TIMESPEC(&tv, <s); + + error = copyout(<s, pargs->timeout_ts, sizeof(lts)); + if (error) + return (error); + } + return retval; +} + +int -- You are receiving this mail because: You are the assignee for the bug.