|
Packit Service |
97d2fb |
/* Get next section.
|
|
Packit Service |
97d2fb |
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2015 Red Hat, Inc.
|
|
Packit Service |
97d2fb |
This file is part of elfutils.
|
|
Packit Service |
97d2fb |
Contributed by Ulrich Drepper <drepper@redhat.com>, 1998.
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
This file is free software; you can redistribute it and/or modify
|
|
Packit Service |
97d2fb |
it under the terms of either
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
* the GNU Lesser General Public License as published by the Free
|
|
Packit Service |
97d2fb |
Software Foundation; either version 3 of the License, or (at
|
|
Packit Service |
97d2fb |
your option) any later version
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
or
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
* the GNU General Public License as published by the Free
|
|
Packit Service |
97d2fb |
Software Foundation; either version 2 of the License, or (at
|
|
Packit Service |
97d2fb |
your option) any later version
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
or both in parallel, as here.
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
elfutils is distributed in the hope that it will be useful, but
|
|
Packit Service |
97d2fb |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
97d2fb |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
97d2fb |
General Public License for more details.
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
You should have received copies of the GNU General Public License and
|
|
Packit Service |
97d2fb |
the GNU Lesser General Public License along with this program. If
|
|
Packit Service |
97d2fb |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
97d2fb |
# include <config.h>
|
|
Packit Service |
97d2fb |
#endif
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
#include <assert.h>
|
|
Packit Service |
97d2fb |
#include <libelf.h>
|
|
Packit Service |
97d2fb |
#include <stddef.h>
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
#include "libelfP.h"
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
Elf_Scn *
|
|
Packit Service |
97d2fb |
elf_nextscn (Elf *elf, Elf_Scn *scn)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
Elf_ScnList *list;
|
|
Packit Service |
97d2fb |
Elf_Scn *result = NULL;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
if (elf == NULL)
|
|
Packit Service |
97d2fb |
return NULL;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
rwlock_rdlock (elf->lock);
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
if (scn == NULL)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
/* If no section handle is given return the first (not 0th) section.
|
|
Packit Service |
97d2fb |
Set scn to the 0th section and perform nextscn. */
|
|
Packit Service |
97d2fb |
if (elf->class == ELFCLASS32
|
|
Packit Service |
97d2fb |
|| (offsetof (Elf, state.elf32.scns)
|
|
Packit Service |
97d2fb |
== offsetof (Elf, state.elf64.scns)))
|
|
Packit Service |
97d2fb |
list = &elf->state.elf32.scns;
|
|
Packit Service |
97d2fb |
else
|
|
Packit Service |
97d2fb |
list = &elf->state.elf64.scns;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
scn = &list->data[0];
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
else
|
|
Packit Service |
97d2fb |
list = scn->list;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
if (scn + 1 < &list->data[list->cnt])
|
|
Packit Service |
97d2fb |
result = scn + 1;
|
|
Packit Service |
97d2fb |
else if (scn + 1 == &list->data[list->max]
|
|
Packit Service |
97d2fb |
&& (list = list->next) != NULL)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
/* If there is another element in the section list it must
|
|
Packit Service |
97d2fb |
have at least one entry. */
|
|
Packit Service |
97d2fb |
assert (list->cnt > 0);
|
|
Packit Service |
97d2fb |
result = &list->data[0];
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
rwlock_unlock (elf->lock);
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
return result;
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
INTDEF(elf_nextscn)
|