On Mon, Jul 13, 2020 at 6:03 PM Jason E. Aten <[email protected]> wrote: > > go1.14.4 / darwin / amd64 > > I'm tracking down an issue where a certain code (not sure where, in large > legacy code) > is touching memory that it should not. > > I thought of the old electric fence technique from C. The electric fence > memory allocator would put each object > on its own page on malloc(). Then on free(), it would mark the page as > invalid, so that the next time > user code tried to read from the memory that had already been freed, an > immediate segfault > would give us a stack trace and tell those of us debugging exactly where the > bad access had > come from. > > I'd like to do the same in Go. > > GODEBUG=efence=1 > > says, quoting from https://golang.org/pkg/runtime/ > > efence: setting efence=1 causes the allocator to run in a mode > where each object is allocated on a unique page and addresses are > never recycled. > > > so the first part is already available in Go. Now I just need your assistance > figuring out the 2nd part. > > How can go code take the pointer address of an object, and mark that page as > "invalid" so that > any read of it will segfault?
In efence mode that already happens for large allocations. See the calls to sysFault in the runtime package. I guess the additional step would be to treat every allocation as a large allocation. You would burn through memory quite quickly, though. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcW6v1X-vjC30%2B_-gdsXLP_hOGyRd%2BHJVMNTju2uEMTosg%40mail.gmail.com.
