| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/linux/services/thread_helpers.h" | 5 #include "sandbox/linux/services/thread_helpers.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool ChangeThreadStateAndWatchProcFS( | 114 bool ChangeThreadStateAndWatchProcFS( |
| 115 int proc_fd, base::Thread* thread, ThreadAction action) { | 115 int proc_fd, base::Thread* thread, ThreadAction action) { |
| 116 DCHECK_LE(0, proc_fd); | 116 DCHECK_LE(0, proc_fd); |
| 117 DCHECK(thread); | 117 DCHECK(thread); |
| 118 DCHECK(action == ThreadAction::Start || action == ThreadAction::Stop); | 118 DCHECK(action == ThreadAction::Start || action == ThreadAction::Stop); |
| 119 | 119 |
| 120 base::Callback<bool(void)> cb; | 120 base::Callback<bool(void)> cb; |
| 121 const char* message; | 121 const char* message; |
| 122 | 122 |
| 123 if (action == ThreadAction::Start) { | 123 if (action == ThreadAction::Start) { |
| 124 // Should start the thread before calling thread_id(). | 124 // Should start the thread before calling GetThreadId(). |
| 125 if (!thread->Start()) | 125 if (!thread->Start()) |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 const base::PlatformThreadId thread_id = thread->thread_id(); | 129 const base::PlatformThreadId thread_id = thread->GetThreadId(); |
| 130 const std::string thread_id_dir_str = | 130 const std::string thread_id_dir_str = |
| 131 "self/task/" + base::IntToString(thread_id) + "/"; | 131 "self/task/" + base::IntToString(thread_id) + "/"; |
| 132 | 132 |
| 133 if (action == ThreadAction::Stop) { | 133 if (action == ThreadAction::Stop) { |
| 134 // The target thread should exist in /proc. | 134 // The target thread should exist in /proc. |
| 135 DCHECK(IsThreadPresentInProcFS(proc_fd, thread_id_dir_str)); | 135 DCHECK(IsThreadPresentInProcFS(proc_fd, thread_id_dir_str)); |
| 136 thread->Stop(); | 136 thread->Stop(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // The kernel is at liberty to wake the thread id futex before updating | 139 // The kernel is at liberty to wake the thread id futex before updating |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 base::Thread* thread) { | 191 base::Thread* thread) { |
| 192 return ChangeThreadStateAndWatchProcFS(proc_fd, thread, ThreadAction::Stop); | 192 return ChangeThreadStateAndWatchProcFS(proc_fd, thread, ThreadAction::Stop); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // static | 195 // static |
| 196 const char* ThreadHelpers::GetAssertSingleThreadedErrorMessageForTests() { | 196 const char* ThreadHelpers::GetAssertSingleThreadedErrorMessageForTests() { |
| 197 return kAssertSingleThreadedError; | 197 return kAssertSingleThreadedError; |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace sandbox | 200 } // namespace sandbox |
| OLD | NEW |