Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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. |
|
John Grabowski
2012/05/07 19:22:15
Add explicit doc on our model: catch signals and p
nilesh
2012/05/08 01:38:10
Done.
| |
| 4 | 4 |
| 5 #include <signal.h> | |
| 5 #include <stdio.h> | 6 #include <stdio.h> |
| 6 | 7 |
| 7 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 9 #include "base/android/path_utils.h" | 10 #include "base/android/path_utils.h" |
| 10 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 17 #include "base/string_tokenizer.h" | 18 #include "base/string_tokenizer.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "base/test/test_suite.h" | 20 #include "base/test/test_suite.h" |
| 20 #include "testing/android/jni/chrome_native_test_activity_jni.h" | 21 #include "testing/android/jni/chrome_native_test_activity_jni.h" |
| 21 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
| 22 | 23 |
| 23 // GTest's main function. | 24 // GTest's main function. |
| 24 extern int main(int argc, char** argv); | 25 extern int main(int argc, char** argv); |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 29 // The list of signals which we consider to be crashes. We rethrow the | |
|
Yaron
2012/05/07 19:22:19
Nit: Don't use "we" in comments.
nilesh
2012/05/08 01:38:10
Done.
| |
| 30 // signal after handling it. | |
| 31 static const int kExceptionSignals[] = { | |
| 32 SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, -1 | |
| 33 }; | |
| 34 | |
| 35 static struct sigaction old_sa[NSIG]; | |
| 36 | |
| 37 void SignalHandler(int sig, siginfo_t *info, void *reserved) | |
| 38 { | |
| 39 // Output the crash marker. | |
| 40 LOG(ERROR) << "[ CRASHED ]"; | |
|
John Grabowski
2012/05/07 19:22:15
Normally you cannot allocate memory in a signal ha
nilesh
2012/05/08 01:38:10
Done. Thanks for catching this.
| |
| 41 old_sa[sig].sa_sigaction(sig, info, reserved); | |
| 42 } | |
| 43 | |
| 44 void InstallHandlers() { | |
| 45 struct sigaction sa; | |
| 46 memset(&sa, 0, sizeof(sa)); | |
| 47 | |
| 48 sa.sa_sigaction = SignalHandler; | |
| 49 sa.sa_flags = SA_SIGINFO; | |
| 50 | |
| 51 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | |
| 52 sigaction(kExceptionSignals[i], &sa, &old_sa[kExceptionSignals[i]]); | |
| 53 } | |
| 54 } | |
| 55 | |
| 28 void ParseArgsFromString(const std::string& command_line, | 56 void ParseArgsFromString(const std::string& command_line, |
| 29 std::vector<std::string>* args) { | 57 std::vector<std::string>* args) { |
| 30 StringTokenizer tokenizer(command_line, kWhitespaceASCII); | 58 StringTokenizer tokenizer(command_line, kWhitespaceASCII); |
| 31 tokenizer.set_quote_chars("\""); | 59 tokenizer.set_quote_chars("\""); |
| 32 while (tokenizer.GetNext()) { | 60 while (tokenizer.GetNext()) { |
| 33 std::string token; | 61 std::string token; |
| 34 RemoveChars(tokenizer.token(), "\"", &token); | 62 RemoveChars(tokenizer.token(), "\"", &token); |
| 35 args->push_back(token); | 63 args->push_back(token); |
| 36 } | 64 } |
| 37 } | 65 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // Set the application context in base. | 210 // Set the application context in base. |
| 183 base::android::ScopedJavaLocalRef<jobject> scoped_context( | 211 base::android::ScopedJavaLocalRef<jobject> scoped_context( |
| 184 env, env->NewLocalRef(app_context)); | 212 env, env->NewLocalRef(app_context)); |
| 185 base::android::InitApplicationContext(scoped_context); | 213 base::android::InitApplicationContext(scoped_context); |
| 186 | 214 |
| 187 main(argc, &argv[0]); | 215 main(argc, &argv[0]); |
| 188 } | 216 } |
| 189 | 217 |
| 190 // This is called by the VM when the shared library is first loaded. | 218 // This is called by the VM when the shared library is first loaded. |
| 191 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 219 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 220 | |
| 221 // Install signal handlers to detect crashes. | |
| 222 InstallHandlers(); | |
| 223 | |
| 192 base::android::InitVM(vm); | 224 base::android::InitVM(vm); |
| 193 JNIEnv* env = base::android::AttachCurrentThread(); | 225 JNIEnv* env = base::android::AttachCurrentThread(); |
| 194 if (!RegisterNativesImpl(env)) { | 226 if (!RegisterNativesImpl(env)) { |
| 195 return -1; | 227 return -1; |
| 196 } | 228 } |
| 197 LibraryLoadedOnMainThread(env); | 229 LibraryLoadedOnMainThread(env); |
| 230 | |
| 198 return JNI_VERSION_1_4; | 231 return JNI_VERSION_1_4; |
| 199 } | 232 } |
| OLD | NEW |