3 * \brief Binary Loader Definitions
4 * \author John Hodge (thePowersGang)
10 typedef struct sBinaryPage
13 * \brief Physical address, or file offset
15 * Physical address of this page or, when the file is not yet
16 * loaded, this is a file offset (or -1 for uninitialised data)
19 tVAddr Virtual; //!< Virtual load address
20 Uint16 Size; //!< Number of bytes to load from the file
21 Uint16 Flags; //!< Load Flags
22 } __attribute__ ((packed)) tBinaryPage;
25 * \brief Flags for ::tBinaryPage.Flags
26 * \name Binary Page Flags
30 #define BIN_PAGEFLAG_RO 0x0001
32 #define BIN_PAGEFLAG_EXEC 0x0002
38 * \brief Defines a binary file
40 * This structure defines and maintains the state of a binary during and
42 * Before the binary is loaded into memory (when it has just been returned
43 * from tBinaryType.Load) the \a Pages array will contain the file offsets
44 * to the page data in the \a Physical fields (or -1 for uninitialised
45 * data) and the \a Size fields define how much data is stored in-file
46 * for the page (to allow partial pages to be loaded from disk)
47 * Once the binary is loaded (NOTE: Drivers do not need to know about this,
48 * it is here for information only) the \a Physical fields now contain the
49 * physical addresses of the pages filled with the data. The \a Virtual
50 * fields contain the preferred virtual address of the pages (a given
51 * process may have these pages mapped to a different location).
53 typedef struct sBinary
55 struct sBinary *Next; //!< Pointer used by the kernel
57 * \brief True path of the file
58 * \note Used to uniquely identify the loaded binary to reduce in-memory
63 * \brief Interpreter used to load the file
64 * \note This can be either requested by the individual file, or a per-driver option
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 pages defined in the file
84 * \brief Array of pages defined by this binary
85 * \note Contains \a NumPages entries
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 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, 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);
160 extern int Binary_RegisterType(tBinaryType *Type);