/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <libelf.h>
#include "decl.h"
#include "msg.h"
/*
* Convert data from file format to memory format.
*/
{
1, /* ELF_T_BYTE */
sizeof (Elf32), /* ELF_T_ADDR */
sizeof (Elf32), /* ELF_T_DYN */
sizeof (Elf32), /* ELF_T_EHDR */
sizeof (Elf32_Half), /* ELF_T_HALF */
sizeof (Elf32), /* ELF_T_OFF */
sizeof (Elf32), /* ELF_T_PHDR */
sizeof (Elf32), /* ELF_T_RELA */
sizeof (Elf32), /* ELF_T_REL */
sizeof (Elf32), /* ELF_T_SHDR */
sizeof (Elf32), /* ELF_T_SWORD */
sizeof (Elf32), /* ELF_T_SYM */
sizeof (Elf32), /* ELF_T_WORD */
sizeof (Elf32), /* ELF_T_VERDEF */
sizeof (Elf32), /* ELF_T_VERNEED */
sizeof (Elf64_Sxword), /* ELF_T_SXWORD */
sizeof (Elf64), /* ELF_T_XWORD */
sizeof (Elf32_Half), /* ELF_T_SYMINFO */
sizeof (Elf32), /* ELF_T_NOTE */
sizeof (Elf32_Lword), /* ELF_T_MOVE */
sizeof (Elf32_Lword), /* ELF_T_MOVEP */
sizeof (Elf32_Word) /* ELF_T_CAP */
};
{
1, /* ELF_T_BYTE */
sizeof (Elf64), /* ELF_T_ADDR */
sizeof (Elf64), /* ELF_T_DYN */
sizeof (Elf64), /* ELF_T_EHDR */
sizeof (Elf64_Half), /* ELF_T_HALF */
sizeof (Elf64), /* ELF_T_OFF */
sizeof (Elf64), /* ELF_T_PHDR */
sizeof (Elf64), /* ELF_T_RELA */
sizeof (Elf64), /* ELF_T_REL */
sizeof (Elf64), /* ELF_T_SHDR */
sizeof (Elf64_Word), /* ELF_T_SWORD */
sizeof (Elf64), /* ELF_T_SYM */
sizeof (Elf64_Word), /* ELF_T_WORD */
sizeof (Elf64), /* ELF_T_VDEF */
sizeof (Elf64), /* ELF_T_VNEED */
sizeof (Elf64), /* ELF_T_SXWORD */
sizeof (Elf64), /* ELF_T_XWORD */
sizeof (Elf32_Half), /* ELF_T_SYMINFO */
sizeof (Elf32), /* ELF_T_NOTE */
sizeof (Elf64), /* ELF_T_MOVE */
sizeof (Elf64), /* ELF_T_MOVEP */
sizeof (Elf64_Word) /* ELF_T_CAP */
};
/*
* Could use an array indexed by ELFCLASS*, but I'd rather
* avoid .data over something this infrequently used. The
* next choice would be to add extra conditionals.
*/
Elf_Data *
{
unsigned work;
/*
* make sure someone else didn't come along and cook
* this stuff.
*/
(void) _elf_cookscn(scn);
}
if (d == 0)
else
d = d->db_next;
/*LINTED*/
return (0);
}
if (d == 0) {
return (0);
}
_elf_seterr(EREQ_DATA, 0);
return (0);
}
if (d->db_myflags & DBF_READY) {
return (&d->db_data);
}
/*
* Prepare return buffer. The data comes from the memory
* image of the file. "Empty" regions get an empty buffer.
*
* Only sections of an ELF_C_READ file can be not READY here.
* Furthermore, the input file must have been cooked or
* frozen by now. Translate cooked files in place if possible.
*/
d->db_myflags |= DBF_READY;
return (&d->db_data);
}
if ((t != ELF_T_BYTE) &&
_elf_seterr(EFMT_ENTSZ, 0);
return (0);
}
_elf_seterr(EFMT_ENTSZ, 0);
return (0);
}
} else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
/*
* validate the region
*/
_elf_seterr(EFMT_DATA, 0);
return (0);
}
/*
* set up translation buffers and validate
*/
return (0);
}
}
/*
* decide where to put destination
*/
case ES_COOKED:
_elf_seterr(EBUG_COOKTYPE, 0);
return (0);
}
/*
* If the destination size (memory) is at least as
* big as the source size (file), and has the necessary
* alignment, reuse the space.
*
* Note that it is not sufficient to check the alignment
* of the offset within the object. Rather, we must check
* the alignment of the actual data buffer. The offset is
* sufficient if the file is a plain object file, which
* will always be mapped on a page boundary. In an archive
* however, the only guarantee is that the object will start
* on an even boundary within the archive file. The
* Solaris ar(1) adds padding in most (but not all cases)
* which minimizes this issue, but it is still important
* for the remaining cases that do not get padded. It also
* matters with archives produced by other versions of
* ar(1), such as the GNU version, or one from another
* ELF based operating system.
*/
d->db_off);
break;
} else { /* Failure: Restore NULL buffer pointer */
}
}
/*FALLTHRU*/
case ES_FROZEN:
return (0);
}
break;
default:
_elf_seterr(EBUG_COOKSTAT, 0);
return (0);
}
return (0);
} else { /* ELFCLASS64 */
return (0);
}
d->db_myflags |= DBF_READY;
return (&d->db_data);
}
Elf_Data *
{
/*
* trap null args, end of list, previous buffer.
* SHT_NULL sections have no buffer list, so they
* fall out here too.
*/
if (scn == 0)
return (0);
return (rc);
}