Commit graph

191 commits

Author SHA1 Message Date
liamwhite
fb3f5b0482 Merge pull request #11155 from liamwhite/memory3
memory: check page against address space size
2023-07-28 09:29:21 -04:00
liamwhite
a28a0c47f8 Merge pull request #10990 from comex/ubsan
Fixes and workarounds to make UBSan happier on macOS
2023-07-26 10:33:28 -04:00
Liam
32a48f0d50 memory: check page against address space size 2023-07-25 09:51:06 -04:00
Liam
7073afff3b memory: minimize dependency on process 2023-07-22 11:19:29 -04:00
comex
85d77f636c Fixes and workarounds to make UBSan happier on macOS
There are still some other issues not addressed here, but it's a start.

Workarounds for false-positive reports:

- `RasterizerAccelerated`: Put a gigantic array behind a `unique_ptr`,
  because UBSan has a [hardcoded limit](https://stackoverflow.com/questions/64531383/c-runtime-error-using-fsanitize-undefined-object-has-a-possibly-invalid-vp)
  of how big it thinks objects can be, specifically when dealing with
  offset-to-top values used with multiple inheritance.  Hopefully this
  doesn't have a performance impact.

- `QueryCacheBase::QueryCacheBase`: Avoid an operation that UBSan thinks
  is UB even though it at least arguably isn't.  See the link in the
  comment for more information.

Fixes for correct reports:

- `PageTable`, `Memory`: Use `uintptr_t` values instead of pointers to
  avoid UB from pointer overflow (when pointer arithmetic wraps around
  the address space).

- `KScheduler::Reload`: `thread->GetOwnerProcess()` can be `nullptr`;
  avoid calling methods on it in this case.  (The existing code returns
  a garbage reference to a field, which is then passed into
  `LoadWatchpointArray`, and apparently it's never used, so it's
  harmless in practice but still triggers UBSan.)

- `KAutoObject::Close`: This function calls `this->Destroy()`, which
  overwrites the beginning of the object with junk (specifically a free
  list pointer).  Then it calls `this->UnregisterWithKernel()`.  UBSan
  complains about a type mismatch because the vtable has been
  overwritten, and I believe this is indeed UB.  `UnregisterWithKernel`
  also loads `m_kernel` from the 'freed' object, which seems to be
  technically safe (the overwriting doesn't extend as far as that
  field), but seems dubious.  Switch to a `static` method and load
  `m_kernel` in advance.
2023-07-15 12:00:28 -07:00
Liam
6b6f0b21b9 k_process: PageTable -> GetPageTable 2023-07-14 21:43:15 -04:00
Kelebek1
42638691b5 Use spans over guest memory where possible instead of copying data. 2023-07-02 23:09:48 +01:00
Fernando Sahmkow
4f68a8f45a Memory Tracking: Optimize tracking to only use atomic writes when contested with the host GPU 2023-06-28 21:32:45 +02:00
Fernando Sahmkow
7ae0cdbb09 MemoryTracking: Initial setup of atomic writes. 2023-06-28 19:34:21 +02:00
Fernando Sahmkow
134c14f089 Address feedback, add CR notice, etc 2023-05-07 23:46:12 +02:00
Fernando Sahmkow
62295b5069 Settings: add option to enable / disable reactive flushing 2023-05-07 23:46:12 +02:00
Fernando Sahmkow
6bc60f78d9 GPU: Add Reactive flushing 2023-05-07 23:46:12 +02:00
Fernando Sahmkow
eeffe68b7f Accuracy Normal: reduce accuracy further for perf improvements in Project Lime 2023-04-23 22:03:44 +02:00
Liam
6eaef51cf2 memory: rename global memory references to application memory 2023-03-23 20:28:47 -04:00
Liam
156516e399 kernel: use KTypedAddress for addresses 2023-03-22 09:35:16 -04:00
Liam
c68577384a general: rename CurrentProcess to ApplicationProcess 2023-02-13 19:03:12 -05:00
Merry
6b50650633 Revert "MemoryManager: use fastmem directly."
This reverts commit 7f18e3bb89.
2023-01-25 10:12:04 +00:00
Liam
0279b94a9e memory: fix watchpoint use when fastmem is enabled 2023-01-15 10:24:31 -05:00
Fernando Sahmkow
7f18e3bb89 MemoryManager: use fastmem directly. 2023-01-05 06:06:33 -05:00
Mai
f23e20a630 Merge pull request #9415 from liamwhite/dc
memory: correct semantics of data cache management operations
2022-12-11 21:09:31 +00:00
Liam
47a89280bf memory: correct semantics of data cache management operations 2022-12-11 12:46:34 -05:00
Liam
8a5667aa70 memory: remove DEBUG_ASSERT pointer test 2022-12-10 13:02:38 -05:00
Liam
e313e4f1ae kernel: implement FlushProcessDataCache 2022-11-12 11:27:04 -05:00
Morph
c6c56d3e9c general: Resolve -Wunused-lambda-capture and C5233 2022-10-22 15:02:04 -04:00
bunnei
d9871bab0b core: device_memory: Templatize GetPointer(..). 2022-10-18 19:13:34 -07:00
Fernando Sahmkow
6a3eca65ea MemoryManager: Fix errors popping out. 2022-10-06 21:00:53 +02:00
Kyle Kienapfel
ea00332a67 code: dodge PAGE_SIZE #define
Some header files, specifically for OSX and Musl libc define PAGE_SIZE to be a number
This is great except in yuzu we're using PAGE_SIZE as a variable

Specific example
`static constexpr u64 PAGE_SIZE = u64(1) << PAGE_BITS;`

PAGE_SIZE PAGE_BITS PAGE_MASK are all similar variables.
Simply deleted the underscores, and then added YUZU_ prefix

Might be worth noting that there are multiple uses in different classes/namespaces
This list may not be exhaustive

Core::Memory   12 bits (4096)
QueryCacheBase 12 bits
ShaderCache    14 bits (16384)
TextureCache   20 bits (1048576, or 1MB)

Fixes #8779
2022-08-19 16:08:40 -07:00
Andrea Pappacoda
6a2efdda2f chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.

Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.

The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.

Following REUSE has a few advantages over the current approach:

- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
  `.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
  files like binary assets / images is always accurate and up to date

To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.

[REUSE]: https://reuse.software

Follow-up to b2eb103829
2022-07-27 12:53:49 +02:00
Kelebek1
be1f5f1d9f Project Andio 2022-07-22 01:11:32 +01:00
Liam
8d2abc710c core/debugger: memory breakpoint support 2022-06-16 13:18:07 -04:00
Liam
2ee161a0bf core/debugger: Implement new GDB stub debugger 2022-06-01 00:01:25 -04:00
bunnei
b149526098 Revert "Memory GPU <-> CPU: reduce infighting in the texture cache by adding CPU Cached memory." 2022-03-26 12:38:30 -07:00
Fernando Sahmkow
6e2cfc4310 Memory: Don't protect reads on Normal accuracy. 2022-03-25 04:24:25 +01:00
bunnei
b928936457 core: device_memory: Use memory size reported by KSystemControl.
- That way, we can consolidate the memory layout to one place.
2022-02-21 13:07:19 -08:00
Andrew Strelsky
5a02e7aabf prevent access violation from iob in Memory::IsValidVirtualAddress 2021-09-29 19:26:44 -04:00
yzct12345
b61be44dbc memory: Address lioncash's review 2021-08-07 03:03:21 +00:00
yzct12345
a21f46127b memory: Dedup Read and Write and fix logging bugs 2021-08-07 01:32:06 +00:00
yzct12345
7a421e7e33 memory: Clean up CopyBlock too 2021-08-05 21:09:08 +00:00
yzct12345
fa26e226de memory: Address lioncash's review 2021-08-05 20:29:43 +00:00
yzct12345
cbe093e865 memory: Clean up code 2021-08-05 20:11:14 +00:00
FernandoS27
3147b9e34c General: Add settings for fastmem and disabling adress space check. 2021-06-11 17:27:17 +02:00
Markus Wick
99f6d60a99 core: Make use of fastmem 2021-06-11 17:27:06 +02:00
Markus Wick
870505def8 core/memory: Check our memory fallbacks for out-of-bound behavior.
This makes it by far harder to crash yuzu.

Also implement the 48bit masking of AARCH64 while touching this code.
2021-05-29 09:28:26 +02:00
bunnei
227f9e5ab2 hle: kernel: Use host memory allocations for KSlabMemory.
- There are some issues with the current workaround, we will just use host memory until we have a complete kernel memory implementation.
2021-05-20 21:41:52 -07:00
bunnei
ad048de3d6 hle: kernel: Rename Process to KProcess. 2021-05-05 16:40:52 -07:00
bunnei
4aebdea6cf core: memory: Add a work-around to allocate and access kernel memory regions by vaddr. 2021-05-05 16:40:50 -07:00
bunnei
5dbcaa2970 hle: kernel: Migrate PageHeap/PageTable to KPageHeap/KPageTable. 2021-02-18 16:16:25 -08:00
MerryMage
e3490b55c1 memory: Remove MemoryHook 2021-01-01 11:34:38 +00:00
ReinUsesLisp
8bfa4d6dbf core/memory: Read and write page table atomically
Squash attributes into the pointer's integer, making them an uintptr_t
pair containing 2 bits at the bottom and then the pointer. These bits
are currently unused thanks to alignment requirements.

Configure Dynarmic to mask out these bits on pointer reads.

While we are at it, remove some unused attributes carried over from
Citra.

Read/Write and other hot functions use a two step unpacking process that
is less readable to stop MSVC from emitting an extra AND instruction in
the hot path:

 mov         rdi,rcx
 shr         rdx,0Ch
 mov         r8,qword ptr [rax+8]
 mov         rax,qword ptr [r8+rdx*8]
 mov         rdx,rax
-and         al,3
 and         rdx,0FFFFFFFFFFFFFFFCh
 je          Core::Memory::Memory::Impl::Read<unsigned char>
 mov         rax,qword ptr [vaddr]
 movzx       eax,byte ptr [rdx+rax]
2020-12-29 21:54:49 -03:00
bunnei
eb609b73a7 core: memory: Ensure thread safe access when pages are rasterizer cached (#5206)
* core: memory: Ensure thread safe access when pages are rasterizer cached.
2020-12-24 21:51:49 -08:00