DebugServer2
Loading...
Searching...
No Matches
Platform.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Types.h"
14
15#include <functional>
16#if defined(OS_DARWIN)
17#include <mach/kern_return.h>
18#endif
19#include <string>
20
21namespace ds2 {
22namespace Host {
23
24class Platform {
25public:
26 static void Initialize();
27
28public:
29 static CPUType GetCPUType();
30 static CPUSubType GetCPUSubType();
31 static Endian GetEndian();
32 static size_t GetPointerSize();
33 static size_t GetPageSize();
34
35public:
36 static char const *GetHostName(bool fqdn = false);
37
38public:
39 static char const *GetOSTypeName();
40 static char const *GetOSVendorName();
41 static char const *GetOSVersion();
42 static char const *GetOSBuild();
43 static char const *GetOSKernelVersion();
44
45public:
46 static bool GetUserName(UserId const &uid, std::string &name);
47 static bool GetGroupName(GroupId const &gid, std::string &name);
48
49public:
50 static int OpenFile(std::string const &path, uint32_t flags, uint32_t mode);
51 static bool CloseFile(int fd);
52 static bool IsFilePresent(std::string const &path);
53 static std::string GetWorkingDirectory();
54 static bool SetWorkingDirectory(std::string const &directory);
55
56public:
57 static ProcessId GetCurrentProcessId();
58 static const char *GetSelfExecutablePath();
59 static bool GetCurrentEnvironment(EnvironmentBlock &env);
60
61public:
62#if defined(OS_POSIX)
63 static ErrorCode TranslateError(int error);
64#elif defined(OS_WIN32)
65 static ErrorCode TranslateError(DWORD error);
66#endif
67 static ErrorCode TranslateError();
68#if defined(OS_DARWIN)
69 static ErrorCode TranslateKernError(kern_return_t kret);
70#endif
71
72public:
73 static bool GetProcessInfo(ProcessId pid, ProcessInfo &info);
74 static void
75 EnumerateProcesses(bool allUsers, UserId const &uid,
76 std::function<void(ProcessInfo const &info)> const &cb);
77 static bool TerminateProcess(ProcessId pid);
78
79public:
80 static std::string GetThreadName(ProcessId pid, ThreadId tid);
81
82public:
83 static bool GetExecutableFileBuildID(std::string const &path, ByteVector &buildId);
84};
85} // namespace Host
86} // namespace ds2
Definition Platform.h:24
Definition Types.h:263