Blame nptl/tst-join7.c

Packit 6c4009
/* Verify that TLS access in separate thread in a dlopened library does not
Packit 6c4009
   deadlock.
Packit 6c4009
   Copyright (C) 2015-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
Packit 6c4009
/* When one dynamically loads a module, which spawns a thread to perform some
Packit 6c4009
   activities, it could be possible that TLS storage is accessed for the first
Packit 6c4009
   time in that thread.  This results in an allocation request within the
Packit 6c4009
   thread, which could result in an attempt to take the rtld load_lock.  This
Packit 6c4009
   is a problem because it would then deadlock with the dlopen (which owns the
Packit 6c4009
   lock), if the main thread is waiting for the spawned thread to exit.  We can
Packit 6c4009
   at least ensure that this problem does not occur due to accesses within
Packit 6c4009
   libc.so, by marking TLS variables within libc.so as IE.  The problem of an
Packit 6c4009
   arbitrary variable being accessed and constructed within such a thread still
Packit 6c4009
   exists but this test case does not verify that.  */
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  void *f = dlopen ("tst-join7mod.so", RTLD_NOW | RTLD_GLOBAL);
Packit 6c4009
  if (f)
Packit 6c4009
    dlclose (f);
Packit 6c4009
  else
Packit 6c4009
    return 1;
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"