| 29 | static Thread ndspThread; |
| 30 | |
| 31 | static inline bool ndspWaitForIrq(u64 timeout_ns) |
| 32 | { |
| 33 | LightLock_Lock(&ndspMutex); |
| 34 | |
| 35 | // BUG: Official sw has a race condition here when entering sleep mode. DSP state might |
| 36 | // have already been torn down, and thus this ends up waiting on an invalid (0) handle. |
| 37 | // There's code that tries to panic if an error happens, however said error handler fails |
| 38 | // to actually panic because it checks that the result code level is specifically 'Fatal'. |
| 39 | // Note that the "invalid handle" result code has a 'Permanent' level... |
| 40 | // We will instead handle invalid handles properly and immediately return. |
| 41 | bool waitOk = false; |
| 42 | if (irqEvent) |
| 43 | { |
| 44 | Result rc = svcWaitSynchronization(irqEvent, timeout_ns); |
| 45 | if (R_FAILED(rc)) |
| 46 | svcBreak(USERBREAK_PANIC); // Shouldn't happen. |
| 47 | |
| 48 | waitOk = R_DESCRIPTION(rc) != RD_TIMEOUT; |
| 49 | } |
| 50 | |
| 51 | if (waitOk) |
| 52 | svcClearEvent(irqEvent); |
| 53 | |
| 54 | LightLock_Unlock(&ndspMutex); |
| 55 | return waitOk; |
| 56 | } |
| 57 | |
| 58 | static inline void ndspSetCounter(int a, int counter) |
| 59 | { |
no test coverage detected