xref: /aosp_15_r20/external/libchrome/base/linux_util.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_LINUX_UTIL_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_LINUX_UTIL_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <stdint.h>
9*635a8641SAndroid Build Coastguard Worker #include <sys/types.h>
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker #include <string>
12*635a8641SAndroid Build Coastguard Worker 
13*635a8641SAndroid Build Coastguard Worker #include "base/base_export.h"
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker namespace base {
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker // This is declared here so the crash reporter can access the memory directly
18*635a8641SAndroid Build Coastguard Worker // in compromised context without going through the standard library.
19*635a8641SAndroid Build Coastguard Worker BASE_EXPORT extern char g_linux_distro[];
20*635a8641SAndroid Build Coastguard Worker 
21*635a8641SAndroid Build Coastguard Worker // Get the Linux Distro if we can, or return "Unknown".
22*635a8641SAndroid Build Coastguard Worker BASE_EXPORT std::string GetLinuxDistro();
23*635a8641SAndroid Build Coastguard Worker 
24*635a8641SAndroid Build Coastguard Worker // Set the Linux Distro string.
25*635a8641SAndroid Build Coastguard Worker BASE_EXPORT void SetLinuxDistro(const std::string& distro);
26*635a8641SAndroid Build Coastguard Worker 
27*635a8641SAndroid Build Coastguard Worker // For a given process |pid|, look through all its threads and find the first
28*635a8641SAndroid Build Coastguard Worker // thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches
29*635a8641SAndroid Build Coastguard Worker // |expected_data|, where N is the length of |expected_data|.
30*635a8641SAndroid Build Coastguard Worker // Returns the thread id or -1 on error.  If |syscall_supported| is
31*635a8641SAndroid Build Coastguard Worker // set to false the kernel does not support syscall in procfs.
32*635a8641SAndroid Build Coastguard Worker BASE_EXPORT pid_t FindThreadIDWithSyscall(pid_t pid,
33*635a8641SAndroid Build Coastguard Worker                                           const std::string& expected_data,
34*635a8641SAndroid Build Coastguard Worker                                           bool* syscall_supported);
35*635a8641SAndroid Build Coastguard Worker 
36*635a8641SAndroid Build Coastguard Worker // For a given process |pid|, look through all its threads and find the first
37*635a8641SAndroid Build Coastguard Worker // thread with /proc/[pid]/task/[thread_id]/status where NSpid matches |ns_tid|.
38*635a8641SAndroid Build Coastguard Worker // Returns the thread id or -1 on error.  If |ns_pid_supported| is
39*635a8641SAndroid Build Coastguard Worker // set to false the kernel does not support NSpid in procfs.
40*635a8641SAndroid Build Coastguard Worker BASE_EXPORT pid_t FindThreadID(pid_t pid, pid_t ns_tid, bool* ns_pid_supported);
41*635a8641SAndroid Build Coastguard Worker 
42*635a8641SAndroid Build Coastguard Worker }  // namespace base
43*635a8641SAndroid Build Coastguard Worker 
44*635a8641SAndroid Build Coastguard Worker #endif  // BASE_LINUX_UTIL_H_
45