Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: 9f913e8f7fe730fe09749e40b821f5f0c0bd45f5 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[email protected]75ae5422009-04-21 17:20:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]9bc8cff2010-04-03 01:05:395#ifndef BASE_LINUX_UTIL_H_
6#define BASE_LINUX_UTIL_H_
[email protected]75ae5422009-04-21 17:20:107
8#include <stdint.h>
[email protected]b28af7522009-10-29 18:21:309#include <sys/types.h>
[email protected]75ae5422009-04-21 17:20:1010
[email protected]912c6452009-07-17 05:55:5111#include <string>
Alexandr Ilind4f4b342019-01-08 15:34:0912#include <vector>
[email protected]912c6452009-07-17 05:55:5113
[email protected]0bea7252011-08-05 15:34:0014#include "base/base_export.h"
[email protected]68a008e82011-05-02 17:54:1415
[email protected]75ae5422009-04-21 17:20:1016namespace base {
17
[email protected]6dde9d72010-08-26 08:55:2218// This is declared here so the crash reporter can access the memory directly
19// in compromised context without going through the standard library.
[email protected]0bea7252011-08-05 15:34:0020BASE_EXPORT extern char g_linux_distro[];
[email protected]6dde9d72010-08-26 08:55:2221
[email protected]a8e20582010-12-31 17:18:5022// Get the Linux Distro if we can, or return "Unknown".
[email protected]0bea7252011-08-05 15:34:0023BASE_EXPORT std::string GetLinuxDistro();
[email protected]912c6452009-07-17 05:55:5124
Tomas Popela5b9b01f2019-09-10 19:42:3125#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.
28BASE_EXPORT std::string GetKeyValueFromOSReleaseFileForTesting(
29 const std::string& input,
30 const char* key);
31#endif // defined(UNIT_TEST)
32
[email protected]6dde9d72010-08-26 08:55:2233// Set the Linux Distro string.
[email protected]0bea7252011-08-05 15:34:0034BASE_EXPORT void SetLinuxDistro(const std::string& distro);
[email protected]6dde9d72010-08-26 08:55:2235
Alexandr Ilind4f4b342019-01-08 15:34:0936// 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.
38BASE_EXPORT bool GetThreadsForProcess(pid_t pid, std::vector<pid_t>* tids);
39
Igor Kraskevichbfc62af2023-10-17 15:09:2840// Get a list of all threads for the current process. On success, returns true
41// and appends the list of threads to |tids|. Otherwise, returns false.
42// Unlike the function above, this function reads /proc/self/tasks, not
43// /proc/<pid>/tasks. On Android, the former should always be accessible to
44// GPU and Browser processes, while the latter may or may not be accessible
45// depending on the system and the app configuration.
46BASE_EXPORT bool GetThreadsForCurrentProcess(std::vector<pid_t>* tids);
47
[email protected]662183142010-07-16 19:28:1748// For a given process |pid|, look through all its threads and find the first
49// thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches
50// |expected_data|, where N is the length of |expected_data|.
[email protected]cb7d53e2011-06-21 04:21:0651// Returns the thread id or -1 on error. If |syscall_supported| is
52// set to false the kernel does not support syscall in procfs.
[email protected]0bea7252011-08-05 15:34:0053BASE_EXPORT pid_t FindThreadIDWithSyscall(pid_t pid,
54 const std::string& expected_data,
55 bool* syscall_supported);
[email protected]662183142010-07-16 19:28:1756
reveman7b97c322016-09-20 02:10:5857// For a given process |pid|, look through all its threads and find the first
58// thread with /proc/[pid]/task/[thread_id]/status where NSpid matches |ns_tid|.
59// Returns the thread id or -1 on error. If |ns_pid_supported| is
60// set to false the kernel does not support NSpid in procfs.
61BASE_EXPORT pid_t FindThreadID(pid_t pid, pid_t ns_tid, bool* ns_pid_supported);
62
[email protected]75ae5422009-04-21 17:20:1063} // namespace base
64
[email protected]9bc8cff2010-04-03 01:05:3965#endif // BASE_LINUX_UTIL_H_