blob: 0ea87d329032c4d1d31ebd3b0ef7f192cce4c818 (
plain) (
blame)
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
|
#pragma once
#include "public.h"
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
//! Enables safe read-only access to the address space of the current process.
/*!
* Inaccessible memory locations will not cause any traps but rather report
* failure via return value.
*/
class TSafeMemoryReader
{
public:
TSafeMemoryReader();
TSafeMemoryReader(const TSafeMemoryReader&) = delete;
~TSafeMemoryReader();
//! Attempts to read #value at address #addr.
//! Returns |true| on success, |false| on failure.
template <class T>
bool Read(const void* addr, T* value);
private:
int FD_ = -1;
bool ReadRaw(const void* addr, void* ptr, size_t size);
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
#define SAFE_MEMORY_READER_INL_H_
#include "safe_memory_reader-inl.h"
#undef SAFE_MEMORY_READER_INL_H_
|