Check out Creating Guard PagesQuote:
Originally Posted by zerver
Printable View
Check out Creating Guard PagesQuote:
Originally Posted by zerver
The way a debugger may implement 'break on memory write' is as followsQuote:
Originally Posted by zerver
1. Set the memory protection on the (virtual memory) page of interest.
2. Trap the interrupt that is generated.
3. Check if the specified memory address has been written; if yes break; else continue.
I do not know if any CPU mechanism that can break on a specific memory address write. Breaking on a page basis is possible. This I suspect is the reason why 'break on this memory write' is not practically feasible - the thing would cause an interrupt on write to any of the memory addresses on that page and some other piece has to then check if the accesses memory is what someone wanted to be interrupted about; even with small page size (say 2K) that may be costly.
Ah, excellent. Many thanks!
This means that if you always make sure to allocate at least two pages more than you currently need and then set up the memory protection accordingly, this technique could actually be used to reallocate a growing array.
And if I understand correctly, performance will not be negatively affected in this case since no other code will write to the protected page. When the interrupt is triggered you disable the protection, reallocate and finally protect the new page.
At least the technique is interesting from a technical standpoint.