OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include <kern/exc_resource.h> | 22 #include <kern/exc_resource.h> |
23 | 23 |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/mac/mach_logging.h" | 25 #include "base/mac/mach_logging.h" |
26 #include "util/mac/mac_util.h" | 26 #include "util/mac/mac_util.h" |
27 | 27 |
28 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 | 28 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 |
29 | 29 |
30 extern "C" { | 30 extern "C" { |
31 | 31 |
32 // proc_get_wakemon_params() is present in the Mac OS X 10.9 SDK, but no | 32 // proc_get_wakemon_params() is present in the OS X 10.9 SDK, but no declaration |
33 // declaration is provided. This provides a declaration and marks it for weak | 33 // is provided. This provides a declaration and marks it for weak import if the |
34 // import if the deployment target is below 10.9. | 34 // deployment target is below 10.9. |
35 int proc_get_wakemon_params(pid_t pid, int* rate_hz, int* flags) | 35 int proc_get_wakemon_params(pid_t pid, int* rate_hz, int* flags) |
36 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0); | 36 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0); |
37 | 37 |
38 // Redeclare the method without the availability annotation to suppress the | 38 // Redeclare the method without the availability annotation to suppress the |
39 // -Wpartial-availability warning. | 39 // -Wpartial-availability warning. |
40 int proc_get_wakemon_params(pid_t pid, int* rate_hz, int* flags); | 40 int proc_get_wakemon_params(pid_t pid, int* rate_hz, int* flags); |
41 | 41 |
42 } // extern "C" | 42 } // extern "C" |
43 | 43 |
44 #else | 44 #else |
(...skipping 24 matching lines...) Expand all Loading... |
69 return proc_get_wakemon_params; | 69 return proc_get_wakemon_params; |
70 } | 70 } |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 #endif | 74 #endif |
75 | 75 |
76 namespace { | 76 namespace { |
77 | 77 |
78 // Wraps proc_get_wakemon_params(), calling it if the system provides it. It’s | 78 // Wraps proc_get_wakemon_params(), calling it if the system provides it. It’s |
79 // present on Mac OS X 10.9 and later. If it’s not available, sets errno to | 79 // present on OS X 10.9 and later. If it’s not available, sets errno to ENOSYS |
80 // ENOSYS and returns -1. | 80 // and returns -1. |
81 int ProcGetWakemonParams(pid_t pid, int* rate_hz, int* flags) { | 81 int ProcGetWakemonParams(pid_t pid, int* rate_hz, int* flags) { |
82 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9 | 82 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_9 |
83 // proc_get_wakemon_params() isn’t in the SDK. Look it up dynamically. | 83 // proc_get_wakemon_params() isn’t in the SDK. Look it up dynamically. |
84 static ProcGetWakemonParamsType proc_get_wakemon_params = | 84 static ProcGetWakemonParamsType proc_get_wakemon_params = |
85 GetProcGetWakemonParams(); | 85 GetProcGetWakemonParams(); |
86 #endif | 86 #endif |
87 | 87 |
88 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 | 88 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 |
89 // proc_get_wakemon_params() is definitely available if the deployment target | 89 // proc_get_wakemon_params() is definitely available if the deployment target |
90 // is 10.9 or newer. | 90 // is 10.9 or newer. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const int resource_flavor = EXC_RESOURCE_DECODE_FLAVOR(code_0); | 139 const int resource_flavor = EXC_RESOURCE_DECODE_FLAVOR(code_0); |
140 | 140 |
141 if (resource_type == RESOURCE_TYPE_CPU && | 141 if (resource_type == RESOURCE_TYPE_CPU && |
142 (resource_flavor == FLAVOR_CPU_MONITOR || | 142 (resource_flavor == FLAVOR_CPU_MONITOR || |
143 resource_flavor == FLAVOR_CPU_MONITOR_FATAL)) { | 143 resource_flavor == FLAVOR_CPU_MONITOR_FATAL)) { |
144 // These exceptions may be fatal. They are not fatal by default at task | 144 // These exceptions may be fatal. They are not fatal by default at task |
145 // creation but can be made fatal by calling proc_rlimit_control() with | 145 // creation but can be made fatal by calling proc_rlimit_control() with |
146 // RLIMIT_CPU_USAGE_MONITOR as the second argument and CPUMON_MAKE_FATAL set | 146 // RLIMIT_CPU_USAGE_MONITOR as the second argument and CPUMON_MAKE_FATAL set |
147 // in the flags. | 147 // in the flags. |
148 if (MacOSXMinorVersion() >= 10) { | 148 if (MacOSXMinorVersion() >= 10) { |
149 // In Mac OS X 10.10, the exception code indicates whether the exception | 149 // In OS X 10.10, the exception code indicates whether the exception is |
150 // is fatal. See 10.10 xnu-2782.1.97/osfmk/kern/thread.c | 150 // fatal. See 10.10 xnu-2782.1.97/osfmk/kern/thread.c |
151 // THIS_THREAD_IS_CONSUMING_TOO_MUCH_CPU__SENDING_EXC_RESOURCE(). | 151 // THIS_THREAD_IS_CONSUMING_TOO_MUCH_CPU__SENDING_EXC_RESOURCE(). |
152 return resource_flavor == FLAVOR_CPU_MONITOR; | 152 return resource_flavor == FLAVOR_CPU_MONITOR; |
153 } | 153 } |
154 | 154 |
155 // In Mac OS X 10.9, there’s no way to determine whether the exception is | 155 // In OS X 10.9, there’s no way to determine whether the exception is fatal. |
156 // fatal. Unlike RESOURCE_TYPE_WAKEUPS below, there’s no way to determine | 156 // Unlike RESOURCE_TYPE_WAKEUPS below, there’s no way to determine this |
157 // this outside the kernel. proc_rlimit_control()’s RLIMIT_CPU_USAGE_MONITOR | 157 // outside the kernel. proc_rlimit_control()’s RLIMIT_CPU_USAGE_MONITOR is |
158 // is the only interface to modify CPUMON_MAKE_FATAL, but it’s only able to | 158 // the only interface to modify CPUMON_MAKE_FATAL, but it’s only able to set |
159 // set this bit, not obtain its current value. | 159 // this bit, not obtain its current value. |
160 // | 160 // |
161 // Default to assuming that these exceptions are nonfatal. They are nonfatal | 161 // Default to assuming that these exceptions are nonfatal. They are nonfatal |
162 // by default and no users of proc_rlimit_control() were found on 10.9.5 | 162 // by default and no users of proc_rlimit_control() were found on 10.9.5 |
163 // 13F1066 in /System and /usr outside of Metadata.framework and associated | 163 // 13F1066 in /System and /usr outside of Metadata.framework and associated |
164 // tools. | 164 // tools. |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 if (resource_type == RESOURCE_TYPE_WAKEUPS && | 168 if (resource_type == RESOURCE_TYPE_WAKEUPS && |
169 resource_flavor == FLAVOR_WAKEUPS_MONITOR) { | 169 resource_flavor == FLAVOR_WAKEUPS_MONITOR) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 // Treat unknown exceptions as fatal. This is the conservative approach: it | 210 // Treat unknown exceptions as fatal. This is the conservative approach: it |
211 // may result in more crash reports being generated, but the type-flavor | 211 // may result in more crash reports being generated, but the type-flavor |
212 // combinations can be evaluated to determine appropriate handling. | 212 // combinations can be evaluated to determine appropriate handling. |
213 LOG(WARNING) << "unknown resource type " << resource_type << " flavor " | 213 LOG(WARNING) << "unknown resource type " << resource_type << " flavor " |
214 << resource_flavor; | 214 << resource_flavor; |
215 return false; | 215 return false; |
216 } | 216 } |
217 | 217 |
218 } // namespace crashpad | 218 } // namespace crashpad |
OLD | NEW |