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

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

Issue 809103002: Add NewMachPort() and its test, and switch call sites to use it (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 6 years 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/mach_extensions_test.cc » ('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 <AvailabilityMacros.h>
18 #include <pthread.h> 18 #include <pthread.h>
19 19
20 #include "base/mac/mach_logging.h"
20 #include "util/mac/mac_util.h" 21 #include "util/mac/mac_util.h"
21 22
22 namespace crashpad { 23 namespace crashpad {
23 24
24 thread_t MachThreadSelf() { 25 thread_t MachThreadSelf() {
25 // The pthreads library keeps its own copy of the thread port. Using it does 26 // The pthreads library keeps its own copy of the thread port. Using it does
26 // not increment its reference count. 27 // not increment its reference count.
27 return pthread_mach_thread_np(pthread_self()); 28 return pthread_mach_thread_np(pthread_self());
28 } 29 }
29 30
31 mach_port_t NewMachPort(mach_port_right_t right) {
32 mach_port_t port = MACH_PORT_NULL;
33 kern_return_t kr = mach_port_allocate(mach_task_self(), right, &port);
34 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_allocate";
35 return port;
36 }
37
30 exception_mask_t ExcMaskAll() { 38 exception_mask_t ExcMaskAll() {
31 // This is necessary because of the way that the kernel validates 39 // This is necessary because of the way that the kernel validates
32 // exception_mask_t arguments to 40 // exception_mask_t arguments to
33 // {host,task,thread}_{get,set,swap}_exception_ports(). It is strict, 41 // {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 42 // 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 43 // 10.9.4 xnu-2422.110.17/osfmk/mach/ipc_host.c and
36 // xnu-2422.110.17/osfmk/mach/ipc_tt.c. 44 // xnu-2422.110.17/osfmk/mach/ipc_tt.c.
37 45
38 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 46 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
39 int mac_os_x_minor_version = MacOSXMinorVersion(); 47 int mac_os_x_minor_version = MacOSXMinorVersion();
(...skipping 22 matching lines...) Expand all
62 } 70 }
63 #endif 71 #endif
64 72
65 // 10.9 added EXC_MASK_GUARD. See 10.9.4 73 // 10.9 added EXC_MASK_GUARD. See 10.9.4
66 // xnu-2422.110.17/osfmk/mach/exception_types.h. 74 // xnu-2422.110.17/osfmk/mach/exception_types.h.
67 const exception_mask_t kExcMaskAll_10_9 = kExcMaskAll_10_8 | EXC_MASK_GUARD; 75 const exception_mask_t kExcMaskAll_10_9 = kExcMaskAll_10_8 | EXC_MASK_GUARD;
68 return kExcMaskAll_10_9; 76 return kExcMaskAll_10_9;
69 } 77 }
70 78
71 } // namespace crashpad 79 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/mach_extensions.h ('k') | util/mach/mach_extensions_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698