• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Return segment type name.
2    Copyright (C) 2001, 2002, 2004 Red Hat, Inc.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
4 
5    This program is Open Source software; you can redistribute it and/or
6    modify it under the terms of the Open Software License version 1.0 as
7    published by the Open Source Initiative.
8 
9    You should have received a copy of the Open Software License along
10    with this program; if not, you may obtain a copy of the Open Software
11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13    3001 King Ranch Road, Ukiah, CA 95482.   */
14 
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 
19 #include <stdio.h>
20 #include <libeblP.h>
21 
22 
23 const char *
ebl_segment_type_name(ebl,segment,buf,len)24 ebl_segment_type_name (ebl, segment, buf, len)
25      Ebl *ebl;
26      int segment;
27      char *buf;
28      size_t len;
29 {
30   const char *res;
31 
32   res = ebl != NULL ? ebl->segment_type_name (segment, buf, len) : NULL;
33   if (res == NULL)
34     {
35       static const char *ptypes[PT_NUM] =
36 	{
37 #define PTYPE(name) [PT_##name] = #name
38 	  PTYPE (NULL),
39 	  PTYPE (LOAD),
40 	  PTYPE (DYNAMIC),
41 	  PTYPE (INTERP),
42 	  PTYPE (NOTE),
43 	  PTYPE (SHLIB),
44 	  PTYPE (PHDR),
45 	  PTYPE (TLS)
46 	};
47 
48       /* Is it one of the standard segment types?  */
49       if (segment >= PT_NULL && segment < PT_NUM)
50 	res = ptypes[segment];
51       else if (segment == PT_GNU_EH_FRAME)
52 	res = "GNU_EH_FRAME";
53       else if (segment == PT_GNU_STACK)
54 	res = "GNU_STACK";
55       else if (segment == PT_GNU_RELRO)
56 	res = "GNU_RELRO";
57       else if (segment == PT_SUNWBSS)
58 	res = "SUNWBSS";
59       else if (segment == PT_SUNWSTACK)
60 	res = "SUNWSTACK";
61       else
62 	{
63 	  if (segment >= PT_LOOS && segment <= PT_HIOS)
64 	    snprintf (buf, len, "LOOS+%d", segment - PT_LOOS);
65 	  else if (segment >= PT_LOPROC && segment <= PT_HIPROC)
66 	    snprintf (buf, len, "LOPROC+%d", segment - PT_LOPROC);
67 	  else
68 	    snprintf (buf, len, "%s: %d", gettext ("<unknown>"), segment);
69 
70 	  res = buf;
71 	}
72     }
73 
74   return res;
75 }
76