michael@0: // Copyright (c) 2013 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_PROCESS_PROCESS_HANDLE_H_ michael@0: #define BASE_PROCESS_PROCESS_HANDLE_H_ michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/basictypes.h" michael@0: #include "base/files/file_path.h" michael@0: #include "build/build_config.h" michael@0: michael@0: #include michael@0: #if defined(OS_WIN) michael@0: #include michael@0: #endif michael@0: michael@0: namespace base { michael@0: michael@0: // ProcessHandle is a platform specific type which represents the underlying OS michael@0: // handle to a process. michael@0: // ProcessId is a number which identifies the process in the OS. michael@0: #if defined(OS_WIN) michael@0: typedef HANDLE ProcessHandle; michael@0: typedef DWORD ProcessId; michael@0: typedef HANDLE UserTokenHandle; michael@0: const ProcessHandle kNullProcessHandle = NULL; michael@0: const ProcessId kNullProcessId = 0; michael@0: #elif defined(OS_POSIX) michael@0: // On POSIX, our ProcessHandle will just be the PID. michael@0: typedef pid_t ProcessHandle; michael@0: typedef pid_t ProcessId; michael@0: const ProcessHandle kNullProcessHandle = 0; michael@0: const ProcessId kNullProcessId = 0; michael@0: #endif // defined(OS_WIN) michael@0: michael@0: // Returns the id of the current process. michael@0: BASE_EXPORT ProcessId GetCurrentProcId(); michael@0: michael@0: // Returns the ProcessHandle of the current process. michael@0: BASE_EXPORT ProcessHandle GetCurrentProcessHandle(); michael@0: michael@0: // Converts a PID to a process handle. This handle must be closed by michael@0: // CloseProcessHandle when you are done with it. Returns true on success. michael@0: BASE_EXPORT bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle); michael@0: michael@0: // Converts a PID to a process handle. On Windows the handle is opened michael@0: // with more access rights and must only be used by trusted code. michael@0: // You have to close returned handle using CloseProcessHandle. Returns true michael@0: // on success. michael@0: // TODO(sanjeevr): Replace all calls to OpenPrivilegedProcessHandle with the michael@0: // more specific OpenProcessHandleWithAccess method and delete this. michael@0: BASE_EXPORT bool OpenPrivilegedProcessHandle(ProcessId pid, michael@0: ProcessHandle* handle); michael@0: michael@0: // Converts a PID to a process handle using the desired access flags. Use a michael@0: // combination of the kProcessAccess* flags defined above for |access_flags|. michael@0: BASE_EXPORT bool OpenProcessHandleWithAccess(ProcessId pid, michael@0: uint32 access_flags, michael@0: ProcessHandle* handle); michael@0: michael@0: // Closes the process handle opened by OpenProcessHandle. michael@0: BASE_EXPORT void CloseProcessHandle(ProcessHandle process); michael@0: michael@0: // Returns the unique ID for the specified process. This is functionally the michael@0: // same as Windows' GetProcessId(), but works on versions of Windows before michael@0: // Win XP SP1 as well. michael@0: BASE_EXPORT ProcessId GetProcId(ProcessHandle process); michael@0: michael@0: #if defined(OS_WIN) michael@0: enum IntegrityLevel { michael@0: INTEGRITY_UNKNOWN, michael@0: LOW_INTEGRITY, michael@0: MEDIUM_INTEGRITY, michael@0: HIGH_INTEGRITY, michael@0: }; michael@0: // Determine the integrity level of the specified process. Returns false michael@0: // if the system does not support integrity levels (pre-Vista) or in the case michael@0: // of an underlying system failure. michael@0: BASE_EXPORT bool GetProcessIntegrityLevel(ProcessHandle process, michael@0: IntegrityLevel* level); michael@0: #endif michael@0: michael@0: #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_BSD) michael@0: // Returns the path to the executable of the given process. michael@0: BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process); michael@0: #endif michael@0: michael@0: #if defined(OS_POSIX) michael@0: // Returns the ID for the parent of the given process. michael@0: BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process); michael@0: #endif michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_PROCESS_PROCESS_HANDLE_H_