3 * \brief Binary Loader Definitions
4 * \author John Hodge (thePowersGang)
11 * \brief Representation of a section in a binary file
13 * Tells the binary loader where the page data resides on disk and where
14 * to load it to (relative to the binary base). Once the data is read,
15 * the \a Physical field contains the physical address of the page.
17 typedef struct sBinarySection
20 tVAddr Virtual; //!< Virtual load address
21 size_t FileSize; //!< Number of bytes to load from the file
22 size_t MemSize; //!< Number of bytes in memory
23 Uint Flags; //!< Load Flags
27 * \brief Flags for ::tBinarySection.Flags
28 * \name Binary Section Flags
32 #define BIN_SECTFLAG_RO 0x0001
34 #define BIN_SECTFLAG_EXEC 0x0002
40 * \brief Defines a binary file
42 * This structure defines and maintains the state of a binary during and
44 * Before the binary is loaded into memory (when it has just been returned
45 * from tBinaryType.Load) the \a Pages array will contain the file offsets
46 * to the page data in the \a Physical fields (or -1 for uninitialised
47 * data) and the \a Size fields define how much data is stored in-file
48 * for the page (to allow partial pages to be loaded from disk)
49 * Once the binary is loaded (NOTE: Drivers do not need to know about this,
50 * it is here for information only) the \a Physical fields now contain the
51 * physical addresses of the pages filled with the data. The \a Virtual
52 * fields contain the preferred virtual address of the pages (a given
53 * process may have these pages mapped to a different location).
55 typedef struct sBinary
57 struct sBinary *Next; //!< Pointer used by the kernel
63 * \brief Interpreter used to load the file
64 * \note This can be either requested by the individual file, or a per-driver option
66 const char *Interpreter;
68 * \brief Entrypoint of the binary (at requested base);
72 * \brief File's requested load base
76 * \brief Number of times this binary has been mapped
80 * \brief Number of sections defined in the file
84 * \brief Array of sections defined by this binary
85 * \note Contains \a NumSections entries
87 tBinarySection LoadSections[];
91 * \brief Binary type definition
93 * This structure is used to define a loader for a specific binary type
94 * so that the kernel's core binary loader can understand that type.
95 * The tBinaryType.Relocate and tBinaryType.GetSymbol need only be non-NULL
96 * if the binary type is to be used for kernel modules, otherwise it will
97 * only be able to load binaries for user space.
99 typedef struct sBinaryType
102 * \brief Pointer used by the kernel
103 * \note Should not be touched by the driver (initialise to NULL)
105 struct sBinaryType *Next;
107 * \brief Identifying DWord
109 * If he first 32-bits of the file match this value (when ANDed with
110 * tBinaryType.Mask), this binary loader will be used to load the file.
113 Uint32 Mask; //!< Mask value for tBinaryType.Ident
114 const char *Name; //!< Name of this executable type (for debug purpouses)
116 * \brief Read a binary from a file
117 * \param FD VFS File handle to file to load
118 * \return Pointer to a ::tBinary that describes how to load the file
120 * This function reads a binary file and returns a ::tBinary pointer
121 * that tells the core binary loader how to read the data from the file
122 * and where to map it to.
124 tBinary *(*Load)(int FD);
127 * \brief Prepares a mapped binary for execution at this address
128 * \param Base Binary loaded in memory
129 * \return Boolean Success
130 * \note This pointer can be NULL, but then the binary cannot be used
131 * to load a kernel module.
133 * tBinaryType.Relocate takes a binary that was loaded according to
134 * tBinaryType.Load and prepares it to run at the address it is
135 * loaded to, attempting to satisfy any external unresolved symbols
136 * required, if a symbol cannot be located, the function will return
139 int (*Relocate)(void *Base);
142 * \brief Gets a symbol's address from a loaded binary
143 * \note The binary pointed to by \a Base may not have been through
144 * tBinaryType.Relocate at this time, so the driver should
147 int (*GetSymbol)(void *Base, const char *Name, Uint *Dest);
151 * \brief Registers an interpreter path with the binary loader
152 * \param Path Path to the requested interpreter (need not be a "true" path)
153 * \return Pointer to the cached string
155 * Speeds up checking if the intepreter is loaded in the kernel by allowing
156 * the search to use pointer comparisons instead of string comparisons.
158 extern char *Binary_RegInterp(char *Path);
161 * \brief Registers a binary type with the kernel's loader
162 * \param Type Pointer to the loader's type structure
163 * \return Boolean success
164 * \note The structure \a Type must be persistant (usually it will be a
165 * constant global variable)
167 * This function tells the binary loader about a new file type, and gives
168 * it the functions to read the type into a ::tBinary structure, relocate
169 * it and to find the value of symbols defined within the binary.
171 extern int Binary_RegisterType(tBinaryType *Type);