2013-07-10 09:26:01 -04:00
|
|
|
/*******************************************************************************
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of Sortix.
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix 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.
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix 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.
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
elf.h
|
|
|
|
Constructs processes from ELF files.
|
2011-08-22 15:54:18 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
*******************************************************************************/
|
2011-08-22 15:54:18 -04:00
|
|
|
|
|
|
|
#ifndef SORTIX_ELF_H
|
|
|
|
#define SORTIX_ELF_H
|
|
|
|
|
|
|
|
namespace Sortix
|
|
|
|
{
|
2011-08-27 10:46:00 -04:00
|
|
|
class Process;
|
|
|
|
|
2011-08-22 15:54:18 -04:00
|
|
|
namespace ELF
|
|
|
|
{
|
|
|
|
struct Header
|
|
|
|
{
|
|
|
|
unsigned char magic[4];
|
|
|
|
unsigned char fileclass;
|
|
|
|
unsigned char dataencoding;
|
|
|
|
unsigned char version;
|
2011-12-01 04:45:44 -05:00
|
|
|
unsigned char osabi;
|
|
|
|
unsigned char abiversion;
|
|
|
|
unsigned char padding[7];
|
2011-08-22 15:54:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const unsigned char CLASSNONE = 0;
|
|
|
|
const unsigned char CLASS32 = 1;
|
|
|
|
const unsigned char CLASS64 = 2;
|
|
|
|
const unsigned char DATA2LSB = 1;
|
|
|
|
const unsigned char DATA2MSB = 2;
|
|
|
|
const unsigned char CURRENTVERSION = 1;
|
|
|
|
|
|
|
|
struct Header32 : public Header
|
|
|
|
{
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t machine;
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t entry;
|
|
|
|
uint32_t programheaderoffset;
|
|
|
|
uint32_t sectionheaderoffset;
|
|
|
|
uint32_t flags;
|
|
|
|
uint16_t elfheadersize;
|
|
|
|
uint16_t programheaderentrysize;
|
|
|
|
uint16_t numprogramheaderentries;
|
|
|
|
uint16_t sectionheaderentrysize;
|
|
|
|
uint16_t numsectionheaderentries;
|
|
|
|
uint16_t sectionheaderstringindex;
|
|
|
|
};
|
|
|
|
|
2011-12-01 04:45:44 -05:00
|
|
|
struct Header64 : public Header
|
|
|
|
{
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t machine;
|
|
|
|
uint32_t version;
|
|
|
|
uint64_t entry;
|
|
|
|
uint64_t programheaderoffset;
|
|
|
|
uint64_t sectionheaderoffset;
|
|
|
|
uint32_t flags;
|
|
|
|
uint16_t elfheadersize;
|
|
|
|
uint16_t programheaderentrysize;
|
|
|
|
uint16_t numprogramheaderentries;
|
|
|
|
uint16_t sectionheaderentrysize;
|
|
|
|
uint16_t numsectionheaderentries;
|
|
|
|
uint16_t sectionheaderstringindex;
|
|
|
|
};
|
|
|
|
|
2011-08-22 15:54:18 -04:00
|
|
|
struct SectionHeader32
|
|
|
|
{
|
|
|
|
uint32_t name;
|
|
|
|
uint32_t type;
|
|
|
|
uint32_t flags;
|
|
|
|
uint32_t addr;
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t link;
|
|
|
|
uint32_t info;
|
|
|
|
uint32_t addralign;
|
|
|
|
uint32_t entsize;
|
|
|
|
};
|
|
|
|
|
2011-12-01 04:45:44 -05:00
|
|
|
struct SectionHeader64
|
|
|
|
{
|
|
|
|
uint32_t name;
|
|
|
|
uint32_t type;
|
|
|
|
uint64_t flags;
|
|
|
|
uint64_t addr;
|
|
|
|
uint64_t offset;
|
|
|
|
uint64_t size;
|
|
|
|
uint32_t link;
|
|
|
|
uint32_t info;
|
|
|
|
uint64_t addralign;
|
|
|
|
uint64_t entsize;
|
|
|
|
};
|
|
|
|
|
2011-08-22 15:54:18 -04:00
|
|
|
const uint32_t SHT_NULL = 0;
|
|
|
|
const uint32_t SHT_PROGBITS = 1;
|
|
|
|
const uint32_t SHT_SYMTAB = 2;
|
|
|
|
const uint32_t SHT_STRTAB = 3;
|
|
|
|
const uint32_t SHT_RELA = 4;
|
|
|
|
const uint32_t SHT_HASH = 5;
|
|
|
|
const uint32_t SHT_DYNAMIC = 6;
|
|
|
|
const uint32_t SHT_NOTE = 7;
|
|
|
|
const uint32_t SHT_NOBITS = 8;
|
|
|
|
const uint32_t SHT_REL = 9;
|
|
|
|
const uint32_t SHT_SHLIB = 10;
|
|
|
|
const uint32_t SHT_DYNSYM = 11;
|
|
|
|
const uint32_t SHT_LOPROC = 0x70000000;
|
|
|
|
const uint32_t SHT_HIPROC = 0x7fffffff;
|
|
|
|
const uint32_t SHT_LOUSER = 0x80000000;
|
|
|
|
const uint32_t SHT_HIUSER = 0xffffffff;
|
|
|
|
|
2011-08-23 11:46:13 -04:00
|
|
|
struct ProgramHeader32
|
|
|
|
{
|
|
|
|
uint32_t type;
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t virtualaddr;
|
|
|
|
uint32_t physicaladdr;
|
|
|
|
uint32_t filesize;
|
|
|
|
uint32_t memorysize;
|
|
|
|
uint32_t flags;
|
|
|
|
uint32_t align;
|
|
|
|
};
|
|
|
|
|
2011-12-01 04:45:44 -05:00
|
|
|
struct ProgramHeader64
|
|
|
|
{
|
|
|
|
uint32_t type;
|
|
|
|
uint32_t flags;
|
|
|
|
uint64_t offset;
|
|
|
|
uint64_t virtualaddr;
|
|
|
|
uint64_t physicaladdr;
|
|
|
|
uint64_t filesize;
|
|
|
|
uint64_t memorysize;
|
|
|
|
uint64_t align;
|
|
|
|
};
|
|
|
|
|
2011-08-23 11:46:13 -04:00
|
|
|
const uint32_t PT_NULL = 0;
|
|
|
|
const uint32_t PT_LOAD = 1;
|
|
|
|
const uint32_t PT_DYNAMIC = 2;
|
|
|
|
const uint32_t PT_INTERP = 3;
|
|
|
|
const uint32_t PT_NOTE = 4;
|
|
|
|
const uint32_t PT_SHLIB = 5;
|
|
|
|
const uint32_t PT_PHDR = 6;
|
|
|
|
const uint32_t PT_LOPROC = 0x70000000;
|
|
|
|
const uint32_t PT_HIPROC = 0x7FFFFFFF;
|
|
|
|
|
2011-12-16 09:33:12 -05:00
|
|
|
const uint32_t PF_X = (1<<0);
|
|
|
|
const uint32_t PF_W = (1<<1);
|
|
|
|
const uint32_t PF_R = (1<<2);
|
|
|
|
|
2011-08-22 15:54:18 -04:00
|
|
|
// Reads the elf file into the current address space and returns the
|
|
|
|
// entry address of the program, or 0 upon failure.
|
2011-08-27 10:46:00 -04:00
|
|
|
addr_t Construct(Process* process, const void* file, size_t filelen);
|
2011-08-22 15:54:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|