Skip to content

Commit 2bc5f86

Browse files
committed
Add mutex for accessing ENV
1 parent b6d9446 commit 2bc5f86

File tree

11 files changed

+31
-4
lines changed

11 files changed

+31
-4
lines changed

dosish.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
# define PERL_SYS_TERM_BODY() \
5252
HINTS_REFCNT_TERM; KEYWORD_PLUGIN_MUTEX_TERM; \
5353
OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; PERLIO_TERM; \
54-
MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM;
54+
MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM; \
55+
ENV_TERM;
5556
#endif
5657
#define dXSUB_SYS dNOOP
5758

embedvar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@
397397
#define PL_Gdo_undump (my_vars->Gdo_undump)
398398
#define PL_dollarzero_mutex (my_vars->Gdollarzero_mutex)
399399
#define PL_Gdollarzero_mutex (my_vars->Gdollarzero_mutex)
400+
#define PL_env_mutex (my_vars->Genv_mutex)
401+
#define PL_Genv_mutex (my_vars->Genv_mutex)
400402
#define PL_fold_locale (my_vars->Gfold_locale)
401403
#define PL_Gfold_locale (my_vars->Gfold_locale)
402404
#define PL_hash_chars (my_vars->Ghash_chars)

makedef.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ sub readvar {
399399
PL_regex_pad
400400
PL_regex_padav
401401
PL_dollarzero_mutex
402+
PL_env_mutex
402403
PL_hints_mutex
403404
PL_locale_mutex
404405
PL_lc_numeric_mutex

perl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ S_init_tls_and_interp(PerlInterpreter *my_perl)
9696
HINTS_REFCNT_INIT;
9797
LOCALE_INIT;
9898
USER_PROP_MUTEX_INIT;
99+
ENV_INIT;
99100
MUTEX_INIT(&PL_dollarzero_mutex);
100101
MUTEX_INIT(&PL_my_ctx_mutex);
101102
# endif

perl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,21 @@ typedef struct padname PADNAME;
29072907
# define USE_ENVIRON_ARRAY
29082908
#endif
29092909

2910+
#ifdef USE_ITHREADS
2911+
/* On some platforms it would be safe to use a read/write mutex with many
2912+
* readers possible at the same time. On other platforms, notably IBM ones,
2913+
* subsequent getenv calls destroy earlier ones. Those platforms would not
2914+
* be able to handle simultaneous getenv calls */
2915+
# define ENV_LOCK MUTEX_LOCK(&PL_env_mutex)
2916+
# define ENV_UNLOCK MUTEX_UNLOCK(&PL_env_mutex)
2917+
# define ENV_INIT MUTEX_INIT(&PL_env_mutex);
2918+
# define ENV_TERM MUTEX_DESTROY(&PL_env_mutex);
2919+
#else
2920+
# define ENV_LOCK NOOP;
2921+
# define ENV_UNLOCK NOOP;
2922+
# define ENV_INIT NOOP;
2923+
# define ENV_TERM NOOP;
2924+
#endif
29102925

29112926
#if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
29122927
/* having sigaction(2) means that the OS supports both 1-arg and 3-arg

perlapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ END_EXTERN_C
119119
#define PL_do_undump (*Perl_Gdo_undump_ptr(NULL))
120120
#undef PL_dollarzero_mutex
121121
#define PL_dollarzero_mutex (*Perl_Gdollarzero_mutex_ptr(NULL))
122+
#undef PL_env_mutex
123+
#define PL_env_mutex (*Perl_Genv_mutex_ptr(NULL))
122124
#undef PL_fold_locale
123125
#define PL_fold_locale (*Perl_Gfold_locale_ptr(NULL))
124126
#undef PL_hash_chars

perlvars.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ PERLVARI(G, mmap_page_size, IV, 0)
104104

105105
#if defined(USE_ITHREADS)
106106
PERLVAR(G, hints_mutex, perl_mutex) /* Mutex for refcounted he refcounting */
107+
PERLVAR(G, env_mutex, perl_mutex) /* Mutex for accessing ENV */
107108
# if ! defined(USE_THREAD_SAFE_LOCALE) || defined(TS_W32_BROKEN_LOCALECONV)
108109
PERLVAR(G, locale_mutex, perl_mutex) /* Mutex for setlocale() changing */
109110
# endif

symbian/symbianish.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
#ifndef PERL_SYS_TERM_BODY
123123
#define PERL_SYS_TERM_BODY() HINTS_REFCNT_TERM; OP_REFCNT_TERM; \
124124
PERLIO_TERM; MALLOC_TERM; CloseSTDLIB(); \
125-
LOCALE_TERM
125+
LOCALE_TERM; ENV_TERM;
126126

127127
#endif
128128

unixish.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ int afstat(int fd, struct stat *statb);
142142
HINTS_REFCNT_TERM; KEYWORD_PLUGIN_MUTEX_TERM; \
143143
OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; PERLIO_TERM; \
144144
MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM; \
145+
ENV_TERM; \
145146
amigaos4_dispose_fork_array();
146147
#endif
147148

@@ -154,7 +155,8 @@ int afstat(int fd, struct stat *statb);
154155
# define PERL_SYS_TERM_BODY() \
155156
HINTS_REFCNT_TERM; KEYWORD_PLUGIN_MUTEX_TERM; \
156157
OP_CHECK_MUTEX_TERM; OP_REFCNT_TERM; PERLIO_TERM; \
157-
MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM;
158+
MALLOC_TERM; LOCALE_TERM; USER_PROP_MUTEX_TERM; \
159+
ENV_TERM;
158160

159161
#endif
160162

vms/vmsish.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ struct interp_intern {
310310
#define BIT_BUCKET "/dev/null"
311311
#define PERL_SYS_INIT_BODY(c,v) MALLOC_CHECK_TAINT2(*c,*v) vms_image_init((c),(v)); PERLIO_INIT; MALLOC_INIT
312312
#define PERL_SYS_TERM_BODY() HINTS_REFCNT_TERM; OP_REFCNT_TERM; \
313-
PERLIO_TERM; MALLOC_TERM; LOCALE_TERM
313+
PERLIO_TERM; MALLOC_TERM; LOCALE_TERM \
314+
ENV_TERM;
314315
#define dXSUB_SYS dNOOP
315316
#define HAS_KILL
316317
#define HAS_WAIT

0 commit comments

Comments
 (0)