dolphin/Source/Core/Core/HW
Dentomologist 3b97a7bded CubebStream: Use WorkQueueThread::PushBlocking instead of sync_event
Push and wait on WorkQueueThread items using PushBlocking. Previously we
created a Common::Event sync_event on the caller's stack, called Wait on
it, then had the WorkQueueThread call Set on the sync_event once the
thread was done.

In addition to being simpler the new way avoids a use-after-free that
could happen in convoluted and unlikely yet possible thread scheduling
sequences.

One such case can be triggered as follows:

* Set your audio backend to Cubeb
* In CubebStream::SetVolume set a breakpoint at the call to Wait and at
  the call to cubeb_stream_set_volume.
* Start a game.
* Continue until the Cubeb Worker thread hits the
  cubeb_stream_set_volume breakpoint and Emuthread hits the Wait
  breakpoint, freezing each thread when it hits its breakpoint.
* Unfreeze Cubeb Worker.
* In Event::Set set a breakpoint at the end of the scope containing the
  lock_guard such that the guard has been constructed but not destructed
  when the breakpoint is hit.
* Continue until that breakpoint is hit by Cubeb Worker. If other
  threads hit it first keep going.
* Freeze Cubeb Worker.
* For convenience remove the breakpoint in Event::Set so other threads
  don't trigger it.
* In CubebStream::SetRunning set a breakpoint at the call to Wait.
* Unfreeze Emuthread and continue until the breakpoint is hit.
* In Cubeb Worker go to Event::Set and examine the values of m_mutex's
  member variables. In Visual Studio Debug these are locking_thread_id
  == 0xcccccc01 and ownership_levels == 0xcccccccc. This is the result
  of Visual Studio overwriting the memory used on the stack by
  sync_event in CubebStream::SetVolume with cc bytes to represent
  uninitialized memory on the stack (since that function already
  returned), and then allocating enough memory on the stack when calling
  AudioCommon::SetSoundStreamRunning and then CubebStream::SetRunning
  that it overwrote one byte of the memory formerly occupied by
  locking_thread_id.
* If you unfreeze Cubeb Worker at this point it will trigger the lock
  guard's destructor which will then try to unlock m_mutex. Since
  m_mutex is no longer in scope this is a use-after-free, and in VS
  debug triggers a debug assert due to locking_thread_id not matching
  the current thread id.
2025-11-07 13:19:18 -08:00
..
DSPHLE DSPEmulator: Remove redundant parameter and code 2025-10-26 18:03:31 -07:00
DSPLLE DSPEmulator: Remove redundant parameter and code 2025-10-26 18:03:31 -07:00
DVD DolphinAnalytics: Use Pascal case for GameQuirk enum 2025-08-14 13:54:23 -07:00
EXI CubebStream: Use WorkQueueThread::PushBlocking instead of sync_event 2025-11-07 13:19:18 -08:00
GCMemcard Merge pull request #13522 from tygyh/Enforce-overriding-destructor-style-Core&UnitTests 2025-06-07 17:55:14 -05:00
HSP HW/HSP: Refactor to class, move to System. 2023-03-07 02:11:39 +01:00
SI libmgba: Fix build when disabled 2025-10-30 12:00:13 -07:00
WiimoteCommon WiimoteEmu: Eliminate dynamic memory allocation in speaker data decoding. 2025-03-18 03:12:50 -05:00
WiimoteEmu WiimoteEmu: Require IRPassthrough has any bound inputs to operate. Users get confused and mistakenly enable it. 2025-10-04 14:34:49 -05:00
WiimoteReal Merge pull request #13984 from jordan-woyak/wmreal-quick-connect-and-disconnect 2025-10-21 19:49:22 -04:00
AddressSpace.cpp MMU: Use templates for Read/Write functions 2025-10-08 11:27:06 +02:00
AddressSpace.h DolphinQt: Properly lock CPU before accessing emulated memory 2023-02-12 11:27:50 +01:00
AudioInterface.cpp Migrate SConfig::bWii to System. 2024-01-31 12:54:07 +01:00
AudioInterface.h HW/DVDInterface: Do DTK math in blocks instead of in samples. 2023-03-14 13:19:44 +01:00
CPU.cpp Merge pull request #14035 from Dentomologist/pauseandlock_refactoring 2025-11-01 10:06:08 +01:00
CPU.h CPU: Update PauseAndLock comment 2025-10-26 18:06:38 -07:00
DSP.cpp Replace 'reinterpret_cast' with 'static_cast' 2024-11-08 07:26:47 +01:00
DSP.h HW/DSP: Refactor to class. 2023-03-09 22:35:29 +01:00
GBACore.cpp libmgba: Fix build when disabled 2025-10-30 12:00:13 -07:00
GBACore.h libmgba: Fix build when disabled 2025-10-30 12:00:13 -07:00
GBAPad.cpp InputCommon: Use distinct values for profile key 2024-02-04 17:55:08 +01:00
GBAPad.h Pad: GBA config 2021-07-13 16:42:35 +02:00
GBAPadEmu.cpp Android: Get profile name from core 2023-10-01 18:47:49 +02:00
GBAPadEmu.h Android: Get profile name from core 2023-10-01 18:47:49 +02:00
GCKeyboard.cpp Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
GCKeyboard.h Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
GCKeyboardEmu.cpp Android: Get profile name from core 2023-10-01 18:47:49 +02:00
GCKeyboardEmu.h Android: Get profile name from core 2023-10-01 18:47:49 +02:00
GCPad.cpp Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
GCPad.h Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
GCPadEmu.cpp InputCommon/ControllerEmu: Break out functionality of EmulatedController 2025-03-15 14:30:43 -05:00
GCPadEmu.h Android: Get profile name from core 2023-10-01 18:47:49 +02:00
GPFifo.cpp HW: Remove calls to GetPointer 2024-03-31 21:58:05 +02:00
GPFifo.h Fix uninitialized variable warnings (C26495) 2023-02-15 19:18:39 -08:00
HW.cpp State: Avoid Global System Accessor 2024-03-01 10:52:50 -08:00
HW.h HW: Pass System to functions. 2023-03-13 18:13:20 +01:00
Memmap.cpp Memmap: Optimize UpdateLogicalMemory by merging mappings 2025-06-21 20:54:05 +02:00
Memmap.h Memmap: Replace GetPointer with GetSpanForAddress 2024-04-20 18:31:08 +02:00
MemoryInterface.cpp Resolve [-Wclass-memaccess] 2023-04-12 03:59:57 -05:00
MemoryInterface.h HW/MemoryInterface: Refactor to class. 2023-03-11 00:57:16 +01:00
MMIO.cpp Merge pull request #13522 from tygyh/Enforce-overriding-destructor-style-Core&UnitTests 2025-06-07 17:55:14 -05:00
MMIO.h Replace Common::BitCast with std::bit_cast 2024-05-03 18:43:51 -07:00
MMIOHandlers.h HW: Pass System to MMIO handlers. 2022-11-23 05:52:21 +01:00
ProcessorInterface.cpp VideoCommon: reset some CP registers during PI_FIFO_RESET 2025-05-05 21:18:37 +01:00
ProcessorInterface.h HW/ProcessorInterface: Store reference to System in class. 2023-03-13 18:13:20 +01:00
Sram.cpp Remove defined-out code 2024-04-15 12:17:35 -07:00
Sram.h Remove redundant semicolons 2024-08-20 14:59:54 +02:00
StreamADPCM.cpp Treewide: Adjust order of includes 2021-12-10 14:49:57 -08:00
StreamADPCM.h treewide: convert GPLv2+ license info to SPDX tags 2021-07-05 04:35:56 +02:00
SystemTimers.cpp Core: Move CountPerformanceMarker to VideoInterface to eliminate a Throttle call. PerformanceMetrics: Fixes/Cleanups. 2025-04-02 23:23:51 -05:00
SystemTimers.h Core: Move CountPerformanceMarker to VideoInterface to eliminate a Throttle call. PerformanceMetrics: Fixes/Cleanups. 2025-04-02 23:23:51 -05:00
VideoInterface.cpp Common: Make HookableEvent use non-static data. 2025-11-02 17:30:43 -06:00
VideoInterface.h VI: set default overclock factor to 1.0 2025-08-30 03:03:21 +01:00
WII_IPC.cpp WII_IPC: fix homebrew that uses the disc drive 2025-07-19 16:42:15 +01:00
WII_IPC.h Core/IOS/WiiIPC: Refactor to class, move to System. 2024-01-12 06:37:10 +01:00
Wiimote.cpp Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
Wiimote.h Core / DolphinQt / InputCommon: reduce the number disk writes when using DynamicInputTextures 2025-03-22 14:53:02 -05:00
WiiSave.cpp Modernize std::copy with ranges 2024-10-10 00:53:48 -07:00
WiiSave.h treewide: convert GPLv2+ license info to SPDX tags 2021-07-05 04:35:56 +02:00
WiiSaveStructs.h Fix all uninitialized variable warnings (C26495) 2021-10-13 12:32:16 -07:00