• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Get next section.
2    Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 1998.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, version 2.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 
22 #include <assert.h>
23 #include <libelf.h>
24 #include <stddef.h>
25 
26 #include "libelfP.h"
27 
28 
29 Elf_Scn *
elf_nextscn(elf,scn)30 elf_nextscn (elf, scn)
31      Elf *elf;
32      Elf_Scn *scn;
33 {
34   Elf_Scn *result = NULL;
35 
36   if (elf == NULL)
37     return NULL;
38 
39   rwlock_rdlock (elf->lock);
40 
41   if (scn == NULL)
42     {
43       /* If no section handle is given return the first (not 0th) section.  */
44       if (elf->class == ELFCLASS32
45 	   || (offsetof (Elf, state.elf32.scns)
46 	       == offsetof (Elf, state.elf64.scns)))
47 	{
48 	  if (elf->state.elf32.scns.cnt > 1)
49 	    result = &elf->state.elf32.scns.data[1];
50 	}
51       else
52 	{
53 	  if (elf->state.elf64.scns.cnt > 1)
54 	    result = &elf->state.elf64.scns.data[1];
55 	}
56     }
57   else
58     {
59       Elf_ScnList *list = scn->list;
60 
61       if (scn + 1 < &list->data[list->cnt])
62 	result = scn + 1;
63       else if (scn + 1 == &list->data[list->max]
64 	       && (list = list->next) != NULL)
65 	{
66 	  /* If there is another element in the section list it must
67 	     have at least one entry.  */
68 	  assert (list->cnt > 0);
69 	  result = &list->data[0];
70 	}
71     }
72 
73   rwlock_unlock (elf->lock);
74 
75   return result;
76 }
77 INTDEF(elf_nextscn)
78