Commit Graph

179 Commits

Author SHA1 Message Date
MechaCat02
7b6902e08f [WIP] Audio/threading fixes + crash investigation; NEW ORACLE: crash is ours not the game
Some checks failed
Orchestrator / Commit Message Validation (push) Has been skipped
Orchestrator / Lint (push) Failing after 1m34s
Orchestrator / Windows (x86-64) (push) Has been skipped
Orchestrator / Linux (x86-64) (push) Has been skipped
Orchestrator / Create Release (push) Has been skipped
Snapshot for handoff. Contains the mission-audio + threading fixes and the
crash-investigation instrumentation (all diagnostic cvars default-OFF).

Fixes (behavioral):
- threading_posix.cc: reap-once guard on PosixCondition<Thread>::post_execution
  (double pthread_join at mission teardown -> fault loop -> audio death + freeze).
- xma_decoder.cc: work_event_->Set() in Pause() so the idle XMA worker observes
  paused_ and signals pause_fence_ (Pause() deadlock -> permanent audio death).
- audio_system / xma_context_master / xboxkrnl_audio / apu_flags / alsa: mission
  audio keepalive + guest_audio_flags + watchdogs.

Instrumentation (additive, default-off): xboxkrnl_debug cache-throw diag +
guest-catch dispatcher, xex_module PE/PDATA/EH scans, kernel_state mem_watch
(NOTE: mem_watch DEFAULTS TRUE -- an always-on host poll thread; prime crash suspect).

NEW ORACLE (see HANDOFF-crash-oracle-2026-07-16.md): stock 6e5b8324f built with
our toolchain + zero custom code = NO crash, NO sound-stop, plays the Ready Room.
=> the Ready-Room out_of_range crash is introduced by THESE changes, not the game
and not the (LTO-broken) build chain. Bisection plan + suspect ranking in the note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 22:43:50 +02:00
MechaCat02
07f09f8fe0 [Audit] round 24: signal-path probes (XEvent::Set + IO + NtDuplicateObject)
Adds AUDIT-HLC probes for every path that signals an XEvent or duplicates
its handle, so the round-23 puzzle (waits completing without visible
NtSetEvent/KeSetEvent) can be cross-referenced by underlying X_KEVENT VA
and by primary handle.

  * NtCreateEvent_inner: always log kevent_va for handle/VA cross-ref
  * XEvent::Set: universal hook prints primary handle + kevent_va + LR;
    catches all paths into the event regardless of shim used
  * NtSetEvent: extended with PPC back-chain walk for caller's guest_lr
    (same idiom as the wait probe), so the signaler function is
    immediately identifiable
  * NtReadFile / NtReadFileScatter / NtWriteFile: log when signal_event
    path fires ev->Set() inline at IO completion (bypasses both
    NtSetEvent and KeSetEvent shims)
  * CompleteOverlappedEx (kernel_state.cc): log when overlapped event
    is signaled at completion
  * NtDuplicateObject: log src/dst handle pair (round-24 confirmed silph
    event is dup'd before signaling, explaining the handle-mismatch
    puzzle between NtSetEvent's `handle=` argument and XEvent::Set's
    primary handle())

Result: silph wait at sub_821CB030+0x1B0 on handle F80000A0 is signaled
via NtSetEvent on handle F80000A8 (the duplicate created by sub_8245D9D8
at lr=0x82450DF4 inside the worker chain sub_82450A28 ← 0xA68 ← 0xB68).
Verdict A confirmed: signaler exists and is reachable, but round-17.β
missed it because the search keyed on the wrong handle. No bypass path;
the worker chain is identical between canary and ours-impl, but ours
signals different handles (work-item queue divergence at sub_82452DC0).

Audit-only diagnostic. No semantic changes. Net delta +86 LOC across 7
files. All probes gated on the existing audit_handle_lifecycle cvar
(default off). Tested via Sylpheed boot (35 s, 4 MB log). Audit-handle-
lifecycle-probes branch, local-only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-12 15:43:23 +02:00
MechaCat02
87e4a67b61 [Audit] JIT-prolog: optional audit_jit_prolog_mem_dump chain (3 levels)
Round-14 of AUDIT-2BF (singleton-dump). Pairs with xenia-rs'
--audit-mem-read-hex to emit one comparable XELOGKERNEL line resolving
the bctrl target at sub_822F1AA8+0x90 (PC 0x822F1B4C):

  [0x828E1F08]        -> singleton instance ptr
  [singleton+0]       -> vtable
  [vtable+0]          -> vtable[0]  (= first virtual method, bctrl tgt)
  [vtable+24]         -> vtable[24] (= slot 6, silph chain target)

Two complementary hooks:

1. src/xenia/cpu/backend/x64/x64_emitter.cc: extend
   AuditLogJitPrologArgs. New cvar `audit_jit_prolog_mem_dump` (uint32).
   When non-zero and an `audit_jit_prolog_pc` fire happens, the host
   side dereferences the VA 3 levels deep and emits one
   AUDIT-MEM-READ line in the same format ours emits. Defensive
   per-level null + VA-range checks.

2. src/xenia/kernel/kernel_state.cc: one-shot dump in
   EmulateCPInterruptDPC of the same chain (hard-coded to
   0x828E1F08). Useful when audit_jit_prolog_pc isn't set; fires the
   first time the CP interrupt path runs (after the singleton ctor
   has had time to populate).

Read-only. Both gates default-off; no impact when cvars unset.
~65 LOC total across the two files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-12 15:43:23 +02:00
MechaCat02
fea4ef31ec [Audit] handle-lifecycle XELOGKERNEL probes (cvar-gated)
New cvar `audit_handle_lifecycle` (Auditing group, default false).
When enabled, emits one-line XELOGKERNEL traces tagged AUDIT-HLC at:
  NtCreateEvent return, NtSetEvent entry, KeSetEvent entry,
  NtWaitForSingleObjectEx entry + completion,
  EmulateCPInterruptDPC entry.

Observation-only: zero-overhead when cvar off (single branch + flag
read). Intended for handle disambiguation between xenia-rs and
canary under the Wine cross-build oracle.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-12 15:43:22 +02:00
Gliniak
9c8e34b29e [Kernel] Moved kernel memory allocation to proper location.
- Moved few globals to kernel memory range to prevent overuse of SystemHeapAlloc
2026-06-22 22:34:03 +02:00
Gliniak
9478cda5d6 [Kernel] Fixed issue with titles not booting due to lack of title id 2026-06-03 22:45:54 +02:00
Gliniak
99ea6da18a [XConfig] Implementation of XConfig 2026-05-19 07:50:16 +02:00
The-Little-Wolf
dc4db67f9c [Kernel] - Change OddObj to X_DISPATCH_HEADER
- Change OddObj to X_DISPATCH_HEADER
- Add unknown X_KWAIT_REASON flag
- Fixed InitializeGuestObject mistake
- Replaces unknowns in kthread using nukernel as reference
2026-05-16 23:57:19 +02:00
Gliniak
74f34818e7 [Lint] Added InsertBraces to linter to unify codebase to one standard 2026-05-08 18:54:50 +02:00
Michael Oliver
6de80dffe2 [Emulator] Load title plugins before main thread execution begins
This keeps the title thread suspended until plugins are loaded, allowing early init and hook setup before guest code starts running.
2026-04-29 20:20:08 +02:00
Adrian
68d409ebba [Kernel] Fixed releasing XObject handles on title termination 2026-04-21 22:42:12 +02:00
Herman S.
c17a3b19fb [Kernel] Implement per-process TLS allocation
Previous global TLS bitmap was shared across all processes. Now
per-process TLS bitmaps stored X_KPROCESS structures which should
better match Xbox360 architecture.
2026-04-13 12:42:42 +09:00
Herman S.
65b74819aa [Threading] Implement priority boost on wake
When a thread wakes from a kernel wait, the Xenon scheduler boosts its
effective priority by the increment passed to the signaling call
(KeSetEvent, KeReleaseSemaphore, KeReleaseMutant). The boost is clamped
to the per-thread max_dynamic_priority cap, respects the guest
boost_disabled flag, and is drained on the next quantum expiry.
Guest KTHREAD priority fields are now initialized from parent process
defaults, and the previously unknown fields involved have been renamed
to match their identified purpose.
2026-04-11 17:05:05 +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.
02fccd9113 [Kernel/XMP] Add title-specific file I/O hooks for XMP volume sync
Some games persist BGM volume through their own save files but never
call XMPSetVolume. Add a TitlePatch system that intercepts NtReadFile/
NtWriteFile to apply game-specific logic as well as logic to identify
the memory location that the volume data is read into and monitor that
memory location for changes, updating XMP player volume if it changes
during gameplay.

Includes patches for known games with this issue:
Dead or Alive Xtreme 2 (544307D2), PGR4 (4D5307F9) and PGR3 (4D5307D1)
2026-03-09 08:59:15 +09:00
Gliniak
9bfaff5040 [XAM] Fixed issue with XamContentCreate reassigning already assigned symlinks 2026-02-19 21:02:45 +01:00
Gliniak
4dd0842087 [Kernel] Fixed incorrect amount of propagated notifications on boot
- Created dedicated method: IsUIActive
2026-01-31 19:24:10 +01:00
Adrian
f85f4c3ca1 [Kernel] Fixed Xbox Live disconnected error code 2025-12-04 21:41:37 +01:00
Gliniak
efa0a8bb39 [XBDM] Added sketchy implementation of DmPMCGetCounterName and DmPMCInstallAndStart 2025-11-03 22:42:43 +01:00
Gliniak
8d2d80dfde [Kernel] Change deferred overlap delay from 100ms to 25ms 2025-10-29 23:31:30 +01:00
Gliniak
2cd35e8dd6 [Kernel] Remove sending tray state change notification when game is booted
- Games do not expect changing disc on boot it should happen when you're in dashboard
2025-10-17 20:24:33 +02:00
The-Little-Wolf
64b7695f52 [Kernel] - restrict kXNotificationLiveConnectionChanged to startup
- allow for dashboard to show achievements and themes again.
2025-08-08 22:44:28 +02:00
Gliniak
06456c20fc [Kernel] Prevent real XAM from initialization while loading dashboard 2025-08-08 22:05:24 +02:00
Gliniak
2969a04145 [Kernel] Added support for loading modules before main 2025-08-03 20:40:30 +02:00
Adrian
4702bfb94c [XBDM] Cleanup Stubs 2025-07-27 18:57:19 +02:00
The-Little-Wolf
39621ddec8 [KERNEL] - Replacing Unk
- Changes here are from Chrispy's Nukernel
2025-07-26 22:27:21 +02:00
The-Little-Wolf
31173107bc kXNotification - adding more
- Added more kXNotification ids
- Added missing Notification to XMPCreateTitlePlaylist
2025-07-26 21:58:57 +02:00
Gliniak
4182852a4b [Base] Split of xbox.h file
- Splitted into: kernel.h and xam.h
- Removed UpdateSpaData from KernelState into ContentManager
2025-07-26 21:25:32 +02:00
Adrian
b6884ba10b [XAM] Added back sleep in CompleteOverlappedDeferred
Revert change from 31ce3e0c71

This fixes accessing RDR free roam in netplay.
2025-07-01 21:36:46 +02:00
The-Little-Wolf
f91be22742 [KERNEL/KERNEL_STATE] - Startup kXNotifyLive
- Notify game user is not connect to live
2025-06-20 23:40:35 +02:00
Gliniak
b864149575 [Misc] Cleanup in Kernel 2025-05-31 12:00:47 +02:00
Gliniak
31ce3e0c71 [XAM] Added overlap to XamUserReadProfileSettings
- Removed delay on CompleteOverlappedDeferredEx
2025-05-30 23:39:17 +02:00
Gliniak
fe739208b6 [VFS] Rewrote STFS to use memory mapping
- Replaced old-style buffer, buffer_length with std::span
- Added STFS and SVOD specific Entry and File classes
- Other smaller improvements
2025-05-14 21:38:02 +02:00
The-Little-Wolf
be44b9ba33 [XAM/INFO] - Implement multiple functions
- Implement XamIsSystemExperienceTitleId, XamIsSystemTitleId, XamIsXbox1TitleId
- Replaced is_title_system_type
- Changed XamIsCurrentTitleDash
- Reduced magic numbers
2025-04-25 11:06:06 +02:00
Michael Oliver
1a356f7344 [Kernel] Add option to ignore incompatible title updates with mismatched signatures 2025-04-12 22:16:41 +02:00
The-Little-Wolf
0771938db6 [Kernel] - Implemented SystemManagementController Class
- Added handling (partial or dummy) for SMC actions:
 - QUERY_TEMP_SENSOR, QUERY_TRAY, QUERY_AV_PACK, QUERY_SMC_VERSION, QUERY_IR_ADDRESS, QUERY_TILT_SENSOR
 - SET_FAN_SPEED_CPU, SET_FAN_SPEED_GPU, SET_DVD_TRAY, SET_IR_ADDRESS, SET_POWER_LED, SET_LEDS

- Stub HalOpenCloseODDTray, XamLoaderGetMediaInfo, XamLoaderGetMediaInfoEx
- Partially Implement HalSendSMCMessage
- Implement XamLoaderGetDvdTrayState
- HalOpenCloseODDTray is used by dash and HalSendSMCMessage can be used by custom dashboards
2025-04-06 17:30:56 +02:00
Gliniak
40bd0080f1 [Kernel] Fixed TU loading on Linux 2025-03-18 22:37:34 +01:00
Gliniak
1110cdd372 [Kernel] Added support for writing/reading GPD files
This breaks settings in games that are using them and savefiles in games that use settings to store progress
2025-03-07 11:59:48 +01:00
The-Little-Wolf
95df198d8a [Xbox] kXNotification Additions
- Discovered new unknown kXNotificationID use by XNotifyBroadcast together and wanted to record them before I forget them.
- Changed kXNotificationID  to kXNotification
- Added kXNotificationSystemPXLiveSystemUpdate
2025-01-02 18:19:21 +01:00
Gliniak
3318ab5d4c [3PP] Uplifted FMT version and adjusted messages 2024-12-12 20:28:11 +01:00
Gliniak
1c4527c1e7 [Kernel] Fixed applying TUs to multi disc games 2024-10-22 20:05:35 +02:00
Gliniak
9bdd07590c [XAM] Implementation of: Profile Manager & Profiles Support
Thanks Emoose for Account Encrypt/Decrypt code!
2024-10-05 10:03:35 +02:00
Gliniak
e409a384ec [Kernel] Removed XAM specific entities from KernelState 2024-09-28 10:14:59 +02:00
Gliniak
71de56416d [Kernel] Cleanup in TU applying code.
Externally it is still applied via: ApplyTitleUpdate
But internally it is splitted into:
 - FindTitleUpdate
 - LoadTitleUpdate
 - IsPatchSignatureProper
 - ApplyTitleUpdate

Added host window with warning about TU incompatibility
2024-09-07 18:26:00 +02:00
Gliniak
0ee6c77d91 [Kernel] Update ExLoadedCommandLine based on executable name 2024-09-05 22:41:35 +02:00
Adrian
2c087406d6 [Kernel] Runtime Module Patching
Fixes source games TUs
2024-09-04 21:18:28 +02:00
The-Little-Wolf
0deafaf9f9 [Kernel] Notification ID Changes
Based off of pull request  xenia-project#2047. Convert magic numbers numbers to enum to improve readability. Includes currently unused one for future use.
2024-09-02 08:24:43 +02:00
Hyper
a867320a87 [Kernel] Implemented XexLoadImageFromMemory 2024-08-27 22:14:21 +02:00
Gliniak
1fdf250f7d [Kernel] Fixed race condition crash related to missing ke_timestamp_bundle_ptr_ 2024-08-10 16:30:31 +02:00
Gliniak
ce990e2828 [HID] Added support for joystick deadzones
- Simplified logic for connected controllers
2024-06-01 14:54:01 +02:00