View of xos/usr/lib/ld-so/auxv.c


XOS | Parent Directory | View | Download

/* Copyright (C) 2008  Emmanuel Varoquaux
 
   This file is part of XOS.
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
#include "auxv.h"
 
#include <auxv.h>
 
void read_auxiliary_vector(unsigned long *auxv, struct auxiliary_vector_data_struct *auxiliary_vector_data)
{
  int ei_index;
  int id;
  unsigned long val;
 
  auxiliary_vector_data->contents.program_header_table = 0;
  auxiliary_vector_data->contents.program_header_entry_size = 0;
  auxiliary_vector_data->contents.program_header_entry_number = 0;
  auxiliary_vector_data->contents.page_size = 0;
  auxiliary_vector_data->contents.interpreter_base_address = 0;
  auxiliary_vector_data->contents.program_entry_point = 0;
  auxiliary_vector_data->contents.not_elf = 0;
  auxiliary_vector_data->contents.vdso_entry_point = 0;
  auxiliary_vector_data->contents.vdso_elf_header = 0;
 
  ei_index = 0;
  while ((id = auxv[ei_index++]) != AT_NULL) {
    val = auxv[ei_index++];
    switch (id) {
    case AT_PHDR: /* program headers for program */
      auxiliary_vector_data->contents.program_header_table = 1;
      auxiliary_vector_data->program_header_table = (Elf32_Phdr *)val;
      break;
    case AT_PHENT: /* size of program header entry */
      auxiliary_vector_data->contents.program_header_entry_size = 1;
      auxiliary_vector_data->program_header_entry_size = val;
      break;
    case AT_PHNUM: /* number of program headers */
      auxiliary_vector_data->contents.program_header_entry_number = 1;
      auxiliary_vector_data->program_header_entry_number = val;
      break;
    case AT_PAGESZ: /* system page size */
      auxiliary_vector_data->contents.page_size = 1;
      auxiliary_vector_data->page_size = val;
      break;
    case AT_BASE: /* base address of interpreter */
      auxiliary_vector_data->contents.interpreter_base_address = 1;
      auxiliary_vector_data->interpreter_base_address = (void *)val;
      break;
    case AT_ENTRY: /* entry point of program */
      auxiliary_vector_data->contents.program_entry_point = 1;
      auxiliary_vector_data->program_entry_point = (void *)val;
      break;
    case AT_NOTELF: /* program is not ELF */
      auxiliary_vector_data->contents.not_elf = 1;
      break;
    case AT_SYSINFO:
      auxiliary_vector_data->contents.vdso_entry_point = 1;
      auxiliary_vector_data->vdso_entry_point = (void *)val;
      break;
    case AT_SYSINFO_EHDR:
      auxiliary_vector_data->contents.vdso_elf_header = 1;
      auxiliary_vector_data->vdso_elf_header = (Elf32_Ehdr *)val;
      break;
    }
  }
}