gelf.c revision f7ba47a3946d92967bf3b928f9156af9249420d0
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <string.h>
#include "_libelf.h"
#include "decl.h"
#include "msg.h"
/*
* Find elf or it's class from a pointer to an Elf_Data struct.
* Warning: this Assumes that the Elf_Data is part of a libelf
* Dnode structure, which is expected to be true for any Elf_Data
* passed into libelf *except* for the xlatetof() and xlatetom() functions.
*/
#define EDATA_CLASS(edata) \
#define EDATA_READLOCKS(edata) \
#define EDATA_READUNLOCKS(edata) \
{
int class;
return (0);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
int
{
return (0);
/*
* Don't rely on the idents, a new ehdr doesn't have it!
*/
}
{
int class;
return (NULL);
if (class == ELFCLASS32) {
if (e == NULL)
return (NULL);
return (dst);
} else if (class == ELFCLASS64) {
if (e == NULL)
return (NULL);
*dst = *e;
return (dst);
}
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
int
{
int class;
return (0);
/*
* In case elf isn't cooked.
*/
if (class == ELFCLASSNONE)
if (class == ELFCLASS32) {
if (d == NULL)
return (0);
/* LINTED */
/* LINTED */
/* LINTED */
/* could memcpy the rest of these... */
return (1);
} else if (class == ELFCLASS64) {
if (d == NULL)
return (0);
*d = *(Elf64_Ehdr *)src;
return (1);
}
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
unsigned long
{
return (0);
if (class == ELFCLASS32)
return ((unsigned long)elf32_newehdr(elf));
else if (class == ELFCLASS64)
return ((unsigned long)elf64_newehdr(elf));
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
{
int class;
return (NULL);
return (NULL);
_elf_seterr(EREQ_RAND, 0);
return (NULL);
}
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
if (class == ELFCLASS32) {
} else if (class == ELFCLASS64) {
}
return (dst);
}
int
{
int class;
return (0);
return (NULL);
_elf_seterr(EREQ_RAND, 0);
return (0);
}
if (class == ELFCLASS32) {
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
} else if (class == ELFCLASS64) {
} else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
return (1);
}
unsigned long
{
int class;
return (0);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
{
return (NULL);
if (s == NULL)
return (NULL);
return (dst);
if (s == NULL)
return (NULL);
*dst = *(Elf64_Shdr *)s;
return (dst);
}
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
int
{
return (0);
return (0);
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
return (1);
return (0);
return (1);
}
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
/*
* gelf_xlatetof/gelf_xlatetom use 'elf' to find the class
* because these are the odd case where the Elf_Data structs
* might not have been allocated by libelf (and therefore
* don't have Dnode's associated with them).
*/
Elf_Data *
{
int class;
return (NULL);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
Elf_Data *
{
int class;
return (NULL);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
GElf_Sym *
{
int class;
return (NULL);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
Elf32_Sym *s;
ELF32_ST_TYPE(s->st_info));
} else
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
Elf32_Sym * d;
/* LINTED */
/* LINTED */
} else
return (rc);
}
{
int class;
return (NULL);
if (class == ELFCLASS32)
entsize = sizeof (Elf32_Syminfo);
else if (class == ELFCLASS64)
entsize = sizeof (GElf_Syminfo);
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
Elf32_Syminfo * si;
} else
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
entsize = sizeof (Elf32_Syminfo);
else if (class == ELFCLASS64)
entsize = sizeof (GElf_Syminfo);
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
} else
return (rc);
}
GElf_Dyn *
{
int class;
return (NULL);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
} else
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
/* LINTED */
/* LINTED */
} else
return (rc);
}
GElf_Sym *
{
return (NULL);
_elf_seterr(EREQ_RAND, 0);
return (NULL);
}
} else {
*xshndx = 0;
}
return (symptr);
}
int
{
return (0);
if (shndxdata) {
_elf_seterr(EREQ_RAND, 0);
return (0);
}
}
return (1);
}
{
int class;
return (NULL);
if (class == ELFCLASS32)
entsize = sizeof (Elf32_Move);
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
ELF32_M_SIZE(m->m_info));
} else {
}
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
entsize = sizeof (Elf32_Move);
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
} else {
}
return (rc);
}
{
int class;
return (NULL);
if (class == ELFCLASS32)
entsize = sizeof (Elf32_Rela);
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
/*
* Elf32 will never have the extra data field that
* Elf64's r_info field can have, so ignore it.
*/
/* LINTED */
ELF32_R_SYM(r->r_info),
ELF32_R_TYPE(r->r_info));
} else
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
entsize = sizeof (Elf32_Rela);
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
/* LINTED */
/* LINTED */
/*
* Elf32 will never have the extra data field that
* Elf64's r_info field can have, so ignore it.
*/
/* LINTED */
} else {
}
return (rc);
}
GElf_Rel *
{
int class;
return (NULL);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
/*
* Elf32 will never have the extra data field that
* Elf64's r_info field can have, so ignore it.
*/
/* LINTED */
ELF32_R_TYPE(r->r_info));
} else
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
/* LINTED */
/*
* Elf32 will never have the extra data field that
* Elf64's r_info field can have, so ignore it.
*/
/* LINTED */
} else {
}
return (rc);
}
long
{
if (class == ELFCLASS32)
return (elf32_checksum(elf));
else if (class == ELFCLASS64)
return (elf64_checksum(elf));
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
GElf_Cap *
{
int class;
return (NULL);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (NULL);
}
_elf_seterr(EREQ_RAND, 0);
} else if (class == ELFCLASS32) {
} else
return (dst);
}
int
{
return (0);
if (class == ELFCLASS32)
else if (class == ELFCLASS64)
else {
_elf_seterr(EREQ_CLASS, 0);
return (0);
}
_elf_seterr(EREQ_RAND, 0);
rc = 0;
} else if (class == ELFCLASS32) {
} else
return (rc);
}
/*
* If the specified object has a dynamic section, and that section
* contains a DT_FLAGS_1 entry, then return the value of that entry.
* Otherwise, return 0.
*/
{
int i, n;
break;
continue;
for (i = 0; i < n; i++) {
}
}
}
break;
}
return (0);
}