Replies: 2 comments 2 replies
-
The answer is that we don't try. We probably could make the linker realise that it's overrun into the reserved area, but we didn't. In fact, we don't bother trying to prevent the allocator smashing the stack or the stack smashing the heap. You can easily smash the heap by infinitely recursing. A solution would be to have a smaller sized stack and invert the position of the heap and stack, but as I've not run into issues here I'm inclined to not bother as I would then have to choose a reasonable stack and heap size whereas now I don't have to decide. By default, we put things in ewram (global alloc is ewram, statics are ewram). |
Beta Was this translation helpful? Give feedback.
-
Thanks, really helpful. Good to know that BIOS zeroes out ram. I don't suppose you have a reference on hand for that? I couldn't find it in GBATek just now (though I may just being blind). I've been writing my own GBA stuff from scratch and this project has been really useful as a reference for some of the stuff I don't know so much about (such as linker scripts). I was turned onto this issue when I had a problem with my interrupt routine overflowing the IRQ stack into the system stack (turns out in debug mode rust can EAT stack space). I guess you should at least configure the iwram allocator to stop at 0x03007eff rather than 0x03008000 (maybe even earlier to give a little user stack headroom. But you're right that something more elaborate is probably diminishing returns. If I ever decide to see what could be done by moving the user stack to a fixed size the bottom of iwram I'll let you know. Might be possible to get "cleaner" errors on a stack overflow that way, if the processor has features to support that. |
Beta Was this translation helpful? Give feedback.
-
I'm pretty noobish when it comes to linker scripts, but there are a couple of things that concern me about the one currently in the
template
directory.Again, I don't fully understand linker scripts, but shouldn't there be some way of "reserving" iwram space for this? Clearly any custom iwram allocator would have to avoid the bottom of IWRAM, but also don't we need to tell the linker not to put anything from .bss there?
Beta Was this translation helpful? Give feedback.
All reactions