summaryrefslogtreecommitdiff
path: root/src/core/memory.h
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 16:29:34 -0500
committerGravatar Lioncash2019-11-26 21:55:39 -0500
commitb05bfc603689419dc515a656b9fc711d79994f13 (patch)
treebc0937d11bbe31458785a69478edbf11a720b0ae /src/core/memory.h
parentcore/memory: Migrate over ZeroBlock() and CopyBlock() to the Memory class (diff)
downloadyuzu-b05bfc603689419dc515a656b9fc711d79994f13.tar.gz
yuzu-b05bfc603689419dc515a656b9fc711d79994f13.tar.xz
yuzu-b05bfc603689419dc515a656b9fc711d79994f13.zip
core/memory: Migrate over Read{8, 16, 32, 64, Block} to the Memory class
With all of the trivial parts of the memory interface moved over, we can get right into moving over the bits that are used. Note that this does require the use of GetInstance from the global system instance to be used within hle_ipc.cpp and the gdbstub. This is fine for the time being, as they both already rely on the global system instance in other functions. These will be removed in a change directed at both of these respectively. For now, it's sufficient, as it still accomplishes the goal of de-globalizing the memory code.
Diffstat (limited to 'src/core/memory.h')
-rw-r--r--src/core/memory.h85
1 files changed, 78 insertions, 7 deletions
diff --git a/src/core/memory.h b/src/core/memory.h
index fc0013a96..cc6ab920e 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -153,6 +153,46 @@ public:
153 const u8* GetPointer(VAddr vaddr) const; 153 const u8* GetPointer(VAddr vaddr) const;
154 154
155 /** 155 /**
156 * Reads an 8-bit unsigned value from the current process' address space
157 * at the given virtual address.
158 *
159 * @param addr The virtual address to read the 8-bit value from.
160 *
161 * @returns the read 8-bit unsigned value.
162 */
163 u8 Read8(VAddr addr);
164
165 /**
166 * Reads a 16-bit unsigned value from the current process' address space
167 * at the given virtual address.
168 *
169 * @param addr The virtual address to read the 16-bit value from.
170 *
171 * @returns the read 16-bit unsigned value.
172 */
173 u16 Read16(VAddr addr);
174
175 /**
176 * Reads a 32-bit unsigned value from the current process' address space
177 * at the given virtual address.
178 *
179 * @param addr The virtual address to read the 32-bit value from.
180 *
181 * @returns the read 32-bit unsigned value.
182 */
183 u32 Read32(VAddr addr);
184
185 /**
186 * Reads a 64-bit unsigned value from the current process' address space
187 * at the given virtual address.
188 *
189 * @param addr The virtual address to read the 64-bit value from.
190 *
191 * @returns the read 64-bit value.
192 */
193 u64 Read64(VAddr addr);
194
195 /**
156 * Reads a null-terminated string from the given virtual address. 196 * Reads a null-terminated string from the given virtual address.
157 * This function will continually read characters until either: 197 * This function will continually read characters until either:
158 * 198 *
@@ -170,6 +210,44 @@ public:
170 std::string ReadCString(VAddr vaddr, std::size_t max_length); 210 std::string ReadCString(VAddr vaddr, std::size_t max_length);
171 211
172 /** 212 /**
213 * Reads a contiguous block of bytes from a specified process' address space.
214 *
215 * @param process The process to read the data from.
216 * @param src_addr The virtual address to begin reading from.
217 * @param dest_buffer The buffer to place the read bytes into.
218 * @param size The amount of data to read, in bytes.
219 *
220 * @note If a size of 0 is specified, then this function reads nothing and
221 * no attempts to access memory are made at all.
222 *
223 * @pre dest_buffer must be at least size bytes in length, otherwise a
224 * buffer overrun will occur.
225 *
226 * @post The range [dest_buffer, size) contains the read bytes from the
227 * process' address space.
228 */
229 void ReadBlock(const Kernel::Process& process, VAddr src_addr, void* dest_buffer,
230 std::size_t size);
231
232 /**
233 * Reads a contiguous block of bytes from the current process' address space.
234 *
235 * @param src_addr The virtual address to begin reading from.
236 * @param dest_buffer The buffer to place the read bytes into.
237 * @param size The amount of data to read, in bytes.
238 *
239 * @note If a size of 0 is specified, then this function reads nothing and
240 * no attempts to access memory are made at all.
241 *
242 * @pre dest_buffer must be at least size bytes in length, otherwise a
243 * buffer overrun will occur.
244 *
245 * @post The range [dest_buffer, size) contains the read bytes from the
246 * current process' address space.
247 */
248 void ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size);
249
250 /**
173 * Fills the specified address range within a process' address space with zeroes. 251 * Fills the specified address range within a process' address space with zeroes.
174 * 252 *
175 * @param process The process that will have a portion of its memory zeroed out. 253 * @param process The process that will have a portion of its memory zeroed out.
@@ -242,18 +320,11 @@ void SetCurrentPageTable(Kernel::Process& process);
242/// Determines if the given VAddr is a kernel address 320/// Determines if the given VAddr is a kernel address
243bool IsKernelVirtualAddress(VAddr vaddr); 321bool IsKernelVirtualAddress(VAddr vaddr);
244 322
245u8 Read8(VAddr addr);
246u16 Read16(VAddr addr);
247u32 Read32(VAddr addr);
248u64 Read64(VAddr addr);
249
250void Write8(VAddr addr, u8 data); 323void Write8(VAddr addr, u8 data);
251void Write16(VAddr addr, u16 data); 324void Write16(VAddr addr, u16 data);
252void Write32(VAddr addr, u32 data); 325void Write32(VAddr addr, u32 data);
253void Write64(VAddr addr, u64 data); 326void Write64(VAddr addr, u64 data);
254 327
255void ReadBlock(const Kernel::Process& process, VAddr src_addr, void* dest_buffer, std::size_t size);
256void ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size);
257void WriteBlock(const Kernel::Process& process, VAddr dest_addr, const void* src_buffer, 328void WriteBlock(const Kernel::Process& process, VAddr dest_addr, const void* src_buffer,
258 std::size_t size); 329 std::size_t size);
259void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size); 330void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);