blob: 0e079d787cf4079ca114e060f69707e9700d4501 [file] [log] [blame]
evan@chromium.org3e208892011-05-03 02:54:14 +09001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
sgk@google.come1f4a242009-04-22 02:20:10 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
thestig@chromium.orgb6ba9432010-04-03 10:05:39 +09005#ifndef BASE_LINUX_UTIL_H_
6#define BASE_LINUX_UTIL_H_
thakis@chromium.org01d14522010-07-27 08:08:24 +09007#pragma once
sgk@google.come1f4a242009-04-22 02:20:10 +09008
9#include <stdint.h>
craig.schlenter@chromium.orgfd4599a2009-10-30 03:21:30 +090010#include <sys/types.h>
sgk@google.come1f4a242009-04-22 02:20:10 +090011
thestig@chromium.orga5a2b6e2009-07-17 14:55:51 +090012#include <string>
13
evan@chromium.org3e208892011-05-03 02:54:14 +090014#include "base/base_api.h"
15
sgk@google.come1f4a242009-04-22 02:20:10 +090016namespace base {
17
thestig@chromium.org4352f4d2009-11-04 17:32:22 +090018static const char kFindInodeSwitch[] = "--find-inode";
19
mnissler@chromium.org8584b6d2010-08-26 17:55:22 +090020// This is declared here so the crash reporter can access the memory directly
21// in compromised context without going through the standard library.
22extern char g_linux_distro[];
23
brettw@google.comf4fe79b2011-01-01 02:18:50 +090024// Get the Linux Distro if we can, or return "Unknown".
thestig@chromium.orga5a2b6e2009-07-17 14:55:51 +090025std::string GetLinuxDistro();
26
mnissler@chromium.org8584b6d2010-08-26 17:55:22 +090027// Set the Linux Distro string.
28void SetLinuxDistro(const std::string& distro);
29
thestig@chromium.org2feb1c82009-10-29 13:02:55 +090030// Return the inode number for the UNIX domain socket |fd|.
evan@chromium.org3e208892011-05-03 02:54:14 +090031BASE_API bool FileDescriptorGetInode(ino_t* inode_out, int fd);
thestig@chromium.org2feb1c82009-10-29 13:02:55 +090032
33// Find the process which holds the given socket, named by inode number. If
34// multiple processes hold the socket, this function returns false.
35bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode);
36
thestig@chromium.org44836d42010-07-17 04:28:17 +090037// For a given process |pid|, look through all its threads and find the first
38// thread with /proc/[pid]/task/[thread_id]/syscall whose first N bytes matches
39// |expected_data|, where N is the length of |expected_data|.
40// Returns the thread id or -1 on error.
41pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data);
42
sgk@google.come1f4a242009-04-22 02:20:10 +090043} // namespace base
44
thestig@chromium.orgb6ba9432010-04-03 10:05:39 +090045#endif // BASE_LINUX_UTIL_H_