linux_util.h 2.2 KB

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