Optimize memory handling. Copy pread if possible. Handle EINTR.

This commit is contained in:
Ulrich Drepper
2005-08-13 22:29:47 +00:00
parent cc1ebdb0ed
commit 1bb18a3a96
2 changed files with 30 additions and 13 deletions
+1
View File
@@ -3,6 +3,7 @@
* elf_begin.c (get_shnum): Optimize memory handling. Always read from
mapped file if available. Fix access to 64-bit sh_size. Recognize
overflow.
(file_read_elf): Likewise.
2005-08-12 Roland McGrath <roland@redhat.com>
+29 -13
View File
@@ -220,6 +220,7 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
{
/* We only read the ELF header now. */
unsigned char *e_ident;
unsigned char e_ident_mem[EI_NIDENT];
size_t scncnt;
Elf *elf;
@@ -229,9 +230,10 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
e_ident = (unsigned char *) map_address + offset;
else
{
e_ident = (unsigned char *) alloca (EI_NIDENT);
e_ident = e_ident_mem;
if (pread (fildes, e_ident, EI_NIDENT, offset) != EI_NIDENT)
if (TEMP_FAILURE_RETRY (pread (fildes, e_ident, EI_NIDENT, offset))
!= EI_NIDENT)
{
__libelf_seterrno (ELF_E_READ_ERROR);
return NULL;
@@ -312,14 +314,21 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
}
else
{
/* Read the data. */
if (pread (elf->fildes, &elf->state.elf32.ehdr_mem,
sizeof (Elf32_Ehdr), offset) != sizeof (Elf32_Ehdr))
{
/* We must be able to read the ELF header. */
__libelf_seterrno (ELF_E_INVALID_FILE);
return NULL;
}
if (likely (map_address != NULL))
/* Copy the data. */
memcpy (&elf->state.elf32.ehdr_mem,
(char *) map_address + offset, sizeof (Elf32_Ehdr));
else
/* Read the data. */
if (TEMP_FAILURE_RETRY (pread (elf->fildes,
&elf->state.elf32.ehdr_mem,
sizeof (Elf32_Ehdr), offset))
!= sizeof (Elf32_Ehdr))
{
/* We must be able to read the ELF header. */
__libelf_seterrno (ELF_E_INVALID_FILE);
return NULL;
}
if (e_ident[EI_DATA] != MY_ELFDATA)
{
@@ -397,9 +406,16 @@ file_read_elf (int fildes, void *map_address, off_t offset, size_t maxsize,
}
else
{
/* Read the data. */
if (pread (elf->fildes, &elf->state.elf64.ehdr_mem,
sizeof (Elf64_Ehdr), offset) != sizeof (Elf64_Ehdr))
if (likely (map_address != NULL))
/* Copy the data. */
memcpy (&elf->state.elf64.ehdr_mem,
(char *) map_address + offset, sizeof (Elf64_Ehdr));
else
/* Read the data. */
if (TEMP_FAILURE_RETRY (pread (elf->fildes,
&elf->state.elf64.ehdr_mem,
sizeof (Elf64_Ehdr), offset))
!= sizeof (Elf64_Ehdr))
{
/* We must be able to read the ELF header. */
__libelf_seterrno (ELF_E_INVALID_FILE);