This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT #76248: double-freed SV with nested sig-handler
[perl5.git] / perlvars.h
CommitLineData
eb1102fc
NIS
1/* perlvars.h
2 *
663f364b 3 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
54ca4ee7 4 * by Larry Wall and others
eb1102fc
NIS
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
9 */
10
88e1f1a2
JV
11/*
12=head1 Global Variables
13*/
49f531da 14
d7cb65f2 15/* Don't forget to re-run regen/embed.pl to propagate changes! */
cb68f92d
GS
16
17/* This file describes the "global" variables used by perl
18 * This used to be in perl.h directly but we want to abstract out into
19 * distinct files which are per-thread, per-interpreter or really global,
20 * and how they're initialized.
21 *
22 * The 'G' prefix is only needed for vars that need appropriate #defines
22c35a8c 23 * generated in embed*.h. Such symbols are also used to generate
14dd3ad8 24 * the appropriate export list for win32. */
cb68f92d 25
49f531da 26/* global state */
cb68f92d 27PERLVAR(Gcurinterp, PerlInterpreter *)
43165c05 28 /* currently running interpreter
ba869deb
GS
29 * (initial parent interpreter under
30 * useithreads) */
3db8f154 31#if defined(USE_ITHREADS)
ba869deb
GS
32PERLVAR(Gthr_key, perl_key) /* key to retrieve per-thread struct */
33#endif
a0ed51b3 34
27da23d5
JH
35/* constants (these are not literals to facilitate pointer comparisons)
36 * (PERLVARISC really does create variables, despite its looks) */
37PERLVARISC(GYes, "1")
38PERLVARISC(GNo, "")
39PERLVARISC(Ghexdigit, "0123456789abcdef0123456789ABCDEF")
40PERLVARISC(Gpatleave, "\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}")
43165c05
GS
41
42/* XXX does anyone even use this? */
43PERLVARI(Gdo_undump, bool, FALSE) /* -u or dump seen? */
b363f7ed 44
3db8f154 45#if defined(MYMALLOC) && defined(USE_ITHREADS)
b363f7ed
GS
46PERLVAR(Gmalloc_mutex, perl_mutex) /* Mutex for malloc */
47#endif
534825c4
GS
48
49#if defined(USE_ITHREADS)
50PERLVAR(Gop_mutex, perl_mutex) /* Mutex for op refcounting */
51#endif
60e4ec2e 52
d90a703e
JH
53#ifdef USE_ITHREADS
54PERLVAR(Gdollarzero_mutex, perl_mutex) /* Modifying $0 */
55#endif
5c728af0 56
95ca8690 57
5c728af0 58/* This is constant on most architectures, a global on OS/2 */
428eed4a 59#ifdef OS2
95ca8690 60# define PERL___C
428eed4a 61#else
95ca8690 62# define PERL___C const
428eed4a 63#endif
95ca8690
DM
64PERLVARI(Gsh_path, PERL___C char *, SH_PATH) /* full path of shell */
65#undef PERL___C
af419de7 66
2f42fcb0 67#ifndef PERL_MICRO
b35112e7
CS
68/* If Perl has to ignore SIGPFE, this is its saved state.
69 * See perl.h macros PERL_FPU_INIT and PERL_FPU_{PRE,POST}_EXEC. */
70PERLVAR(Gsigfpe_saved, Sighandler_t)
2f42fcb0 71#endif
b35112e7 72
643157af
JH
73/* Restricted hashes placeholder value.
74 * The contents are never used, only the address. */
75PERLVAR(Gsv_placeholder, SV)
76
2f42fcb0 77#ifndef PERL_MICRO
1c127fab 78PERLVARI(Gcsighandlerp, Sighandler_t, Perl_csighandler) /* Pointer to C-level sighandler */
2f42fcb0 79#endif
5c1546dc 80
50acdf95
MS
81#ifndef PERL_USE_SAFE_PUTENV
82PERLVARI(Guse_safe_putenv, int, 1)
83#endif
27da23d5
JH
84
85#ifdef USE_PERLIO
22c96fc1
NC
86PERLVARI(Gperlio_fd_refcnt, int*, 0) /* Pointer to array of fd refcounts. */
87PERLVARI(Gperlio_fd_refcnt_size, int, 0) /* Size of the array */
27da23d5
JH
88PERLVARI(Gperlio_debug_fd, int, 0) /* the fd to write perlio debug into, 0 means not set yet */
89#endif
90
91#ifdef HAS_MMAP
92PERLVARI(Gmmap_page_size, IV, 0)
93#endif
94
95#if defined(FAKE_PERSISTENT_SIGNAL_HANDLERS)||defined(FAKE_DEFAULT_SIGNAL_HANDLERS)
96PERLVARI(Gsig_handlers_initted, int, 0)
97#endif
98#ifdef FAKE_PERSISTENT_SIGNAL_HANDLERS
99PERLVARA(Gsig_ignoring, SIG_SIZE, int) /* which signals we are ignoring */
100#endif
101#ifdef FAKE_DEFAULT_SIGNAL_HANDLERS
aadb217d 102PERLVARA(Gsig_defaulting, SIG_SIZE, int)
27da23d5
JH
103#endif
104
27da23d5
JH
105/* XXX signals are process-wide anyway, so we
106 * ignore the implications of this for threading */
107#ifndef HAS_SIGACTION
108PERLVARI(Gsig_trapped, int, 0)
109#endif
110
111#ifdef DEBUGGING
112PERLVAR(Gwatch_pvx, char*)
113#endif
114
115#ifdef PERL_GLOBAL_STRUCT
116PERLVAR(Gppaddr, Perl_ppaddr_t*) /* or opcode.h */
117PERLVAR(Gcheck, Perl_check_t *) /* or opcode.h */
118PERLVARA(Gfold_locale, 256, unsigned char) /* or perl.h */
4dc941f7 119PERLVARA(Gcharclass, 256, U32)
27da23d5
JH
120#endif
121
122#ifdef PERL_NEED_APPCTX
123PERLVAR(Gappctx, void*) /* the application context */
124#endif
125
126PERLVAR(Gop_sequence, HV*) /* dump.c */
127PERLVARI(Gop_seq, UV, 0) /* dump.c */
128
129#if defined(HAS_TIMES) && defined(PERL_NEED_TIMESBASE)
130PERLVAR(Gtimesbase, struct tms)
131#endif
132
f16dd614 133/* allocate a unique index to every module that calls MY_CXT_INIT */
27da23d5 134
f16dd614 135#ifdef PERL_IMPLICIT_CONTEXT
97aff369 136# ifdef USE_ITHREADS
f16dd614 137PERLVAR(Gmy_ctx_mutex, perl_mutex)
97aff369 138# endif
f16dd614
DM
139PERLVARI(Gmy_cxt_index, int, 0)
140#endif
71ad1b0c
NC
141
142#if defined(USE_ITHREADS)
143PERLVAR(Ghints_mutex, perl_mutex) /* Mutex for refcounted he refcounting */
144#endif
6cb8cb21 145
8b84d7dd 146#if defined(USE_ITHREADS)
6cb8cb21
RGS
147PERLVAR(Gperlio_mutex, perl_mutex) /* Mutex for perlio fd refcounts */
148#endif
c301d606
DM
149
150/* this is currently set without MUTEX protection, so keep it a type which
151 * can be set atomically (ie not a bit field) */
152PERLVARI(Gveto_cleanup, int, FALSE) /* exit without cleanup */
153
4b8f2e61
DM
154/* dummy variables that hold pointers to both runops functions, thus forcing
155 * them *both* to get linked in (useful for Peek.xs, debugging etc) */
156
ef69c8fc
BM
157PERLVARI(Grunops_std, runops_proc_t, Perl_runops_standard)
158PERLVARI(Grunops_dbg, runops_proc_t, Perl_runops_debug)
4b8f2e61 159
ffee3ff6
NC
160
161/* These are baked at compile time into any shared perl library.
162 In future 5.10.x releases this will allow us in main() to sanity test the
163 library we're linking against. */
164
165PERLVARI(Grevision, U8, PERL_REVISION)
166PERLVARI(Gversion, U8, PERL_VERSION)
167PERLVARI(Gsubversion, U8, PERL_SUBVERSION)
168
169#if defined(MULTIPLICITY)
170# define PERL_INTERPRETER_SIZE_UPTO_MEMBER(member) \
171 STRUCT_OFFSET(struct interpreter, member) + \
172 sizeof(((struct interpreter*)0)->member)
173
174/* These might be useful. */
01523419 175PERLVARI(Ginterp_size, U16, sizeof(struct interpreter))
ffee3ff6
NC
176#if defined(PERL_GLOBAL_STRUCT)
177PERLVARI(Gglobal_struct_size, U16, sizeof(struct perl_vars))
178#endif
179
180/* This will be useful for subsequent releases, because this has to be the
181 same in your libperl as in main(), else you have a mismatch and must abort.
182*/
01523419 183PERLVARI(Ginterp_size_5_10_0, U16,
ffee3ff6
NC
184 PERL_INTERPRETER_SIZE_UPTO_MEMBER(PERL_LAST_5_10_0_INTERP_MEMBER))
185#endif
88e1f1a2
JV
186
187/*
188=for apidoc AmUx|Perl_keyword_plugin_t|PL_keyword_plugin
189
190Function pointer, pointing at a function used to handle extended keywords.
191The function should be declared as
192
193 int keyword_plugin_function(pTHX_
194 char *keyword_ptr, STRLEN keyword_len,
195 OP **op_ptr)
196
197The function is called from the tokeniser, whenever a possible keyword
198is seen. C<keyword_ptr> points at the word in the parser's input
199buffer, and C<keyword_len> gives its length; it is not null-terminated.
200The function is expected to examine the word, and possibly other state
201such as L<%^H|perlvar/%^H>, to decide whether it wants to handle it
202as an extended keyword. If it does not, the function should return
203C<KEYWORD_PLUGIN_DECLINE>, and the normal parser process will continue.
204
205If the function wants to handle the keyword, it first must
206parse anything following the keyword that is part of the syntax
f0e67a1d 207introduced by the keyword. See L</Lexer interface> for details.
88e1f1a2
JV
208
209When a keyword is being handled, the plugin function must build
210a tree of C<OP> structures, representing the code that was parsed.
211The root of the tree must be stored in C<*op_ptr>. The function then
364f83bf 212returns a constant indicating the syntactic role of the construct that
88e1f1a2
JV
213it has parsed: C<KEYWORD_PLUGIN_STMT> if it is a complete statement, or
214C<KEYWORD_PLUGIN_EXPR> if it is an expression. Note that a statement
215construct cannot be used inside an expression (except via C<do BLOCK>
216and similar), and an expression is not a complete statement (it requires
217at least a terminating semicolon).
218
219When a keyword is handled, the plugin function may also have
220(compile-time) side effects. It may modify C<%^H>, define functions, and
221so on. Typically, if side effects are the main purpose of a handler,
222it does not wish to generate any ops to be included in the normal
223compilation. In this case it is still required to supply an op tree,
224but it suffices to generate a single null op.
225
226That's how the C<*PL_keyword_plugin> function needs to behave overall.
227Conventionally, however, one does not completely replace the existing
228handler function. Instead, take a copy of C<PL_keyword_plugin> before
229assigning your own function pointer to it. Your handler function should
230look for keywords that it is interested in and handle those. Where it
231is not interested, it should call the saved plugin function, passing on
232the arguments it received. Thus C<PL_keyword_plugin> actually points
233at a chain of handler functions, all of which have an opportunity to
234handle keywords, and only the last function in the chain (built into
235the Perl core) will normally return C<KEYWORD_PLUGIN_DECLINE>.
236
237=cut
238*/
239
ef69c8fc 240PERLVARI(Gkeyword_plugin, Perl_keyword_plugin_t, Perl_keyword_plugin_standard)