[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] Super() bug



 
*Rule:* If the stack is different than the value it was at 1), the stack value after the trap is totally bogus !!
Actually, it seems to be the value of the stack as it was at 1) minus 4.
Of course that stack must absolutely not be used.
Well, yes, but you breaks another ("bigger") rule, i.e. use Super() everytime from the same context. It's true GCC can use stack even in the same context somehow but this is not an excuse as Super() is not regular call (at least from clean system point of view) so it must receive a special treatment. One should always follow: never use SV - use Supexec() - use Super() (as the last resort). Programmer must be aware of risks.
 
Unfortunately, this trick must not be used in the rare case (never used ?) when Super() is used to switch to supervisor mode using a specified stack. Of course the old SP must not be restored. 
So we can't simply change the Super() binding. 

So I propose a new and safe binding named SuperToUser() to be always used when returning to user mode, and only in that case. See the attached file. Oh, I used an inline function, but since the MiNTLib uses macros we should convert that one to a macro as well. 

Final note, this problem does not appear with FreeMiNT, because it is probably more clever and does not trash the stack when it is supposed to be unchanged.
Personally, I don't like it very much, esp. when there are differences between TOS and FreeMiNT (what about MagiC, Geneva?). One should always follow basic rules (be careful with Super()). Much better solution would be some directive for GCC which avoids stack usage in given context (of course function parameters passing and restoring is OK) but I fear this is not available.


--
MiKRO / Mystic Bytes
http://mikro.atari.org