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

Re: [MiNT] Safe stack overflow




Am 24.02.2014 um 22:33 schrieb Miro Kropáček <miro.kropacek@gmail.com>:

as soon as the SP leaves the program's allocated and protected area => boom, memory violation.

You could of course use memory protection to protect the stack, but that probably would only need slight changes to your program, not necessarily to MiNT: just put the stack into a malloc’d region and make sure you don’t own adjacent memory below.
Yes, this could work too ... and fragments memory.



I’m not even sure that’s the case.

If your program only needs a small stack (say 8k) it’s pretty likely that Malloc() would be able to fit it nicely into a „hole" left over from previous fragmentation which wouldn’t be usable for larger allocations (as malloc() typically tends to do) anyway. It might even be the case that your program will fit into another hole (instead of further reduction of the global heap) when loading since it’s smaller (allocating only a tiny stack needed for startup within the monolithic executable).

It’s true that you will need an additional TOS memory descriptor (which is a sacre resource also), but overall I’d guess fragmentation would rather reduce than increase.