Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "util/posix/symbolic_constants_posix.h" | |
| 16 | |
| 17 #include <sys/signal.h> | |
|
Robert Sesek
2014/09/10 20:01:04
Just for NSIG? (maybe "// for NSIG" if that's the
Mark Mentovai
2014/09/10 20:30:52
rsesek wrote:
| |
| 18 | |
| 19 #include "base/basictypes.h" | |
| 20 #include "base/strings/stringprintf.h" | |
| 21 #include "util/stdlib/string_number_conversion.h" | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 const char* kSignalNames[] = { | |
| 26 NULL, | |
| 27 | |
| 28 #if defined(OS_MACOSX) | |
| 29 // sed -Ene 's/^#define[[:space:]]SIG([[:alnum:]]+)[[:space:]]+[[:digit:]]{1 ,2}([[:space:]]|$).*/ "\1",/p' | |
| 30 // /usr/include/sys/signal.h | |
| 31 // and fix up by removing the entry for SIGPOLL. | |
| 32 "HUP", | |
| 33 "INT", | |
| 34 "QUIT", | |
| 35 "ILL", | |
| 36 "TRAP", | |
| 37 "ABRT", | |
| 38 "EMT", | |
| 39 "FPE", | |
| 40 "KILL", | |
| 41 "BUS", | |
| 42 "SEGV", | |
| 43 "SYS", | |
| 44 "PIPE", | |
| 45 "ALRM", | |
| 46 "TERM", | |
| 47 "URG", | |
| 48 "STOP", | |
| 49 "TSTP", | |
| 50 "CONT", | |
| 51 "CHLD", | |
| 52 "TTIN", | |
| 53 "TTOU", | |
| 54 "IO", | |
| 55 "XCPU", | |
| 56 "XFSZ", | |
| 57 "VTALRM", | |
| 58 "PROF", | |
| 59 "WINCH", | |
| 60 "INFO", | |
| 61 "USR1", | |
| 62 "USR2", | |
| 63 #elif defined(OS_LINUX) | |
| 64 // sed -Ene 's/^#define[[:space:]]SIG([[:alnum:]]+)[[:space:]]+[[:digit:]]{1 ,2}([[:space:]]|$).*/ "\1",/p' | |
| 65 // /usr/include/asm-generic/signal.h | |
| 66 // and fix up by removing SIGIOT, SIGLOST, SIGUNUSED, and SIGRTMIN. | |
| 67 "HUP", | |
| 68 "INT", | |
| 69 "QUIT", | |
| 70 "ILL", | |
| 71 "TRAP", | |
| 72 "ABRT", | |
| 73 "BUS", | |
| 74 "FPE", | |
| 75 "KILL", | |
| 76 "USR1", | |
| 77 "SEGV", | |
| 78 "USR2", | |
| 79 "PIPE", | |
| 80 "ALRM", | |
| 81 "TERM", | |
| 82 "STKFLT", | |
| 83 "CHLD", | |
| 84 "CONT", | |
| 85 "STOP", | |
| 86 "TSTP", | |
| 87 "TTIN", | |
| 88 "TTOU", | |
| 89 "URG", | |
| 90 "XCPU", | |
| 91 "XFSZ", | |
| 92 "VTALRM", | |
| 93 "PROF", | |
| 94 "WINCH", | |
| 95 "IO", | |
| 96 "PWR", | |
| 97 "SYS", | |
| 98 #endif | |
| 99 }; | |
| 100 #if defined(OS_LINUX) | |
| 101 // NSIG is 64 to account for real-time signals. | |
| 102 COMPILE_ASSERT(arraysize(kSignalNames) == 32, kSignalNames_length); | |
| 103 #else | |
| 104 COMPILE_ASSERT(arraysize(kSignalNames) == NSIG, kSignalNames_length); | |
| 105 #endif | |
| 106 | |
| 107 const char kSigPrefix[] = "SIG"; | |
| 108 | |
| 109 } // namespace | |
| 110 | |
| 111 namespace crashpad { | |
| 112 | |
| 113 std::string SignalToString(int signal, | |
| 114 SymbolicConstantToStringOptions options) { | |
| 115 const char* signal_name = | |
| 116 static_cast<size_t>(signal) < arraysize(kSignalNames) | |
| 117 ? kSignalNames[signal] | |
| 118 : NULL; | |
| 119 if (!signal_name) { | |
| 120 if (options & kUnknownIsNumeric) { | |
| 121 return base::StringPrintf("%d", signal); | |
| 122 } | |
| 123 return std::string(); | |
| 124 } | |
| 125 | |
| 126 if (options & kUseShortName) { | |
| 127 return std::string(signal_name); | |
| 128 } | |
| 129 return std::string(kSigPrefix).append(signal_name); | |
|
Robert Sesek
2014/09/10 20:01:04
StringPrintf instead? Not sure which would be more
| |
| 130 } | |
| 131 | |
| 132 bool StringToSignal(const base::StringPiece& string, | |
| 133 StringToSymbolicConstantOptions options, | |
| 134 int* signal) { | |
| 135 if ((options & kAllowFullName) || (options & kAllowShortName)) { | |
| 136 bool can_match_full = | |
| 137 (options & kAllowFullName) && | |
| 138 string.substr(0, strlen(kSigPrefix)).compare(kSigPrefix) == 0; | |
| 139 base::StringPiece short_string = | |
| 140 can_match_full ? string.substr(strlen(kSigPrefix)) : string; | |
| 141 for (int index = 0; | |
| 142 index < static_cast<int>(arraysize(kSignalNames)); | |
| 143 ++index) { | |
| 144 const char* signal_name = kSignalNames[index]; | |
| 145 if (!signal_name) { | |
| 146 continue; | |
| 147 } | |
| 148 if (can_match_full && short_string.compare(signal_name) == 0) { | |
| 149 *signal = index; | |
| 150 return true; | |
| 151 } | |
| 152 if ((options & kAllowShortName) && string.compare(signal_name) == 0) { | |
| 153 *signal = index; | |
| 154 return true; | |
| 155 } | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 if (options & kAllowNumber) { | |
| 160 return StringToNumber(string, signal); | |
| 161 } | |
| 162 | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 } // namespace crashpad | |
| OLD | NEW |