From 3f3bd10104550243781f0b4d9248975e35d91ac7 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 22 Aug 2014 09:21:33 +0000 Subject: * Throughout, use __try/__except/__endtry blocks, rather than myfault handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate. --- winsup/cygwin/timer.cc | 201 +++++++++++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 91 deletions(-) (limited to 'winsup/cygwin/timer.cc') diff --git a/winsup/cygwin/timer.cc b/winsup/cygwin/timer.cc index b1c6e27aa..bfa1495f6 100644 --- a/winsup/cygwin/timer.cc +++ b/winsup/cygwin/timer.cc @@ -1,6 +1,6 @@ /* timer.cc - Copyright 2004, 2005, 2006, 2008, 2010, 2011, 2012, 2013 Red Hat, Inc. + Copyright 2004, 2005, 2006, 2008, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc. This file is part of Cygwin. @@ -219,45 +219,49 @@ it_bad (const timespec& t) int timer_tracker::settime (int in_flags, const itimerspec *value, itimerspec *ovalue) { - if (!value) + int ret = -1; + + __try { - set_errno (EINVAL); - return -1; - } + if (!value) + { + set_errno (EINVAL); + __leave; + } - myfault efault; - if (efault.faulted (EFAULT) - || it_bad (value->it_value) - || it_bad (value->it_interval)) - return -1; + if (it_bad (value->it_value) || it_bad (value->it_interval)) + __leave; - long long now = in_flags & TIMER_ABSTIME ? 0 : gtod.usecs (); + long long now = in_flags & TIMER_ABSTIME ? 0 : gtod.usecs (); - lock_timer_tracker here; - cancel (); + lock_timer_tracker here; + cancel (); - if (ovalue) - gettime (ovalue); + if (ovalue) + gettime (ovalue); - if (!value->it_value.tv_sec && !value->it_value.tv_nsec) - interval_us = sleepto_us = 0; - else - { - sleepto_us = now + to_us (value->it_value); - interval_us = to_us (value->it_interval); - it_interval = value->it_interval; - if (!hcancel) - hcancel = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); - else - ResetEvent (hcancel); - if (!syncthread) - syncthread = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); + if (!value->it_value.tv_sec && !value->it_value.tv_nsec) + interval_us = sleepto_us = 0; else - ResetEvent (syncthread); - new cygthread (timer_thread, this, "itimer", syncthread); + { + sleepto_us = now + to_us (value->it_value); + interval_us = to_us (value->it_interval); + it_interval = value->it_interval; + if (!hcancel) + hcancel = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); + else + ResetEvent (hcancel); + if (!syncthread) + syncthread = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); + else + ResetEvent (syncthread); + new cygthread (timer_thread, this, "itimer", syncthread); + } + ret = 0; } - - return 0; + __except (EFAULT) {} + __endtry + return ret; } void @@ -280,43 +284,51 @@ timer_tracker::gettime (itimerspec *ovalue) extern "C" int timer_gettime (timer_t timerid, struct itimerspec *ovalue) { - myfault efault; - if (efault.faulted (EFAULT)) - return -1; + int ret = -1; - timer_tracker *tt = (timer_tracker *) timerid; - if (tt->magic != TT_MAGIC) + __try { - set_errno (EINVAL); - return -1; - } + timer_tracker *tt = (timer_tracker *) timerid; + if (tt->magic != TT_MAGIC) + { + set_errno (EINVAL); + return -1; + } - tt->gettime (ovalue); - return 0; + tt->gettime (ovalue); + ret = 0; + } + __except (EFAULT) {} + __endtry + return ret; } extern "C" int timer_create (clockid_t clock_id, struct sigevent *__restrict evp, timer_t *__restrict timerid) { - myfault efault; - if (efault.faulted (EFAULT)) - return -1; + int ret = -1; - if (CLOCKID_IS_PROCESS (clock_id) || CLOCKID_IS_THREAD (clock_id)) + __try { - set_errno (ENOTSUP); - return -1; - } + if (CLOCKID_IS_PROCESS (clock_id) || CLOCKID_IS_THREAD (clock_id)) + { + set_errno (ENOTSUP); + return -1; + } - if (clock_id != CLOCK_REALTIME) - { - set_errno (EINVAL); - return -1; - } + if (clock_id != CLOCK_REALTIME) + { + set_errno (EINVAL); + return -1; + } - *timerid = (timer_t) new timer_tracker (clock_id, evp); - return 0; + *timerid = (timer_t) new timer_tracker (clock_id, evp); + ret = 0; + } + __except (EFAULT) {} + __endtry + return ret; } extern "C" int @@ -324,42 +336,52 @@ timer_settime (timer_t timerid, int flags, const struct itimerspec *__restrict value, struct itimerspec *__restrict ovalue) { - timer_tracker *tt = (timer_tracker *) timerid; - myfault efault; - if (efault.faulted (EFAULT)) - return -1; - if (tt->magic != TT_MAGIC) + int ret = -1; + + __try { - set_errno (EINVAL); - return -1; + timer_tracker *tt = (timer_tracker *) timerid; + if (tt->magic != TT_MAGIC) + { + set_errno (EINVAL); + __leave; + } + ret = tt->settime (flags, value, ovalue); } - - return tt->settime (flags, value, ovalue); + __except (EFAULT) {} + __endtry + return ret; } extern "C" int timer_delete (timer_t timerid) { - timer_tracker *in_tt = (timer_tracker *) timerid; - myfault efault; - if (efault.faulted (EFAULT)) - return -1; - if (in_tt->magic != TT_MAGIC) + int ret = -1; + + __try { + timer_tracker *in_tt = (timer_tracker *) timerid; + if (in_tt->magic != TT_MAGIC) + { + set_errno (EINVAL); + __leave; + } + + lock_timer_tracker here; + for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next) + if (tt->next == in_tt) + { + tt->next = in_tt->next; + delete in_tt; + ret = 0; + __leave; + } set_errno (EINVAL); - return -1; + ret = 0; } - - lock_timer_tracker here; - for (timer_tracker *tt = &ttstart; tt->next != NULL; tt = tt->next) - if (tt->next == in_tt) - { - tt->next = in_tt->next; - delete in_tt; - return 0; - } - set_errno (EINVAL); - return 0; + __except (EFAULT) {} + __endtry + return ret; } void @@ -412,18 +434,13 @@ setitimer (int which, const struct itimerval *__restrict value, extern "C" int getitimer (int which, struct itimerval *ovalue) { - int ret; + int ret = -1; + if (which != ITIMER_REAL) - { - set_errno (EINVAL); - ret = -1; - } + set_errno (EINVAL); else { - myfault efault; - if (efault.faulted (EFAULT)) - ret = -1; - else + __try { struct itimerspec spec_ovalue; ret = timer_gettime ((timer_t) &ttstart, &spec_ovalue); @@ -435,6 +452,8 @@ getitimer (int which, struct itimerval *ovalue) ovalue->it_value.tv_usec = spec_ovalue.it_value.tv_nsec / 1000; } } + __except (EFAULT) {} + __endtry } syscall_printf ("%R = getitimer()", ret); return ret; -- cgit v1.2.3