Skip to content

Memory protected allocations feature request #60

@hvassbotn

Description

@hvassbotn

Hi Pierre,

And then a feature request, that I think would be very useful. As you know, debugging and finding the actual cause of memory overwrites can be very tricky indeed (since any buggy code or DLL could cause it).

Earlier we had success using FastMM to detect reproducible memory overwrites, then using the madExcept debug feature "instantly crash on buffer...." "overrun" to find the culprit. That isn't always enough and for our application, not really feasible as we have way too many allocations for realistic workflows.

So after thinking about this some more, I think I would like two separate features, actually:

  1. Global flag to turn on Memory overrun protected allocations
    In this mode, FastMM would revert to allocate each memory block from separate 4 Kb pages, and put the user accessible part of the allocation at the end of the page. It should then also virtual protect the next page in address space, so that any memory overrun after the size of the block would cause an access violation.

  2. Global flag to turn on Memory overrun protected allocations and frees
    This mode would work like the one above, with the difference that when freeing the memory block (in debug mode), it would also change the virtual protection bits for the allocated user page to be no-read and no-write. Then any in-memory overwrite or even read in an already freed block would cause an access violation.

Both these flags would only be used in debug situations and only for specific short periods of time. For instance, the overwrite it detected now, happened on a block allocated by TSizeConstraints.Create (for some reason). To debug it, I would patch the Vcl.Controls unit to use FastMM5 and to turn on the new global setting FastMM_DebugMode_AllocateAndFreeProtection := True before the call to TSizeConstraints.Create and FastMM_DebugMode_AllocateAndFreeProtection := False after the call. FastMM would know to allocate in this mode, and the mode would be encoded into the block, so that it would know to keep and expand the protection when it is freed.

I don't know if I was able to convey the concept properly.
I might find the time to try to code this myself and create a pull request for you.

/Hallvard

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions