}
+static inline void
+fill_mmap (size_t offset, char *last_position, char *scn_start,
+ char *const shdr_start, char *const shdr_end)
+{
+ size_t written = 0;
+
+ if (last_position < shdr_start)
+ {
+ written = MIN (scn_start + offset - last_position,
+ shdr_start - last_position);
+
+ memset (last_position, __libelf_fill_byte, written);
+ }
+
+ if (last_position + written != scn_start + offset
+ && shdr_end < scn_start + offset)
+ {
+ char *fill_start = MAX (shdr_end, scn_start);
+ memset (fill_start, __libelf_fill_byte,
+ scn_start + offset - fill_start);
+ }
+}
+
int
internal_function
__elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
Elf_Data_List *dl = &scn->data_list;
bool scn_changed = false;
- void fill_mmap (size_t offset)
- {
- size_t written = 0;
-
- if (last_position < shdr_start)
- {
- written = MIN (scn_start + offset - last_position,
- shdr_start - last_position);
-
- memset (last_position, __libelf_fill_byte, written);
- }
-
- if (last_position + written != scn_start + offset
- && shdr_end < scn_start + offset)
- {
- char *fill_start = MAX (shdr_end, scn_start);
- memset (fill_start, __libelf_fill_byte,
- scn_start + offset - fill_start);
- }
- }
-
if (scn->data_list_rear != NULL)
do
{
|| ((scn->flags | dl->flags | elf->flags)
& ELF_F_DIRTY) != 0))
{
- fill_mmap (dl->data.d.d_off);
+ fill_mmap (dl->data.d.d_off, last_position, scn_start,
+ shdr_start, shdr_end);
last_position = scn_start + dl->data.d.d_off;
}
/* If the previous section (or the ELF/program
header) changed we might have to fill the gap. */
if (scn_start > last_position && previous_scn_changed)
- fill_mmap (0);
+ fill_mmap (0, last_position, scn_start,
+ shdr_start, shdr_end);
/* We have to trust the existing section header information. */
last_position = scn_start + shdr->sh_size;
return result;
}
+/* Lock if necessary before dup an archive. */
+static inline Elf *
+lock_dup_elf (int fildes, Elf_Cmd cmd, Elf *ref)
+{
+ /* We need wrlock to dup an archive. */
+ if (ref->kind == ELF_K_AR)
+ {
+ rwlock_unlock (ref->lock);
+ rwlock_wrlock (ref->lock);
+ }
+ /* Duplicate the descriptor. */
+ return dup_elf (fildes, cmd, ref);
+}
/* Return a descriptor for the file belonging to FILDES. */
Elf *
return NULL;
}
- Elf *lock_dup_elf (void)
- {
- /* We need wrlock to dup an archive. */
- if (ref->kind == ELF_K_AR)
- {
- rwlock_unlock (ref->lock);
- rwlock_wrlock (ref->lock);
- }
-
- /* Duplicate the descriptor. */
- return dup_elf (fildes, cmd, ref);
- }
-
switch (cmd)
{
case ELF_C_NULL:
case ELF_C_READ:
case ELF_C_READ_MMAP:
if (ref != NULL)
- retval = lock_dup_elf ();
+ retval = lock_dup_elf (fildes, cmd, ref);
else
/* Create descriptor for existing file. */
retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL);
retval = NULL;
}
else
- retval = lock_dup_elf ();
+ retval = lock_dup_elf (fildes, cmd, ref);
}
else
/* Create descriptor for existing file. */