Changeset 2861 for trunk/kLdr/kLdrRdr.c


Ignore:
Timestamp:
Nov 10, 2006, 4:04:42 AM (19 years ago)
Author:
bird
Message:

Put the PE module interpreter thru the wringer and learnt how much the window file mapping API sucks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrRdr.c

    r2856 r2861  
    223223
    224224/**
    225  * Prepares a memory region to map file sections into.
    226  *
    227  * @returns 0 on success, OS specific error code on failure.
    228  * @param   pRdr        The file provider instance.
    229  * @param   ppv         If fFixed is set, *ppv contains the memory location which
    230  *                      the region should be based at. If fFixed is clear the OS
    231  *                      is free to choose the location.
    232  *                      On successful return *ppv contains address of the prepared
    233  *                      memory region.
    234  * @param   cb          The size of the memory region to prepare.
    235  * @param   fFixed      When set *ppv will contain the desired region address.
    236  *
    237  */
    238 int kLdrRdrPrepare(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed)
    239 {
    240     KLDRRDR_VALIDATE(pRdr);
    241     return pRdr->pOps->pfnPrepare(pRdr, ppv, cb, fFixed);
    242 }
    243 
    244 
    245 /**
    246  * Maps a section of the file into the memory region reserved by pfnPrepare.
    247  *
    248  * @returns 0 on success, OS specific error code on failure.
    249  * @param   pRdr        The file provider instance.
    250  * @param   pv          The address in the prepared region.
    251  * @param   cb          The size of the memory mapping.
    252  * @param   enmProt     The desired memory protection.
    253  * @param   offFile     The start of the raw file bytes.
    254  * @param   cbFile      The number of raw file bytes. This must be less or equal to cb.
    255  */
    256 int kLdrRdrMap(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile)
    257 {
    258     KLDRRDR_VALIDATE(pRdr);
    259     return pRdr->pOps->pfnMap(pRdr, pv, cb, enmProt, offFile, cbFile);
    260 }
    261 
    262 
    263 /**
    264  * Reloads dirty pages in mapped section.
    265  *
    266  * @returns 0 on success, OS specific error code on failure.
    267  * @param   pRdr        The file provider instance.
    268  * @param   pv          The address in the prepared region.
    269  * @param   cb          The size of the memory mapping.
    270  * @param   enmProt     The desired memory protection.
    271  * @param   offFile     The start of the raw file bytes.
    272  * @param   cbFile      The number of raw file bytes. This must be less or equal to cb.
    273  */
    274 int kLdrRdrRefreshMap(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile)
    275 {
    276     KLDRRDR_VALIDATE(pRdr);
    277     return pRdr->pOps->pfnRefreshMap(pRdr, pv, cb, enmProt, offFile, cbFile);
    278 }
    279 
    280 
    281 /**
    282  * Changes the page protection of a section mapped using pfnMap.
    283  *
    284  * This is typically used for applying fixups and similar.
    285  *
    286  * @returns 0 on success, OS specific error code on failure.
    287  * @param   pRdr        The file provider instance.
    288  * @param   pv          The address passed to pfnMap.
    289  * @param   cb          The size passed to pfnMap.
    290  * @param   enmProt     The desired memory protection.
    291  */
    292 int kLdrRdrProtect(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt)
    293 {
    294     KLDRRDR_VALIDATE(pRdr);
    295     return pRdr->pOps->pfnProtect(pRdr, pv, cb, enmProt);
    296 }
    297 
    298 
    299 /**
    300  * Unmaps a section of the file previously mapped using pfnMap.
    301  *
    302  * @returns 0 on success, OS specific error code on failure.
    303  * @param   pRdr        The file provider instance.
    304  * @param   pv          The address passed to pfnMap.
    305  * @param   cb          The size passed to pfnMap.
    306  */
    307 int kLdrRdrUnmap(PKLDRRDR pRdr, void *pv, size_t cb)
    308 {
    309     KLDRRDR_VALIDATE(pRdr);
    310     return pRdr->pOps->pfnUnmap(pRdr, pv, cb);
    311 }
    312 
    313 
    314 /**
    315  * Releases the memory region prepared by pfnPrepare().
    316  *
    317  * Before calling this function, all sections mapped by pfnMap must first be unmapped by calling pfnUnmap.
    318  *
    319  * @returns 0 on success, OS specific error code on failure.
    320  * @param   pRdr        The file provider instance.
    321  * @param   pv          The address of the prepared region.
    322  * @param   cb          The size of the prepared region.
    323  */
    324 int kLdrRdrUnprepare(PKLDRRDR pRdr, void *pv, size_t cb)
    325 {
    326     KLDRRDR_VALIDATE(pRdr);
    327     return pRdr->pOps->pfnUnprepare(pRdr, pv, cb);
     225 * Maps the segments of a image into memory.
     226 *
     227 * The file reader will be using the RVA member of each segment to figure out where
     228 * it goes relative to the image base address.
     229 *
     230 * @returns 0 on success, OS specific error code on failure.
     231 * @param   pRdr        The file provider instance.
     232 * @param   ppvBase     On input when fFixed is set, this contains the base address of the mapping.
     233 *                      On output this contains the base of the image mapping.
     234 * @param   cSegments   The number of segments in the array pointed to by paSegments.
     235 * @param   paSegments  The segments thats going to be mapped.
     236 * @param   fFixed      If set, the address at *ppvBase should be the base address of the mapping.
     237 */
     238int kLdrRdrMap(PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed)
     239{
     240    KLDRRDR_VALIDATE(pRdr);
     241    return pRdr->pOps->pfnMap(pRdr, ppvBase, cSegments, paSegments, fFixed);
     242}
     243
     244
     245/**
     246 * Reloads dirty pages in mapped image.
     247 *
     248 * @returns 0 on success, OS specific error code on failure.
     249 * @param   pRdr        The file provider instance.
     250 * @param   pvBase      The base address of the image mapping.
     251 * @param   cSegments   The number of segments in the array pointed to by paSegments.
     252 * @param   paSegments  The segments thats going to be mapped.
     253 */
     254int kLdrRdrRefresh(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments)
     255{
     256    KLDRRDR_VALIDATE(pRdr);
     257    return pRdr->pOps->pfnRefresh(pRdr, pvBase, cSegments, paSegments);
     258}
     259
     260
     261/**
     262 * Protects or unprotects an image mapping.
     263 *
     264 * This is typically used for getting write access to read or execute only
     265 * pages while applying fixups.
     266 *
     267 * @returns 0 on success, OS specific error code on failure.
     268 * @param   pRdr        The file provider instance.
     269 * @param   pvBase      The base address of the image mapping.
     270 * @param   cSegments   The number of segments in the array pointed to by paSegments.
     271 * @param   paSegments  The segments thats going to be mapped.
     272 * @param   fUnprotectOrProtect     When set the all mapped segments are made writable.
     273 *                                  When clean the segment protection is restored.
     274 */
     275int kLdrRdrProtect(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)
     276{
     277    KLDRRDR_VALIDATE(pRdr);
     278    return pRdr->pOps->pfnProtect(pRdr, pvBase, cSegments, paSegments, fUnprotectOrProtect);
     279}
     280
     281
     282/**
     283 * Unmaps a image mapping.
     284 *
     285 * @returns 0 on success, OS specific error code on failure.
     286 * @param   pRdr        The file provider instance.
     287 * @param   pvBase      The base address of the image mapping.
     288 * @param   cSegments   The number of segments in the array pointed to by paSegments.
     289 * @param   paSegments  The segments thats going to be mapped.
     290 */
     291int kLdrRdrUnmap(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments)
     292{
     293    KLDRRDR_VALIDATE(pRdr);
     294    return pRdr->pOps->pfnUnmap(pRdr, pvBase, cSegments, paSegments);
    328295}
    329296
Note: See TracChangeset for help on using the changeset viewer.