about summary refs log tree commit diff
path: root/resource/Makefile
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2024-11-21 21:10:52 +0100
committerFlorian Weimer <fweimer@redhat.com>2024-11-21 21:10:52 +0100
commit7a61e7f557a97ab597d6fca5e2d1f13f65685c61 (patch)
tree987d2206286ac0e371924a10b9a3e40d6586d3ec /resource/Makefile
parente6590f0c86632c36c9a784cf96075f4be2e920d2 (diff)
downloadglibc-master.tar.gz
glibc-master.tar.xz
glibc-master.zip
stdlib: Make getenv thread-safe in more cases HEAD master
Async-signal-safety is preserved, too.  In fact, getenv is fully
reentrant and can be called from the malloc call in setenv
(if a replacement malloc uses getenv during its initialization).

This is relatively easy to implement because even before this change,
setenv, unsetenv, clearenv, putenv do not deallocate the environment
strings themselves as they are removed from the environment.

The main changes are:

* Use release stores for environment array updates, following
  the usual pattern for safely publishing immutable data
  (in this case, the environment strings).

* Do not deallocate the environment array.  Instead, keep older
  versions around and adopt an  exponential resizing policy.  This
  results in an amortized constant space leak per active environment
  variable, but there already is such a leak for the variable itself
  (and that is even length-dependent, and includes no-longer used
  values).

* Add a seqlock-like mechanism to retry getenv if a concurrent
  unsetenv is observed.  Without that, it is possible that
  getenv returns NULL for a variable that is never unset.  This
  is visible on some AArch64 implementations with the newly
  added stdlib/tst-getenv-unsetenv test case.  The mechanism
  is not a pure seqlock because it tolerates one write from
  unsetenv.  This avoids the need for a second copy of the
  environ array that getenv can read from a signal handler
  that happens to interrupt an unsetenv call.

No manual updates are included with this patch because environ
usage with execve, posix_spawn, system is still not thread-safe
relative unsetenv.  The new process may end up with an environment
that misses entries that were never unset.  This is the same issue
described above for getenv.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'resource/Makefile')
0 files changed, 0 insertions, 0 deletions