Home | History | Annotate | Download | only in libebl
      1 /* Print contents of core note.
      2    Copyright (C) 2002, 2004 Red Hat, Inc.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2002.
      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 <inttypes.h>
     20 #include <stdio.h>
     21 #include <stddef.h>
     22 #include <libeblP.h>
     23 
     24 
     25 void
     26 ebl_core_note (ebl, name, type, descsz, desc)
     27      Ebl *ebl;
     28      const char *name;
     29      uint32_t type;
     30      uint32_t descsz;
     31      const char *desc;
     32 {
     33   int class = gelf_getclass (ebl->elf);
     34 
     35   if (! ebl->core_note (name, type, descsz, desc))
     36     /* The machine specific function did not know this type.  */
     37     switch (type)
     38       {
     39       case NT_PLATFORM:
     40 	printf (gettext ("    Platform: %.*s\n"), (int) descsz, desc);
     41 	break;
     42 
     43       case NT_AUXV:
     44 	;
     45 	size_t cnt;
     46 	size_t elsize = (class == ELFCLASS32
     47 			 ? sizeof (Elf32_auxv_t) : sizeof (Elf64_auxv_t));
     48 
     49 	for (cnt = 0; (cnt + 1) * elsize <= descsz; ++cnt)
     50 	  {
     51 	    unsigned long int atype;
     52 	    unsigned long int val;
     53 
     54 	    if (class == ELFCLASS32)
     55 	      {
     56 		Elf32_auxv_t *auxv = &((Elf32_auxv_t *) desc)[cnt];
     57 
     58 		atype = auxv->a_type;
     59 		val = auxv->a_un.a_val;
     60 	      }
     61 	    else
     62 	      {
     63 		Elf64_auxv_t *auxv = &((Elf64_auxv_t *) desc)[cnt];
     64 
     65 		atype = auxv->a_type;
     66 		val = auxv->a_un.a_val;
     67 	      }
     68 
     69 	    /* XXX Do we need the auxiliary vector info anywhere
     70 	       else?  If yes, move code into a separate function.  */
     71 	    const char *at;
     72 
     73 	    switch (atype)
     74 	      {
     75 #define NEW_AT(name) case AT_##name: at = #name; break
     76 		NEW_AT (NULL);
     77 		NEW_AT (IGNORE);
     78 		NEW_AT (EXECFD);
     79 		NEW_AT (PHDR);
     80 		NEW_AT (PHENT);
     81 		NEW_AT (PHNUM);
     82 		NEW_AT (PAGESZ);
     83 		NEW_AT (BASE);
     84 		NEW_AT (FLAGS);
     85 		NEW_AT (ENTRY);
     86 		NEW_AT (NOTELF);
     87 		NEW_AT (UID);
     88 		NEW_AT (EUID);
     89 		NEW_AT (GID);
     90 		NEW_AT (EGID);
     91 		NEW_AT (CLKTCK);
     92 		NEW_AT (PLATFORM);
     93 		NEW_AT (HWCAP);
     94 		NEW_AT (FPUCW);
     95 		NEW_AT (DCACHEBSIZE);
     96 		NEW_AT (ICACHEBSIZE);
     97 		NEW_AT (UCACHEBSIZE);
     98 		NEW_AT (IGNOREPPC);
     99 
    100 	      default:
    101 		at = "???";
    102 		break;
    103 	      }
    104 
    105 	    switch (atype)
    106 	      {
    107 	      case AT_NULL:
    108 	      case AT_IGNORE:
    109 	      case AT_IGNOREPPC:
    110 	      case AT_NOTELF:
    111 	      default:
    112 		printf ("    %s\n", at);
    113 		break;
    114 
    115 	      case AT_EXECFD:
    116 	      case AT_PHENT:
    117 	      case AT_PHNUM:
    118 	      case AT_PAGESZ:
    119 	      case AT_UID:
    120 	      case AT_EUID:
    121 	      case AT_GID:
    122 	      case AT_EGID:
    123 	      case AT_CLKTCK:
    124 	      case AT_FPUCW:
    125 	      case AT_DCACHEBSIZE:
    126 	      case AT_ICACHEBSIZE:
    127 	      case AT_UCACHEBSIZE:
    128 		printf ("    %s: %" PRId64 "\n", at, (int64_t) val);
    129 		break;
    130 
    131 	      case AT_PHDR:
    132 	      case AT_BASE:
    133 	      case AT_FLAGS:	/* XXX Print flags?  */
    134 	      case AT_ENTRY:
    135 	      case AT_PLATFORM:	/* XXX Get string?  */
    136 	      case AT_HWCAP:	/* XXX Print flags?  */
    137 		printf ("    %s: %" PRIx64 "\n", at, (uint64_t) val);
    138 		break;
    139 	      }
    140 
    141 	    if (atype == AT_NULL)
    142 	      /* Reached the end.  */
    143 	      break;
    144 	  }
    145 	break;
    146 
    147       default:
    148 	/* Unknown type.  */
    149 	break;
    150       }
    151 }
    152