1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Use of this source code is governed by a BSD-style license that can be
3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// found in the LICENSE file.
4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef BASE_LINUX_UTIL_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define BASE_LINUX_UTIL_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include <stdint.h>
10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include <sys/types.h>
11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include <string>
13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace base {
15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstatic const char kFindInodeSwitch[] = "--find-inode";
17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
183345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// This is declared here so the crash reporter can access the memory directly
193345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// in compromised context without going through the standard library.
203345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickextern char g_linux_distro[];
213345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
223f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen// Get the Linux Distro if we can, or return "Unknown".
23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottstd::string GetLinuxDistro();
24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
253345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// Set the Linux Distro string.
263345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickvoid SetLinuxDistro(const std::string& distro);
273345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Return the inode number for the UNIX domain socket |fd|.
29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottbool FileDescriptorGetInode(ino_t* inode_out, int fd);
30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Find the process which holds the given socket, named by inode number. If
32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// multiple processes hold the socket, this function returns false.
33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottbool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode);
34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// For a given process |pid|, look through all its threads and find the first
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// |expected_data|, where N is the length of |expected_data|.
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Returns the thread id or -1 on error.
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochpid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data);
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}  // namespace base
42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // BASE_LINUX_UTIL_H_
44