-
Notifications
You must be signed in to change notification settings - Fork 35
/
proc_service.cc
221 lines (194 loc) · 4.59 KB
/
proc_service.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "libpstack/proc.h"
#include "libpstack/ps_callback.h"
#include "libpstack/fs.h"
#include <cstdarg>
using pstack::Procman::Process;
using namespace pstack;
extern "C" {
ps_err_e
ps_pcontinue(const struct ps_prochandle *ph)
{
auto p = const_cast<Process *>(static_cast<const Process *>(ph));
try {
p->resumeProcess();
return PS_OK;
}
catch (...) {
return PS_ERR;
}
}
ps_err_e
ps_lcontinue(const struct ps_prochandle *ph, lwpid_t pid)
{
auto p = const_cast<Process *>(static_cast<const Process *>(ph));
try {
p->resume(pid);
return PS_OK;
}
catch (...) {
return PS_ERR;
}
}
ps_err_e ps_pdmodel(struct ps_prochandle * /* unused */, int * /* unused */)
{
abort();
return (PS_ERR);
}
ps_err_e
ps_pglobal_lookup(struct ps_prochandle *ph, const char *ld_object_name,
const char *ld_symbol_name, psaddr_t *ld_symbol_addr)
{
auto p = static_cast<Process *>(ph);
try {
*ld_symbol_addr = psaddr_t(intptr_t(p->resolveSymbol(ld_symbol_name, true,
[ld_object_name](std::string_view name) {
auto bn = basename(std::string(name));
return bn == ld_object_name || bn == "libc.so.6";
}
)));
return PS_OK;
}
catch (...) {
return PS_ERR;
}
}
void
ps_plog(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
ps_err_e
ps_pread(struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t len)
{
auto *p = static_cast<const Process *>(ph);
try {
p->io->readObj(Elf::Off(addr), (char *)buf, len);
return PS_OK;
}
catch (...) {
return PS_ERR;
}
}
ps_err_e
ps_pstop(const struct ps_prochandle *ph)
{
auto *p = const_cast<Process *>(static_cast<const Process *>(ph));
try {
p->stopProcess();
return PS_OK;
} catch (...) {
return PS_ERR;
}
}
ps_err_e
ps_pwrite(struct ps_prochandle * /* unused */, psaddr_t /* unused */, const void * /* unused */, size_t /* unused */)
{
return (PS_ERR);
}
pid_t
ps_getpid(struct ps_prochandle *p)
{
return static_cast<Process *>(p)->getPID();
}
ps_err_e
ps_pdread(struct ps_prochandle *p, psaddr_t addr, void *d, size_t l)
{
try {
static_cast<Process *>(p)->io->readObj(Elf::Off(addr), (char *)d, l);
return PS_OK;
}
catch (...) {
return PS_ERR;
}
}
ps_err_e
ps_pdwrite(struct ps_prochandle * /* unused */, psaddr_t /* unused */,
const void * /* unused */, size_t /* unused */)
{
abort();
return PS_ERR;
}
ps_err_e
ps_ptread(struct ps_prochandle * /* unused */, psaddr_t /* unused */,
void * /* unused */, size_t /* unused */)
{
abort();
return PS_ERR;
}
ps_err_e
ps_ptwrite(struct ps_prochandle * /* unused */, psaddr_t /* unused */,
const void * /* unused */, size_t /* unused */)
{
abort();
return PS_ERR;
}
#ifdef __i386__
ps_err_e
ps_lgetxmmregs (struct ps_prochandle * /* unused */,
lwpid_t /* unused */, char * /* unused */)
{
abort();
return (PS_ERR);
}
ps_err_e
ps_lsetxmmregs (struct ps_prochandle * /* unused */, lwpid_t /* unused */,
const char * /* unused */)
{
abort();
return (PS_ERR);
}
#endif
ps_err_e ps_lgetfpregs(struct ps_prochandle * /* unused */, lwpid_t /* unused */,
prfpregset_t * /* unused */)
{
abort();
return (PS_ERR);
}
ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t pid, prgregset_t gregset)
{
auto p = static_cast<Process *>(ph);
return p->getRegset<Elf::CoreRegisters, NT_PRSTATUS>(pid, *(user_regs_struct *)gregset) ? PS_OK : PS_ERR;
}
ps_err_e ps_lsetfpregs(struct ps_prochandle * /* unused */, lwpid_t /* unused */,
const prfpregset_t * /* unused */)
{
abort();
return (PS_ERR);
}
ps_err_e ps_lsetregs(struct ps_prochandle * /* unused */, lwpid_t /* unused */,
const prgregset_t /* unused */)
{
abort();
return (PS_ERR);
}
ps_err_e ps_lstop(const struct ps_prochandle *ph, lwpid_t lwpid)
{
Process *p = const_cast<Process *>(static_cast<const Process *>(ph));
try {
p->stop(lwpid);
return PS_OK;
}
catch (...) {
return PS_ERR;
}
}
#if defined(__FreeBSD__)
ps_err_e
ps_linfo(struct ps_prochandle *p, lwpid_t pid, void *info)
{
if (p->pid == -1) {
if (ptrace(PT_LWPINFO, pid, info,
sizeof (struct ptrace_lwpinfo)) == -1)
return (PS_ERR);
else
return (PS_OK);
} else {
memset(info, 0, sizeof(struct ptrace_lwpinfo));
return PS_OK;
}
}
#endif
}