OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/linux_util.h" | 5 #include "base/linux_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <glib.h> | 10 #include <glib.h> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 245 } |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 closedir(fd); | 249 closedir(fd); |
250 } | 250 } |
251 | 251 |
252 return already_found; | 252 return already_found; |
253 } | 253 } |
254 | 254 |
255 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data) { | 255 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data, |
| 256 bool* syscall_supported) { |
256 char buf[256]; | 257 char buf[256]; |
257 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); | 258 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); |
| 259 |
| 260 if (syscall_supported != NULL) |
| 261 *syscall_supported = false; |
| 262 |
258 DIR* task = opendir(buf); | 263 DIR* task = opendir(buf); |
259 if (!task) { | 264 if (!task) { |
260 LOG(WARNING) << "Cannot open " << buf; | 265 LOG(WARNING) << "Cannot open " << buf; |
261 return -1; | 266 return -1; |
262 } | 267 } |
263 | 268 |
264 std::vector<pid_t> tids; | 269 std::vector<pid_t> tids; |
265 struct dirent* dent; | 270 struct dirent* dent; |
266 while ((dent = readdir(task))) { | 271 while ((dent = readdir(task))) { |
267 char *endptr; | 272 char *endptr; |
268 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); | 273 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); |
269 if (tid_ul == ULONG_MAX || *endptr) | 274 if (tid_ul == ULONG_MAX || *endptr) |
270 continue; | 275 continue; |
271 tids.push_back(tid_ul); | 276 tids.push_back(tid_ul); |
272 } | 277 } |
273 closedir(task); | 278 closedir(task); |
274 | 279 |
275 scoped_array<char> syscall_data(new char[expected_data.length()]); | 280 scoped_array<char> syscall_data(new char[expected_data.length()]); |
276 for (std::vector<pid_t>::const_iterator | 281 for (std::vector<pid_t>::const_iterator |
277 i = tids.begin(); i != tids.end(); ++i) { | 282 i = tids.begin(); i != tids.end(); ++i) { |
278 const pid_t current_tid = *i; | 283 const pid_t current_tid = *i; |
279 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid); | 284 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid); |
280 int fd = open(buf, O_RDONLY); | 285 int fd = open(buf, O_RDONLY); |
281 if (fd < 0) | 286 if (fd < 0) |
282 continue; | 287 continue; |
| 288 if (syscall_supported != NULL) |
| 289 *syscall_supported = true; |
283 bool read_ret = | 290 bool read_ret = |
284 file_util::ReadFromFD(fd, syscall_data.get(), expected_data.length()); | 291 file_util::ReadFromFD(fd, syscall_data.get(), expected_data.length()); |
285 close(fd); | 292 close(fd); |
286 if (!read_ret) | 293 if (!read_ret) |
287 continue; | 294 continue; |
288 | 295 |
289 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), | 296 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), |
290 expected_data.length())) { | 297 expected_data.length())) { |
291 return current_tid; | 298 return current_tid; |
292 } | 299 } |
293 } | 300 } |
294 return -1; | 301 return -1; |
295 } | 302 } |
296 | 303 |
297 } // namespace base | 304 } // namespace base |
OLD | NEW |