Changeset 2829
- Timestamp:
- Oct 23, 2006, 7:04:04 PM (19 years ago)
- Location:
- trunk/kLdr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdr.h
r2827 r2829 53 53 * @{ */ 54 54 55 typedef enum KLDRPROT 56 { 57 /** The usual invalid 0. */ 58 KLDRPROT_INVALID = 0, 59 /** No access (page not present). */ 60 KLDRPROT_NOACCESS, 61 /** Read only. */ 62 KLDRPROT_READONLY, 63 /** Read & write. */ 64 KLDRPROT_READWRITE, 65 /** Read & copy on write. */ 66 KLDRPROT_WRITECOPY, 67 /** Execute only. */ 68 KLDRPROT_EXECUTE, 69 /** Execute & read. */ 70 KLDRPROT_EXECUTE_READONLY, 71 /** Execute, read & write. */ 72 KLDRPROT_EXECUTE_READWRITE, 73 /** Execute, read & copy on write. */ 74 KLDRPROT_EXECUTE_WRITECOPY, 75 /** The usual end value. (exclusive) */ 76 KLDRPROT_END, 77 /** Blow the type up to 32-bits. */ 78 KLDRPROT_32BIT_HACK = 0x7fffffff 79 } KLDRPROT; 80 81 55 82 /** Pointer to a file provider instance core. */ 56 83 typedef struct KLDRRDR *PKLDRRDR; … … 106 133 */ 107 134 int (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits); 108 /** @todo generic mmap/MapViewOfFile */109 135 /** Get the file size. 110 136 * … … 125 151 */ 126 152 const char * (* pfnName)(PKLDRRDR pRdr); 153 /** 154 * Prepares a memory region to map file sections into. 155 * 156 * @returns 0 on success, OS specific error code on failure. 157 * @param pRdr The file provider instance. 158 * @param ppv If fFixed is set, *ppv contains the memory location which 159 * the region should be based at. If fFixed is clear the OS 160 * is free to choose the location. 161 * On successful return *ppv contains address of the prepared 162 * memory region. 163 * @param cb The size of the memory region to prepare. 164 * @param fFixed When set *ppv will contain the desired region address. 165 * 166 */ 167 int (* pfnPrepare)(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed); 168 /** 169 * Maps a section of the file into the memory region reserved by pfnPrepare. 170 * 171 * @returns 0 on success, OS specific error code on failure. 172 * @param pRdr The file provider instance. 173 * @param pv The address in the prepared region. 174 * @param cb The size of the memory mapping. 175 * @param enmProt The desired memory protection. 176 * @param offFile The start of the raw file bytes. 177 * @param cbFile The number of raw file bytes. This must be less or equal to cb. 178 */ 179 int (* pfnMap)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile); 180 /** 181 * Changes the page protection of a section mapped using pfnMap. 182 * 183 * This is typically used for applying fixups and similar. 184 * 185 * @returns 0 on success, OS specific error code on failure. 186 * @param pRdr The file provider instance. 187 * @param pv The address passed to pfnMap. 188 * @param cb The size passed to pfnMap. 189 * @param enmProt The desired memory protection. 190 */ 191 int (* pfnProtect)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt); 192 /** 193 * Unmaps a section of the file previously mapped using pfnMap. 194 * 195 * @returns 0 on success, OS specific error code on failure. 196 * @param pRdr The file provider instance. 197 * @param pv The address passed to pfnMap. 198 * @param cb The size passed to pfnMap. 199 */ 200 int (* pfnUnmap)(PKLDRRDR pRdr, void *pv, size_t cb); 201 /** 202 * Releases the memory region prepared by pfnPrepare(). 203 * 204 * Before calling this function, all sections mapped by pfnMap must first be unmapped by calling pfnUnmap. 205 * 206 * @returns 0 on success, OS specific error code on failure. 207 * @param pRdr The file provider instance. 208 * @param pv The address of the prepared region. 209 * @param cb The size of the prepared region. 210 */ 211 int (* pfnUnprepare)(PKLDRRDR pRdr, void *pv, size_t cb); 212 /** 213 * We're done reading from the file but would like to keep file mappings. 214 * 215 * If the OS support closing the file handle while the file is mapped, 216 * the reader should do so. 217 * 218 * @param pRdr The file provider instance. 219 */ 220 void (* pfnDone)(PKLDRRDR pRdr); 221 /** The usual non-zero dummy that makes sure we've initialized all members. */ 222 uint32_t u32Dummy; 127 223 } KLDRRDROPS; 128 224 /** Pointer to file provider operations. */ -
trunk/kLdr/kLdrRdrFile.c
r2828 r2829 82 82 * Internal Functions * 83 83 *******************************************************************************/ 84 static void kldrRdrFileDone(PKLDRRDR pRdr); 85 static int kldrRdrFileUnprepare(PKLDRRDR pRdr, void *pv, size_t cb); 86 static int kldrRdrFileUnmap(PKLDRRDR pRdr, void *pv, size_t cb); 87 static int kldrRdrFileProtect(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt); 88 static int kldrRdrFileMap(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile); 89 static int kldrRdrFilePrepare(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed); 84 90 static const char *kldrRdrFileName(PKLDRRDR pRdr); 85 91 static off_t kldrRdrFileTell(PKLDRRDR pRdr); … … 107 113 kldrRdrFileSize, 108 114 kldrRdrFileTell, 109 kldrRdrFileName 115 kldrRdrFileName, 116 kldrRdrFilePrepare, 117 kldrRdrFileMap, 118 kldrRdrFileProtect, 119 kldrRdrFileUnmap, 120 kldrRdrFileUnprepare, 121 kldrRdrFileDone, 122 42 110 123 }; 111 124 125 126 /** @copydoc KLDRRDR::pfnDone */ 127 static void kldrRdrFileDone(PKLDRRDR pRdr) 128 { 129 } 130 131 /** @copydoc KLDRRDR::pfnUnprepare */ 132 static int kldrRdrFileUnprepare(PKLDRRDR pRdr, void *pv, size_t cb) 133 { 134 return -1; 135 } 136 137 138 /** @copydoc KLDRRDR::pfnUnmap */ 139 static int kldrRdrFileUnmap(PKLDRRDR pRdr, void *pv, size_t cb) 140 { 141 return -1; 142 } 143 144 145 /** @copydoc KLDRRDR::pfnProtect */ 146 static int kldrRdrFileProtect(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt) 147 { 148 return -1; 149 } 150 151 152 /** @copydoc KLDRRDR::pfnMap */ 153 static int kldrRdrFileMap(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile) 154 { 155 return -1; 156 } 157 158 159 /** @copydoc KLDRRDR:pfnPrepare */ 160 static int kldrRdrFilePrepare(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed) 161 { 162 #ifdef __OS2__ 163 164 165 #elif defined(__WIN__) 166 167 #else 168 # error "port me." 169 #endif 170 return -1; 171 } 112 172 113 173
Note:
See TracChangeset
for help on using the changeset viewer.