From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25413 invoked by alias); 16 Jan 2019 17:41:06 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 25297 invoked by uid 9078); 16 Jan 2019 17:41:04 -0000 Date: Wed, 16 Jan 2019 17:41:00 -0000 Message-ID: <20190116174104.25294.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: timerfd: implement execve semantics X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 4195bae67f19b02e860678c8d2c2db3eddd4276a X-Git-Newrev: 0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef X-SW-Source: 2019-q1/txt/msg00064.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef commit 0e8c7b8689d18b75371ee3411a3ac68ed37fa3ef Author: Corinna Vinschen Date: Wed Jan 16 18:40:26 2019 +0100 Cygwin: timerfd: implement execve semantics Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler_timerfd.cc | 9 +++++++-- winsup/cygwin/timer.cc | 28 +++++++++++++++++----------- winsup/cygwin/timer.h | 6 ++++-- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/fhandler_timerfd.cc b/winsup/cygwin/fhandler_timerfd.cc index 8ce91af..cbcbefd 100644 --- a/winsup/cygwin/fhandler_timerfd.cc +++ b/winsup/cygwin/fhandler_timerfd.cc @@ -161,10 +161,15 @@ fhandler_timerfd::dup (fhandler_base *child, int flags) void fhandler_timerfd::fixup_after_exec () { - if (!close_on_exec ()) + if (close_on_exec ()) + return; + __try { - /* TODO after exec */ + timer_tracker *tt = (timer_tracker *) timerid; + tt->fixup_after_exec (); } + __except (EFAULT) {} + __endtry } int diff --git a/winsup/cygwin/timer.cc b/winsup/cygwin/timer.cc index bd412f0..be3fcf7 100644 --- a/winsup/cygwin/timer.cc +++ b/winsup/cygwin/timer.cc @@ -108,16 +108,6 @@ timer_tracker::timer_tracker (clockid_t c, const sigevent *e, bool fd) } } -void timer_tracker::increment_instances () -{ - InterlockedIncrement (&instance_count); -} - -LONG timer_tracker::decrement_instances () -{ - return InterlockedDecrement (&instance_count); -} - static inline int64_t timespec_to_us (const timespec& ts) { @@ -152,7 +142,6 @@ timer_tracker::_disarm_event () yield (); if (ret == EVENT_ARMED) { - InterlockedExchange64 (&overrun_count_curr, overrun_count); ret = overrun_count_curr; InterlockedExchange64 (&overrun_count, 0); @@ -461,6 +450,23 @@ timer_tracker::restart () } } +/* Only called from fhandler_timerfd::fixup_after_exec. Note that + we don't touch the instance count. This is handled by closing + the timer from fhandler_timerfd::close on O_CLOEXEC. Ultimately + the instance count should be correct after execve. */ +void +timer_tracker::fixup_after_exec () +{ + lock_timer_tracker here; + /* Check if timer is already in the list. If so, skip it. */ + for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next) + if (tt->next == this) + return; + next = ttstart.next; + ttstart.next = this; + restart (); +} + void timer_tracker::fixup_after_fork () { diff --git a/winsup/cygwin/timer.h b/winsup/cygwin/timer.h index f4c89bc..3b426a3 100644 --- a/winsup/cygwin/timer.h +++ b/winsup/cygwin/timer.h @@ -30,7 +30,7 @@ class timer_tracker LONG64 overrun_count; bool cancel (); - LONG decrement_instances (); + LONG decrement_instances () { return InterlockedDecrement (&instance_count); } int clean_and_unhook (); LONG64 _disarm_event (); void restart (); @@ -45,7 +45,8 @@ class timer_tracker ~timer_tracker (); inline bool is_timer_tracker () const { return magic == TT_MAGIC; } - void increment_instances (); + + void increment_instances () { InterlockedIncrement (&instance_count); } LONG64 wait (bool nonblocking); HANDLE get_timerfd_handle () const { return timerfd_event; } @@ -58,6 +59,7 @@ class timer_tracker unsigned int disarm_event (); DWORD thread_func (); + void fixup_after_exec (); static void fixup_after_fork (); static int close (timer_tracker *tt); };