FreeNOS
ExecutableFormat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIBEXEC_EXECUTABLEFORMAT_H
19 #define __LIBEXEC_EXECUTABLEFORMAT_H
20 #ifndef __ASSEMBLER__
21 
22 #include <Memory.h>
23 #include <Types.h>
24 
35 
37 class ExecutableFormat;
38 
43 typedef ExecutableFormat * FormatDetector(u8 *image, Size size);
44 
49 {
50  public:
51 
55  typedef struct Region
56  {
62  }
63  Region;
64 
68  enum Result
69  {
74  };
75 
76  public:
77 
84  ExecutableFormat(const u8 *image, const Size size);
85 
89  virtual ~ExecutableFormat();
90 
100  virtual Result regions(Region *regions, Size *count) const = 0;
101 
108  virtual Result entry(Address *entry) const = 0;
109 
121  static Result find(const u8 *image, const Size size, ExecutableFormat **fmt);
122 
123  protected:
124 
126  const u8 *m_image;
127 
129  const Size m_size;
130 };
131 
137 #endif /* __ASSEMBLER__ */
138 #endif /* __LIBEXEC_EXECUTABLEFORMAT_H */
ExecutableFormat::Region
struct ExecutableFormat::Region Region
Memory region.
FormatDetector
ExecutableFormat * FormatDetector(u8 *image, Size size)
Confirms if we understand the given format.
Definition: ExecutableFormat.h:43
ExecutableFormat::NotFound
@ NotFound
Definition: ExecutableFormat.h:71
Types.h
ExecutableFormat::Region::access
Memory::Access access
Definition: ExecutableFormat.h:61
ExecutableFormat::Region
Memory region.
Definition: ExecutableFormat.h:55
ExecutableFormat::ExecutableFormat
ExecutableFormat(const u8 *image, const Size size)
Class constructor.
Definition: ExecutableFormat.cpp:22
Address
unsigned long Address
A memory address.
Definition: Types.h:131
ExecutableFormat::regions
virtual Result regions(Region *regions, Size *count) const =0
Memory regions a program needs at runtime.
ExecutableFormat::find
static Result find(const u8 *image, const Size size, ExecutableFormat **fmt)
Find a ExecutableFormat which can handle the given format.
Definition: ExecutableFormat.cpp:32
ExecutableFormat::m_size
const Size m_size
Input image size in bytes.
Definition: ExecutableFormat.h:129
ExecutableFormat::Region::dataOffset
Address dataOffset
Definition: ExecutableFormat.h:58
ExecutableFormat::Region::virt
Address virt
Definition: ExecutableFormat.h:57
ExecutableFormat::m_image
const u8 * m_image
Input image raw data.
Definition: ExecutableFormat.h:126
ExecutableFormat::Result
Result
Result code.
Definition: ExecutableFormat.h:68
ExecutableFormat::OutOfMemory
@ OutOfMemory
Definition: ExecutableFormat.h:73
ExecutableFormat::Region::memorySize
Size memorySize
Definition: ExecutableFormat.h:60
EntryPoint
Address EntryPoint
Entry point of a program.
Definition: ExecutableFormat.h:34
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Memory::Access
Access
Memory access flags.
Definition: Memory.h:38
Memory.h
ExecutableFormat::entry
virtual Result entry(Address *entry) const =0
Lookup the program entry point.
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
ExecutableFormat::Region::dataSize
Size dataSize
Definition: ExecutableFormat.h:59
ExecutableFormat::~ExecutableFormat
virtual ~ExecutableFormat()
Class destructor.
Definition: ExecutableFormat.cpp:28
ExecutableFormat::InvalidFormat
@ InvalidFormat
Definition: ExecutableFormat.h:72
ExecutableFormat
Abstraction class of various executable formats.
Definition: ExecutableFormat.h:48
ExecutableFormat::Success
@ Success
Definition: ExecutableFormat.h:70