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

Side by Side Diff: chrome/nacl/nacl_broker_listener.cc

Issue 10211007: NaCl: Split the debug exception handler thread into a separate file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to chrome/common Created 8 years, 7 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
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 "chrome/nacl/nacl_broker_listener.h" 5 #include "chrome/nacl/nacl_broker_listener.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/threading/platform_thread.h"
15 #include "chrome/common/nacl_cmd_line.h" 14 #include "chrome/common/nacl_cmd_line.h"
15 #include "chrome/common/nacl_debug_exception_handler_win.h"
16 #include "chrome/common/nacl_messages.h" 16 #include "chrome/common/nacl_messages.h"
17 #include "content/common/sandbox_policy.h" 17 #include "content/common/sandbox_policy.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "ipc/ipc_switches.h" 19 #include "ipc/ipc_switches.h"
20 #include "native_client/src/trusted/service_runtime/win/debug_exception_handler. h"
21 20
22 namespace { 21 namespace {
23 22
24 void SendReply(IPC::Channel* channel, int32 pid) { 23 void SendReply(IPC::Channel* channel, int32 pid) {
25 channel->Send(new NaClProcessMsg_DebugExceptionHandlerLaunched(pid)); 24 channel->Send(new NaClProcessMsg_DebugExceptionHandlerLaunched(pid));
26 } 25 }
27 26
28 class DebugExceptionHandler : public base::PlatformThread::Delegate {
29 public:
30 DebugExceptionHandler(base::MessageLoopProxy* message_loop,
31 IPC::Channel* channel, int32 pid)
32 : message_loop_(message_loop), channel_(channel), pid_(pid) {
33 }
34
35 virtual void ThreadMain() OVERRIDE {
36 // In the Windows API, the set of processes being debugged is
37 // thread-local, so we have to attach to the process (using
38 // DebugActiveProcess()) on the same thread on which
39 // NaClDebugLoop() receives debug events for the process.
40 BOOL attached = false;
41 base::ProcessHandle process_handle = base::kNullProcessHandle;
42 if (!base::OpenProcessHandleWithAccess(
43 pid_,
44 base::kProcessAccessQueryInformation |
45 base::kProcessAccessSuspendResume |
46 base::kProcessAccessTerminate |
47 base::kProcessAccessVMOperation |
48 base::kProcessAccessVMRead |
49 base::kProcessAccessVMWrite |
50 base::kProcessAccessWaitForTermination,
51 &process_handle)) {
52 LOG(ERROR) << "Failed to get process handle";
53 } else {
54 attached = DebugActiveProcess(pid_);
55 if (!attached) {
56 LOG(ERROR) << "Failed to connect to the process";
57 }
58 }
59 // At the moment we do not say in the reply whether attaching as a
60 // debugger succeeded. In the future, when we attach on demand
61 // when an exception handler is first registered, we can make the
62 // NaCl syscall indicate whether attaching succeeded.
63 message_loop_->PostDelayedTask(FROM_HERE,
64 base::Bind(SendReply, channel_, pid_), base::TimeDelta());
65
66 if (attached) {
67 DWORD exit_code;
68 NaClDebugLoop(process_handle, &exit_code);
69 }
70 if (process_handle != base::kNullProcessHandle) {
71 base::CloseProcessHandle(process_handle);
72 }
73 delete this;
74 }
75
76 private:
77 base::MessageLoopProxy* message_loop_;
78 IPC::Channel* channel_;
79 int32 pid_;
80
81 DISALLOW_COPY_AND_ASSIGN(DebugExceptionHandler);
82 };
83
84 } // namespace 27 } // namespace
85 28
86 NaClBrokerListener::NaClBrokerListener() 29 NaClBrokerListener::NaClBrokerListener()
87 : browser_handle_(base::kNullProcessHandle) { 30 : browser_handle_(base::kNullProcessHandle) {
88 } 31 }
89 32
90 NaClBrokerListener::~NaClBrokerListener() { 33 NaClBrokerListener::~NaClBrokerListener() {
91 base::CloseProcessHandle(browser_handle_); 34 base::CloseProcessHandle(browser_handle_);
92 } 35 }
93 36
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 browser_handle_, &loader_handle_in_browser, 92 browser_handle_, &loader_handle_in_browser,
150 PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION , FALSE, 0); 93 PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION , FALSE, 0);
151 base::CloseProcessHandle(loader_process); 94 base::CloseProcessHandle(loader_process);
152 } 95 }
153 } 96 }
154 channel_->Send(new NaClProcessMsg_LoaderLaunched(loader_channel_id, 97 channel_->Send(new NaClProcessMsg_LoaderLaunched(loader_channel_id,
155 loader_handle_in_browser)); 98 loader_handle_in_browser));
156 } 99 }
157 100
158 void NaClBrokerListener::OnLaunchDebugExceptionHandler(int32 pid) { 101 void NaClBrokerListener::OnLaunchDebugExceptionHandler(int32 pid) {
159 // The new PlatformThread will take ownership of the 102 base::Closure reply_sender(base::Bind(SendReply, channel_.get(), pid));
160 // DebugExceptionHandler object, which will delete itself on exit. 103 NaClStartDebugExceptionHandlerThread(pid, base::MessageLoopProxy::current(),
161 DebugExceptionHandler* handler = new DebugExceptionHandler( 104 reply_sender);
162 base::MessageLoopProxy::current(), channel_.get(), pid);
163 if (!base::PlatformThread::CreateNonJoinable(0, handler)) {
164 SendReply(channel_.get(), pid);
165 delete handler;
166 }
167 } 105 }
168 106
169 void NaClBrokerListener::OnStopBroker() { 107 void NaClBrokerListener::OnStopBroker() {
170 MessageLoop::current()->Quit(); 108 MessageLoop::current()->Quit();
171 } 109 }
OLDNEW
« chrome/common/nacl_debug_exception_handler_win.h ('K') | « chrome/nacl.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698