XboxDev / nxdk-sdl

SDL2 (adapted for original Xbox / nxdk toolchain)
Other
20 stars 8 forks source link

SDL does not call ``usbh_core_deinit()`` on exit #45

Open LoveMHz opened 1 year ago

LoveMHz commented 1 year ago

In its current implementation, SDL does not call usbh_core_deinit() on exit.

When software exits, or when an XBE is launched, the system performs a soft reset, but the kernel has no mechanisms, to my knowledge, that would reset the USB hardware (all retail software attempts to uninitialize previously initialized hardware on exit).

This leaves a brief amount of time where, from soft-reset to the next application re-initializing the USB stack, that memory corruption can occur due to the USB hardware now pointing to an invalid region of memory.

I understand that as implemented, it's implied that it's up to the application to call usbh_core_deinit(). Ref

I'm opening this issue because I can not find any proof that software is currently doing this, and I believe it is an anti-pattern to the design and implementation goals of SDL.

I believe we need to handle this better, and I'm open to discussing what would be the better implementation. Right now, I'm investigating any possible side effects that may arise from this type of change.

JayFoxRox commented 1 year ago

How about ref-counting in the USB stack?

@Ryzee119 is probably most familiar with that code