Calling convention mismatch in hyp_view.app causes bus error crash #110
In the German Atari-Home forum, a user reported a crash when starting hyp_view.app bundled with this snapshot build: https://bintray.com/freemint/freemint/download_file?file_path=snapshots%2F1-19-36cf2b41%2Ffreemint-1-19-36c-02060-tt_falcon_clones.zip
I traced back the bus error: It occurs within the Getcookie() function. Looking at the disassembly, I see:
Clearly, it loads its parameters from D0 and A0, i.e., it uses the fastcall calling convention. However, hyp_view.app uses the conventional cdecl calling convention:
This mismatch in calling conventions is the root cause of the crash.
Looking at the source code of libcmini (that is used for hyp_view.app), one can see that Getcookie() indeed uses the fastcall convention: https://github.com/mfro0/libcmini/blob/ab8f44e3c174dd6ae772b9a3d97dceab9a4785fc/sources/getcookie.S#L30. One would have to call getcookie() (with a "g" instead of a "G") to get the cdecl wrapper.
However, this getcookie() was removed by libcmini author @mfro0: "remove getcookie() (as it collides with hypview compilation)".
This unfortunately means that FreeMiNT ships with a broken and crashing hyp_view.app.
Ok, so to get this fixed we'd need to call a function which has been removed to fix compilation of the very same project, nice. :-)
Frankly, I don't get why
I agree with @mikrosk , that looks like a bug in libcmini. Originally, it had both functions available since Getcookie is also called directly in checkcpu.S with fastcall convention. It should be the other way around: provide a Getcookie function that is compatible with mintlib (using cdecl), and a getcookie function (or maybe even a different name to avoid confusion) that can be called from checkcpu.S
Sorry gents, was away last week a few thousand miles west and unable to access the internet (not because of lack of it, but because I had to battle with jetlag ;) )
You are right - this appears to be a bug in libcmini.
I didn't yet find time and patience to look into this deeply, but at a glance, the bug seems to be introduced by a nice fellow that provided commit mfro0/libcmini@91c67e4#diff-1bc2b6e7048019bf47e33f364cc0dc0f that apparently inverted the meaning of
I don't blame @th-otto for that, as obviously, there wasn't enough testing of that said patch on my side.
Will try to fix that during the weekend.
Never mind. Mistakes happen ;)
Fixed now in latest libcmini (0.491) release.
If the next automated build picks up the latest libcmini release (I think that was what we agreed upon, @mikrosk , right?), hypview should now work again.