summaryrefslogtreecommitdiff
path: root/perliol.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2010-11-22 19:18:49 +0000
committerDavid Mitchell <davem@iabyn.com>2010-11-26 16:01:34 +0000
commitabf9167d3fff002ddaed53abb44d638387bca978 (patch)
treef81a5b1c720adff647b3866f0a7b7890b444534b /perliol.h
parentcc6623a84b782d30463b9046c2916f35064a7e3f (diff)
downloadperl-abf9167d3fff002ddaed53abb44d638387bca978.tar.gz
Make PerlIO marginally reentrant
Currently if an operation on a file handle is interrupted, and if the signal handler accesses that same file handle (e.g. closes it), then perl will crash. See [perl #75556]. This commit provides some basic infrastructure to avoid segfaults. Basically it adds a lock count field to each handle (by re-purposing the unused flags field in the PL_perlio array), then each time a signal handler is called, the count is incremented. Then various parts of PerlIO use a positive count to change behaviour. Most importantly, when layers are popped, the PerlIOl structure is cleared, but not freed, and is left in the chain of layers. This means that callers still holding pointers to the various layers won't access freed structures. It does however mean that PerlIOl structs may be leaked, and possibly slots in PL_perlio. But this is better than crashing. Not much has been done to give sensible behaviour on re-entrancy; for example, a buffer that has already been written once might get written again. Fixing this sort of thing would require a large-scale audit of perlio.c.
Diffstat (limited to 'perliol.h')
-rw-r--r--perliol.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/perliol.h b/perliol.h
index 744ffc8870..019fa8ca04 100644
--- a/perliol.h
+++ b/perliol.h
@@ -90,6 +90,7 @@ struct _PerlIO {
#define PERLIO_F_FASTGETS 0x00400000
#define PERLIO_F_TTY 0x00800000
#define PERLIO_F_NOTREG 0x01000000
+#define PERLIO_F_CLEARED 0x02000000 /* layer cleared but not freed */
#define PerlIOBase(f) (*(f))
#define PerlIOSelf(f,type) ((type *)PerlIOBase(f))