15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_LINUX_UTIL_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_LINUX_UTIL_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdint.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <sys/types.h> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/base_export.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT extern const char kFindInodeSwitch[]; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is declared here so the crash reporter can access the memory directly 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in compromised context without going through the standard library. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT extern char g_linux_distro[]; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the Linux Distro if we can, or return "Unknown". 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT std::string GetLinuxDistro(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the Linux Distro string. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT void SetLinuxDistro(const std::string& distro); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return the inode number for the UNIX domain socket |fd|. 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT bool FileDescriptorGetInode(ino_t* inode_out, int fd); 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Find the process which holds the given socket, named by inode number. If 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// multiple processes hold the socket, this function returns false. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// For a given process |pid|, look through all its threads and find the first 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |expected_data|, where N is the length of |expected_data|. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the thread id or -1 on error. If |syscall_supported| is 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// set to false the kernel does not support syscall in procfs. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT pid_t FindThreadIDWithSyscall(pid_t pid, 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& expected_data, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* syscall_supported); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace base 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // BASE_LINUX_UTIL_H_ 48