summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-10-10 00:51:29 +0000
committerUlrich Drepper <drepper@redhat.com>2006-10-10 00:51:29 +0000
commit1100f84983f22e570a5081cbe79b0ef8fe4952d7 (patch)
tree3472df1372abf7816fb10f02573ba114c5b5a003 /include
parent7484f797e4d4f9c174d4391f59d208e83027b285 (diff)
downloadglibc-1100f84983f22e570a5081cbe79b0ef8fe4952d7.tar.gz
glibc-1100f84983f22e570a5081cbe79b0ef8fe4952d7.tar.xz
glibc-1100f84983f22e570a5081cbe79b0ef8fe4952d7.zip
Jakub Jelinek <jakub@redhat.com>
	Implement reference counting of scope records.
	* elf/dl-close.c (_dl_close): Remove all scopes from removed objects
	from the list in objects which remain.  Always allocate new scope
	record.
	* elf/dl-open.c (dl_open_worker): When growing array for scopes,
	don't resize, allocate a new one.
	* elf/dl-runtime.c: Update reference counters before using a scope
	array.
	* elf/dl-sym.c: Likewise.
	* elf/dl-libc.c: Adjust for l_scope name change.
	* elf/dl-load.c: Likewise.
	* elf/dl-object.c: Likewise.
	* elf/rtld.c: Likewise.
	* include/link.h: Inlcude <rtld-lowlevel.h>.  Define struct
	r_scoperec.  Replace r_scope with pointer to r_scoperec structure.
	Add l_scoperec_lock.
	* sysdeps/generic/ldsodefs.h: Include <rtld-lowlevel.h>.
	* sysdeps/generic/rtld-lowlevel.h: New file.

	* include/atomic.h: Rename atomic_and to atomic_and_val and
	atomic_or to atomic_or_val.  Define new macros atomic_and and
	atomic_or which do not return values.
	* sysdeps/x86_64/bits/atomic.h: Define atomic_and and atomic_or.
	Various cleanups.
	* sysdeps/i386/i486/bits/atomic.h: Likewise.
Diffstat (limited to 'include')
-rw-r--r--include/atomic.h38
-rw-r--r--include/link.h35
2 files changed, 69 insertions, 4 deletions
diff --git a/include/atomic.h b/include/atomic.h
index a1598e3850..bd2e2f13f7 100644
--- a/include/atomic.h
+++ b/include/atomic.h
@@ -273,9 +273,27 @@
      __oldval & __mask; })
 #endif
 
-/* Atomically *mem &= mask and return the old value of *mem.  */
+/* Atomically *mem &= mask.  */
 #ifndef atomic_and
 # define atomic_and(mem, mask) \
+  do {									      \
+    __typeof (*(mem)) __oldval;						      \
+    __typeof (mem) __memp = (mem);					      \
+    __typeof (*(mem)) __mask = (mask);					      \
+									      \
+    do									      \
+      __oldval = (*__memp);						      \
+    while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,    \
+								   __oldval   \
+								   & __mask,  \
+								   __oldval), \
+			     0));					      \
+  } while (0)
+#endif
+
+/* Atomically *mem &= mask and return the old value of *mem.  */
+#ifndef atomic_and_val
+# define atomic_and_val(mem, mask) \
   ({ __typeof (*(mem)) __oldval;					      \
      __typeof (mem) __memp = (mem);					      \
      __typeof (*(mem)) __mask = (mask);					      \
@@ -294,6 +312,24 @@
 /* Atomically *mem |= mask and return the old value of *mem.  */
 #ifndef atomic_or
 # define atomic_or(mem, mask) \
+  do {									      \
+    __typeof (*(mem)) __oldval;						      \
+    __typeof (mem) __memp = (mem);					      \
+    __typeof (*(mem)) __mask = (mask);					      \
+									      \
+    do									      \
+      __oldval = (*__memp);						      \
+    while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,    \
+								   __oldval   \
+								   | __mask,  \
+								   __oldval), \
+			      0));					      \
+  } while (0)
+#endif
+
+/* Atomically *mem |= mask and return the old value of *mem.  */
+#ifndef atomic_or_val
+# define atomic_or_val(mem, mask) \
   ({ __typeof (*(mem)) __oldval;					      \
      __typeof (mem) __memp = (mem);					      \
      __typeof (*(mem)) __mask = (mask);					      \
diff --git a/include/link.h b/include/link.h
index 0d6b66100e..4b2f07e862 100644
--- a/include/link.h
+++ b/include/link.h
@@ -43,6 +43,8 @@ extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
 #include <bits/linkmap.h>
 #include <dl-lookupcfg.h>
 #include <tls.h>		/* Defines USE_TLS.  */
+#include <bits/libc-lock.h>
+#include <rtld-lowlevel.h>
 
 
 /* Some internal data structures of the dynamic linker used in the
@@ -73,6 +75,18 @@ struct r_search_path_struct
   };
 
 
+/* Structure for a scope.  Each such data structure has a lock.  The
+   lock allows many readers.  It can be invalidated by setting bit 31
+   which means that no more lockers are allowe */
+struct r_scoperec
+{
+  bool remove_after_use;
+  bool notify;
+  int nusers;
+  struct r_scope_elem *scope[0];
+};
+
+
 /* Structure describing a loaded shared object.  The `l_next' and `l_prev'
    members form a chain of all the shared objects loaded at startup.
 
@@ -120,7 +134,7 @@ struct link_map
        are indexed by DT_ADDRTAGIDX(tagvalue), see <elf.h>.  */
 
     ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM
-		     + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
+		      + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM];
     const ElfW(Phdr) *l_phdr;	/* Pointer to program header table in core.  */
     ElfW(Addr) l_entry;		/* Entry point location.  */
     ElfW(Half) l_phnum;		/* Number of program header entries.  */
@@ -212,12 +226,27 @@ struct link_map
     ElfW(Addr) l_text_end;
 
     /* Default array for 'l_scope'.  */
-    struct r_scope_elem *l_scope_mem[4];
+    union
+    {
+      struct r_scoperec l_scoperec_mem;
+      struct
+      {
+	struct r_scoperec scoperec_struct;
+	/* XXX This number should be increased once the scope memory
+	   handling has been tested.  */
+	struct r_scope_elem *scope_elems[4];
+#define NINIT_SCOPE_ELEMS(map) \
+	(sizeof ((map)->l_scope_realmem.scope_elems)			      \
+	 / sizeof ((map)->l_scope_realmem.scope_elems[0]))
+      } l_scope_realmem;
+    };
     /* Size of array allocated for 'l_scope'.  */
     size_t l_scope_max;
     /* This is an array defining the lookup scope for this link map.
        There are initially at most three different scope lists.  */
-    struct r_scope_elem **l_scope;
+    struct r_scoperec *l_scoperec;
+    /* We need to protect using the SCOPEREC.  */
+    __rtld_mrlock_define (, l_scoperec_lock)
 
     /* A similar array, this time only with the local scope.  This is
        used occasionally.  */