libthread_xu - Clean up the red zone on library unload
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 16 Apr 2014 17:01:14 +0000 (10:01 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 16 Apr 2014 17:01:14 +0000 (10:01 -0700)
commit0dc5e56d98ab5fc55416a204886f8b132cc9b7f1
treea5277a3941d505d96765dce469033cc867140aab
parent34bf0d2d9e56a77a19b2de6473b7076716921e62
libthread_xu - Clean up the red zone on library unload

* If the main program is not linked against -pthread but dynamically
  loads a shared library that is via dlopen(), then dlclose()'s it,
  libthread_xu leaves red-zone and cached thread stacks dangling.

  The second attempt to (indirectly) load libthread_xu then fails with a
  red-zone panic.

* Add a destructor for libthread_xu to unmap the red-zone and to clean out
  any cached thread stacks.

* Note that neither libthread_xu nor most other large libraries are designed
  to be unloaded.  That is, even if loading/unloading works, numerous libraries
  will almost certainly leak memory.  This change prevents the fatal error but
  doesn't fix the general memory leakage problem.

  IMHO Only libraries designed to be unloadable should be unloaded.

Reported-by: Vasily Postnicov <shamaz.mazum@gmail.com>
lib/libthread_xu/thread/thr_init.c
lib/libthread_xu/thread/thr_private.h
lib/libthread_xu/thread/thr_stack.c