Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOLTECS: Fix unaligned access causing SIGBUS in Screen::addAnimatedSprite() #3974

Conversation

dwatteau
Copy link
Contributor

@dwatteau dwatteau commented Jun 6, 2022

The toltecs-demo.zip demo would SIGBUS in Screen::addAnimatedSprite() when playing it on OpenBSD/loongson, which has a mips64el CPU with strict-alignment constraints. This is the same setup as for my older PR #2241.

Changing the FROM_LE_16() calls there to READ_LE_UINT16() calls fixes the issue. Looking a bit at common/endian.h, it appears that only the latter properly deals with unaligned memory accesses. Commit 30e3a81 was a similar change.

This possibly fixes the game on other strict-alignment ports such as Dreamcast, PSP or some old ARM devices.

On x86-64 and Apple M1, screen.o remains identical before and after this change, as expected. I think it's safe to cherry-pick this for the 2.6.0 release, but you're the judges :)

Use READ_LE_UINT16 instead of FROM_LE_16 to avoid unaligned memory
access, as seen on OpenBSD/loongson (mips64el) where it would SIGBUS
when trying to play the demo.
@bluegr
Copy link
Member

@bluegr bluegr commented Jun 7, 2022

Nice! Thanks for spotting this

@bluegr bluegr merged commit 980b693 into scummvm:master Jun 7, 2022
8 checks passed
@dwatteau dwatteau deleted the fix/toltecs-addAnimatedSprite-unaligned-access branch Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants