summaryrefslogtreecommitdiff
path: root/src/core/memory_hook.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/memory_hook.h')
-rw-r--r--src/core/memory_hook.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/core/memory_hook.h b/src/core/memory_hook.h
new file mode 100644
index 000000000..feebd850a
--- /dev/null
+++ b/src/core/memory_hook.h
@@ -0,0 +1,46 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8#include <boost/optional.hpp>
9#include "common/common_types.h"
10
11namespace Memory {
12
13/**
14 * Memory hooks have two purposes:
15 * 1. To allow reads and writes to a region of memory to be intercepted. This is used to implement
16 * texture forwarding and memory breakpoints for debugging.
17 * 2. To allow for the implementation of MMIO devices.
18 *
19 * A hook may be mapped to multiple regions of memory.
20 *
21 * If a boost::none or false is returned from a function, the read/write request is passed through
22 * to the underlying memory region.
23 */
24class MemoryHook {
25public:
26 virtual ~MemoryHook() = default;
27
28 virtual boost::optional<bool> IsValidAddress(VAddr addr) = 0;
29
30 virtual boost::optional<u8> Read8(VAddr addr) = 0;
31 virtual boost::optional<u16> Read16(VAddr addr) = 0;
32 virtual boost::optional<u32> Read32(VAddr addr) = 0;
33 virtual boost::optional<u64> Read64(VAddr addr) = 0;
34
35 virtual bool ReadBlock(VAddr src_addr, void* dest_buffer, size_t size) = 0;
36
37 virtual bool Write8(VAddr addr, u8 data) = 0;
38 virtual bool Write16(VAddr addr, u16 data) = 0;
39 virtual bool Write32(VAddr addr, u32 data) = 0;
40 virtual bool Write64(VAddr addr, u64 data) = 0;
41
42 virtual bool WriteBlock(VAddr dest_addr, const void* src_buffer, size_t size) = 0;
43};
44
45using MemoryHookPointer = std::shared_ptr<MemoryHook>;
46} // namespace Memory