Changeset 2856 for trunk/kLdr/kLdr.h
- Timestamp:
- Nov 4, 2006, 11:19:33 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdr.h
r2855 r2856 136 136 */ 137 137 int (* pfnDestroy)( PKLDRRDR pRdr); 138 /** Read bits from the file. 139 * 140 * @returns 0 on success, OS specific error code on failure. 141 * @param pRdr The file provider instance. 142 * @param pvBuf Where to put the bits. 143 * @param cb The number of bytes to read. 144 * @param off Where to start reading. 145 */ 138 /** @copydoc kLdrRdrRead */ 146 139 int (* pfnRead)( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off); 147 /** Map all the file bits into memory (read only). 148 * 149 * @returns 0 on success, OS specific error code on failure. 150 * @param pRdr The file provider instance. 151 * @param ppvBits Where to store the address of the mapping. 152 * The size can be obtained using pfnSize. 153 */ 140 /** @copydoc kLdrRdrAllMap */ 154 141 int (* pfnAllMap)( PKLDRRDR pRdr, const void **ppvBits); 155 /** Unmap a file bits mapping obtained by KLDRRDROPS::pfnAllMap. 156 * 157 * @returns 0 on success, OS specific error code on failure. 158 * @param pRdr The file provider instance. 159 * @param pvBits The mapping address. 160 */ 142 /** @copydoc kLdrRdrAllUnmap */ 161 143 int (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits); 162 /** Get the file size. 163 * 164 * @returns The file size. Returns -1 on failure. 165 * @param pRdr The file provider instance. 166 */ 144 /** @copydoc kLdrRdrSize */ 167 145 off_t (* pfnSize)( PKLDRRDR pRdr); 168 /** Get the file pointer offset. 169 * 170 * @returns The file pointer offset. Returns -1 on failure. 171 * @param pRdr The file provider instance. 172 */ 146 /** @copydoc kLdrRdrTell */ 173 147 off_t (* pfnTell)( PKLDRRDR pRdr); 174 /** Get the file name. 175 * 176 * @returns The file size. Returns -1 on failure. 177 * @param pRdr The file provider instance. 178 */ 148 /** @copydoc kLdrRdrName */ 179 149 const char * (* pfnName)(PKLDRRDR pRdr); 180 /** 181 * Prepares a memory region to map file sections into. 182 * 183 * @returns 0 on success, OS specific error code on failure. 184 * @param pRdr The file provider instance. 185 * @param ppv If fFixed is set, *ppv contains the memory location which 186 * the region should be based at. If fFixed is clear the OS 187 * is free to choose the location. 188 * On successful return *ppv contains address of the prepared 189 * memory region. 190 * @param cb The size of the memory region to prepare. 191 * @param fFixed When set *ppv will contain the desired region address. 192 * 193 */ 150 /** @copydoc kLdrRdrPageSize */ 151 size_t (* pfnPageSize)(PKLDRRDR pRdr); 152 /** @copydoc kLdrRdrPrepare */ 194 153 int (* pfnPrepare)(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed); 195 /** 196 * Maps a section of the file into the memory region reserved by pfnPrepare. 197 * 198 * @returns 0 on success, OS specific error code on failure. 199 * @param pRdr The file provider instance. 200 * @param pv The address in the prepared region. 201 * @param cb The size of the memory mapping. 202 * @param enmProt The desired memory protection. 203 * @param offFile The start of the raw file bytes. 204 * @param cbFile The number of raw file bytes. This must be less or equal to cb. 205 */ 154 /** @copydoc kLdrRdrMap */ 206 155 int (* pfnMap)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile); 207 /** 208 * Changes the page protection of a section mapped using pfnMap. 209 * 210 * This is typically used for applying fixups and similar. 211 * 212 * @returns 0 on success, OS specific error code on failure. 213 * @param pRdr The file provider instance. 214 * @param pv The address passed to pfnMap. 215 * @param cb The size passed to pfnMap. 216 * @param enmProt The desired memory protection. 217 */ 156 /** @copydoc kLdrRdrRefreshMap */ 157 int (* pfnRefreshMap)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile); 158 /** @copydoc kLdrRdrProtect */ 218 159 int (* pfnProtect)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt); 219 /** 220 * Unmaps a section of the file previously mapped using pfnMap. 221 * 222 * @returns 0 on success, OS specific error code on failure. 223 * @param pRdr The file provider instance. 224 * @param pv The address passed to pfnMap. 225 * @param cb The size passed to pfnMap. 226 */ 160 /** @copydoc kLdrRdrUnmap */ 227 161 int (* pfnUnmap)(PKLDRRDR pRdr, void *pv, size_t cb); 228 /** 229 * Releases the memory region prepared by pfnPrepare(). 230 * 231 * Before calling this function, all sections mapped by pfnMap must first be unmapped by calling pfnUnmap. 232 * 233 * @returns 0 on success, OS specific error code on failure. 234 * @param pRdr The file provider instance. 235 * @param pv The address of the prepared region. 236 * @param cb The size of the prepared region. 237 */ 162 /** @copydoc kLdrRdrUnprepare */ 238 163 int (* pfnUnprepare)(PKLDRRDR pRdr, void *pv, size_t cb); 239 /** 240 * We're done reading from the file but would like to keep file mappings. 241 * 242 * If the OS support closing the file handle while the file is mapped, 243 * the reader should do so. 244 * 245 * @param pRdr The file provider instance. 246 */ 164 /** @copydoc kLdrRdrDone */ 247 165 void (* pfnDone)(PKLDRRDR pRdr); 248 166 /** The usual non-zero dummy that makes sure we've initialized all members. */ … … 260 178 typedef struct KLDRRDR 261 179 { 180 /** Magic number (KLDRRDR_MAGIC). */ 181 uint32_t u32Magic; 262 182 /** Pointer to the file provider operations. */ 263 183 PCKLDRRDROPS pOps; 264 184 } KLDRRDR; 185 186 /** The magic for KLDRRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */ 187 #define KLDRRDR_MAGIC 0x19610919 265 188 266 189 void kLdrRdrAddProvider(PKLDRRDROPS pAdd); … … 274 197 off_t kLdrRdrTell( PKLDRRDR pRdr); 275 198 const char *kLdrRdrName(PKLDRRDR pRdr); 199 size_t kLdrRdrPageSize(PKLDRRDR pRdr); 200 int kLdrRdrPrepare( PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed); 201 int kLdrRdrMap( PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile); 202 int kLdrRdrRefreshMap(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile); 203 int kLdrRdrProtect( PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt); 204 int kLdrRdrUnmap( PKLDRRDR pRdr, void *pv, size_t cb); 205 int kLdrRdrUnprepare(PKLDRRDR pRdr, void *pv, size_t cb); 206 void kLdrRdrDone( PKLDRRDR pRdr); 276 207 277 208 /** @} */ … … 399 330 /** The usual invalid enum value. */ 400 331 KLDRDBGINFOTYPE_INVALID = 0, 332 /** Unknown debug info format. */ 333 KLDRDBGINFOTYPE_UNKNOWN, 401 334 /** Stabs. */ 402 335 KLDRDBGINFOTYPE_STABS, … … 456 389 /** The size of the segment. */ 457 390 KLDRSIZE cb; 458 /** The required segment alignment. */ 391 /** The required segment alignment. 392 * The to 0 if the segment isn't supposed to be mapped. */ 459 393 KLDRADDR Alignment; 460 394 /** The link address. 461 * Set to NIL_KLDRADDR if the segment isn't supposed to be mapped. */ 395 * Set to NIL_KLDRADDR if the segment isn't supposed to be 396 * mapped or if the image doesn't have link addresses. */ 462 397 KLDRADDR LinkAddress; 463 /** The address the segment was mapped at by kLdrModMap().464 * Set to NIL_KLDRADDR if not mapped. */465 KLDRADDR MapAddress;466 398 /** The segment protection. */ 467 399 KLDRPROT enmProt; 400 /** The address the segment was mapped at by kLdrModMap(). 401 * Set to 0 if not mapped. */ 402 uintptr_t MapAddress; 403 /** File offset of the segment. 404 * Set to -1 if no file backing (like BSS). */ 405 off_t offFile; 406 /** Size of the file bits of the segment. 407 * Set to -1 if no file backing (like BSS). */ 408 off_t cbFile; 468 409 } KLDRSEG; 469 410 /** Pointer to a loader segment. */ … … 563 504 typedef struct KLDRMOD 564 505 { 565 /** Magic number . */506 /** Magic number (KLDRMOD_MAGIC). */ 566 507 uint32_t u32Magic; 567 508 /** The format of this module. */ … … 696 637 * 697 638 * @param pMod The module. 639 * @param iDbgInfo The debug info ordinal number / id. 698 640 * @param enmType The debug info type. 699 * @param iDbgInfo The debug info ordinal number / id. 641 * @param iMajorVer The major version number of the debug info format. -1 if unknow - implies invalid iMinorVer. 642 * @param iMinorVer The minor version number of the debug info format. -1 when iMajorVer is -1. 700 643 * @param offFile The file offset *if* this type has one specific location in the executable image file. 701 644 * This is -1 if there isn't any specific file location. 702 * @param cbFile The file size.703 * This is 0 if there isn't any specific file location.645 * @param LinkAddress The link address of the debug info if it's loadable. NIL_KLDRADDR if not loadable. 646 * @param cb The size of the debug information. -1 is used if this isn't applicable. 704 647 * @param pszExtFile This points to the name of an external file containing the debug info. 705 648 * This is NULL if there isn't any external file. 706 649 * @param pvUser The user parameter specified to kLdrModEnumDbgInfo. 707 650 */ 708 typedef int FNKLDRENUMDBG(PKLDRMOD pMod, KLDRDBGINFOTYPE enmType, uint32_t iDbgInfo, off_t offFile, off_t cbFile, 709 const char *pszExtFile, void *pvUser); 651 typedef int FNKLDRENUMDBG(PKLDRMOD pMod, uint32_t iDbgInfo, KLDRDBGINFOTYPE enmType, int16_t iMajorVer, int16_t iMinorVer, 652 off_t offFile, KLDRADDR LinkAddress, off_t cb, const char *pszExtFile, void *pvUser); 653 /** Pointer to a debug info enumberator callback. */ 654 typedef FNKLDRENUMDBG *PFNKLDRENUMDBG; 710 655 711 656 int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod); … … 724 669 int kLdrModGetStackInfo(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo); 725 670 int kLdrModQueryMainEntrypoint(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress); 726 /** Pointer to a debug info enumberator callback. */727 typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;728 671 int kLdrModEnumDbgInfo(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser); 729 672 int kLdrModHasDbgInfo(PKLDRMOD pMod, const void *pvBits); … … 737 680 int kLdrModReload(PKLDRMOD pMod); 738 681 int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 739 int kLdrModCallInit(PKLDRMOD pMod );740 int kLdrModCallTerm(PKLDRMOD pMod );741 int kLdrModCallThread(PKLDRMOD pMod, u nsigned fAttachingOrDetaching);682 int kLdrModCallInit(PKLDRMOD pMod, uintptr_t uHandle); 683 int kLdrModCallTerm(PKLDRMOD pMod, uintptr_t uHandle); 684 int kLdrModCallThread(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching); 742 685 /** @} */ 743 686 744 687 /** @name Operations On The Externally Managed Mappings 745 688 * @{ */ 746 size_tkLdrModSize(PKLDRMOD pMod);689 KLDRADDR kLdrModSize(PKLDRMOD pMod); 747 690 int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 748 691 int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress, … … 818 761 int (* pfnFixupMapping)(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 819 762 /** @copydoc kLdrModCallInit */ 820 int (* pfnCallInit)(PKLDRMOD pMod );763 int (* pfnCallInit)(PKLDRMOD pMod, uintptr_t uHandle); 821 764 /** @copydoc kLdrModCallTerm */ 822 int (* pfnCallTerm)(PKLDRMOD pMod );765 int (* pfnCallTerm)(PKLDRMOD pMod, uintptr_t uHandle); 823 766 /** @copydoc kLdrModCallThread */ 824 int (* pfnCallThread)(PKLDRMOD pMod, u nsigned fAttachingOrDetaching);767 int (* pfnCallThread)(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching); 825 768 /** @copydoc kLdrModSize */ 826 size_t(* pfnSize)(PKLDRMOD pMod);769 KLDRADDR (* pfnSize)(PKLDRMOD pMod); 827 770 /** @copydoc kLdrModGetBits */ 828 771 int (* pfnGetBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); … … 1052 995 /** A forwarder chain was too long. */ 1053 996 #define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN (KLDR_ERR_BASE + 51) 997 /** The module has no debug info. */ 998 #define KLDR_ERR_NO_DEBUG_INFO (KLDR_ERR_BASE + 52) 999 /** The module is already mapped. 1000 * kLdrModMap() can only be called once (without kLdrModUnmap() in between). */ 1001 #define KLDR_ERR_ALREADY_MAPPED (KLDR_ERR_BASE + 53) 1002 /** The module was not mapped. 1003 * kLdrModUnmap() should not called without being preceeded by a kLdrModMap(). */ 1004 #define KLDR_ERR_NOT_MAPPED (KLDR_ERR_BASE + 54) 1054 1005 1055 1006 /** @name kLdrModPE status codes
Note:
See TracChangeset
for help on using the changeset viewer.