Commit Graph

191 Commits (689dc4a17bb5f849b644705b54c3667db03d8f5d)

Author SHA1 Message Date
liamwhite 689dc4a17b
Merge pull request #11155 from liamwhite/memory3
memory: check page against address space size
2 years ago
liamwhite d3da1e6517
Merge pull request #10990 from comex/ubsan
Fixes and workarounds to make UBSan happier on macOS
2 years ago
Liam 07f71e2620 memory: check page against address space size 2 years ago
Liam d144168442 memory: minimize dependency on process 2 years ago
comex d7c532d889 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.
2 years ago
Liam a85ce8ea56 k_process: PageTable -> GetPageTable 2 years ago
Kelebek1 6f7cb69c94 Use spans over guest memory where possible instead of copying data. 2 years ago
Fernando Sahmkow da440da9f5 Memory Tracking: Optimize tracking to only use atomic writes when contested with the host GPU 2 years ago
Fernando Sahmkow 47d0d292d5 MemoryTracking: Initial setup of atomic writes. 2 years ago
Fernando Sahmkow 6f90dff293 Address feedback, add CR notice, etc 2 years ago
Fernando Sahmkow 92da86290c Settings: add option to enable / disable reactive flushing 2 years ago
Fernando Sahmkow c6cac2ffaa GPU: Add Reactive flushing 2 years ago
Fernando Sahmkow 7e76c1642c Accuracy Normal: reduce accuracy further for perf improvements in Project Lime 3 years ago
Liam 41d99aa89d memory: rename global memory references to application memory 3 years ago
Liam fb49ec19c1 kernel: use KTypedAddress for addresses 3 years ago
Liam ceda2d280e general: rename CurrentProcess to ApplicationProcess 3 years ago
Merry dc7ab4c5d6 Revert "MemoryManager: use fastmem directly."
This reverts commit af5ecb0b15.
3 years ago
Liam f1a0ce0e70 memory: fix watchpoint use when fastmem is enabled 3 years ago
Fernando Sahmkow af5ecb0b15 MemoryManager: use fastmem directly. 3 years ago
Mai d5684dbe7d
Merge pull request #9415 from liamwhite/dc
memory: correct semantics of data cache management operations
3 years ago
Liam ed37192441 memory: correct semantics of data cache management operations 3 years ago
Liam 985ed1e160 memory: remove DEBUG_ASSERT pointer test 3 years ago
Liam 651f6598ac kernel: implement FlushProcessDataCache 3 years ago
Morph c7e079a5d4 general: Resolve -Wunused-lambda-capture and C5233 3 years ago
bunnei 47b8160666 core: device_memory: Templatize GetPointer(..). 3 years ago
Fernando Sahmkow 5a568b1655 MemoryManager: Fix errors popping out. 3 years ago
Kyle Kienapfel 14e9de6678 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
3 years ago
Andrea Pappacoda cdb240f3d4
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 01cf05bc75
3 years ago
Kelebek1 458da8a948 Project Andio 3 years ago
Liam 208ed712f4 core/debugger: memory breakpoint support 3 years ago
Liam fb4b3c127f core/debugger: Implement new GDB stub debugger 3 years ago
bunnei af04f8b8e9
Revert "Memory GPU <-> CPU: reduce infighting in the texture cache by adding CPU Cached memory." 4 years ago
Fernando Sahmkow a2d7b2f905 Memory: Don't protect reads on Normal accuracy. 4 years ago
bunnei c0e45a3c78 core: device_memory: Use memory size reported by KSystemControl.
- That way, we can consolidate the memory layout to one place.
4 years ago
Andrew Strelsky 4ce0a650d1
prevent access violation from iob in Memory::IsValidVirtualAddress 4 years ago
yzct12345 5f97f74a9a
memory: Address lioncash's review 4 years ago
yzct12345 70cc4c0f46
memory: Dedup Read and Write and fix logging bugs 4 years ago
yzct12345 e611f522c2
memory: Clean up CopyBlock too 4 years ago
yzct12345 4edfa6ad8f
memory: Address lioncash's review 4 years ago
yzct12345 6df9611059
memory: Clean up code 4 years ago
FernandoS27 5ba28325b2 General: Add settings for fastmem and disabling adress space check. 4 years ago
Markus Wick 621f3f5f47 core: Make use of fastmem 4 years ago
Markus Wick 42a7c5d017 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.
4 years ago
bunnei b4fc2e52a2 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.
4 years ago
bunnei 2a7eff57a8 hle: kernel: Rename Process to KProcess. 5 years ago
bunnei 3401676768 core: memory: Add a work-around to allocate and access kernel memory regions by vaddr. 5 years ago
bunnei 93e20867b0 hle: kernel: Migrate PageHeap/PageTable to KPageHeap/KPageTable. 5 years ago
MerryMage 6d30745d77 memory: Remove MemoryHook 5 years ago
ReinUsesLisp b3587102d1 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]
5 years ago
bunnei c8a4967c9d
core: memory: Ensure thread safe access when pages are rasterizer cached (#5206)
* core: memory: Ensure thread safe access when pages are rasterizer cached.
5 years ago