summaryrefslogtreecommitdiff
path: root/src/core/memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/memory.h')
-rw-r--r--src/core/memory.h88
1 files changed, 47 insertions, 41 deletions
diff --git a/src/core/memory.h b/src/core/memory.h
index 31fe699d8..ed4e87739 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -6,7 +6,7 @@
6#include <cstddef> 6#include <cstddef>
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include "common/common_types.h" 9#include "common/typed_address.h"
10#include "core/hle/result.h" 10#include "core/hle/result.h"
11 11
12namespace Common { 12namespace Common {
@@ -33,7 +33,7 @@ constexpr u64 YUZU_PAGESIZE = 1ULL << YUZU_PAGEBITS;
33constexpr u64 YUZU_PAGEMASK = YUZU_PAGESIZE - 1; 33constexpr u64 YUZU_PAGEMASK = YUZU_PAGESIZE - 1;
34 34
35/// Virtual user-space memory regions 35/// Virtual user-space memory regions
36enum : VAddr { 36enum : u64 {
37 /// TLS (Thread-Local Storage) related. 37 /// TLS (Thread-Local Storage) related.
38 TLS_ENTRY_SIZE = 0x200, 38 TLS_ENTRY_SIZE = 0x200,
39 39
@@ -74,7 +74,8 @@ public:
74 * @param target Buffer with the memory backing the mapping. Must be of length at least 74 * @param target Buffer with the memory backing the mapping. Must be of length at least
75 * `size`. 75 * `size`.
76 */ 76 */
77 void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, PAddr target); 77 void MapMemoryRegion(Common::PageTable& page_table, Common::ProcessAddress base, u64 size,
78 Common::PhysicalAddress target);
78 79
79 /** 80 /**
80 * Unmaps a region of the emulated process address space. 81 * Unmaps a region of the emulated process address space.
@@ -83,7 +84,7 @@ public:
83 * @param base The address to begin unmapping at. 84 * @param base The address to begin unmapping at.
84 * @param size The amount of bytes to unmap. 85 * @param size The amount of bytes to unmap.
85 */ 86 */
86 void UnmapRegion(Common::PageTable& page_table, VAddr base, u64 size); 87 void UnmapRegion(Common::PageTable& page_table, Common::ProcessAddress base, u64 size);
87 88
88 /** 89 /**
89 * Checks whether or not the supplied address is a valid virtual 90 * Checks whether or not the supplied address is a valid virtual
@@ -93,7 +94,7 @@ public:
93 * 94 *
94 * @returns True if the given virtual address is valid, false otherwise. 95 * @returns True if the given virtual address is valid, false otherwise.
95 */ 96 */
96 [[nodiscard]] bool IsValidVirtualAddress(VAddr vaddr) const; 97 [[nodiscard]] bool IsValidVirtualAddress(Common::ProcessAddress vaddr) const;
97 98
98 /** 99 /**
99 * Checks whether or not the supplied range of addresses are all valid 100 * Checks whether or not the supplied range of addresses are all valid
@@ -104,7 +105,7 @@ public:
104 * 105 *
105 * @returns True if all bytes in the given range are valid, false otherwise. 106 * @returns True if all bytes in the given range are valid, false otherwise.
106 */ 107 */
107 [[nodiscard]] bool IsValidVirtualAddressRange(VAddr base, u64 size) const; 108 [[nodiscard]] bool IsValidVirtualAddressRange(Common::ProcessAddress base, u64 size) const;
108 109
109 /** 110 /**
110 * Gets a pointer to the given address. 111 * Gets a pointer to the given address.
@@ -114,11 +115,11 @@ public:
114 * @returns The pointer to the given address, if the address is valid. 115 * @returns The pointer to the given address, if the address is valid.
115 * If the address is not valid, nullptr will be returned. 116 * If the address is not valid, nullptr will be returned.
116 */ 117 */
117 u8* GetPointer(VAddr vaddr); 118 u8* GetPointer(Common::ProcessAddress vaddr);
118 u8* GetPointerSilent(VAddr vaddr); 119 u8* GetPointerSilent(Common::ProcessAddress vaddr);
119 120
120 template <typename T> 121 template <typename T>
121 T* GetPointer(VAddr vaddr) { 122 T* GetPointer(Common::ProcessAddress vaddr) {
122 return reinterpret_cast<T*>(GetPointer(vaddr)); 123 return reinterpret_cast<T*>(GetPointer(vaddr));
123 } 124 }
124 125
@@ -130,10 +131,10 @@ public:
130 * @returns The pointer to the given address, if the address is valid. 131 * @returns The pointer to the given address, if the address is valid.
131 * If the address is not valid, nullptr will be returned. 132 * If the address is not valid, nullptr will be returned.
132 */ 133 */
133 [[nodiscard]] const u8* GetPointer(VAddr vaddr) const; 134 [[nodiscard]] const u8* GetPointer(Common::ProcessAddress vaddr) const;
134 135
135 template <typename T> 136 template <typename T>
136 const T* GetPointer(VAddr vaddr) const { 137 const T* GetPointer(Common::ProcessAddress vaddr) const {
137 return reinterpret_cast<T*>(GetPointer(vaddr)); 138 return reinterpret_cast<T*>(GetPointer(vaddr));
138 } 139 }
139 140
@@ -145,7 +146,7 @@ public:
145 * 146 *
146 * @returns the read 8-bit unsigned value. 147 * @returns the read 8-bit unsigned value.
147 */ 148 */
148 u8 Read8(VAddr addr); 149 u8 Read8(Common::ProcessAddress addr);
149 150
150 /** 151 /**
151 * Reads a 16-bit unsigned value from the current process' address space 152 * Reads a 16-bit unsigned value from the current process' address space
@@ -155,7 +156,7 @@ public:
155 * 156 *
156 * @returns the read 16-bit unsigned value. 157 * @returns the read 16-bit unsigned value.
157 */ 158 */
158 u16 Read16(VAddr addr); 159 u16 Read16(Common::ProcessAddress addr);
159 160
160 /** 161 /**
161 * Reads a 32-bit unsigned value from the current process' address space 162 * Reads a 32-bit unsigned value from the current process' address space
@@ -165,7 +166,7 @@ public:
165 * 166 *
166 * @returns the read 32-bit unsigned value. 167 * @returns the read 32-bit unsigned value.
167 */ 168 */
168 u32 Read32(VAddr addr); 169 u32 Read32(Common::ProcessAddress addr);
169 170
170 /** 171 /**
171 * Reads a 64-bit unsigned value from the current process' address space 172 * Reads a 64-bit unsigned value from the current process' address space
@@ -175,7 +176,7 @@ public:
175 * 176 *
176 * @returns the read 64-bit value. 177 * @returns the read 64-bit value.
177 */ 178 */
178 u64 Read64(VAddr addr); 179 u64 Read64(Common::ProcessAddress addr);
179 180
180 /** 181 /**
181 * Writes an 8-bit unsigned integer to the given virtual address in 182 * Writes an 8-bit unsigned integer to the given virtual address in
@@ -186,7 +187,7 @@ public:
186 * 187 *
187 * @post The memory at the given virtual address contains the specified data value. 188 * @post The memory at the given virtual address contains the specified data value.
188 */ 189 */
189 void Write8(VAddr addr, u8 data); 190 void Write8(Common::ProcessAddress addr, u8 data);
190 191
191 /** 192 /**
192 * Writes a 16-bit unsigned integer to the given virtual address in 193 * Writes a 16-bit unsigned integer to the given virtual address in
@@ -197,7 +198,7 @@ public:
197 * 198 *
198 * @post The memory range [addr, sizeof(data)) contains the given data value. 199 * @post The memory range [addr, sizeof(data)) contains the given data value.
199 */ 200 */
200 void Write16(VAddr addr, u16 data); 201 void Write16(Common::ProcessAddress addr, u16 data);
201 202
202 /** 203 /**
203 * Writes a 32-bit unsigned integer to the given virtual address in 204 * Writes a 32-bit unsigned integer to the given virtual address in
@@ -208,7 +209,7 @@ public:
208 * 209 *
209 * @post The memory range [addr, sizeof(data)) contains the given data value. 210 * @post The memory range [addr, sizeof(data)) contains the given data value.
210 */ 211 */
211 void Write32(VAddr addr, u32 data); 212 void Write32(Common::ProcessAddress addr, u32 data);
212 213
213 /** 214 /**
214 * Writes a 64-bit unsigned integer to the given virtual address in 215 * Writes a 64-bit unsigned integer to the given virtual address in
@@ -219,7 +220,7 @@ public:
219 * 220 *
220 * @post The memory range [addr, sizeof(data)) contains the given data value. 221 * @post The memory range [addr, sizeof(data)) contains the given data value.
221 */ 222 */
222 void Write64(VAddr addr, u64 data); 223 void Write64(Common::ProcessAddress addr, u64 data);
223 224
224 /** 225 /**
225 * Writes a 8-bit unsigned integer to the given virtual address in 226 * Writes a 8-bit unsigned integer to the given virtual address in
@@ -232,7 +233,7 @@ public:
232 * 233 *
233 * @post The memory range [addr, sizeof(data)) contains the given data value. 234 * @post The memory range [addr, sizeof(data)) contains the given data value.
234 */ 235 */
235 bool WriteExclusive8(VAddr addr, u8 data, u8 expected); 236 bool WriteExclusive8(Common::ProcessAddress addr, u8 data, u8 expected);
236 237
237 /** 238 /**
238 * Writes a 16-bit unsigned integer to the given virtual address in 239 * Writes a 16-bit unsigned integer to the given virtual address in
@@ -245,7 +246,7 @@ public:
245 * 246 *
246 * @post The memory range [addr, sizeof(data)) contains the given data value. 247 * @post The memory range [addr, sizeof(data)) contains the given data value.
247 */ 248 */
248 bool WriteExclusive16(VAddr addr, u16 data, u16 expected); 249 bool WriteExclusive16(Common::ProcessAddress addr, u16 data, u16 expected);
249 250
250 /** 251 /**
251 * Writes a 32-bit unsigned integer to the given virtual address in 252 * Writes a 32-bit unsigned integer to the given virtual address in
@@ -258,7 +259,7 @@ public:
258 * 259 *
259 * @post The memory range [addr, sizeof(data)) contains the given data value. 260 * @post The memory range [addr, sizeof(data)) contains the given data value.
260 */ 261 */
261 bool WriteExclusive32(VAddr addr, u32 data, u32 expected); 262 bool WriteExclusive32(Common::ProcessAddress addr, u32 data, u32 expected);
262 263
263 /** 264 /**
264 * Writes a 64-bit unsigned integer to the given virtual address in 265 * Writes a 64-bit unsigned integer to the given virtual address in
@@ -271,7 +272,7 @@ public:
271 * 272 *
272 * @post The memory range [addr, sizeof(data)) contains the given data value. 273 * @post The memory range [addr, sizeof(data)) contains the given data value.
273 */ 274 */
274 bool WriteExclusive64(VAddr addr, u64 data, u64 expected); 275 bool WriteExclusive64(Common::ProcessAddress addr, u64 data, u64 expected);
275 276
276 /** 277 /**
277 * Writes a 128-bit unsigned integer to the given virtual address in 278 * Writes a 128-bit unsigned integer to the given virtual address in
@@ -284,7 +285,7 @@ public:
284 * 285 *
285 * @post The memory range [addr, sizeof(data)) contains the given data value. 286 * @post The memory range [addr, sizeof(data)) contains the given data value.
286 */ 287 */
287 bool WriteExclusive128(VAddr addr, u128 data, u128 expected); 288 bool WriteExclusive128(Common::ProcessAddress addr, u128 data, u128 expected);
288 289
289 /** 290 /**
290 * Reads a null-terminated string from the given virtual address. 291 * Reads a null-terminated string from the given virtual address.
@@ -301,7 +302,7 @@ public:
301 * 302 *
302 * @returns The read string. 303 * @returns The read string.
303 */ 304 */
304 std::string ReadCString(VAddr vaddr, std::size_t max_length); 305 std::string ReadCString(Common::ProcessAddress vaddr, std::size_t max_length);
305 306
306 /** 307 /**
307 * Reads a contiguous block of bytes from a specified process' address space. 308 * Reads a contiguous block of bytes from a specified process' address space.
@@ -320,8 +321,8 @@ public:
320 * @post The range [dest_buffer, size) contains the read bytes from the 321 * @post The range [dest_buffer, size) contains the read bytes from the
321 * process' address space. 322 * process' address space.
322 */ 323 */
323 void ReadBlock(const Kernel::KProcess& process, VAddr src_addr, void* dest_buffer, 324 void ReadBlock(const Kernel::KProcess& process, Common::ProcessAddress src_addr,
324 std::size_t size); 325 void* dest_buffer, std::size_t size);
325 326
326 /** 327 /**
327 * Reads a contiguous block of bytes from the current process' address space. 328 * Reads a contiguous block of bytes from the current process' address space.
@@ -339,7 +340,7 @@ public:
339 * @post The range [dest_buffer, size) contains the read bytes from the 340 * @post The range [dest_buffer, size) contains the read bytes from the
340 * current process' address space. 341 * current process' address space.
341 */ 342 */
342 void ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size); 343 void ReadBlock(Common::ProcessAddress src_addr, void* dest_buffer, std::size_t size);
343 344
344 /** 345 /**
345 * Reads a contiguous block of bytes from the current process' address space. 346 * Reads a contiguous block of bytes from the current process' address space.
@@ -358,7 +359,7 @@ public:
358 * @post The range [dest_buffer, size) contains the read bytes from the 359 * @post The range [dest_buffer, size) contains the read bytes from the
359 * current process' address space. 360 * current process' address space.
360 */ 361 */
361 void ReadBlockUnsafe(VAddr src_addr, void* dest_buffer, std::size_t size); 362 void ReadBlockUnsafe(Common::ProcessAddress src_addr, void* dest_buffer, std::size_t size);
362 363
363 /** 364 /**
364 * Writes a range of bytes into a given process' address space at the specified 365 * Writes a range of bytes into a given process' address space at the specified
@@ -380,8 +381,8 @@ public:
380 * and will mark that region as invalidated to caches that the active 381 * and will mark that region as invalidated to caches that the active
381 * graphics backend may be maintaining over the course of execution. 382 * graphics backend may be maintaining over the course of execution.
382 */ 383 */
383 void WriteBlock(const Kernel::KProcess& process, VAddr dest_addr, const void* src_buffer, 384 void WriteBlock(const Kernel::KProcess& process, Common::ProcessAddress dest_addr,
384 std::size_t size); 385 const void* src_buffer, std::size_t size);
385 386
386 /** 387 /**
387 * Writes a range of bytes into the current process' address space at the specified 388 * Writes a range of bytes into the current process' address space at the specified
@@ -402,7 +403,7 @@ public:
402 * and will mark that region as invalidated to caches that the active 403 * and will mark that region as invalidated to caches that the active
403 * graphics backend may be maintaining over the course of execution. 404 * graphics backend may be maintaining over the course of execution.
404 */ 405 */
405 void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size); 406 void WriteBlock(Common::ProcessAddress dest_addr, const void* src_buffer, std::size_t size);
406 407
407 /** 408 /**
408 * Writes a range of bytes into the current process' address space at the specified 409 * Writes a range of bytes into the current process' address space at the specified
@@ -420,7 +421,8 @@ public:
420 * will be ignored and an error will be logged. 421 * will be ignored and an error will be logged.
421 * 422 *
422 */ 423 */
423 void WriteBlockUnsafe(VAddr dest_addr, const void* src_buffer, std::size_t size); 424 void WriteBlockUnsafe(Common::ProcessAddress dest_addr, const void* src_buffer,
425 std::size_t size);
424 426
425 /** 427 /**
426 * Copies data within a process' address space to another location within the 428 * Copies data within a process' address space to another location within the
@@ -434,8 +436,8 @@ public:
434 * @post The range [dest_addr, size) within the process' address space contains the 436 * @post The range [dest_addr, size) within the process' address space contains the
435 * same data within the range [src_addr, size). 437 * same data within the range [src_addr, size).
436 */ 438 */
437 void CopyBlock(const Kernel::KProcess& process, VAddr dest_addr, VAddr src_addr, 439 void CopyBlock(const Kernel::KProcess& process, Common::ProcessAddress dest_addr,
438 std::size_t size); 440 Common::ProcessAddress src_addr, std::size_t size);
439 441
440 /** 442 /**
441 * Zeros a range of bytes within the current process' address space at the specified 443 * Zeros a range of bytes within the current process' address space at the specified
@@ -448,7 +450,8 @@ public:
448 * @post The range [dest_addr, size) within the process' address space contains the 450 * @post The range [dest_addr, size) within the process' address space contains the
449 * value 0. 451 * value 0.
450 */ 452 */
451 void ZeroBlock(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size); 453 void ZeroBlock(const Kernel::KProcess& process, Common::ProcessAddress dest_addr,
454 std::size_t size);
452 455
453 /** 456 /**
454 * Invalidates a range of bytes within the current process' address space at the specified 457 * Invalidates a range of bytes within the current process' address space at the specified
@@ -459,7 +462,8 @@ public:
459 * @param size The size of the range to invalidate, in bytes. 462 * @param size The size of the range to invalidate, in bytes.
460 * 463 *
461 */ 464 */
462 Result InvalidateDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size); 465 Result InvalidateDataCache(const Kernel::KProcess& process, Common::ProcessAddress dest_addr,
466 std::size_t size);
463 467
464 /** 468 /**
465 * Stores a range of bytes within the current process' address space at the specified 469 * Stores a range of bytes within the current process' address space at the specified
@@ -470,7 +474,8 @@ public:
470 * @param size The size of the range to store, in bytes. 474 * @param size The size of the range to store, in bytes.
471 * 475 *
472 */ 476 */
473 Result StoreDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size); 477 Result StoreDataCache(const Kernel::KProcess& process, Common::ProcessAddress dest_addr,
478 std::size_t size);
474 479
475 /** 480 /**
476 * Flushes a range of bytes within the current process' address space at the specified 481 * Flushes a range of bytes within the current process' address space at the specified
@@ -481,7 +486,8 @@ public:
481 * @param size The size of the range to flush, in bytes. 486 * @param size The size of the range to flush, in bytes.
482 * 487 *
483 */ 488 */
484 Result FlushDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size); 489 Result FlushDataCache(const Kernel::KProcess& process, Common::ProcessAddress dest_addr,
490 std::size_t size);
485 491
486 /** 492 /**
487 * Marks each page within the specified address range as cached or uncached. 493 * Marks each page within the specified address range as cached or uncached.
@@ -491,7 +497,7 @@ public:
491 * @param cached Whether or not any pages within the address range should be 497 * @param cached Whether or not any pages within the address range should be
492 * marked as cached or uncached. 498 * marked as cached or uncached.
493 */ 499 */
494 void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached); 500 void RasterizerMarkRegionCached(Common::ProcessAddress vaddr, u64 size, bool cached);
495 501
496 /** 502 /**
497 * Marks each page within the specified address range as debug or non-debug. 503 * Marks each page within the specified address range as debug or non-debug.
@@ -502,7 +508,7 @@ public:
502 * @param debug Whether or not any pages within the address range should be 508 * @param debug Whether or not any pages within the address range should be
503 * marked as debug or non-debug. 509 * marked as debug or non-debug.
504 */ 510 */
505 void MarkRegionDebug(VAddr vaddr, u64 size, bool debug); 511 void MarkRegionDebug(Common::ProcessAddress vaddr, u64 size, bool debug);
506 512
507private: 513private:
508 Core::System& system; 514 Core::System& system;