X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Finclude%2Fbinary.h;h=c94a1b09a96b0ab5a6ade168c0af3c62468467a5;hb=05c5d7098a054591d75113ecc3503979cc5754c9;hp=ed163bd00e6087c8f019b3f2495f82179ed9ce20;hpb=1e7db40300bc594cf708bb6082a6e05a268da946;p=tpg%2Facess2.git diff --git a/Kernel/include/binary.h b/Kernel/include/binary.h index ed163bd0..c94a1b09 100644 --- a/Kernel/include/binary.h +++ b/Kernel/include/binary.h @@ -7,6 +7,35 @@ #define _BINARY_H // === TYPES === +/** + * \brief Representation of a section in a binary file + * + * Tells the binary loader where the page data resides on disk and where + * to load it to (relative to the binary base). Once the data is read, + * the \a Physical field contains the physical address of the page. + */ +typedef struct sBinarySection +{ + Uint64 Offset; //!< File offset of the section + tVAddr Virtual; //!< Virtual load address + size_t FileSize; //!< Number of bytes to load from the file + size_t MemSize; //!< Number of bytes in memory + Uint Flags; //!< Load Flags +} tBinarySection; + +/** + * \brief Flags for ::tBinarySection.Flags + * \name Binary Section Flags + * \{ + */ +//! \brief Read-only +#define BIN_SECTFLAG_RO 0x0001 +//! \brief Executable +#define BIN_SECTFLAG_EXEC 0x0002 +/** + * \} + */ + /** * \brief Defines a binary file * @@ -26,49 +55,36 @@ typedef struct sBinary { struct sBinary *Next; //!< Pointer used by the kernel - /** - * \brief True path of the file - * \note Used to uniquely identify the loaded binary to reduce in-memory - * duplication. - */ - char *TruePath; + + tMount MountID; //!< Mount ID + tInode Inode; //!< Inode (Used for fast reopen) + /** * \brief Interpreter used to load the file * \note This can be either requested by the individual file, or a per-driver option */ - char *Interpreter; + const char *Interpreter; /** * \brief Entrypoint of the binary (at requested base); */ - Uint Entry; + tVAddr Entry; /** * \brief File's requested load base */ - Uint Base; + tVAddr Base; /** * \brief Number of times this binary has been mapped */ int ReferenceCount; /** - * \brief Number of pages defined in the file + * \brief Number of sections defined in the file */ - int NumPages; + int NumSections; /** - * \brief Array of pages defined by this binary - * \note Contains \a NumPages entries + * \brief Array of sections defined by this binary + * \note Contains \a NumSections entries */ - struct { - /** - * \brief Physical address, or file offset - * - * Physical address of this page or, when the file is not yet - * loaded, this is a file offset (or -1 for uninitialised data) - */ - tPAddr Physical; - tVAddr Virtual; //!< Virtual load address - Uint16 Size; //!< Number of bytes to load from the file - Uint16 Flags; //!< Load Flags - } Pages[]; + tBinarySection LoadSections[]; } tBinary; /** @@ -95,7 +111,7 @@ typedef struct sBinaryType */ Uint32 Ident; Uint32 Mask; //!< Mask value for tBinaryType.Ident - char *Name; //!< Name of this executable type (for debug purpouses) + const char *Name; //!< Name of this executable type (for debug purpouses) /** * \brief Read a binary from a file * \param FD VFS File handle to file to load @@ -128,7 +144,7 @@ typedef struct sBinaryType * tBinaryType.Relocate at this time, so the driver should * accomodate this. */ - int (*GetSymbol)(void *Base, char *Name, Uint *Dest); + int (*GetSymbol)(void *Base, const char *Name, Uint *Dest); } tBinaryType; /** @@ -141,4 +157,17 @@ typedef struct sBinaryType */ extern char *Binary_RegInterp(char *Path); +/** + * \brief Registers a binary type with the kernel's loader + * \param Type Pointer to the loader's type structure + * \return Boolean success + * \note The structure \a Type must be persistant (usually it will be a + * constant global variable) + * + * This function tells the binary loader about a new file type, and gives + * it the functions to read the type into a ::tBinary structure, relocate + * it and to find the value of symbols defined within the binary. + */ +extern int Binary_RegisterType(tBinaryType *Type); + #endif