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

Side by Side Diff: util/mach/mach_extensions.cc

Issue 563383002: Add SymbolicConstantsMach and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 6 years, 3 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 | « util/mach/mach_extensions.h ('k') | util/mach/symbolic_constants_mach.h » ('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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/mach/mach_extensions.h" 15 #include "util/mach/mach_extensions.h"
16 16
17 #include <AvailabilityMacros.h>
17 #include <pthread.h> 18 #include <pthread.h>
18 19
20 #include "util/mac/mac_util.h"
21
19 namespace crashpad { 22 namespace crashpad {
20 23
21 mach_port_t MachThreadSelf() { 24 mach_port_t MachThreadSelf() {
22 // The pthreads library keeps its own copy of the mach_port_t. Using it does 25 // The pthreads library keeps its own copy of the mach_port_t. Using it does
23 // not increment its reference count. 26 // not increment its reference count.
24 return pthread_mach_thread_np(pthread_self()); 27 return pthread_mach_thread_np(pthread_self());
25 } 28 }
26 29
30 exception_mask_t ExcMaskAll() {
31 // This is necessary because of the way that the kernel validates
32 // exception_mask_t arguments to
33 // {host,task,thread}_{get,set,swap}_exception_ports(). It is strict,
34 // rejecting attempts to operate on any bits that it does not recognize. See
35 // 10.9.4 xnu-2422.110.17/osfmk/mach/ipc_host.c and
36 // xnu-2422.110.17/osfmk/mach/ipc_tt.c.
37
38 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
39 int mac_os_x_minor_version = MacOSXMinorVersion();
40 #endif
41
42 // See 10.6.8 xnu-1504.15.3/osfmk/mach/exception_types.h. 10.7 uses the same
43 // definition as 10.6. See 10.7.5 xnu-1699.32.7/osfmk/mach/exception_types.h
44 //
45 // The 10.5 SDK actually defined EXC_MASK_ALL as including EXC_MASK_CRASH.
46 // Later SDKs removed EXC_MASK_CRASH from EXC_MASK_ALL, but placed it into a
47 // new constant, EXC_MASK_VALID. For consistent behavior, don’t include
48 // EXC_MASK_CRASH in the 10.5 EXC_MASK_ALL. Consumers that want EXC_MASK_ALL
49 // along with EXC_MASK_CRASH must use ExcMaskAll() | EXC_MASK_CRASH
50 // explicitly. 10.5 otherwise behaves identically to 10.6. See 10.5.8
51 // xnu-1228.15.4/osfmk/mach/exception_types.h.
52 const exception_mask_t kExcMaskAll_10_6 =
53 EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC |
54 EXC_MASK_EMULATION | EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT |
55 EXC_MASK_SYSCALL | EXC_MASK_MACH_SYSCALL | EXC_MASK_RPC_ALERT |
56 EXC_MASK_MACHINE;
57 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_7
58 if (mac_os_x_minor_version <= 7) {
59 return kExcMaskAll_10_6;
60 }
61 #endif
62
63 // 10.8 added EXC_MASK_RESOURCE. See 10.8.5
64 // xnu-2050.48.11/osfmk/mach/exception_types.h.
65 const exception_mask_t kExcMaskAll_10_8 =
66 kExcMaskAll_10_6 | EXC_MASK_RESOURCE;
67 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_8
68 if (mac_os_x_minor_version <= 8) {
69 return kExcMaskAll_10_8;
70 }
71 #endif
72
73 // 10.9 added EXC_MASK_GUARD. See 10.9.4
74 // xnu-2422.110.17/osfmk/mach/exception_types.h.
75 const exception_mask_t kExcMaskAll_10_9 = kExcMaskAll_10_8 | EXC_MASK_GUARD;
76 return kExcMaskAll_10_9;
77 }
78
27 } // namespace crashpad 79 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/mach_extensions.h ('k') | util/mach/symbolic_constants_mach.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698