Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/mac/exception_processor.mm

Issue 2649253003: [Mac] Sinkhole __NSFireDelayedPerform and _CFXNotificationPost in the exception preprocessor. (Closed)
Patch Set: DVLOG Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/mac/exception_processor_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/mac/exception_processor.h" 5 #import "chrome/browser/mac/exception_processor.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include <libunwind.h> 9 #include <libunwind.h>
10 #include <objc/objc-exception.h> 10 #include <objc/objc-exception.h>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 void RecordExceptionWithUma(NSException* exception) { 73 void RecordExceptionWithUma(NSException* exception) {
74 UMA_HISTOGRAM_ENUMERATION("OSX.NSException", 74 UMA_HISTOGRAM_ENUMERATION("OSX.NSException",
75 BinForException(exception), kUnknownNSException); 75 BinForException(exception), kUnknownNSException);
76 } 76 }
77 77
78 static objc_exception_preprocessor g_next_preprocessor = nullptr; 78 static objc_exception_preprocessor g_next_preprocessor = nullptr;
79 79
80 static const char* const kExceptionSinkholes[] = { 80 static const char* const kExceptionSinkholes[] = {
81 "CFRunLoopRunSpecific", 81 "CFRunLoopRunSpecific",
82 "_CFXNotificationPost",
82 "_dispatch_client_callout", 83 "_dispatch_client_callout",
84 "__NSFireDelayedPerform",
83 }; 85 };
84 86
85 // This function is used to make it clear to the crash processor that this is 87 // This function is used to make it clear to the crash processor that this is
86 // a forced exception crash. 88 // a forced exception crash.
87 static NOINLINE void TERMINATING_FROM_UNCAUGHT_NSEXCEPTION(id exception) { 89 static NOINLINE void TERMINATING_FROM_UNCAUGHT_NSEXCEPTION(id exception) {
88 NSString* exception_message_ns = [NSString 90 NSString* exception_message_ns = [NSString
89 stringWithFormat:@"%@: %@", [exception name], [exception reason]]; 91 stringWithFormat:@"%@: %@", [exception name], [exception reason]];
90 std::string exception_message = base::SysNSStringToUTF8(exception_message_ns); 92 std::string exception_message = base::SysNSStringToUTF8(exception_message_ns);
91 base::debug::SetCrashKeyValue(crash_keys::mac::kNSException, 93 base::debug::SetCrashKeyValue(crash_keys::mac::kNSException,
92 exception_message); 94 exception_message);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 168
167 // Check if the function is one that is known to obscure (by way of 169 // Check if the function is one that is known to obscure (by way of
168 // catch-and-rethrow) exception stack traces. If it is, sinkhole it 170 // catch-and-rethrow) exception stack traces. If it is, sinkhole it
169 // by crashing here at the point of throw. 171 // by crashing here at the point of throw.
170 for (const auto& sinkhole : kExceptionSinkholes) { 172 for (const auto& sinkhole : kExceptionSinkholes) {
171 if (strcmp(sinkhole, proc_name) == 0) { 173 if (strcmp(sinkhole, proc_name) == 0) {
172 TERMINATING_FROM_UNCAUGHT_NSEXCEPTION(exception); 174 TERMINATING_FROM_UNCAUGHT_NSEXCEPTION(exception);
173 } 175 }
174 } 176 }
175 177
178 DVLOG(1) << "Stopping search for exception handler at " << proc_name;
179
176 break; 180 break;
177 } 181 }
178 } 182 }
179 183
180 // Forward to the next preprocessor. 184 // Forward to the next preprocessor.
181 if (g_next_preprocessor) 185 if (g_next_preprocessor)
182 return g_next_preprocessor(exception); 186 return g_next_preprocessor(exception);
183 187
184 return exception; 188 return exception;
185 } 189 }
186 190
187 void InstallObjcExceptionPreprocessor() { 191 void InstallObjcExceptionPreprocessor() {
188 if (g_next_preprocessor) 192 if (g_next_preprocessor)
189 return; 193 return;
190 194
191 g_next_preprocessor = 195 g_next_preprocessor =
192 objc_setExceptionPreprocessor(&ObjcExceptionPreprocessor); 196 objc_setExceptionPreprocessor(&ObjcExceptionPreprocessor);
193 } 197 }
194 198
195 void UninstallObjcExceptionPreprocessor() { 199 void UninstallObjcExceptionPreprocessor() {
196 objc_setExceptionPreprocessor(g_next_preprocessor); 200 objc_setExceptionPreprocessor(g_next_preprocessor);
197 g_next_preprocessor = nullptr; 201 g_next_preprocessor = nullptr;
198 } 202 }
199 203
200 } // namespace chrome 204 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/mac/exception_processor_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698