diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-03 21:25:26 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-03 21:25:26 +0000 |
commit | 62a314e56fbfbf90e89462166e63aff6715fa3b0 (patch) | |
tree | 39ef4016af38b3d03f3e96621d79767a1aeef6bc /base/message_loop | |
parent | f88d7e8756f4672b95145590b75b1277c9ac1faa (diff) | |
download | chromium_src-62a314e56fbfbf90e89462166e63aff6715fa3b0.zip chromium_src-62a314e56fbfbf90e89462166e63aff6715fa3b0.tar.gz chromium_src-62a314e56fbfbf90e89462166e63aff6715fa3b0.tar.bz2 |
removing SEH exception restoration #2
The only real caller was the NPAPI plugin code trying to
prevent flash 9 from stealing the unhandled exception handler.
The need for that is long gone.
This is a followup of
https://codereview.chromium.org/122553003/
TBR=mark
BUG=none
Review URL: https://codereview.chromium.org/122583004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242926 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop')
-rw-r--r-- | base/message_loop/message_loop.cc | 51 | ||||
-rw-r--r-- | base/message_loop/message_loop.h | 24 | ||||
-rw-r--r-- | base/message_loop/message_loop_test.cc | 33 | ||||
-rw-r--r-- | base/message_loop/message_loop_test.h | 4 | ||||
-rw-r--r-- | base/message_loop/message_loop_unittest.cc | 126 |
5 files changed, 1 insertions, 237 deletions
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc index 52948e0..712fcfa 100644 --- a/base/message_loop/message_loop.cc +++ b/base/message_loop/message_loop.cc @@ -102,28 +102,6 @@ bool AlwaysNotifyPump(MessageLoop::Type type) { //------------------------------------------------------------------------------ -#if defined(OS_WIN) - -// Upon a SEH exception in this thread, it restores the original unhandled -// exception filter. -static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) { - ::SetUnhandledExceptionFilter(old_filter); - return EXCEPTION_CONTINUE_SEARCH; -} - -// Retrieves a pointer to the current unhandled exception filter. There -// is no standalone getter method. -static LPTOP_LEVEL_EXCEPTION_FILTER GetTopSEHFilter() { - LPTOP_LEVEL_EXCEPTION_FILTER top_filter = NULL; - top_filter = ::SetUnhandledExceptionFilter(0); - ::SetUnhandledExceptionFilter(top_filter); - return top_filter; -} - -#endif // defined(OS_WIN) - -//------------------------------------------------------------------------------ - MessageLoop::TaskObserver::TaskObserver() { } @@ -137,7 +115,6 @@ MessageLoop::DestructionObserver::~DestructionObserver() { MessageLoop::MessageLoop(Type type) : type_(type), - exception_restoration_(false), nestable_tasks_allowed_(true), #if defined(OS_WIN) os_modal_loop_(false), @@ -152,7 +129,6 @@ MessageLoop::MessageLoop(Type type) MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) : pump_(pump.Pass()), type_(TYPE_CUSTOM), - exception_restoration_(false), nestable_tasks_allowed_(true), #if defined(OS_WIN) os_modal_loop_(false), @@ -405,34 +381,7 @@ void MessageLoop::Init() { new ThreadTaskRunnerHandle(message_loop_proxy_)); } -// Runs the loop in two different SEH modes: -// enable_SEH_restoration_ = false : any unhandled exception goes to the last -// one that calls SetUnhandledExceptionFilter(). -// enable_SEH_restoration_ = true : any unhandled exception goes to the filter -// that was existed before the loop was run. void MessageLoop::RunHandler() { -#if defined(OS_WIN) - if (exception_restoration_) { - RunInternalInSEHFrame(); - return; - } -#endif - - RunInternal(); -} - -#if defined(OS_WIN) -__declspec(noinline) void MessageLoop::RunInternalInSEHFrame() { - LPTOP_LEVEL_EXCEPTION_FILTER current_filter = GetTopSEHFilter(); - __try { - RunInternal(); - } __except(SEHFilter(current_filter)) { - } - return; -} -#endif - -void MessageLoop::RunInternal() { DCHECK_EQ(this, current()); StartHistogrammer(); diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h index 29e0f7e..f4ed5a1 100644 --- a/base/message_loop/message_loop.h +++ b/base/message_loop/message_loop.h @@ -359,14 +359,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { bool old_state_; }; - // Enables or disables the restoration during an exception of the unhandled - // exception filter that was active when Run() was called. This can happen - // if some third party code call SetUnhandledExceptionFilter() and never - // restores the previous filter. - void set_exception_restoration(bool restore) { - exception_restoration_ = restore; - } - // Returns true if we are currently running a nested message loop. bool IsNested(); @@ -446,21 +438,9 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { // Configures various members for the two constructors. void Init(); - // A function to encapsulate all the exception handling capability in the - // stacks around the running of a main message loop. It will run the message - // loop in a SEH try block or not depending on the set_SEH_restoration() - // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). + // Invokes the actual run loop using the message pump. void RunHandler(); -#if defined(OS_WIN) - __declspec(noinline) void RunInternalInSEHFrame(); -#endif - - // A surrounding stack frame around the running of the message loop that - // supports all saving and restoring of state, as is needed for any/all (ugly) - // recursive calls. - void RunInternal(); - // Called to process any delayed non-nestable tasks. bool ProcessNextDelayedNonNestableTask(); @@ -527,8 +507,6 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { ObserverList<DestructionObserver> destruction_observers_; - bool exception_restoration_; - // A recursion block that prevents accidentally running additional tasks when // insider a (accidentally induced?) nested message pump. bool nestable_tasks_allowed_; diff --git a/base/message_loop/message_loop_test.cc b/base/message_loop/message_loop_test.cc index f39845d..eca6c8f 100644 --- a/base/message_loop/message_loop_test.cc +++ b/base/message_loop/message_loop_test.cc @@ -114,39 +114,6 @@ void RunTest_PostTask(MessagePumpFactory factory) { EXPECT_EQ(foo->result(), "abacad"); } -void RunTest_PostTask_SEH(MessagePumpFactory factory) { - scoped_ptr<MessagePump> pump(factory()); - MessageLoop loop(pump.Pass()); - - // Add tests to message loop - scoped_refptr<Foo> foo(new Foo()); - std::string a("a"), b("b"), c("c"), d("d"); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test0, foo.get())); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test1ConstRef, foo.get(), a)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test1Ptr, foo.get(), &b)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test1Int, foo.get(), 100)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test2Ptr, foo.get(), &a, &c)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test2Mixed, foo.get(), a, &d)); - - // After all tests, post a message that will shut down the message loop - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &MessageLoop::Quit, Unretained(MessageLoop::current()))); - - // Now kick things off with the SEH block active. - MessageLoop::current()->set_exception_restoration(true); - MessageLoop::current()->Run(); - MessageLoop::current()->set_exception_restoration(false); - - EXPECT_EQ(foo->test_count(), 105); - EXPECT_EQ(foo->result(), "abacad"); -} - void RunTest_PostDelayedTask_Basic(MessagePumpFactory factory) { scoped_ptr<MessagePump> pump(factory()); MessageLoop loop(pump.Pass()); diff --git a/base/message_loop/message_loop_test.h b/base/message_loop/message_loop_test.h index 5d1a4f5..3d9889c 100644 --- a/base/message_loop/message_loop_test.h +++ b/base/message_loop/message_loop_test.h @@ -19,7 +19,6 @@ namespace test { typedef MessageLoop::MessagePumpFactory MessagePumpFactory; void RunTest_PostTask(MessagePumpFactory factory); -void RunTest_PostTask_SEH(MessagePumpFactory factory); void RunTest_PostDelayedTask_Basic(MessagePumpFactory factory); void RunTest_PostDelayedTask_InDelayOrder(MessagePumpFactory factory); void RunTest_PostDelayedTask_InPostOrder(MessagePumpFactory factory); @@ -52,9 +51,6 @@ void RunTest_RecursivePosts(MessagePumpFactory factory); TEST(MessageLoopTestType##id, PostTask) { \ base::test::RunTest_PostTask(factory); \ } \ - TEST(MessageLoopTestType##id, PostTask_SEH) { \ - base::test::RunTest_PostTask_SEH(factory); \ - } \ TEST(MessageLoopTestType##id, PostDelayedTask_Basic) { \ base::test::RunTest_PostDelayedTask_Basic(factory); \ } \ diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc index e6d25ece..64cf7c8 100644 --- a/base/message_loop/message_loop_unittest.cc +++ b/base/message_loop/message_loop_unittest.cc @@ -167,120 +167,6 @@ void RunTest_PostDelayedTask_SharedTimer_SubPump() { EXPECT_TRUE(run_time.is_null()); } -LONG WINAPI BadExceptionHandler(EXCEPTION_POINTERS *ex_info) { - ADD_FAILURE() << "bad exception handler"; - ::ExitProcess(ex_info->ExceptionRecord->ExceptionCode); - return EXCEPTION_EXECUTE_HANDLER; -} - -// This task throws an SEH exception: initially write to an invalid address. -// If the right SEH filter is installed, it will fix the error. -class Crasher : public RefCounted<Crasher> { - public: - // Ctor. If trash_SEH_handler is true, the task will override the unhandled - // exception handler with one sure to crash this test. - explicit Crasher(bool trash_SEH_handler) - : trash_SEH_handler_(trash_SEH_handler) { - } - - void Run() { - PlatformThread::Sleep(TimeDelta::FromMilliseconds(1)); - if (trash_SEH_handler_) - ::SetUnhandledExceptionFilter(&BadExceptionHandler); - // Generate a SEH fault. We do it in asm to make sure we know how to undo - // the damage. - -#if defined(_M_IX86) - - __asm { - mov eax, dword ptr [Crasher::bad_array_] - mov byte ptr [eax], 66 - } - -#elif defined(_M_X64) - - bad_array_[0] = 66; - -#else -#error "needs architecture support" -#endif - - MessageLoop::current()->QuitWhenIdle(); - } - // Points the bad array to a valid memory location. - static void FixError() { - bad_array_ = &valid_store_; - } - - private: - bool trash_SEH_handler_; - static volatile char* bad_array_; - static char valid_store_; -}; - -volatile char* Crasher::bad_array_ = 0; -char Crasher::valid_store_ = 0; - -// This SEH filter fixes the problem and retries execution. Fixing requires -// that the last instruction: mov eax, [Crasher::bad_array_] to be retried -// so we move the instruction pointer 5 bytes back. -LONG WINAPI HandleCrasherException(EXCEPTION_POINTERS *ex_info) { - if (ex_info->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) - return EXCEPTION_EXECUTE_HANDLER; - - Crasher::FixError(); - -#if defined(_M_IX86) - - ex_info->ContextRecord->Eip -= 5; - -#elif defined(_M_X64) - - ex_info->ContextRecord->Rip -= 5; - -#endif - - return EXCEPTION_CONTINUE_EXECUTION; -} - -void RunTest_Crasher(MessageLoop::Type message_loop_type) { - MessageLoop loop(message_loop_type); - - if (::IsDebuggerPresent()) - return; - - LPTOP_LEVEL_EXCEPTION_FILTER old_SEH_filter = - ::SetUnhandledExceptionFilter(&HandleCrasherException); - - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&Crasher::Run, new Crasher(false))); - MessageLoop::current()->set_exception_restoration(true); - MessageLoop::current()->Run(); - MessageLoop::current()->set_exception_restoration(false); - - ::SetUnhandledExceptionFilter(old_SEH_filter); -} - -void RunTest_CrasherNasty(MessageLoop::Type message_loop_type) { - MessageLoop loop(message_loop_type); - - if (::IsDebuggerPresent()) - return; - - LPTOP_LEVEL_EXCEPTION_FILTER old_SEH_filter = - ::SetUnhandledExceptionFilter(&HandleCrasherException); - - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&Crasher::Run, new Crasher(true))); - MessageLoop::current()->set_exception_restoration(true); - MessageLoop::current()->Run(); - MessageLoop::current()->set_exception_restoration(false); - - ::SetUnhandledExceptionFilter(old_SEH_filter); -} - const wchar_t kMessageBoxTitle[] = L"MessageLoop Unit Test"; enum TaskType { @@ -781,18 +667,6 @@ TEST(MessageLoopTest, PostDelayedTask_SharedTimer_SubPump) { RunTest_PostDelayedTask_SharedTimer_SubPump(); } -TEST(MessageLoopTest, Crasher) { - RunTest_Crasher(MessageLoop::TYPE_DEFAULT); - RunTest_Crasher(MessageLoop::TYPE_UI); - RunTest_Crasher(MessageLoop::TYPE_IO); -} - -TEST(MessageLoopTest, CrasherNasty) { - RunTest_CrasherNasty(MessageLoop::TYPE_DEFAULT); - RunTest_CrasherNasty(MessageLoop::TYPE_UI); - RunTest_CrasherNasty(MessageLoop::TYPE_IO); -} - // This test occasionally hangs http://crbug.com/44567 TEST(MessageLoopTest, DISABLED_RecursiveDenial2) { RunTest_RecursiveDenial2(MessageLoop::TYPE_DEFAULT); |