fixup! [M120 Migration] Notify media device state to webbrowser
[platform/framework/web/chromium-efl.git] / base / linux_util.h
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 // 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.
46 BASE_EXPORT bool GetThreadsForCurrentProcess(std::vector<pid_t>* tids);
47
48 // 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|.
51 // Returns the thread id or -1 on error.  If |syscall_supported| is
52 // set to false the kernel does not support syscall in procfs.
53 BASE_EXPORT pid_t FindThreadIDWithSyscall(pid_t pid,
54                                           const std::string& expected_data,
55                                           bool* syscall_supported);
56
57 // 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.
61 BASE_EXPORT pid_t FindThreadID(pid_t pid, pid_t ns_tid, bool* ns_pid_supported);
62
63 }  // namespace base
64
65 #endif  // BASE_LINUX_UTIL_H_