1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_LINUX_UTIL_H_ 6 #define BASE_LINUX_UTIL_H_ 7 8 #include <stdint.h> 9 #include <sys/types.h> 10 11 #include <string> 12 #include <vector> 13 14 #include "base/base_export.h" 15 16 namespace base { 17 18 // This is declared here so the crash reporter can access the memory directly 19 // in compromised context without going through the standard library. 20 BASE_EXPORT extern char g_linux_distro[]; 21 22 // Get the Linux Distro if we can, or return "Unknown". 23 BASE_EXPORT std::string GetLinuxDistro(); 24 25 #if defined(UNIT_TEST) 26 // Get the value of given key from the given input (content of the 27 // /etc/os-release file. Exposed for testing. 28 BASE_EXPORT std::string GetKeyValueFromOSReleaseFileForTesting( 29 const std::string& input, 30 const char* key); 31 #endif // defined(UNIT_TEST) 32 33 // Set the Linux Distro string. 34 BASE_EXPORT void SetLinuxDistro(const std::string& distro); 35 36 // For a given process |pid|, get a list of all its threads. On success, returns 37 // true and appends the list of threads to |tids|. Otherwise, returns false. 38 BASE_EXPORT bool GetThreadsForProcess(pid_t pid, std::vector<pid_t>* tids); 39 40 // For a given process |pid|, look through all its threads and find the first 41 // thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches 42 // |expected_data|, where N is the length of |expected_data|. 43 // Returns the thread id or -1 on error. If |syscall_supported| is 44 // set to false the kernel does not support syscall in procfs. 45 BASE_EXPORT pid_t FindThreadIDWithSyscall(pid_t pid, 46 const std::string& expected_data, 47 bool* syscall_supported); 48 49 // For a given process |pid|, look through all its threads and find the first 50 // thread with /proc/[pid]/task/[thread_id]/status where NSpid matches |ns_tid|. 51 // Returns the thread id or -1 on error. If |ns_pid_supported| is 52 // set to false the kernel does not support NSpid in procfs. 53 BASE_EXPORT pid_t FindThreadID(pid_t pid, pid_t ns_tid, bool* ns_pid_supported); 54 55 } // namespace base 56 57 #endif // BASE_LINUX_UTIL_H_ 58