Commit Graph

687 Commits

Author SHA1 Message Date
Adrian
b2aa8b200a [BASE] Use FlushAllSinks instead of inline loop 2026-05-21 07:43:48 +02:00
Adrian
a261b83def [APP] Flush log & save config on quick exit 2026-05-17 12:05:20 +02:00
Gliniak
74f34818e7 [Lint] Added InsertBraces to linter to unify codebase to one standard 2026-05-08 18:54:50 +02:00
Gliniak
ec18a89da4 [APP] Allow profiler to be enabled via cmake option
- Hide profiler buttons if profiler is disabled
- From default it is disabled
2026-05-04 19:53:37 +02:00
Herman S.
4fcb8e4498 [Memory] Treat AllocRange high_page_number as exclusive
The free-block tracker search in BaseHeap::AllocRange treats
high_page_number as inclusive, shifting allocator-returned addresses
by one stride relative to the old loop-based search. Some titles
encode allocator-returned addresses in PPC code and break when that
layout shifts (Far Cry 3, Far Cry 4, Watchdogs).

In addition, reapply xe::align on the high side of AllocRange
(essentially reverting c28019e33). Without the round-up, a caller
passing a min/max window exactly the size of its request loses a
stride at the top and fails the early page_count size check.
2026-04-14 13:59:45 +09:00
Herman S.
763b160c7a [Threading/Linux] Add fallback to nice values
SCHED_FIFO requires CAP_SYS_NICE or root, try SCHED_FIFO first for real-time
priority control, then fall back to setpriority() nice values if permission
is denied.
2026-04-13 16:23:27 +09:00
Herman S.
c28019e333 [Memory] Fix AllocRange upper bound and update PhysicalHeap tests
BaseHeap::AllocRange was rounding the inclusive high_address UP via
xe::align(), which could push the search range one alignment stride
past the requested end. The new free-block-tracker top-down search
treats high_page_number as an inclusive max (usable_end =
high_page_number + 1), so the round-up caused it to return a base
page one stride beyond the caller's bound — most visibly when
PhysicalHeap::Alloc passed parent_heap_end = GetPhysicalAddress(...)
just below a page boundary, producing a translated address one page
past the child heap and tripping "passed out of range address range"
in BaseHeap::AllocFixed.

Drop the xe::align on the high side so high_address stays a true
inclusive bound. The low_address round-up is still correct since
allocations must START at or above the aligned low.
2026-04-13 11:38:01 +09:00
Herman S.
ea02e8d317 [Memory] Add free block tracker to BaseHeap for O(log n) allocation
Replace linear page_table_ scans in AllocRange with a std::map-based
free block index that tracks contiguous free regions.

Insertions now coalesce with adjacent blocks on release and AllocFixed
uses the targeted tracker for pure reserves and falls back to a full rebuild
for mixed-state commits.

Also fixing PhysicalHeap leaking parent memory on child allocation failure,
Reset() not restoring unreserved_page_count_ and some incorrect method names
in PhysicalHeap error messages
2026-04-13 09:31:48 +09:00
Herman S.
b3d8a21b72 [Threading] Add thread priority mapping with timer-driven quantum decay
And default ignore_thread_priorities to false.

Map Xenon's 0-31 priority range across all 5 host priority levels
instead of collapsing 0-17 into kNormal.

Use timer-driven quantum decay (~20ms period) matching Xenon's
60-quantum / 3-per-tick cycle to prevent starvation by gradually lowering
effective priority for non-real-time threads (< 18), piggybacking on the
existing 1ms timestamp timer.
2026-04-10 08:21:42 +09:00
Herman S.
11ad6b0a87 [Memory] Add alignment guards to PhysicalHeap allocations
Add alignment checks and parent release on failure in Alloc, AllocFixed,
and AllocRange to prevent misaligned addresses reaching BaseHeap.

Fixes #954
2026-03-31 21:49:19 +09:00
Herman S.
84b05bd20a [A64] Skip software denormal flushing when FPCR.FZ handles inputs
Depends on hardware support, detected and runtime and controllable
via a64_extension_mask bit 1.
2026-03-31 18:21:21 +09:00
Adrian
1a53f261f7 [Base] Increase arena chunk size
Fixed Phantom Breaker (465607DE) from crashing.
2026-03-28 21:41:26 +01:00
Herman S.
57c4051eca [macOS] Build infrastructure and portability fixes
Build system:
- Enable ObjC++, macOS deployment target, framework linking
- Fix AppleClang detection
- macOS platform name for output directories
- Skip Vulkan on macOS, null graphics without Vulkan dependency
- macOS SDL2 framework detection and discord-rpc macOS sources

Portability fixes:
- mach_absolute_time for macOS tick counting
- _NSGetExecutablePath for macOS
- guard MAP_FIXED_NOREPLACE, ftruncate64->ftruncate
- guard Vulkan include/usage, fix data root for all POSIX
2026-03-27 02:44:00 +09:00
Herman S.
cf013fdc15 [Base/Posix] mapped_memory portability and correctness fixes
Replace Linux-specific fstat64/ftruncate64 with portable POSIX equivalents.
Fix mmap error check to use MAP_FAILED instead of null pointer comparison.
Remove unconditional ftruncate after mmap that could corrupt files.
Add zero-length guard.
2026-03-26 23:10:47 +09:00
Herman S.
19e9d0c2de [Base/Posix] filesystem portability and correctness fixes
Replace Linux-specific fseeko64/ftello64/ftruncate64 with portable
POSIX equivalents.
Fix pread/pwrite error handling that assigned -1 to unsigned size_t.
Implement SetAttributes via chmod instead of stubbing it out.
Fix potential overflow in Unix-to-Windows filetime conversion.
Clean up unused removeCallback.
2026-03-26 23:10:47 +09:00
Herman S.
cb12f7fa1e [Build] Generalize POSIX platform guards
Most non-Windows code paths use standard POSIX APIs (sockets, signals,
dlopen, threading) that work on any POSIX platform. Change Linux-specific
guards to !WIN32 or #else where the code is portable. Linux-specific
APIs (SIGRTMIN, Vulkan/X11, fontconfig/GTK) remain Linux-guarded.
2026-03-26 23:10:47 +09:00
Herman S.
3efc88abbb [Base] Fix math.h portability: use __builtin_ffs and fix lzcnt narrowing
ffs() can collide with POSIX macro definitions on some platforms;
__builtin_ffs is the portable GCC/Clang intrinsic. log2_floor/log2_ceil
passed template types directly to lzcnt which has only uint32_t and
uint64_t overloads, causing implicit narrowing on smaller types.
2026-03-26 16:28:27 +09:00
Wunkolo
dd3ffeb9cb [a64] Implement FEAT_LSE optimizations
Adds `platform_arm64` similar to `platform_arm64` to populate a 64-bit feature-flag value and creates a `a64_extension_mask` configuration-mask for the detection and utilization of certain arm ISA features. The first feature being `FEAT_LSE` which maps to `XBYAK_AARCH64_HWCAP_ATOMIC`.

Just like the x64 backend, implements `IsFeatureEnabled` to the emitter for checking if the host processor supports a certain subset of feature flag(s) at once.

Optimizes `OPCODE_ATOMIC_EXCHANGE`, `OPCODE_ATOMIC_COMPARE_EXCHANGE`,
and `OPCODE_RESERVED_STORE` with `FEAT_LSE` instructions.
2026-03-25 14:31:53 +09:00
Wunkolo
5b9c13b23f [a64] Implement raw clock with CNTVCT_EL0
Implements a raw clock by directly accessing the `CNTVCT_EL0` and
`CNTFRQ_EL0` registers by using `mrs` intrinsics.

Should allow for a raw-clock to work on all ARM platforms without having
to make a per-platform implementation for any further a64 platforms like
MacOS or Linux or Android and such.
2026-03-25 13:30:51 +09:00
Herman S.
883c2030d0 [ARM64] Initial commit for arm64 backend
Based entirely off existing xbyak x86 implementation and available
tests. Still needs a lot of optimization and testing on non-Windows
platforms.

So far passes all tests and boots at least some games on Windows.
2026-03-22 15:57:37 +09:00
Herman S.
3bf6823e5b [ARM64] Fix constexpr -> const for NEON vector types.
constexpr uint8x16_t isn't valid on all compilers since vcombine_u8/vcreate_u8
aren't constexpr
2026-03-21 01:30:32 +09:00
Herman S.
1e8f1837cf [Build] Use CMAKE_BINARY_DIR for output paths and version.h include
version.h is now found via CMAKE_BINARY_DIR on the include path instead
of a hardcoded "build/version.h" path. This allows out-of-tree and
multi-config builds to each generate and find their own version header
without colliding.
2026-03-21 01:30:31 +09:00
Herman S.
9fbcdae5dc [Base] Limit AVX startup checks to AMD64 2026-03-17 13:55:38 +09:00
Herman S.
f3a456d353 [Base/Debugging] Replaces x86 hack with arch agnostic Win32 API call 2026-03-17 13:30:56 +09:00
Herman S.
61639c8906 [Threading/Posix] Fix issue with nested suspend
When SuspendThread is called on an already-suspended thread, it would send
another pthread_kill signal, which would nest signal handlers and create
multiple outstanding sem_wait calls while Resume only posts once when count
reaches 0. Instead we increment suspend count and skip redundant signal.
2026-03-16 09:25:55 +09:00
Herman S.
ecae4b6a0b [Base/Mem] Add platform guard for AVX/SSE streaming stores in vastcpy.
Prevents build failures on non-x86 platforms
2026-03-16 09:24:59 +09:00
Herman S.
c7f041ced0 [Base] Fix from_chars float parsing assertion on MSVC 2026-03-15 16:34:34 +09:00
Herman S.
6f18c98502 [Thread/Posix] Fix thread suspend deadlock
Replace std::mutex/condition_variable with sem_wait/sem_post for thread
suspension, as WaitSuspended is called from the SIGRTMIN signal handler
where pthread_mutex_lock is not async-signal-safe.
2026-03-10 23:55:27 +09:00
Herman S.
4f1394bbaa [Kernel/Threading] Fix some kernel threading issues
- broken atomic exchange on linux
- spinlock release memory buffer
- race in thread suspension
- removed misleading volatile qualifiers
2026-03-10 23:53:03 +09:00
Herman S.
c4bd0c3f33 [Testing] Inclrease timer test timeout and update default test targets
The threading test is verifying that the timer fires, not that it fires
within a specific timeout, so increasing to 100 to keep it from failing
randomly. Also removing xenia-cpu-ppc-tests from list of default targets
as they take forever to run, they can still be run run using xb test
with --target xenia-cpu-ppc-tests explicitly.
2026-03-10 16:49:41 +09:00
Gliniak
ce94f7fc03 [Base] Win-Style assertion on linux. No more forced termination while debugging 2026-03-09 19:40:20 +01:00
Herman S.
bf6e1a81eb [Posix] Fix DeallocFixed crashes / memory leaks
BaseHeap::Dispose() walks the page table and calls
DeallocFixed(addr, 0, kRelease) for every allocated page region.
These addresses are within file-backed view mappings (i.e. guest memory).
On Windows, VirtualFree on file-mapped pages silently returns FALSE.
On POSIX, the code hit assert_always() and crashed. Changed to return false
to match Windows behavior.

Memory leaks from munmap(addr, 0):

Callers passed length=0 to DeallocFixed(kRelease). On Windows this works because
VirtualFree(addr, 0, MEM_RELEASE) means "release the entire region" — Windows
ignores the length parameter for MEM_RELEASE and always frees the whole
allocation. On POSIX, munmap(addr, 0) fails with EINVAL, so the memory was
silently leaked every time.
2026-03-09 13:43:56 +09:00
Herman S.
52297ea8f8 [Linux] Implement fast mutex similar to Windows version 2026-03-09 13:43:56 +09:00
Herman S.
15483b02af [Memory] Linux cleanup shm files on exit
Prevents running out of /dev/shm space and crashing the whole system.
2026-03-09 13:43:56 +09:00
Herman S.
ae1706d1dc [Threads] Ensure proper RTTI/vtable emission for PosixWaitHandle 2026-03-09 13:43:56 +09:00
Herman S.
174d2d4205 [Posix Threading] Robust mutexes 2026-03-09 13:43:56 +09:00
Herman S.
1ae82023ea [Posix Threads] Refactored condition variables from static to per-instance members and replaced deadlock-prone predicate-based WaitMultiple with polling using try_lock. 2026-03-09 13:43:56 +09:00
Herman S.
c9eba5daf8 [Threading] Signal handler / self-suspension improvements 2026-03-09 13:43:56 +09:00
Herman S.
81dd887e74 [Kernel] Thread suspend for posix to match windows semantics 2026-03-09 13:43:56 +09:00
Herman S.
32b8c341ee [Kernel] ReleaseSemaphore for Posix to match Windows semantics 2026-03-09 13:43:56 +09:00
Herman S.
28e48410c5 Fix potential buffer overflow in posix memory handling 2026-03-09 13:43:56 +09:00
Herman S.
77535b7cec [Base] Replace CRITICAL_SECTION with SRWLOCK based mutexes
xe_fast_mutex now also asserts on recursive lock attempts
2026-03-09 00:19:32 +09:00
Herman S.
de63bb18a6 [Base] Use function-local static for global_mutex
File-scope static initialization order is undefined across translation
units. Code that acquires the global critical region during early startup
could run before the mutex constructor, operating on uninitialized state.
A function-local static is constructed on first use, guaranteeing the
mutex is initialized before any caller can access it.
2026-03-09 00:18:08 +09:00
Gliniak
6446150a5e [Cmake] Moved tests to separate folders 2026-03-06 19:59:38 +01:00
Herman S.
71c5702ee8 [Build] Convert build system to raw cmake and remove premake layer 2026-03-04 17:37:36 +09:00
Adrian
8d5565da8a [Misc] Fixed missing guard header (#887) 2026-02-23 17:07:23 +09:00
Herman S.
434644c301 Merge commit 'f2fabfdf0' into canary_experimental
Sync changes from master up to before the recent GPU changes, those will be
merged later
2026-02-17 16:59:38 +09:00
Herman S.
09a15fbedc [Testing] Get tests running (dirty hack for linux) 2026-02-13 13:32:39 +09:00
Adrian
ac66db337b [XAM] Fixed size used in read_u16string_and_swap 2025-12-22 19:33:47 +01:00
oltolm
492fa7c632 use concepts instead of SFINAE 2025-12-22 10:00:52 +01:00