summaryrefslogtreecommitdiff
path: root/src/common/memory_hook.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2019-03-17 14:42:57 -0400
committerGitHub <noreply@github.com>2019-03-17 14:42:57 -0400
commit57ca1e3e6942d1ef1b59c458e76ba969f0b739d5 (patch)
tree1d7a026c695a73932030048329a2c0707656666e /src/common/memory_hook.h
parent41566c615b86183c4dbec5a6bc7596ed4d8a116b (diff)
parent93da8e0abfcdcc6e3cb5488a0db12373429f1377 (diff)
Merge pull request #2252 from bunnei/move-page-table
core: Move PageTable struct into Common.
Diffstat (limited to 'src/common/memory_hook.h')
-rw-r--r--src/common/memory_hook.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/common/memory_hook.h b/src/common/memory_hook.h
new file mode 100644
index 000000000..adaa4c2c5
--- /dev/null
+++ b/src/common/memory_hook.h
@@ -0,0 +1,47 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <optional>
+
+#include "common/common_types.h"
+
+namespace Common {
+
+/**
+ * Memory hooks have two purposes:
+ * 1. To allow reads and writes to a region of memory to be intercepted. This is used to implement
+ * texture forwarding and memory breakpoints for debugging.
+ * 2. To allow for the implementation of MMIO devices.
+ *
+ * A hook may be mapped to multiple regions of memory.
+ *
+ * If a std::nullopt or false is returned from a function, the read/write request is passed through
+ * to the underlying memory region.
+ */
+class MemoryHook {
+public:
+ virtual ~MemoryHook();
+
+ virtual std::optional<bool> IsValidAddress(VAddr addr) = 0;
+
+ virtual std::optional<u8> Read8(VAddr addr) = 0;
+ virtual std::optional<u16> Read16(VAddr addr) = 0;
+ virtual std::optional<u32> Read32(VAddr addr) = 0;
+ virtual std::optional<u64> Read64(VAddr addr) = 0;
+
+ virtual bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) = 0;
+
+ virtual bool Write8(VAddr addr, u8 data) = 0;
+ virtual bool Write16(VAddr addr, u16 data) = 0;
+ virtual bool Write32(VAddr addr, u32 data) = 0;
+ virtual bool Write64(VAddr addr, u64 data) = 0;
+
+ virtual bool WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size) = 0;
+};
+
+using MemoryHookPointer = std::shared_ptr<MemoryHook>;
+} // namespace Common