[email protected] | 68a008e8 | 2011-05-02 17:54:14 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 75ae542 | 2009-04-21 17:20:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 5 | #ifndef BASE_LINUX_UTIL_H_ |
6 | #define BASE_LINUX_UTIL_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 75ae542 | 2009-04-21 17:20:10 | [diff] [blame] | 8 | |
9 | #include <stdint.h> | ||||
[email protected] | b28af752 | 2009-10-29 18:21:30 | [diff] [blame] | 10 | #include <sys/types.h> |
[email protected] | 75ae542 | 2009-04-21 17:20:10 | [diff] [blame] | 11 | |
[email protected] | 912c645 | 2009-07-17 05:55:51 | [diff] [blame] | 12 | #include <string> |
13 | |||||
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 14 | #include "base/base_export.h" |
[email protected] | 68a008e8 | 2011-05-02 17:54:14 | [diff] [blame] | 15 | |
[email protected] | 75ae542 | 2009-04-21 17:20:10 | [diff] [blame] | 16 | namespace base { |
17 | |||||
[email protected] | 8ecd3aad | 2009-11-04 08:32:22 | [diff] [blame] | 18 | static const char kFindInodeSwitch[] = "--find-inode"; |
19 | |||||
[email protected] | 6dde9d7 | 2010-08-26 08:55:22 | [diff] [blame] | 20 | // This is declared here so the crash reporter can access the memory directly |
21 | // in compromised context without going through the standard library. | ||||
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 22 | BASE_EXPORT extern char g_linux_distro[]; |
[email protected] | 6dde9d7 | 2010-08-26 08:55:22 | [diff] [blame] | 23 | |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 24 | // Get the Linux Distro if we can, or return "Unknown". |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 25 | BASE_EXPORT std::string GetLinuxDistro(); |
[email protected] | 912c645 | 2009-07-17 05:55:51 | [diff] [blame] | 26 | |
[email protected] | 6dde9d7 | 2010-08-26 08:55:22 | [diff] [blame] | 27 | // Set the Linux Distro string. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 28 | BASE_EXPORT void SetLinuxDistro(const std::string& distro); |
[email protected] | 6dde9d7 | 2010-08-26 08:55:22 | [diff] [blame] | 29 | |
[email protected] | 85ebe8f | 2009-10-29 04:02:55 | [diff] [blame] | 30 | // Return the inode number for the UNIX domain socket |fd|. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 31 | BASE_EXPORT bool FileDescriptorGetInode(ino_t* inode_out, int fd); |
[email protected] | 85ebe8f | 2009-10-29 04:02:55 | [diff] [blame] | 32 | |
33 | // Find the process which holds the given socket, named by inode number. If | ||||
34 | // multiple processes hold the socket, this function returns false. | ||||
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 35 | BASE_EXPORT bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode); |
[email protected] | 85ebe8f | 2009-10-29 04:02:55 | [diff] [blame] | 36 | |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 37 | // For a given process |pid|, look through all its threads and find the first |
38 | // thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches | ||||
39 | // |expected_data|, where N is the length of |expected_data|. | ||||
[email protected] | cb7d53e | 2011-06-21 04:21:06 | [diff] [blame] | 40 | // Returns the thread id or -1 on error. If |syscall_supported| is |
41 | // set to false the kernel does not support syscall in procfs. | ||||
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame^] | 42 | BASE_EXPORT pid_t FindThreadIDWithSyscall(pid_t pid, |
43 | const std::string& expected_data, | ||||
44 | bool* syscall_supported); | ||||
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 45 | |
[email protected] | 75ae542 | 2009-04-21 17:20:10 | [diff] [blame] | 46 | } // namespace base |
47 | |||||
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 48 | #endif // BASE_LINUX_UTIL_H_ |