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

Side by Side Diff: content/renderer/renderer_main_platform_delegate_mac.mm

Issue 148893005: [Mac] Disable Mach IPC between renderers and cfprefsd. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
4 4
5 #include "content/renderer/renderer_main_platform_delegate.h" 5 #include "content/renderer/renderer_main_platform_delegate.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <objc/runtime.h> 9 #include <objc/runtime.h>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #import "base/mac/foundation_util.h" 13 #import "base/mac/foundation_util.h"
14 #import "base/mac/mac_util.h" 14 #import "base/mac/mac_util.h"
15 #include "base/mac/scoped_cftyperef.h" 15 #include "base/mac/scoped_cftyperef.h"
16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
17 #include "content/common/sandbox_mac.h" 18 #include "content/common/sandbox_mac.h"
18 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
19 #import "content/public/common/injection_test_mac.h" 20 #import "content/public/common/injection_test_mac.h"
20 #include "content/common/sandbox_init_mac.h" 21 #include "content/common/sandbox_init_mac.h"
21 #include "third_party/mach_override/mach_override.h" 22 #include "third_party/mach_override/mach_override.h"
22 23
23 extern "C" { 24 extern "C" {
24 // SPI logging functions for CF that are exported externally. 25 // SPI logging functions for CF that are exported externally.
25 void CFLog(int32_t level, CFStringRef format, ...); 26 void CFLog(int32_t level, CFStringRef format, ...);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return; 62 return;
62 } 63 }
63 } 64 }
64 65
65 va_list args; 66 va_list args;
66 va_start(args, format); 67 va_start(args, format);
67 _CFLogvEx(NULL, NULL, NULL, level, format, args); 68 _CFLogvEx(NULL, NULL, NULL, level, format, args);
68 va_end(args); 69 va_end(args);
69 } 70 }
70 71
72 // You are about to read a pretty disgusting hack. In a static initializer,
73 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is
74 // no public way to close this Mach port after-the-fact, nor a way to stop it
75 // from happening since it is done pre-main in dyld. But the address of the
76 // CFMachPort can be found in the run loop's string description. Below, that
77 // address is parsed, cast, and then used to invalidate the Mach port to
78 // disable communication with cfprefsd.
79 void DisconnectCFNotificationCenter() {
80 base::ScopedCFTypeRef<CFStringRef> run_loop_description(
81 CFCopyDescription(CFRunLoopGetCurrent()));
82 const CFIndex length = CFStringGetLength(run_loop_description);
83 for (CFIndex i = 0; i < length; ) {
84 // Find the start of a CFMachPort run loop source, which looks like this,
85 // without new lines:
86 // 1 : <CFRunLoopSource 0x7d16ea90 [0xa160af80]>{signalled = No,
87 // valid = Yes, order = 0, context =
88 // <CFMachPort 0x7d16fe00 [0xa160af80]>{valid = Yes, port = 3a0f,
89 // source = 0x7d16ea90, callout =
90 // _ZL14MessageHandlerP12__CFMachPortPvlS1_ (0x96df59c2), context =
91 // <CFMachPort context 0x1475b>}}
92 CFRange run_loop_source_context_range;
93 if (!CFStringFindWithOptions(run_loop_description,
94 CFSTR("context = <CFMachPort "), CFRangeMake(i, length - i),
Mark Mentovai 2014/02/25 18:07:47 Leading commaspace on this one too?
Robert Sesek 2014/02/25 19:07:16 Done.
95 0, &run_loop_source_context_range)) {
96 break;
97 }
98 i = run_loop_source_context_range.location +
99 run_loop_source_context_range.length;
100
101 // The address of the CFMachPort is the first hexadecimal address after the
102 // CF type name.
103 CFRange port_address_range = CFRangeMake(i, 0);
104 for (CFIndex j = port_address_range.location; j < length; ++j) {
105 UniChar c = CFStringGetCharacterAtIndex(run_loop_description, j);
106 if (c == ' ')
107 break;
108 ++port_address_range.length;
Mark Mentovai 2014/02/25 18:07:47 Maybe don’t even bother with this inside the loop.
Robert Sesek 2014/02/25 19:07:16 Then j would have to be scoped outside of the loop
109 }
110
111 base::ScopedCFTypeRef<CFStringRef> port_address_string(
112 CFStringCreateWithSubstring(NULL, run_loop_description,
113 port_address_range));
114 if (!port_address_string)
115 continue;
116
117 // Convert the string to an address.
118 std::string port_address_std_string =
119 base::SysCFStringRefToUTF8(port_address_string);
120 #if __LP64__
121 uint64 port_address = 0;
122 if (!base::HexStringToUInt64(port_address_std_string, &port_address))
123 continue;
124 #else
125 uint32 port_address = 0;
126 if (!base::HexStringToUInt(port_address_std_string, &port_address))
127 continue;
128 #endif
129
130 // Cast the address to an object.
131 CFMachPortRef mach_port = reinterpret_cast<CFMachPortRef>(port_address);
132 if (CFGetTypeID(mach_port) != CFMachPortGetTypeID())
133 continue;
134
135 // Verify that this is the Mach port that needs to be disconnected by the
136 // name of its callout function. Example description (no new lines):
137 // <CFMachPort 0x7d16fe00 [0xa160af80]>{valid = Yes, port = 3a0f, source =
138 // 0x7d16ea90, callout = __CFXNotificationReceiveFromServer (0x96df59c2),
139 // context = <CFMachPort context 0x1475b>}
140 base::ScopedCFTypeRef<CFStringRef> port_description(
141 CFCopyDescription(mach_port));
142 if (CFStringFindWithOptions(port_description,
143 CFSTR(", callout = __CFXNotificationReceiveFromServer ("),
144 CFRangeMake(0, CFStringGetLength(port_description)),
145 0,
146 NULL)) {
147 CFMachPortInvalidate(mach_port);
148 return;
149 }
150 }
151 }
152
71 } // namespace 153 } // namespace
72 154
73 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 155 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
74 const MainFunctionParams& parameters) 156 const MainFunctionParams& parameters)
75 : parameters_(parameters) { 157 : parameters_(parameters) {
76 } 158 }
77 159
78 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { 160 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
79 } 161 }
80 162
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::ScopedCFTypeRef<TISInputSourceRef> layout_source( 248 base::ScopedCFTypeRef<TISInputSourceRef> layout_source(
167 TISCopyCurrentKeyboardLayoutInputSource()); 249 TISCopyCurrentKeyboardLayoutInputSource());
168 base::ScopedCFTypeRef<TISInputSourceRef> input_source( 250 base::ScopedCFTypeRef<TISInputSourceRef> input_source(
169 TISCopyCurrentKeyboardInputSource()); 251 TISCopyCurrentKeyboardInputSource());
170 252
171 CFTypeRef source_list[] = { layout_source.get(), input_source.get() }; 253 CFTypeRef source_list[] = { layout_source.get(), input_source.get() };
172 g_text_input_services_source_list_ = CFArrayCreate(kCFAllocatorDefault, 254 g_text_input_services_source_list_ = CFArrayCreate(kCFAllocatorDefault,
173 source_list, arraysize(source_list), &kCFTypeArrayCallBacks); 255 source_list, arraysize(source_list), &kCFTypeArrayCallBacks);
174 } 256 }
175 257
258 DisconnectCFNotificationCenter();
259
176 return sandbox_initialized; 260 return sandbox_initialized;
177 } 261 }
178 262
179 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { 263 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) {
180 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); 264 Class tests_runner = objc_getClass("RendererSandboxTestsRunner");
181 if (tests_runner) { 265 if (tests_runner) {
182 if (![tests_runner runTests]) 266 if (![tests_runner runTests])
183 LOG(ERROR) << "Running renderer with failing sandbox tests!"; 267 LOG(ERROR) << "Running renderer with failing sandbox tests!";
184 [sandbox_tests_bundle_ unload]; 268 [sandbox_tests_bundle_ unload];
185 [sandbox_tests_bundle_ release]; 269 [sandbox_tests_bundle_ release];
186 sandbox_tests_bundle_ = nil; 270 sandbox_tests_bundle_ = nil;
187 } 271 }
188 } 272 }
189 273
190 } // namespace content 274 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698