#ifndef BASE_PROCESS_PROCESS_HANDLE_H_
#define BASE_PROCESS_PROCESS_HANDLE_H_
#include <stdint.h>
#include <sys/types.h>
#include <iosfwd>
#include "base/base_export.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#endif
#if BUILDFLAG(IS_FUCHSIA)
#include <zircon/types.h>
#endif
namespace base {
class FilePath;
#if BUILDFLAG(IS_WIN)
typedef HANDLE ProcessHandle;
typedef DWORD ProcessId;
typedef HANDLE UserTokenHandle;
const ProcessHandle kNullProcessHandle = NULL;
const ProcessId kNullProcessId = 0;
#elif BUILDFLAG(IS_FUCHSIA)
typedef zx_handle_t ProcessHandle;
typedef zx_koid_t ProcessId;
const ProcessHandle kNullProcessHandle = ZX_HANDLE_INVALID;
const ProcessId kNullProcessId = ZX_KOID_INVALID;
#elif BUILDFLAG(IS_POSIX)
typedef pid_t ProcessHandle;
typedef pid_t ProcessId;
const ProcessHandle kNullProcessHandle = 0;
const ProcessId kNullProcessId = 0;
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA)
#define CrPRIdPid "ld"
#else
#define CrPRIdPid "d"
#endif
class UniqueProcId {
public:
explicit UniqueProcId(ProcessId value) : value_(value) {}
UniqueProcId(const UniqueProcId& other) = default;
UniqueProcId& operator=(const UniqueProcId& other) = default;
ProcessId GetUnsafeValue() const { return value_; }
bool operator==(const UniqueProcId& other) const {
return value_ == other.value_;
}
bool operator!=(const UniqueProcId& other) const {
return value_ != other.value_;
}
bool operator<(const UniqueProcId& other) const {
return value_ < other.value_;
}
bool operator<=(const UniqueProcId& other) const {
return value_ <= other.value_;
}
bool operator>(const UniqueProcId& other) const {
return value_ > other.value_;
}
bool operator>=(const UniqueProcId& other) const {
return value_ >= other.value_;
}
private:
ProcessId value_;
};
std::ostream& operator<<(std::ostream& os, const UniqueProcId& obj);
BASE_EXPORT ProcessId GetCurrentProcId();
#if BUILDFLAG(IS_OHOS)
BASE_EXPORT ProcessId GetCurrentRealPid();
#endif
BASE_EXPORT UniqueProcId GetUniqueIdForProcess();
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_OHOS)
BASE_EXPORT void InitUniqueIdForProcessInPidNamespace(
ProcessId pid_outside_of_namespace);
#endif
BASE_EXPORT ProcessHandle GetCurrentProcessHandle();
BASE_EXPORT ProcessId GetProcId(ProcessHandle process);
#if !BUILDFLAG(IS_FUCHSIA)
BASE_EXPORT ProcessId GetParentProcessId(ProcessHandle process);
#endif
#if BUILDFLAG(IS_POSIX)
BASE_EXPORT FilePath GetProcessExecutablePath(ProcessHandle process);
#endif
}
#endif