~vorlon/ubuntu/natty/eglibc/multiarch

« back to all changes in this revision

Viewing changes to elf/dl-close.c

  • Committer: Steve Langasek
  • Date: 2011-02-18 21:18:44 UTC
  • mfrom: (103.1.7 eglibc)
  • Revision ID: steve.langasek@linaro.org-20110218211844-lodmi8b1qhyq3f3x
Tags: 2.13~pre1-0ubuntu1+multiarch.1
merge from natty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Close a shared object opened by `_dl_open'.
2
 
   Copyright (C) 1996-2007, 2009 Free Software Foundation, Inc.
 
2
   Copyright (C) 1996-2007, 2009, 2010 Free Software Foundation, Inc.
3
3
   This file is part of the GNU C Library.
4
4
 
5
5
   The GNU C Library is free software; you can redistribute it and/or
274
274
            }
275
275
 
276
276
#ifdef SHARED
277
 
          /* Auditing checkpoint: we have a new object.  */
 
277
          /* Auditing checkpoint: we remove an object.  */
278
278
          if (__builtin_expect (do_audit, 0))
279
279
            {
280
280
              struct audit_ifaces *afct = GLRO(dl_audit);
748
748
 
749
749
  __rtld_lock_unlock_recursive (GL(dl_load_lock));
750
750
}
751
 
 
752
 
 
753
 
static bool __libc_freeres_fn_section
754
 
free_slotinfo (struct dtv_slotinfo_list **elemp)
755
 
{
756
 
  size_t cnt;
757
 
 
758
 
  if (*elemp == NULL)
759
 
    /* Nothing here, all is removed (or there never was anything).  */
760
 
    return true;
761
 
 
762
 
  if (!free_slotinfo (&(*elemp)->next))
763
 
    /* We cannot free the entry.  */
764
 
    return false;
765
 
 
766
 
  /* That cleared our next pointer for us.  */
767
 
 
768
 
  for (cnt = 0; cnt < (*elemp)->len; ++cnt)
769
 
    if ((*elemp)->slotinfo[cnt].map != NULL)
770
 
      /* Still used.  */
771
 
      return false;
772
 
 
773
 
  /* We can remove the list element.  */
774
 
  free (*elemp);
775
 
  *elemp = NULL;
776
 
 
777
 
  return true;
778
 
}
779
 
 
780
 
 
781
 
libc_freeres_fn (free_mem)
782
 
{
783
 
  for (Lmid_t nsid = 0; nsid < GL(dl_nns); ++nsid)
784
 
    if (__builtin_expect (GL(dl_ns)[nsid]._ns_global_scope_alloc, 0) != 0
785
 
        && (GL(dl_ns)[nsid]._ns_main_searchlist->r_nlist
786
 
            // XXX Check whether we need NS-specific initial_searchlist
787
 
            == GLRO(dl_initial_searchlist).r_nlist))
788
 
      {
789
 
        /* All object dynamically loaded by the program are unloaded.  Free
790
 
           the memory allocated for the global scope variable.  */
791
 
        struct link_map **old = GL(dl_ns)[nsid]._ns_main_searchlist->r_list;
792
 
 
793
 
        /* Put the old map in.  */
794
 
        GL(dl_ns)[nsid]._ns_main_searchlist->r_list
795
 
          // XXX Check whether we need NS-specific initial_searchlist
796
 
          = GLRO(dl_initial_searchlist).r_list;
797
 
        /* Signal that the original map is used.  */
798
 
        GL(dl_ns)[nsid]._ns_global_scope_alloc = 0;
799
 
 
800
 
        /* Now free the old map.  */
801
 
        free (old);
802
 
      }
803
 
 
804
 
  if (USE___THREAD || GL(dl_tls_dtv_slotinfo_list) != NULL)
805
 
    {
806
 
      /* Free the memory allocated for the dtv slotinfo array.  We can do
807
 
         this only if all modules which used this memory are unloaded.  */
808
 
#ifdef SHARED
809
 
      if (GL(dl_initial_dtv) == NULL)
810
 
        /* There was no initial TLS setup, it was set up later when
811
 
           it used the normal malloc.  */
812
 
        free_slotinfo (&GL(dl_tls_dtv_slotinfo_list));
813
 
      else
814
 
#endif
815
 
        /* The first element of the list does not have to be deallocated.
816
 
           It was allocated in the dynamic linker (i.e., with a different
817
 
           malloc), and in the static library it's in .bss space.  */
818
 
        free_slotinfo (&GL(dl_tls_dtv_slotinfo_list)->next);
819
 
    }
820
 
 
821
 
  void *scope_free_list = GL(dl_scope_free_list);
822
 
  GL(dl_scope_free_list) = NULL;
823
 
  free (scope_free_list);
824
 
}