This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PERL_DEBUG_READONLY_COW
authorFather Chrysostomos <sprout@cpan.org>
Wed, 4 Dec 2013 12:39:14 +0000 (04:39 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 17 Jan 2014 01:57:35 +0000 (17:57 -0800)
commitb001a0d149ed99df18916796f3a72b2c888b94d8
tree87fd41cc8413cf6655f49e648df790f8fd6c2b55
parent0ec58bfa3d152b9e214f52a7f2ca0aa9d7a09d6e
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.
embed.fnc
embed.h
op.c
perl.h
proto.h
sv.c
util.c