AC_ARG_ENABLE([tls],
AS_HELP_STRING([--enable-tls], [enable use of thread local storage]),
-AC_DEFINE(USE_TLS))
+use_tls=yes, use_tls=no)
+AM_CONDITIONAL(USE_TLS, test "$use_tls" = yes)
+AS_IF([test "$use_tls" = yes], [AC_DEFINE(USE_TLS)])
+
AH_TEMPLATE([USE_TLS], [Defined if thread local storage should be used.])
dnl Add all the languages for which translations are available.
dnl Test of the config.h file. We hide all kinds of configuration magic
dnl in there.
AH_BOTTOM([
+#ifdef USE_TLS
+# include <pthread.h>
+# define tls_key_t __thread void *
+# define key_create(keyp, freefct) (1)
+# define getspecific(key) key
+# define setspecific(key,val) key = val
+# define once_define(class,name) class struct { } name
+# define once_execute(name,fct) ((void) &name, (void) (fct))
+# define rwlock_define(class,name) class pthread_rwlock_t name
+# define rwlock_init(lock) pthread_rwlock_init (&lock, NULL)
+# define rwlock_fini(lock) pthread_rwlock_destroy (&lock)
+# define rwlock_rdlock(lock) pthread_rwlock_rdlock (&lock)
+# define rwlock_wrlock(lock) pthread_rwlock_wrlock (&lock)
+# define rwlock_unlock(lock) pthread_rwlock_unlock (&lock)
+#else
/* Eventually we will allow multi-threaded applications to use the
libraries. Therefore we will add the necessary locking although
the macros used expand to nothing for now. */
fct (); \
name = 1; \
} while (0)
+#endif
/* gettext helper macro. */
#define N_(Str) Str
libasm_pic_a_SOURCES =
am_libasm_pic_a_OBJECTS = $(libasm_a_SOURCES:.c=.os)
+libasm_so_LDLIBS =
+if USE_TLS
+libasm_so_LDLIBS += -lpthread
+endif
+
libasm_so_SOURCES =
libasm.so: libasm_pic.a libasm.map
$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
-Wl,--version-script,$(srcdir)/libasm.map,--no-undefined \
-Wl,--soname,$@.$(VERSION) \
- ../libebl/libebl.a ../libelf/libelf.so
+ ../libebl/libebl.a ../libelf/libelf.so $(libasm_so_LDLIBS)
if readelf -d $@ | fgrep -q TEXTREL; then exit 1; fi
ln -fs $@ $@.$(VERSION)
+2008-07-15 Petr Machata <pmachata@redhat.com>
+
+ * linux-kernel-modules.c: #undef __USE_FILE_OFFSET64, it doesn't
+ work with fts. It gets defined through <pthread.h> include in
+ <config.h>.
+
2008-08-03 Roland McGrath <roland@redhat.com>
* linux-kernel-modules.c: Include <fts.h> before <config.h>.
+2008-08-05 Petr Machata <pmachata@redhat.com>
+
+ * elf_getdata.c, libelfP.h (__elf_getdata_internal):
+ Add lockstat argument in a fashion similar to elf32_getehdr below.
+ * elf32_updatenull.c (__elf32_updatenull, __elf64_updatenull):
+ Call __elf32_getshdr_internal and __elf64_getshdr_internal
+ explicitly, not via INTUSE.
+ Call __elf_getdata_internal explicitly, not via INTUSE.
+
+2008-08-05 Petr Machata <pmachata@redhat.com>
+
+ * gelf_getehdr.c, libelfP.h (__gelf_getehdr_internal):
+ Add lockstat argument in a fashion similar to elf32_getehdr below.
+ * elf_getdata.c, libelfP.h (__libelf_set_rawdata):
+ Add lockstat argument.
+ Call __gelf_getehdr_internal explicitly, not via INTUSE.
+ Call rwlock_to_wrlock instead of RWLOCK_UNLOCK/_WRLOCK sequence.
+ (elf_getdata): Pass lockstat argument to __libelf_set_rawdata.
+ * elf32_updatenull.c, libelfP.h
+ (__elf32_updatenull, __elf64_updatenull):
+ Add lockstat argument in a fashion similar to elf32_getehdr below.
+ Pass lockstat argument to __libelf_set_rawdata.
+ * elf_strptr.c (elf_strptr):
+ Pass lockstat argument to __libelf_set_rawdata.
+ * elf_update.c (elf_update):
+ Pass lockstat argument to __elf32_updatenull and
+ __elf64_updatenull.
+
+2008-08-05 Petr Machata <pmachata@redhat.com>
+
+ * common.h (rwlock_to_wrlock, rwlock_from_wrlock): New functions.
+ * elf32_getphdr.c, libelfP.h
+ (__elf32_getphdr_internal, __elf64_getphdr_internal):
+ Add lockstat argument in a fashion similar to elf32_getehdr below.
+ * gelf_getphdr.c (gelf_getphdr): Call __elf32_getphdr_internal and
+ __elf32_getphdr_internal explicitly, not via INTUSE.
+
+2008-08-05 Petr Machata <pmachata@redhat.com>
+
+ * libelfP.h (lockstat_t): New enum that describes what type of
+ lock is currently being held. To be used by _internal functions.
+ * elf32_getehdr.c, libelfP.h
+ (__elf32_getehdr_internal, __elf64_getehdr_internal):
+ Take extra lockstat argument.
+ Move "meat" of the getehdr functinonality here.
+ * elf32_getehdr.c (elf32_getehdr, elf64_getehdr):
+ Make this a simple wrapper that calls _internal variant.
+ * elf32_updatenull.c: Call __elf32_getehdr_internal explicitly,
+ not via INTUSE.
+ * elf32_getshdr.c, libelfP.h
+ (__elf32_getshdr_internal, __elf64_getshdr_internal):
+ Add lockstat argument in a fashion similar to elf32_getehdr.
+ * elf_getshnum.c, libelfP.h (__elf_getshnum_internal):
+ Likewise.
+ * gelf_getshdr.c (gelf_getshdr): Call __elf32_getshdr_internal,
+ __elf64_getshdr_internal explicitly, not via INTUSE.
+
+2008-08-04 Petr Machata <pmachata@redhat.com>
+
+ * common.h, elf32_getehdr.c, elf32_getphdr.c, elf32_getshdr.c,
+ elf32_newehdr.c, elf32_newphdr.c, elf32_offscn.c, elf_begin.c,
+ elf_clone.c, elf_cntl.c, elf_end.c, elf_getarsym.c, elf_getdata.c,
+ elf_getscn.c, elf_getshnum.c, elf_getshstrndx.c, elf_newdata.c,
+ elf_newscn.c, elf_nextscn.c, elf_readall.c, elf_strptr.c,
+ elf_update.c, gelf_getauxv.c, gelf_getdyn.c, gelf_getehdr.c,
+ gelf_getlib.c, gelf_getmove.c, gelf_getnote.c, gelf_getphdr.c,
+ gelf_getrel.c, gelf_getrela.c, gelf_getshdr.c, gelf_getsym.c,
+ gelf_getsyminfo.c, gelf_getsymshndx.c, gelf_getverdaux.c,
+ gelf_getverdef.c, gelf_getvernaux.c, gelf_getverneed.c,
+ gelf_getversym.c, gelf_update_auxv.c, gelf_update_dyn.c,
+ gelf_update_ehdr.c, gelf_update_lib.c, gelf_update_move.c,
+ gelf_update_phdr.c, gelf_update_rel.c, gelf_update_rela.c,
+ gelf_update_sym.c, gelf_update_syminfo.c, gelf_update_symshndx.c,
+ gelf_update_verdaux.c, gelf_update_verdef.c,
+ gelf_update_vernaux.c, gelf_update_verneed.c,
+ gelf_update_versym.c:
+ Change rwlock_{rd,wr,un}lock calls to RWLOCK_{RD,WR,UN}LOCK.
+
+2008-08-04 Petr Machata <pmachata@redhat.com>
+
+ * libelfP.h (RWLOCK_RDLOCK, RWLOCK_WRLOCK, RWLOCK_UNLOCK): New macros.
+
2008-07-28 Roland McGrath <roland@redhat.com>
* elf.h: Update from glibc.
libelf_pic_a_SOURCES =
am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os)
+libelf_so_LDLIBS =
+if USE_TLS
+libelf_so_LDLIBS += -lpthread
+endif
+
libelf_so_SOURCES =
libelf.so: libelf_pic.a libelf.map
$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
-Wl,--version-script,$(srcdir)/libelf.map,--no-undefined \
- -Wl,--soname,$@.$(VERSION),-z,-defs,-z,relro
+ -Wl,--soname,$@.$(VERSION),-z,-defs,-z,relro $(libelf_so_LDLIBS)
if readelf -d $@ | fgrep -q TEXTREL; then exit 1; fi
ln -fs $@ $@.$(VERSION)
#include <stdlib.h>
#include <string.h>
+#include "libelfP.h"
static inline Elf_Kind
__attribute__ ((unused))
__attribute__ ((unused))
libelf_acquire_all (Elf *elf)
{
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->kind == ELF_K_AR)
{
}
}
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
+}
+
+/* Convert given lock LOCK with lock state FROM to lock state
+ LS_WRLOCKED. */
+static void
+__attribute__ ((unused))
+rwlock_to_wrlock(lockstat_t from, rwlock_define (,*lock))
+{
+ if (from == LS_WRLOCKED)
+ return;
+ if (from == LS_RDLOCKED)
+ RWLOCK_UNLOCK (*lock);
+ RWLOCK_WRLOCK (*lock);
+}
+
+/* Convert given lock LOCK with lock state LS_WRLOCKED to lock state
+ TO. */
+static void
+__attribute__ ((unused))
+rwlock_from_wrlock(lockstat_t to, rwlock_define (,*lock))
+{
+ if (to == LS_WRLOCKED)
+ return;
+ RWLOCK_UNLOCK (*lock);
+ if (to == LS_RDLOCKED)
+ RWLOCK_RDLOCK (*lock);
}
}
/* Iterate through the list of data blocks. */
- while ((data = INTUSE(elf_getdata) (scn, data)) != NULL)
+ while ((data = __elf_getdata_internal (scn, data, LS_UNLOCKED)) != NULL)
/* If the file byte order is the same as the host byte order
process the buffer directly. If the data is just a stream
of bytes which the library will not convert we can use it
ElfW2(LIBELFBITS,Ehdr) *
-elfw2(LIBELFBITS,getehdr) (elf)
+__elfw2(LIBELFBITS,getehdr_internal) (elf, locked)
Elf *elf;
+ lockstat_t locked;
{
ElfW2(LIBELFBITS,Ehdr) *result;
return NULL;
}
- rwlock_rdlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_RDLOCK (elf->lock);
if (elf->class == 0)
elf->class = ELFW(ELFCLASS,LIBELFBITS);
result = elf->state.ELFW(elf,LIBELFBITS).ehdr;
out:
- rwlock_unlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
-INTDEF(elfw2(LIBELFBITS,getehdr))
+
+ElfW2(LIBELFBITS,Ehdr) *
+elfw2(LIBELFBITS,getehdr) (elf)
+ Elf *elf;
+{
+ if (elf == NULL)
+ return NULL;
+
+ return __elfw2(LIBELFBITS,getehdr_internal) (elf, LS_UNLOCKED);
+}
ElfW2(LIBELFBITS,Phdr) *
-elfw2(LIBELFBITS,getphdr) (elf)
+__elfw2(LIBELFBITS,getphdr_internal) (elf, locked)
+ lockstat_t locked;
Elf *elf;
{
ElfW2(LIBELFBITS,Phdr) *result;
if (likely (result != NULL))
return result;
- rwlock_wrlock (elf->lock);
+ rwlock_to_wrlock (locked, &elf->lock);
if (elf->class == 0)
elf->class = ELFW(ELFCLASS,LIBELFBITS);
}
out:
- rwlock_unlock (elf->lock);
-
+ rwlock_from_wrlock (locked, &elf->lock);
return result;
}
-INTDEF(elfw2(LIBELFBITS,getphdr))
+
+ElfW2(LIBELFBITS,Phdr) *
+elfw2(LIBELFBITS,getphdr) (elf)
+ Elf *elf;
+{
+ if (elf == NULL)
+ return NULL;
+
+ return __elfw2(LIBELFBITS,getphdr_internal) (elf, LS_UNLOCKED);
+}
ElfW2(LIBELFBITS,Shdr) *
-elfw2(LIBELFBITS,getshdr) (scn)
+__elfw2(LIBELFBITS,getshdr_internal) (scn, locked)
Elf_Scn *scn;
+ lockstat_t locked;
{
+ /* XXX: no read locking here, figure out why is it not necessary. */
ElfW2(LIBELFBITS,Shdr) *result;
if (scn == NULL)
Elf *elf = scn->elf;
ElfW2(LIBELFBITS,Ehdr) *ehdr = elf->state.ELFW(elf,LIBELFBITS).ehdr;
- rwlock_wrlock (elf->lock);
+ rwlock_to_wrlock (locked, &elf->lock);
/* Try again, maybe the data is there now. */
result = scn->shdr.ELFW(e,LIBELFBITS);
goto out;
size_t shnum;
- if (INTUSE (elf_getshnum) (elf, &shnum) != 0)
+ if (__elf_getshnum_internal (elf, &shnum, LS_WRLOCKED) != 0)
goto out;
size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr));
assert (result != NULL);
out:
- rwlock_unlock (elf->lock);
+ rwlock_from_wrlock (locked, &elf->lock);
}
return result;
}
-INTDEF(elfw2(LIBELFBITS,getshdr))
+
+ElfW2(LIBELFBITS,Shdr) *
+elfw2(LIBELFBITS,getshdr) (scn)
+ Elf_Scn *scn;
+{
+ return __elfw2(LIBELFBITS,getshdr_internal) (scn, LS_UNLOCKED);
+}
return NULL;
}
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->class == 0)
elf->class = ELFW(ELFCLASS,LIBELFBITS);
result = elf->state.ELFW(elf,LIBELFBITS).ehdr;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
return NULL;
}
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->class == 0)
elf->class = ELFW(ELFCLASS,LIBELFBITS);
}
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
&& unlikely (elfw2(LIBELFBITS,getshdr) (&runp->data[0]) == NULL))
return NULL;
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
Elf_Scn *result = NULL;
}
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
off_t
internal_function
-__elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop, size_t shnum)
+__elfw2(LIBELFBITS,updatenull) (Elf *elf, int *change_bop,
+ size_t shnum, lockstat_t locked)
{
- ElfW2(LIBELFBITS,Ehdr) *ehdr = INTUSE(elfw2(LIBELFBITS,getehdr)) (elf);
+ ElfW2(LIBELFBITS,Ehdr) *ehdr;
int changed = 0;
int ehdr_flags = 0;
+ ehdr = __elfw2(LIBELFBITS,getehdr_internal) (elf, locked);
+
/* Set the default values. */
if (ELFW(default_ehdr,LIBELFBITS) (elf, ehdr, shnum, change_bop) != 0)
return -1;
if (elf->state.ELFW(elf,LIBELFBITS).phdr == NULL
&& (ehdr->e_type == ET_EXEC || ehdr->e_type == ET_DYN
|| ehdr->e_type == ET_CORE))
- (void) INTUSE(elfw2(LIBELFBITS,getphdr)) (elf);
+ (void) __elfw2(LIBELFBITS,getphdr_internal) (elf, locked);
if (elf->state.ELFW(elf,LIBELFBITS).phdr != NULL)
{
/* Only executables, shared objects, and core files have a program
/* Load the section headers if necessary. This loads the
headers for all sections. */
if (list->data[1].shdr.ELFW(e,LIBELFBITS) == NULL)
- (void) INTUSE(elfw2(LIBELFBITS,getshdr)) (&list->data[1]);
+ (void) __elfw2(LIBELFBITS,getshdr_internal) (&list->data[1], locked);
do
{
update_if_changed (shdr->sh_entsize, sh_entsize,
scn->shdr_flags);
- if (scn->data_read == 0 && __libelf_set_rawdata (scn) != 0)
+ if (scn->data_read == 0
+ && __libelf_set_rawdata (scn, locked) != 0)
/* Something went wrong. The error value is already set. */
return -1;
{
/* The position of the section in the file
changed. Create the section data list. */
- if (INTUSE(elf_getdata) (scn, NULL) == NULL)
+ if (__elf_getdata_internal (scn, NULL, locked) == NULL)
return -1;
}
if (ref != NULL)
/* Make sure the descriptor is not suddenly going away. */
- rwlock_rdlock (ref->lock);
+ RWLOCK_RDLOCK (ref->lock);
else if (unlikely (fcntl (fildes, F_GETFL) == -1 && errno == EBADF))
{
/* We cannot do anything productive without a file descriptor. */
/* Release the lock. */
if (ref != NULL)
- rwlock_unlock (ref->lock);
+ RWLOCK_UNLOCK (ref->lock);
return retval;
}
return NULL;
/* Make sure the descriptor is not suddenly going away. */
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
if (cmd != ELF_C_EMPTY)
// XXX TODO handle ELF_C_READ/WRITE etc
/* Release the lock. */
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return retval;
}
return -1;
}
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
switch (cmd)
{
break;
}
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
return 0;
/* Make sure we are alone. */
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->ref_count != 0 && --elf->ref_count != 0)
{
/* Not yet the last activation. */
int result = elf->ref_count;
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
solve this problem by giving free the child lock. The
state of REF_COUNT==0 is handled all over the library, so
this should be ok. */
- rwlock_unlock (elf->lock);
- rwlock_rdlock (parent->lock);
- rwlock_wrlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
+ RWLOCK_RDLOCK (parent->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (parent->state.ar.children == elf)
parent->state.ar.children = elf->next;
child->next = elf->next;
}
- rwlock_unlock (parent->lock);
+ RWLOCK_UNLOCK (parent->lock);
}
/* This was the last activation. Free all resources. */
if (result == NULL)
{
/* We have not yet read the index. */
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
/* In case we find no index remember this for the next call. */
elf->state.ar.ar_sym = (Elf_Arsym *) -1l;
result = elf->state.ar.ar_sym;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
}
if (ptr != NULL)
/* Store the information for the raw data in the `rawdata' element. */
int
internal_function
-__libelf_set_rawdata (Elf_Scn *scn)
+__libelf_set_rawdata (Elf_Scn *scn, lockstat_t locked)
{
size_t offset;
size_t size;
if (elf->class == ELFCLASS32)
{
- Elf32_Shdr *shdr = scn->shdr.e32 ?: INTUSE(elf32_getshdr) (scn);
+ Elf32_Shdr *shdr
+ = scn->shdr.e32 ?: __elf32_getshdr_internal (scn, locked);
if (shdr == NULL)
/* Something went terribly wrong. */
}
else
{
- Elf64_Shdr *shdr = scn->shdr.e64 ?: INTUSE(elf64_getshdr) (scn);
+ Elf64_Shdr *shdr
+ = scn->shdr.e64 ?: __elf64_getshdr_internal (scn, locked);
if (shdr == NULL)
/* Something went terribly wrong. */
if (type == SHT_HASH)
{
GElf_Ehdr ehdr_mem;
-
- entsize = SH_ENTSIZE_HASH (INTUSE(gelf_getehdr) (elf, &ehdr_mem));
+ GElf_Ehdr *ehdr = __gelf_getehdr_internal (elf, &ehdr_mem, locked);
+ entsize = SH_ENTSIZE_HASH (ehdr);
}
else
{
if (type == SHT_HASH && elf->class == ELFCLASS64)
{
GElf_Ehdr ehdr_mem;
-
+ GElf_Ehdr *ehdr = __gelf_getehdr_internal (elf, &ehdr_mem, locked);
scn->rawdata.d.d_type
- = (SH_ENTSIZE_HASH (INTUSE(gelf_getehdr) (elf, &ehdr_mem)) == 4
- ? ELF_T_WORD : ELF_T_XWORD);
+ = (SH_ENTSIZE_HASH (ehdr) == 4 ? ELF_T_WORD : ELF_T_XWORD);
}
else
scn->rawdata.d.d_type = shtype_map[LIBELF_EV_IDX][TYPEIDX (type)];
Elf_Data *
-elf_getdata (scn, data)
+__elf_getdata_internal (scn, data, locked)
Elf_Scn *scn;
Elf_Data *data;
+ lockstat_t locked;
{
Elf_Data *result = NULL;
Elf *elf;
/* We will need this multiple times later on. */
elf = scn->elf;
- rwlock_rdlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_RDLOCK (elf->lock);
/* If `data' is not NULL this means we are not addressing the initial
data in the file. But this also means this data is already read
lock. Therefore give up the read lock and then get the write
lock. But this means that the data could meanwhile be
modified, therefore start the tests again. */
- rwlock_unlock (elf->lock);
- rwlock_wrlock (elf->lock);
+ rwlock_to_wrlock (LS_RDLOCKED, &elf->lock);
/* Read the data from the file. There is always a file (or
memory region) associated with this descriptor since
otherwise the `data_read' flag would be set. */
- if (scn->data_read == 0 && __libelf_set_rawdata (scn) != 0)
+ if (scn->data_read == 0 && __libelf_set_rawdata (scn, LS_WRLOCKED) != 0)
/* Something went wrong. The error value is already set. */
goto out;
}
result = &scn->data_list.data.d;
out:
- rwlock_unlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
-INTDEF(elf_getdata)
+
+Elf_Data *
+elf_getdata (scn, data)
+ Elf_Scn *scn;
+ Elf_Data *data;
+{
+ if (scn == NULL)
+ return NULL;
+
+ return __elf_getdata_internal (scn, data, LS_UNLOCKED);
+}
return NULL;
}
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
Elf_Scn *result = NULL;
}
}
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
int
-elf_getshnum (elf, dst)
+__elf_getshnum_internal (elf, dst, locked)
Elf *elf;
size_t *dst;
+ lockstat_t locked;
{
int result = 0;
int idx;
return -1;
}
- rwlock_rdlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_RDLOCK (elf->lock);
idx = elf->state.elf.scns_last->cnt;
if (idx != 0
else
*dst = 0;
- rwlock_unlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
-INTDEF(elf_getshnum)
+
+int
+elf_getshnum (elf, dst)
+ Elf *elf;
+ size_t *dst;
+{
+ if (elf == NULL)
+ return -1;
+
+ return __elf_getshnum_internal (elf, dst, LS_UNLOCKED);
+}
return -1;
}
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
/* We rely here on the fact that the `elf' element is a common prefix
of `elf32' and `elf64'. */
}
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
return NULL;
}
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
if (scn->data_read && scn->data_list_rear == NULL)
{
scn->data_list_rear = result;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
/* Please note that the following is thread safe and is also defined
for RESULT == NULL since it still return NULL. */
assert (offsetof (Elf, state.elf32.scns)
== offsetof (Elf, state.elf64.scns));
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
again:
if (elf->state.elf.scns_last->cnt < elf->state.elf.scns_last->max)
result->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
if (elf == NULL)
return NULL;
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
if (scn == NULL)
{
}
}
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
/* First thing we do is to read the data from the file. There is
always a file (or memory region) associated with this descriptor
since otherwise the `data_read' flag would be set. */
- if (__libelf_set_rawdata (scn) != 0)
+ if (__libelf_set_rawdata (scn, LS_UNLOCKED) != 0)
/* Something went wrong. The error value is already set. */
return NULL;
}
Elf *elf;
{
/* Get the file. */
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->map_address == NULL && unlikely (elf->fildes == -1))
{
__libelf_seterrno (ELF_E_INVALID_HANDLE);
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return NULL;
}
libelf_release_all (elf);
}
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return (char *) elf->map_address;
}
return NULL;
}
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
char *result = NULL;
Elf_Scn *strscn;
if (strscn->rawdata_base == NULL && ! strscn->data_read
/* Read the section data. */
- && __libelf_set_rawdata (strscn) != 0)
+ && __libelf_set_rawdata (strscn, LS_RDLOCKED) != 0)
goto out;
if (likely (strscn->rawdata_base != NULL))
}
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
return -1;
}
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
/* Make sure we have an ELF header. */
if (elf->state.elf.ehdr == NULL)
will come right after the ELF header. The count the size of all
sections and finally place the section table. */
size = (elf->class == ELFCLASS32
- ? __elf32_updatenull (elf, &change_bo, shnum)
- : __elf64_updatenull (elf, &change_bo, shnum));
+ ? __elf32_updatenull (elf, &change_bo, shnum, LS_WRLOCKED)
+ : __elf64_updatenull (elf, &change_bo, shnum, LS_WRLOCKED));
if (likely (size != -1)
/* See whether we actually have to write out the data. */
&& (cmd == ELF_C_WRITE || cmd == ELF_C_WRITE_MMAP))
}
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return size;
}
elf = data_scn->s->elf;
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
/* This is the one place where we have to take advantage of the fact
that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
result = dst;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
elf = data_scn->s->elf;
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
/* This is the one place where we have to take advantage of the fact
that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
result = dst;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
GElf_Ehdr *
-gelf_getehdr (elf, dest)
+__gelf_getehdr_internal (elf, dest, locked)
Elf *elf;
GElf_Ehdr *dest;
+ lockstat_t locked;
{
GElf_Ehdr *result = NULL;
return NULL;
}
- rwlock_rdlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_RDLOCK (elf->lock);
/* The following is an optimization: the ehdr element is at the same
position in both the elf32 and elf64 structure. */
else
result = memcpy (dest, elf->state.elf64.ehdr, sizeof (*dest));
- rwlock_unlock (elf->lock);
+ if (locked == LS_UNLOCKED)
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
-INTDEF(gelf_getehdr)
+
+GElf_Ehdr *
+gelf_getehdr (elf, dest)
+ Elf *elf;
+ GElf_Ehdr *dest;
+{
+ if (elf == NULL)
+ return NULL;
+
+ return __gelf_getehdr_internal (elf, dest, LS_UNLOCKED);
+}
Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
- rwlock_rdlock (data_scn->s->elf->lock);
+ RWLOCK_RDLOCK (data_scn->s->elf->lock);
/* The on disk format of Elf32_Lib and Elf64_Lib is identical. So
we can simplify things significantly. */
result = dst;
}
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return result;
}
}
elf = ((Elf_Data_Scn *) data)->s->elf;
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
*dst = ((GElf_Move *) data->d_buf)[ndx];
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
result = dst;
assert (sizeof (GElf_Nhdr) == sizeof (Elf32_Nhdr));
assert (sizeof (GElf_Nhdr) == sizeof (Elf64_Nhdr));
- rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
/* The data is already in the correct form. Just make sure the
offset is OK. */
}
}
- rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
return offset;
}
return NULL;
}
- rwlock_rdlock (elf->lock);
+ RWLOCK_RDLOCK (elf->lock);
if (elf->class == ELFCLASS32)
{
if (phdr == NULL)
{
- phdr = INTUSE(elf32_getphdr) (elf);
+ phdr = __elf32_getphdr_internal (elf, LS_RDLOCKED);
if (phdr == NULL)
/* The error number is already set. */
goto out;
if (phdr == NULL)
{
- phdr = INTUSE(elf64_getphdr) (elf);
+ phdr = __elf64_getphdr_internal (elf, LS_RDLOCKED);
if (phdr == NULL)
/* The error number is already set. */
goto out;
}
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
The interface is broken so that it requires this hack. */
scn = data_scn->s;
- rwlock_rdlock (scn->elf->lock);
+ RWLOCK_RDLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
sizeof (Elf64_Rel));
}
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
The interface is broken so that it requires this hack. */
scn = data_scn->s;
- rwlock_rdlock (scn->elf->lock);
+ RWLOCK_RDLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
sizeof (Elf64_Rela));
}
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
return NULL;
}
- rwlock_rdlock (scn->elf->lock);
+ RWLOCK_RDLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
/* Copy the elements one-by-one. */
- Elf32_Shdr *shdr = scn->shdr.e32 ?: INTUSE(elf32_getshdr) (scn);
+ Elf32_Shdr *shdr
+ = scn->shdr.e32 ?: __elf32_getshdr_internal (scn, LS_RDLOCKED);
if (shdr == NULL)
{
}
else
{
- Elf64_Shdr *shdr = scn->shdr.e64 ?: INTUSE(elf64_getshdr) (scn);
+ Elf64_Shdr *shdr
+ = scn->shdr.e64 ?: __elf64_getshdr_internal (scn, LS_RDLOCKED);
if (shdr == NULL)
{
}
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
return NULL;
}
- rwlock_rdlock (data_scn->s->elf->lock);
+ RWLOCK_RDLOCK (data_scn->s->elf->lock);
/* This is the one place where we have to take advantage of the fact
that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
result = dst;
out:
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return result;
}
assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
- rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
/* The data is already in the correct form. Just make sure the
index is OK. */
result = dst;
out:
- rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
return result;
}
return NULL;
}
- rwlock_rdlock (symdata_scn->s->elf->lock);
+ RWLOCK_RDLOCK (symdata_scn->s->elf->lock);
/* The user is not required to pass a data descriptor for an extended
section index table. */
result = dst;
out:
- rwlock_unlock (symdata_scn->s->elf->lock);
+ RWLOCK_UNLOCK (symdata_scn->s->elf->lock);
return result;
}
assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
- rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
/* The data is already in the correct form. Just make sure the
index is OK. */
sizeof (GElf_Verdaux));
- rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
return result;
}
assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
- rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
/* The data is already in the correct form. Just make sure the
index is OK. */
result = (GElf_Verdef *) memcpy (dst, (char *) data->d_buf + offset,
sizeof (GElf_Verdef));
- rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
return result;
}
assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
- rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
/* The data is already in the correct form. Just make sure the
index is OK. */
result = (GElf_Vernaux *) memcpy (dst, (char *) data->d_buf + offset,
sizeof (GElf_Verneed));
- rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
return result;
}
assert (sizeof (GElf_Verneed) == sizeof (Elf32_Vernaux));
assert (sizeof (GElf_Verneed) == sizeof (Elf64_Vernaux));
- rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_RDLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
/* The data is already in the correct form. Just make sure the
index is OK. */
result = (GElf_Verneed *) memcpy (dst, (char *) data->d_buf + offset,
sizeof (GElf_Verneed));
- rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
+ RWLOCK_UNLOCK (((Elf_Data_Scn *) data)->s->elf->lock);
return result;
}
assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
- rwlock_rdlock (scn->elf->lock);
+ RWLOCK_RDLOCK (scn->elf->lock);
/* The data is already in the correct form. Just make sure the
index is OK. */
result = dst;
}
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
}
scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
}
scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
return 0;
}
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->class == ELFCLASS32)
{
result = 1;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
}
Elf_Scn *scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
/* Check whether we have to resize the data buffer. */
int result = 0;
scn->flags |= ELF_F_DIRTY;
}
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
return 0;
}
- rwlock_wrlock (data_scn->s->elf->lock);
+ RWLOCK_WRLOCK (data_scn->s->elf->lock);
((GElf_Move *) data_scn->d.d_buf)[ndx] = *src;
/* Mark the section as modified. */
data_scn->s->flags |= ELF_F_DIRTY;
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return 1;
}
return 0;
}
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->class == ELFCLASS32)
{
if (phdr == NULL)
{
- phdr = INTUSE(elf32_getphdr) (elf);
+ phdr = __elf32_getphdr_internal (elf, LS_WRLOCKED);
if (phdr == NULL)
/* The error number is already set. */
goto out;
if (phdr == NULL)
{
- phdr = INTUSE(elf64_getphdr) (elf);
+ phdr = __elf64_getphdr_internal (elf, LS_WRLOCKED);
if (phdr == NULL)
/* The error number is already set. */
goto out;
result = 1;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
}
scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
}
scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
return 0;
elf = scn->elf;
- rwlock_wrlock (elf->lock);
+ RWLOCK_WRLOCK (elf->lock);
if (elf->class == ELFCLASS32)
{
- Elf32_Shdr *shdr = scn->shdr.e32 ?: INTUSE(elf32_getshdr) (scn);
+ Elf32_Shdr *shdr
+ = scn->shdr.e32 ?: __elf32_getshdr_internal (scn, LS_WRLOCKED);
if (shdr == NULL)
{
}
else
{
- Elf64_Shdr *shdr = scn->shdr.e64 ?: INTUSE(elf64_getshdr) (scn);
+ Elf64_Shdr *shdr
+ = scn->shdr.e64 ?: __elf64_getshdr_internal (scn, LS_WRLOCKED);
if (shdr == NULL)
{
result = 1;
out:
- rwlock_unlock (elf->lock);
+ RWLOCK_UNLOCK (elf->lock);
return result;
}
}
scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
if (scn->elf->class == ELFCLASS32)
{
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
scn = data_scn->s;
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
/* Check whether we have to resize the data buffer. */
if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size))
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
scn = symdata_scn->s;
/* We simply have to believe the user that the two sections belong to
the same ELF file. */
- rwlock_wrlock (scn->elf->lock);
+ RWLOCK_WRLOCK (scn->elf->lock);
/* The user is not required to pass a data descriptor for an extended
section index table. */
scn->flags |= ELF_F_DIRTY;
out:
- rwlock_unlock (scn->elf->lock);
+ RWLOCK_UNLOCK (scn->elf->lock);
return result;
}
return 0;
}
- rwlock_wrlock (data_scn->s->elf->lock);
+ RWLOCK_WRLOCK (data_scn->s->elf->lock);
memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Verdaux));
/* Mark the section as modified. */
data_scn->s->flags |= ELF_F_DIRTY;
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return 1;
}
return 0;
}
- rwlock_wrlock (data_scn->s->elf->lock);
+ RWLOCK_WRLOCK (data_scn->s->elf->lock);
memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Verdef));
/* Mark the section as modified. */
data_scn->s->flags |= ELF_F_DIRTY;
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return 1;
}
return 0;
}
- rwlock_wrlock (data_scn->s->elf->lock);
+ RWLOCK_WRLOCK (data_scn->s->elf->lock);
memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Vernaux));
/* Mark the section as modified. */
data_scn->s->flags |= ELF_F_DIRTY;
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return 1;
}
return 0;
}
- rwlock_wrlock (data_scn->s->elf->lock);
+ RWLOCK_WRLOCK (data_scn->s->elf->lock);
memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Verneed));
/* Mark the section as modified. */
data_scn->s->flags |= ELF_F_DIRTY;
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return 1;
}
return 0;
}
- rwlock_wrlock (data_scn->s->elf->lock);
+ RWLOCK_WRLOCK (data_scn->s->elf->lock);
((GElf_Versym *) data_scn->d.d_buf)[ndx] = *src;
/* Mark the section as modified. */
data_scn->s->flags |= ELF_F_DIRTY;
- rwlock_unlock (data_scn->s->elf->lock);
+ RWLOCK_UNLOCK (data_scn->s->elf->lock);
return 1;
}
#ifndef _LIBELFP_H
#define _LIBELFP_H 1
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <ar.h>
#include <gelf.h>
+
+#include <errno.h>
#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
/* gettext helper macros. */
#define _(Str) dgettext ("libelf", Str)
/* There absolutely never must be anything following the union. */
};
+/* For _locked calls. This gives the callee insight into how is the
+ object locked. Some functions, e.g. elf32_getshdr, are called from
+ both callers of both rwlock_wrlock and rwlock_rdlock. */
+typedef enum
+{
+ LS_UNLOCKED = 0,
+ LS_RDLOCKED,
+ LS_WRLOCKED
+} lockstat_t;
/* Type of the conversion functions. These functions will convert the
byte order. */
extern int __libelf_readsections (Elf *elf) internal_function;
/* Store the information for the raw data in the `rawdata_list' element. */
-extern int __libelf_set_rawdata (Elf_Scn *scn) internal_function;
+extern int __libelf_set_rawdata (Elf_Scn *scn, lockstat_t locked)
+ internal_function;
/* Helper functions for elf_update. */
-extern off_t __elf32_updatenull (Elf *elf, int *change_bop, size_t shnum)
+extern off_t __elf32_updatenull (Elf *elf, int *change_bop, size_t shnum,
+ lockstat_t locked)
internal_function;
-extern off_t __elf64_updatenull (Elf *elf, int *change_bop, size_t shnum)
+extern off_t __elf64_updatenull (Elf *elf, int *change_bop, size_t shnum,
+ lockstat_t locked)
internal_function;
extern int __elf32_updatemmap (Elf *elf, int change_bo, size_t shnum)
extern int __elf_end_internal (Elf *__elf);
extern Elf *__elf_begin_internal (int __fildes, Elf_Cmd __cmd, Elf *__ref)
attribute_hidden;
-extern Elf32_Ehdr *__elf32_getehdr_internal (Elf *__elf) attribute_hidden;
-extern Elf64_Ehdr *__elf64_getehdr_internal (Elf *__elf) attribute_hidden;
+extern Elf32_Ehdr *__elf32_getehdr_internal (Elf *__elf, lockstat_t locked)
+ attribute_hidden;
+extern Elf64_Ehdr *__elf64_getehdr_internal (Elf *__elf, lockstat_t locked)
+ attribute_hidden;
extern Elf32_Ehdr *__elf32_newehdr_internal (Elf *__elf) attribute_hidden;
extern Elf64_Ehdr *__elf64_newehdr_internal (Elf *__elf) attribute_hidden;
-extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf) attribute_hidden;
-extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf) attribute_hidden;
+extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf, lockstat_t locked)
+ attribute_hidden;
+extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf, lockstat_t locked)
+ attribute_hidden;
extern Elf32_Phdr *__elf32_newphdr_internal (Elf *__elf, size_t __cnt)
attribute_hidden;
extern Elf64_Phdr *__elf64_newphdr_internal (Elf *__elf, size_t __cnt)
attribute_hidden;
extern Elf_Scn *__elf64_offscn_internal (Elf *__elf, Elf64_Off __offset)
attribute_hidden;
-extern int __elf_getshnum_internal (Elf *__elf, size_t *__dst)
+extern int __elf_getshnum_internal (Elf *__elf, size_t *__dst,
+ lockstat_t locked)
attribute_hidden;
extern int __elf_getshstrndx_internal (Elf *__elf, size_t *__dst)
attribute_hidden;
-extern Elf32_Shdr *__elf32_getshdr_internal (Elf_Scn *__scn) attribute_hidden;
-extern Elf64_Shdr *__elf64_getshdr_internal (Elf_Scn *__scn) attribute_hidden;
+extern Elf32_Shdr *__elf32_getshdr_internal (Elf_Scn *__scn, lockstat_t locked)
+ attribute_hidden;
+extern Elf64_Shdr *__elf64_getshdr_internal (Elf_Scn *__scn, lockstat_t locked)
+ attribute_hidden;
extern Elf_Scn *__elf_getscn_internal (Elf *__elf, size_t __index)
attribute_hidden;
extern Elf_Scn *__elf_nextscn_internal (Elf *__elf, Elf_Scn *__scn)
attribute_hidden;
extern int __elf_scnshndx_internal (Elf_Scn *__scn) attribute_hidden;
-extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data)
+extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data,
+ lockstat_t locked)
attribute_hidden;
extern Elf_Data *__elf_rawdata_internal (Elf_Scn *__scn, Elf_Data *__data)
attribute_hidden;
extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden;
-extern GElf_Ehdr *__gelf_getehdr_internal (Elf *__elf, GElf_Ehdr *__dest);
+extern GElf_Ehdr *__gelf_getehdr_internal (Elf *__elf, GElf_Ehdr *__dest,
+ lockstat_t locked)
+ attribute_hidden;
extern size_t __gelf_fsize_internal (Elf *__elf, Elf_Type __type,
size_t __count, unsigned int __version)
attribute_hidden;
/* Align offset to 4 bytes as needed for note name and descriptor data. */
#define NOTE_ALIGN(n) (((n) + 3) & -4U)
+#ifdef NDEBUG
+# define LIBELF_CHECKED_LOCK(V, S) ((void)(V))
+#else
+/* Checked locking primitives. Prints out an error to stderr if the
+ locking or unlocking function returns an error code. A development
+ aid similar to assert, the user is not supposed to ever see any of
+ these. */
+# if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+# error The XSI-compliant version of strerror_r() is provided, but in following, \
+ the GNU version is assumed. Please rewrite.
+# endif
+
+# define LIBELF_CHECKED_LOCK(V, S) \
+ do { \
+ int err = (V); \
+ if (err != 0) \
+ { \
+ char __buf[128]; \
+ char *__ptr = strerror_r (err, __buf, sizeof __buf); \
+ fprintf (stderr, "%s:%d: %s: %s\n", \
+ __FILE__, __LINE__, (S), __ptr); \
+ } \
+ } while (0)
+
+#endif
+
+#define RWLOCK_RDLOCK(LOCK) LIBELF_CHECKED_LOCK (rwlock_rdlock (LOCK), "rwlock_rdlock")
+#define RWLOCK_WRLOCK(LOCK) LIBELF_CHECKED_LOCK (rwlock_wrlock (LOCK), "rwlock_wrlock")
+#define RWLOCK_UNLOCK(LOCK) LIBELF_CHECKED_LOCK (rwlock_unlock (LOCK), "rwlock_unlock")
+
#endif /* libelfP.h */
/* SHDR->SH_LINK now contains the index of the string section. */
/* Get the data for the symbol section. */
- data = INTUSE(elf_getdata) (symscn, NULL);
+ data = __elf_getdata_internal (symscn, NULL, LS_UNLOCKED);
if (data == NULL)
goto fail_close;