This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PERL_DEBUG_READONLY_COW
Make perls compiled with -Accflags=-DPERL_DEBUG_READONLY_COW to turn
COW buffer violations into crashes.
We do this using mmap to allocate memory and then mprotect to mark
memory as read-only when buffers are shared.
We have to do this at the safesysmalloc level, because some code does
SvPV_set with buffers it allocates on its own via safemalloc().
Unfortunately this means many things are allocated using mmap that
will never be marked read-only, slowing things down considerably, but
I see no other way.
Because munmap and mprotect need to know the length, we use the
existing sTHX/perl_memory_debug_header mechanism used already by
PERL_TRACK_MEMPOOL and store the size there (as PERL_POISON already
does when PERL_TRACK_MEMPOOL is enabled). perl_memory_debug_header is
a struct positioned at the beginning of every allocated buffer, for
tracking things.