Changed the x86 architecture to have tPAddr be 64-bits always
[tpg/acess2.git] / Kernel / include / binary.h
1 /**
2  * \file binary.h
3  * \brief Binary Loader Definitions
4  * \author John Hodge (thePowersGang)
5  */
6 #ifndef _BINARY_H
7 #define _BINARY_H
8
9 // === TYPES ===
10 typedef struct sBinaryPage
11 {
12         /**
13          * \brief Physical address, or file offset
14          * 
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)
17          */
18         tPAddr  Physical;
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;
23
24 /**
25  * \brief Defines a binary file
26  * 
27  * This structure defines and maintains the state of a binary during and
28  * after loading.
29  * Before the binary is loaded into memory (when it has just been returned
30  * from tBinaryType.Load) the \a Pages array will contain the file offsets
31  * to the page data in the \a Physical fields (or -1 for uninitialised
32  * data) and the \a Size fields define how much data is stored in-file
33  * for the page (to allow partial pages to be loaded from disk)
34  * Once the binary is loaded (NOTE: Drivers do not need to know about this,
35  * it is here for information only) the \a Physical fields now contain the
36  * physical addresses of the pages filled with the data. The \a Virtual
37  * fields contain the preferred virtual address of the pages (a given
38  * process may have these pages mapped to a different location).
39  */
40 typedef struct sBinary
41 {
42         struct sBinary  *Next;  //!< Pointer used by the kernel
43         /**
44          * \brief True path of the file
45          * \note Used to uniquely identify the loaded binary to reduce in-memory
46          *       duplication.
47          */
48         char    *TruePath;
49         /**
50          * \brief Interpreter used to load the file
51          * \note This can be either requested by the individual file, or a per-driver option
52          */
53         char    *Interpreter;
54         /**
55          * \brief Entrypoint of the binary (at requested base);
56          */
57         Uint    Entry;
58         /**
59          * \brief File's requested load base
60          */
61         Uint    Base;
62         /**
63          * \brief Number of times this binary has been mapped
64          */
65          int    ReferenceCount;
66         /**
67          * \brief Number of pages defined in the file
68          */
69          int    NumPages;
70         /**
71          * \brief Array of pages defined by this binary
72          * \note Contains \a NumPages entries
73          */
74         tBinaryPage     Pages[];
75 }       tBinary;
76
77 /**
78  * \brief Binary type definition
79  * 
80  * This structure is used to define a loader for a specific binary type
81  * so that the kernel's core binary loader can understand that type.
82  * The tBinaryType.Relocate and tBinaryType.GetSymbol need only be non-NULL
83  * if the binary type is to be used for kernel modules, otherwise it will
84  * only be able to load binaries for user space.
85  */
86 typedef struct sBinaryType
87 {
88         /**
89          * \brief Pointer used by the kernel
90          * \note Should not be touched by the driver (initialise to NULL)
91          */
92         struct sBinaryType      *Next;
93         /**
94          * \brief Identifying DWord
95          * 
96          * If he first 32-bits of the file match this value (when ANDed with
97          * tBinaryType.Mask), this binary loader will be used to load the file.
98          */
99         Uint32  Ident;
100         Uint32  Mask;   //!< Mask value for tBinaryType.Ident
101         char    *Name;  //!< Name of this executable type (for debug purpouses)
102         /**
103          * \brief Read a binary from a file
104          * \param FD    VFS File handle to file to load
105          * \return Pointer to a ::tBinary that describes how to load the file
106          * 
107          * This function reads a binary file and returns a ::tBinary pointer
108          * that tells the core binary loader how to read the data from the file
109          * and where to map it to.
110          */
111         tBinary *(*Load)(int FD);
112         
113         /**
114          * \brief Prepares a mapped binary for execution at this address
115          * \param Base  Binary loaded in memory
116          * \return Boolean Success
117          * \note This pointer can be NULL, but then the binary cannot be used
118          *       to load a kernel module.
119          * 
120          * tBinaryType.Relocate takes a binary that was loaded according to
121          * tBinaryType.Load and prepares it to run at the address it is
122          * loaded to, attempting to satisfy any external unresolved symbols
123          * required, if a symbol cannot be located, the function will return
124          * zero.
125          */
126          int    (*Relocate)(void *Base);
127          
128          /**
129           * \brief Gets a symbol's address from a loaded binary
130           * \note The binary pointed to by \a Base may not have been through
131           *       tBinaryType.Relocate at this time, so the driver should
132           *       accomodate this.
133           */
134          int    (*GetSymbol)(void *Base, char *Name, Uint *Dest);
135 } tBinaryType;
136
137 /**
138  * \brief Registers an interpreter path with the binary loader
139  * \param Path  Path to the requested interpreter (need not be a "true" path)
140  * \return Pointer to the cached string
141  * 
142  * Speeds up checking if the intepreter is loaded in the kernel by allowing
143  * the search to use pointer comparisons instead of string comparisons.
144  */
145 extern char     *Binary_RegInterp(char *Path);
146
147 #endif

UCC git Repository :: git.ucc.asn.au