DebugServer2
Loading...
Searching...
No Matches
Process.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/Host/ProcessSpawner.h"
14#include "DebugServer2/Target/ProcessBase.h"
15
16namespace ds2 {
17namespace Target {
18namespace Windows {
19
21 public ds2::make_unique_enabler<Process> {
22protected:
23 HANDLE _handle;
24
25protected:
26 Process();
27
28public:
29 ~Process() override;
30
31public:
32 inline HANDLE handle() const { return _handle; }
33
34protected:
35 ErrorCode initialize(ProcessId pid, uint32_t flags) override;
36
37private:
38 ErrorCode writeDebugBreakCode(uint64_t address);
39
40public:
41 ErrorCode detach() override;
42 ErrorCode interrupt() override;
43 ErrorCode terminate() override;
44 bool isAlive() const override;
45
46public:
47 ErrorCode readString(Address const &address, std::string &str, size_t length,
48 size_t *nread = nullptr) override;
49 ErrorCode readMemory(Address const &address, void *data, size_t length,
50 size_t *nread = nullptr) override;
51 ErrorCode writeMemory(Address const &address, void const *data, size_t length,
52 size_t *nwritten = nullptr) override;
53
54private:
55 ErrorCode makeMemoryWritable(Address const &address, size_t length,
56 std::vector<MemoryRegionInfo> &modifiedRegions);
57 ErrorCode
58 restoreRegionsProtection(const std::vector<MemoryRegionInfo> &regions);
59
60protected:
61 DWORD convertMemoryProtectionToWindows(uint32_t protection) const;
62 uint32_t convertMemoryProtectionFromWindows(DWORD winProtection) const;
63
64public:
65 ErrorCode getMemoryRegionInfo(Address const &address,
66 MemoryRegionInfo &info) override;
67
68public:
69 ErrorCode updateInfo() override;
70
71public:
72 ErrorCode allocateMemory(size_t size, uint32_t protection,
73 uint64_t *address) override;
74 ErrorCode deallocateMemory(uint64_t address, size_t size) override;
75
76public:
77 ErrorCode wait() override;
78
79public:
80 static Target::Process *Create(Host::ProcessSpawner &spawner);
81 static Target::Process *Attach(ProcessId pid);
82
83public:
84 ErrorCode enumerateSharedLibraries(
85 std::function<void(SharedLibraryInfo const &)> const &cb) override;
86};
87} // namespace Windows
88} // namespace Target
89} // namespace ds2
Definition Types.h:95
Definition ProcessSpawner.h:20
Definition ProcessBase.h:25
Definition Process.h:21
Definition Types.h:361
Definition Types.h:397
Definition Base.h:138