- Timestamp:
- Aug 25, 2007, 8:48:53 AM (18 years ago)
- Location:
- trunk/kStuff
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/include/k/kErrors.h
r3541 r3544 91 91 /** @} */ 92 92 93 /** @name kRdr Specific 94 * @{ */ 95 /** the base of the kRdr specific status codes. */ 96 #define KRDR_ERR_BASE (KDBG_ERR_BASE + 4) 97 /** The file reader can't take more concurrent mappings. */ 98 #define KRDR_ERR_TOO_MANY_MAPPINGS (KRDR_ERR_BASE + 59) 99 /** @} */ 100 93 101 /** @}*/ 94 102 -
trunk/kStuff/kRdr/kRdrFile.c
r3543 r3544 1 1 /* $Id$ */ 2 2 /** @file 3 * kRdrFile - The Native File Provider 4 */ 5 6 /* 7 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net> 3 8 * 4 * kLdr - The Dynamic Loader, file abstraction.9 * This file is part of kStuff. 5 10 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net> 7 * 8 * 9 * This file is part of kLdr. 10 * 11 * kLdr is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 11 * kStuff is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License as published 13 * by the Free Software Foundation; either version 2 of the License, or 14 14 * (at your option) any later version. 15 15 * 16 * k Ldris distributed in the hope that it will be useful,16 * kStuff is distributed in the hope that it will be useful, 17 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details.19 * GNU Lesser General Public License for more details. 20 20 * 21 * You should have received a copy of the GNU General Public License22 * along with k Ldr; if not, write to the Free Software21 * You should have received a copy of the GNU Lesser General Public License 22 * along with kStuff; if not, write to the Free Software 23 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 24 * … … 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #ifdef __OS2__ 31 #include <k/kDefs.h> 32 33 #if K_OS == K_OS_OS2 32 34 # define INCL_ERRORS 33 35 # define INCL_BASE 34 36 # include <os2.h> 35 37 36 #elif defined(__WIN32__) || defined(__WIN64__) || defined(__WIN__)38 #elif K_OS == K_OS_WINDOWS 37 39 # define WIN32_NO_STATUS 38 40 # include <Windows.h> … … 152 154 #endif 153 155 154 #include <kLdr.h> 155 #include "kLdrHlp.h" 156 157 158 /******************************************************************************* 159 * Defined Constants And Macros * 160 *******************************************************************************/ 161 /** @def KLDRRDRFILE_STRICT 162 * Define KLDRRDRFILE_STRICT to enabled strict checks in KLDRRDRFILE. */ 163 #define KLDRRDRFILE_STRICT 1 164 165 /** @def KLDRRDRFILE_ASSERT 166 * Assert that an expression is true when KLDRRDRFILE_STRICT is defined. 167 */ 168 #ifdef KLDRRDRFILE_STRICT 169 # define KLDRRDRFILE_ASSERT(expr) kldrHlpAssert(expr) 170 #else 171 # define KLDRRDRFILE_ASSERT(expr) do {} while (0) 172 #endif 156 #include "kRdrInternal.h" 157 #include <k/kHlpAlloc.h> 158 #include <k/kHlpString.h> 173 159 174 160 … … 179 165 * Prepared stuff. 180 166 */ 181 typedef struct K LDRRDRFILEPREP167 typedef struct KRDRFILEPREP 182 168 { 183 169 /** The address of the prepared region. */ 184 170 void *pv; 185 171 /** The size of the prepared region. */ 186 size_tcb;187 #if defined(__WIN__) || defined(__NT__)172 KSIZE cb; 173 #if K_OS == K_OS_WINDOWS 188 174 /** Handle to the section created to map the file. */ 189 175 HANDLE hSection; 190 176 #endif 191 } K LDRRDRFILEPREP, *PKLDRRDRFILEPREP;177 } KRDRFILEPREP, *PKRDRFILEPREP; 192 178 193 179 /** 194 180 * The file provier instance for native files. 195 181 */ 196 typedef struct K LDRRDRFILE182 typedef struct KRDRFILE 197 183 { 198 184 /** The file reader vtable. */ 199 K LDRRDRCore;185 KRDR Core; 200 186 /** The file handle. */ 201 #if def __OS2__187 #if K_OS == K_OS_OS2 202 188 HFILE File; 203 #elif defined(__WIN__) || defined(__NT__)189 #elif K_OS == K_OS_WINDOWS 204 190 HANDLE File; 205 191 #else … … 207 193 #endif 208 194 /** The current file offset. */ 209 K LDRFOFFoff;195 KFOFF off; 210 196 /** The file size. */ 211 K LDRFOFFcb;197 KFOFF cb; 212 198 /** Array where we stuff the mapping area data. */ 213 K LDRRDRFILEPREPaPreps[4];199 KRDRFILEPREP aPreps[4]; 214 200 /** The number of current preps. */ 215 uint32_tcPreps;201 KU32 cPreps; 216 202 /** Number of mapping references. */ 217 int32_tcMappings;203 KI32 cMappings; 218 204 /** The memory mapping. */ 219 205 void *pvMapping; 220 206 /** The filename. */ 221 207 char szFilename[1]; 222 } K LDRRDRFILE, *PKLDRRDRFILE;208 } KRDRFILE, *PKRDRFILE; 223 209 224 210 … … 226 212 * Internal Functions * 227 213 *******************************************************************************/ 228 static void kldrRdrFileDone(PKLDRRDR pRdr); 229 static int kldrRdrFileUnmap(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments); 230 static int kldrRdrFileGenericUnmap(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_t cSegments, PCKLDRSEG paSegments); 231 static int kldrRdrFileProtect(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect); 232 static int kldrRdrFileGenericProtect(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect); 233 static int kldrRdrFileRefresh(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments); 234 static int kldrRdrFileGenericRefresh(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_t cSegments, PCKLDRSEG paSegments); 235 static int kldrRdrFileMap(PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed); 236 static int kldrRdrFileGenericMap(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed); 237 static size_t kldrRdrFilePageSize(PKLDRRDR pRdr); 238 static const char *kldrRdrFileName(PKLDRRDR pRdr); 239 static KLDRFOFF kldrRdrFileTell(PKLDRRDR pRdr); 240 static KLDRFOFF kldrRdrFileSize(PKLDRRDR pRdr); 241 static int kldrRdrFileAllUnmap(PKLDRRDR pRdr, const void *pvBits); 242 static int kldrRdrFileAllMap(PKLDRRDR pRdr, const void **ppvBits); 243 static int kldrRdrFileRead(PKLDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off); 244 static int kldrRdrFileDestroy(PKLDRRDR pRdr); 245 static int kldrRdrFileCreate(PPKLDRRDR ppRdr, const char *pszFilename); 214 static void krdrFileDone(PKRDR pRdr); 215 static int krdrFileUnmap(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments); 216 static int krdrFileGenericUnmap(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments); 217 static int krdrFileProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect); 218 static int krdrFileGenericProtect(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect); 219 static int krdrFileRefresh(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments); 220 static int krdrFileGenericRefresh(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments); 221 static int krdrFileMap(PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed); 222 static int krdrFileGenericMap(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed); 223 static KSIZE krdrFilePageSize(PKRDR pRdr); 224 static const char *krdrFileName(PKRDR pRdr); 225 static KIPTR krdrFileNativeFH(PKRDR pRdr); 226 static KFOFF krdrFileTell(PKRDR pRdr); 227 static KFOFF krdrFileSize(PKRDR pRdr); 228 static int krdrFileAllUnmap(PKRDR pRdr, const void *pvBits); 229 static int krdrFileAllMap(PKRDR pRdr, const void **ppvBits); 230 static int krdrFileRead(PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off); 231 static int krdrFileDestroy(PKRDR pRdr); 232 static int krdrFileCreate(PPKRDR ppRdr, const char *pszFilename); 246 233 247 234 … … 250 237 *******************************************************************************/ 251 238 /** Native file provider operations. */ 252 const K LDRRDROPS g_kLdrRdrFileOps =239 const KRDROPS g_kRdrFileOps = 253 240 { 254 241 "native file", 255 242 NULL, 256 kldrRdrFileCreate, 257 kldrRdrFileDestroy, 258 kldrRdrFileRead, 259 kldrRdrFileAllMap, 260 kldrRdrFileAllUnmap, 261 kldrRdrFileSize, 262 kldrRdrFileTell, 263 kldrRdrFileName, 264 kldrRdrFilePageSize, 265 kldrRdrFileMap, 266 kldrRdrFileRefresh, 267 kldrRdrFileProtect, 268 kldrRdrFileUnmap, 269 kldrRdrFileDone, 243 krdrFileCreate, 244 krdrFileDestroy, 245 krdrFileRead, 246 krdrFileAllMap, 247 krdrFileAllUnmap, 248 krdrFileSize, 249 krdrFileTell, 250 krdrFileName, 251 krdrFileNativeFH, 252 krdrFilePageSize, 253 krdrFileMap, 254 krdrFileRefresh, 255 krdrFileProtect, 256 krdrFileUnmap, 257 krdrFileDone, 270 258 42 271 259 }; 272 260 273 261 274 #if defined(__WIN__) || defined(__NT__)262 #if K_OS == K_OS_WINDOWS 275 263 /** 276 264 * Converts a kLdr segment protection to NT protection for a mapping. … … 279 267 * @param enmProt kLdr protection. 280 268 */ 281 static ULONG k ldrRdrFileGetNtMapProt(KLDRPROT enmProt)269 static ULONG krdrFileGetNtMapProt(KLDRPROT enmProt) 282 270 { 283 271 switch (enmProt) … … 302 290 * @param enmProt kLdr protection. 303 291 */ 304 static ULONG k ldrRdrFileGetNtAllocProt(KLDRPROT enmProt)292 static ULONG krdrFileGetNtAllocProt(KLDRPROT enmProt) 305 293 { 306 294 switch (enmProt) … … 320 308 321 309 322 /** @copydoc K LDRRDR::pfnDone */323 static void k ldrRdrFileDone(PKLDRRDR pRdr)310 /** @copydoc KRDROPS::pfnDone */ 311 static void krdrFileDone(PKRDR pRdr) 324 312 { 325 313 } … … 333 321 * @param pv The base of the region. 334 322 */ 335 static PK LDRRDRFILEPREP kldrRdrFileFindPrepExact(PKLDRRDRFILE pFile, void *pv)336 { 337 int32_ti = pFile->cPreps;323 static PKRDRFILEPREP krdrFileFindPrepExact(PKRDRFILE pFile, void *pv) 324 { 325 KI32 i = pFile->cPreps; 338 326 while (i-- > 0) 339 327 if (pFile->aPreps[i].pv == pv) … … 343 331 344 332 345 /** @copydoc K LDRRDR::pfnUnmap */346 static int k ldrRdrFileUnmap(PKLDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments)347 { 348 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;349 PK LDRRDRFILEPREP pPrep = kldrRdrFileFindPrepExact(pRdrFile, pvBase);333 /** @copydoc KRDROPS::pfnUnmap */ 334 static int krdrFileUnmap(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 335 { 336 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 337 PKRDRFILEPREP pPrep = krdrFileFindPrepExact(pRdrFile, pvBase); 350 338 int rc; 351 339 if (!pPrep) 352 return K LDR_ERR_INVALID_PARAMETER;353 354 #if defined(__WIN__) || defined(__NT__)340 return KERR_INVALID_PARAMETER; 341 342 #if K_OS == K_OS_WINDOWS 355 343 if (pPrep->hSection != NULL) 356 344 { … … 360 348 #endif 361 349 362 rc = k ldrRdrFileGenericUnmap(pRdr, pPrep, cSegments, paSegments);350 rc = krdrFileGenericUnmap(pRdr, pPrep, cSegments, paSegments); 363 351 364 352 /* remove the mapping data on success. */ … … 373 361 374 362 375 /** Generic implementation of k ldrRdrFileUnmap. */376 static int k ldrRdrFileGenericUnmap(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_tcSegments, PCKLDRSEG paSegments)377 { 378 k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */);379 return k ldrHlpPageFree(pPrep->pv, pPrep->cb);380 } 381 382 383 /** @copydoc K LDRRDR::pfnProtect */384 static int k ldrRdrFileProtect(PKLDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)385 { 386 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;387 PK LDRRDRFILEPREP pPrep = kldrRdrFileFindPrepExact(pRdrFile, pvBase);363 /** Generic implementation of krdrFileUnmap. */ 364 static int krdrFileGenericUnmap(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments) 365 { 366 krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */); 367 return kHlpPageFree(pPrep->pv, pPrep->cb); 368 } 369 370 371 /** @copydoc KRDROPS::pfnProtect */ 372 static int krdrFileProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect) 373 { 374 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 375 PKRDRFILEPREP pPrep = krdrFileFindPrepExact(pRdrFile, pvBase); 388 376 if (!pPrep) 389 return K LDR_ERR_INVALID_PARAMETER;390 391 #if defined(__WIN__) || defined(__NT__)377 return KERR_INVALID_PARAMETER; 378 379 #if K_OS == K_OS_WINDOWS 392 380 if (pPrep->hSection != NULL) 393 381 { … … 397 385 #endif 398 386 399 return k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, fUnprotectOrProtect);400 } 401 402 403 /** Generic implementation of k ldrRdrFileProtect. */404 static int k ldrRdrFileGenericProtect(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_tcSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)405 { 406 uint32_ti;387 return krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, fUnprotectOrProtect); 388 } 389 390 391 /** Generic implementation of krdrFileProtect. */ 392 static int krdrFileGenericProtect(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect) 393 { 394 KU32 i; 407 395 408 396 /* … … 437 425 break; 438 426 default: 439 KLDRRDRFILE_ASSERT(!"bad enmProt");427 kRdrAssert(!"bad enmProt"); 440 428 return -1; 441 429 } … … 452 440 pv = (uint8_t *)pPrep->pv + paSegments[i].RVA; 453 441 454 rc = k ldrHlpPageProtect(pv, paSegments[i].cbMapped, enmProt);442 rc = kHlpPageProtect(pv, paSegments[i].cbMapped, enmProt); 455 443 if (rc) 456 444 break; … … 461 449 462 450 463 /** @copydoc K LDRRDR::pfnRefresh */464 static int k ldrRdrFileRefresh(PKLDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments)465 { 466 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;467 PK LDRRDRFILEPREP pPrep = kldrRdrFileFindPrepExact(pRdrFile, pvBase);451 /** @copydoc KRDROPS::pfnRefresh */ 452 static int krdrFileRefresh(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 453 { 454 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 455 PKRDRFILEPREP pPrep = krdrFileFindPrepExact(pRdrFile, pvBase); 468 456 if (!pPrep) 469 return K LDR_ERR_INVALID_PARAMETER;470 471 #if defined(__WIN__) || defined(__NT__)457 return KERR_INVALID_PARAMETER; 458 459 #if K_OS == K_OS_WINDOWS 472 460 if (pPrep->hSection != NULL) 473 461 { … … 477 465 #endif 478 466 479 return k ldrRdrFileGenericRefresh(pRdr, pPrep, cSegments, paSegments);480 } 481 482 483 /** Generic implementation of k ldrRdrFileRefresh. */484 static int k ldrRdrFileGenericRefresh(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_tcSegments, PCKLDRSEG paSegments)467 return krdrFileGenericRefresh(pRdr, pPrep, cSegments, paSegments); 468 } 469 470 471 /** Generic implementation of krdrFileRefresh. */ 472 static int krdrFileGenericRefresh(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments) 485 473 { 486 474 int rc; 487 475 int rc2; 488 uint32_ti;476 KU32 i; 489 477 490 478 /* 491 479 * Make everything writable again. 492 480 */ 493 rc = k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */);481 rc = krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */); 494 482 if (rc) 495 483 { 496 k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */);484 krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */); 497 485 return rc; 498 486 } … … 502 490 */ 503 491 /** @todo only zero the areas not covered by raw file bits. */ 504 k LdrHlpMemSet(pPrep->pv, 0, pPrep->cb);492 kHlpMemSet(pPrep->pv, 0, pPrep->cb); 505 493 506 494 /* … … 526 514 * Protect the bits again. 527 515 */ 528 rc2 = k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */);516 rc2 = krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */); 529 517 if (rc2 && rc) 530 518 rc = rc2; … … 534 522 535 523 536 /** @copydoc K LDRRDR::pfnMap */537 static int k ldrRdrFileMap(PKLDRRDR pRdr, void **ppvBase, uint32_tcSegments, PCKLDRSEG paSegments, unsigned fFixed)538 { 539 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;540 PK LDRRDRFILEPREPpPrep = &pRdrFile->aPreps[pRdrFile->cPreps];541 KLDRSIZE 542 const size_tcbPage = pRdr->pOps->pfnPageSize(pRdr);543 int 544 uint32_ti;545 546 if (pRdrFile->cPreps >= K LDR_ELEMENTS(pRdrFile->aPreps))547 return K LDR_ERR_TOO_MANY_MAPPINGS;524 /** @copydoc KRDROPS::pfnMap */ 525 static int krdrFileMap(PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed) 526 { 527 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 528 PKRDRFILEPREP pPrep = &pRdrFile->aPreps[pRdrFile->cPreps]; 529 KLDRSIZE cbTotal; 530 const KSIZE cbPage = pRdr->pOps->pfnPageSize(pRdr); 531 int rc; 532 KU32 i; 533 534 if (pRdrFile->cPreps >= K_ELEMENTS(pRdrFile->aPreps)) 535 return KRDR_ERR_TOO_MANY_MAPPINGS; 548 536 549 537 /* … … 560 548 cbTotal = uRVASegmentEnd; 561 549 } 562 pPrep->cb = ( size_t)cbTotal;550 pPrep->cb = (KSIZE)cbTotal; 563 551 if (pPrep->cb != cbTotal) 564 552 return KLDR_ERR_ADDRESS_OVERFLOW; 565 553 pPrep->cb = (pPrep->cb + (cbPage - 1)) & ~(cbPage- 1); 566 554 567 #if defined(__WIN__) || defined(__NT__)555 #if K_OS == K_OS_WINDOWS 568 556 /* 569 557 * The NT memory mapped file API sucks in a lot of ways. Unless you're actually … … 646 634 { 647 635 pv = NULL; 648 ViewSize = ( size_t)cbTotal;636 ViewSize = (KSIZE)cbTotal; 649 637 650 638 Status = NtAllocateVirtualMemory(NtCurrentProcess(), … … 682 670 SectionOffset.QuadPart = paSegments[i].offFile; 683 671 ViewSize = paSegments[i].cbFile; 684 fPageProt = k ldrRdrFileGetNtMapProt(paSegments[i].enmProt);672 fPageProt = krdrFileGetNtMapProt(paSegments[i].enmProt); 685 673 /* STATUS_MAPPED_ALIGNMENT 686 674 STATUS_CONFLICTING_ADDRESSES … … 706 694 { 707 695 ViewSize = paSegments[i].cbMapped; 708 fPageProt = k ldrRdrFileGetNtAllocProt(paSegments[i].enmProt);696 fPageProt = krdrFileGetNtAllocProt(paSegments[i].enmProt); 709 697 Status = NtAllocateVirtualMemory(NtCurrentProcess(), 710 698 &pv, … … 751 739 */ 752 740 pPrep->pv = fFixed ? *ppvBase : NULL; 753 rc = k ldrRdrFileGenericMap(pRdr, pPrep, cSegments, paSegments, fFixed);741 rc = krdrFileGenericMap(pRdr, pPrep, cSegments, paSegments, fFixed); 754 742 if (!rc) 755 743 { … … 762 750 763 751 764 /** Generic implementation of k ldrRdrFileMap. */765 static int k ldrRdrFileGenericMap(PKLDRRDR pRdr, PKLDRRDRFILEPREP pPrep, uint32_tcSegments, PCKLDRSEG paSegments, unsigned fFixed)752 /** Generic implementation of krdrFileMap. */ 753 static int krdrFileGenericMap(PKRDR pRdr, PKRDRFILEPREP pPrep, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed) 766 754 { 767 755 int rc; 768 uint32_ti;769 770 /* 771 * Generic mapping code using k ldrHlpPageAlloc(), kldrHlpPageFree() and kldrHlpPageProtect().772 */ 773 rc = k ldrHlpPageAlloc(&pPrep->pv, pPrep->cb, KLDRPROT_EXECUTE_READWRITE, fFixed);756 KU32 i; 757 758 /* 759 * Generic mapping code using kHlpPageAlloc(), kHlpPageFree() and kHlpPageProtect(). 760 */ 761 rc = kHlpPageAlloc(&pPrep->pv, pPrep->cb, KLDRPROT_EXECUTE_READWRITE, fFixed); 774 762 if (rc) 775 763 return rc; … … 797 785 if (!rc) 798 786 { 799 rc = k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */);787 rc = krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 0 /* protect */); 800 788 if (!rc) 801 789 return 0; 802 k ldrRdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */);790 krdrFileGenericProtect(pRdr, pPrep, cSegments, paSegments, 1 /* unprotect */); 803 791 } 804 792 805 793 /* bailout */ 806 k ldrHlpPageFree(pPrep->pv, pPrep->cb);794 kHlpPageFree(pPrep->pv, pPrep->cb); 807 795 return rc; 808 796 } 809 797 810 798 811 /** @copydoc K LDRRDR::pfnPageSize */812 static size_t kldrRdrFilePageSize(PKLDRRDR pRdr)813 { 814 #if def __OS2__799 /** @copydoc KRDROPS::pfnPageSize */ 800 static KSIZE krdrFilePageSize(PKRDR pRdr) 801 { 802 #if K_OS == K_OS_OS2 815 803 /* The page size on OS/2 wont change anytime soon. :-) */ 816 804 return 0x1000; … … 827 815 828 816 829 /** @copydoc K LDRRDR::pfnName */830 static const char *k ldrRdrFileName(PKLDRRDR pRdr)831 { 832 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;817 /** @copydoc KRDROPS::pfnName */ 818 static const char *krdrFileName(PKRDR pRdr) 819 { 820 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 833 821 return &pRdrFile->szFilename[0]; 834 822 } 835 823 836 824 837 /** @copydoc KLDRRDR::pfnTell */ 838 static KLDRFOFF kldrRdrFileTell(PKLDRRDR pRdr) 839 { 840 PKLDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr; 825 static KIPTR krdrFileNativeFH(PKRDR pRdr) 826 { 827 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 828 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS 829 return (KIPTR)pRdrFile->File; 830 #else 831 # error "port me" 832 #endif 833 } 834 835 836 /** @copydoc KRDROPS::pfnTell */ 837 static KFOFF krdrFileTell(PKRDR pRdr) 838 { 839 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 841 840 842 841 /* … … 845 844 if (pRdrFile->off == -1) 846 845 { 847 #if def __OS2__846 #if K_OS == K_OS_OS2 848 847 ULONG ulNew; 849 848 APIRET rc = DosSetFilePtr(pRdrFile->File, 0, FILE_CURRENT, &ulNew); … … 862 861 if (rc) 863 862 return -1; 864 pRdrFile->off = ((K LDRFOFF)offHigh << 32) | offLow;863 pRdrFile->off = ((KFOFF)offHigh << 32) | offLow; 865 864 866 865 #else … … 872 871 873 872 874 /** @copydoc K LDRRDR::pfnSize */875 static K LDRFOFF kldrRdrFileSize(PKLDRRDR pRdr)876 { 877 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;873 /** @copydoc KRDROPS::pfnSize */ 874 static KFOFF krdrFileSize(PKRDR pRdr) 875 { 876 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 878 877 return pRdrFile->cb; 879 878 } 880 879 881 880 882 /** @copydoc K LDRRDR::pfnAllUnmap */883 static int k ldrRdrFileAllUnmap(PKLDRRDR pRdr, const void *pvBits)884 { 885 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;881 /** @copydoc KRDROPS::pfnAllUnmap */ 882 static int krdrFileAllUnmap(PKRDR pRdr, const void *pvBits) 883 { 884 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 886 885 887 886 /* check for underflow */ … … 896 895 if (!--pRdrFile->cMappings) 897 896 { 898 k ldrHlpFree(pRdrFile->pvMapping);897 kHlpFree(pRdrFile->pvMapping); 899 898 pRdrFile->pvMapping = NULL; 900 899 } … … 904 903 905 904 906 /** @copydoc K LDRRDR::pfnAllMap */907 static int k ldrRdrFileAllMap(PKLDRRDR pRdr, const void **ppvBits)908 { 909 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;905 /** @copydoc KRDROPS::pfnAllMap */ 906 static int krdrFileAllMap(PKRDR pRdr, const void **ppvBits) 907 { 908 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 910 909 911 910 /* … … 915 914 { 916 915 int rc; 917 K LDRFOFF cb = pRdrFile->Core.pOps->pfnSize(pRdr);918 919 pRdrFile->pvMapping = k ldrHlpAlloc(cb);916 KFOFF cb = pRdrFile->Core.pOps->pfnSize(pRdr); 917 918 pRdrFile->pvMapping = kHlpAlloc(cb); 920 919 if (!pRdrFile->pvMapping) 921 920 #if defined(__OS2__) || defined(__WIN__) … … 927 926 if (rc) 928 927 { 929 k ldrHlpFree(pRdrFile->pvMapping);928 kHlpFree(pRdrFile->pvMapping); 930 929 pRdrFile->pvMapping = NULL; 931 930 return rc; … … 940 939 941 940 942 /** @copydoc K LDRRDR::pfnRead */943 static int k ldrRdrFileRead(PKLDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off)944 { 945 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;941 /** @copydoc KRDROPS::pfnRead */ 942 static int krdrFileRead(PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off) 943 { 944 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 946 945 947 946 /* … … 950 949 if (pRdrFile->off != off) 951 950 { 952 #if def __OS2__951 #if K_OS == K_OS_OS2 953 952 ULONG ulNew; 954 953 APIRET rc; … … 965 964 LONG offLow; 966 965 967 offHigh = sizeof(K LDRFOFF) == 4 ? 0 : (off >> 32);966 offHigh = sizeof(KFOFF) == 4 ? 0 : (off >> 32); 968 967 offLow = SetFilePointer(pRdrFile->File, (LONG)off, &offHigh, FILE_BEGIN); 969 968 if ( offLow != (LONG)off 970 || offHigh != (LONG)(sizeof(K LDRFOFF) == 4 ? 0 : (off >> 32)))969 || offHigh != (LONG)(sizeof(KFOFF) == 4 ? 0 : (off >> 32))) 971 970 { 972 971 int rc = GetLastError(); … … 985 984 * Do the read. 986 985 */ 987 #if def __OS2__986 #if K_OS == K_OS_OS2 988 987 { 989 988 ULONG cbRead = 0; … … 1028 1027 1029 1028 1030 /** @copydoc K LDRRDR::pfnDestroy */1031 static int k ldrRdrFileDestroy(PKLDRRDR pRdr)1032 { 1033 PK LDRRDRFILE pRdrFile = (PKLDRRDRFILE)pRdr;1029 /** @copydoc KRDROPS::pfnDestroy */ 1030 static int krdrFileDestroy(PKRDR pRdr) 1031 { 1032 PKRDRFILE pRdrFile = (PKRDRFILE)pRdr; 1034 1033 int rc; 1035 #if def __OS2__1034 #if K_OS == K_OS_OS2 1036 1035 rc = DosClose(pRdrFile->File); 1037 1036 … … 1047 1046 if (pRdrFile->pvMapping) 1048 1047 { 1049 k ldrHlpFree(pRdrFile->pvMapping);1048 kHlpFree(pRdrFile->pvMapping); 1050 1049 pRdrFile->pvMapping = NULL; 1051 1050 } 1052 1051 1053 k ldrHlpFree(pRdr);1052 kHlpFree(pRdr); 1054 1053 return rc; 1055 1054 } 1056 1055 1057 1056 1058 /** @copydoc K LDRRDROPS::pfnCreate */1059 static int k ldrRdrFileCreate(PPKLDRRDR ppRdr, const char *pszFilename)1060 { 1061 size_tcchFilename;1062 PK LDRRDRFILEpRdrFile;1057 /** @copydoc KRDROPS::pfnCreate */ 1058 static int krdrFileCreate(PPKRDR ppRdr, const char *pszFilename) 1059 { 1060 KSIZE cchFilename; 1061 PKRDRFILE pRdrFile; 1063 1062 1064 1063 /* 1065 1064 * Open the file and determin its size. 1066 1065 */ 1067 #if def __OS2__1066 #if K_OS == K_OS_OS2 1068 1067 ULONG ulAction = 0; 1069 1068 FILESTATUS3 Info; 1070 1069 APIRET rc; 1071 1070 HFILE File = 0; 1072 K LDRFOFFcb;1071 KFOFF cb; 1073 1072 char szFilename[CCHMAXPATH]; 1074 1073 … … 1076 1075 { 1077 1076 char *psz; 1078 cchFilename = k LdrHlpStrLen(szFilename);1079 psz = (char *)k LdrHlpAllocA(cchFilename + 1);1080 k LdrHlpMemCopy(psz, pszFilename, cchFilename + 1);1077 cchFilename = kHlpStrLen(szFilename); 1078 psz = (char *)kHlpAllocA(cchFilename + 1); 1079 kHlpMemCopy(psz, pszFilename, cchFilename + 1); 1081 1080 pszFilename = psz; 1082 1081 } … … 1109 1108 int rc; 1110 1109 HANDLE File; 1111 K LDRFOFF cb;1110 KFOFF cb; 1112 1111 char szFilename[MAX_PATH]; 1113 1112 … … 1134 1133 return rc; 1135 1134 } 1136 if (sizeof(K LDRFOFF) == 4)1135 if (sizeof(KFOFF) == 4) 1137 1136 cb = High ? 0x7fffffff : Low; 1138 1137 else 1139 cb = ((K LDRFOFF)High << 32) | Low;1138 cb = ((KFOFF)High << 32) | Low; 1140 1139 1141 1140 #else … … 1147 1146 * Allocate the reader instance. 1148 1147 */ 1149 cchFilename = k LdrHlpStrLen(szFilename);1150 pRdrFile = (PK LDRRDRFILE)kldrHlpAlloc(sizeof(*pRdrFile) + cchFilename);1148 cchFilename = kHlpStrLen(szFilename); 1149 pRdrFile = (PKRDRFILE)kHlpAlloc(sizeof(*pRdrFile) + cchFilename); 1151 1150 if (!pRdrFile) 1152 1151 #if defined(__OS2__) … … 1168 1167 */ 1169 1168 pRdrFile->Core.u32Magic = KLDRRDR_MAGIC; 1170 pRdrFile->Core.pOps = &g_k LdrRdrFileOps;1169 pRdrFile->Core.pOps = &g_kRdrFileOps; 1171 1170 pRdrFile->File = File; 1172 1171 pRdrFile->cb = cb; … … 1174 1173 pRdrFile->cMappings = 0; 1175 1174 pRdrFile->cPreps = 0; 1176 k LdrHlpMemCopy(&pRdrFile->szFilename[0], szFilename, cchFilename + 1);1175 kHlpMemCopy(&pRdrFile->szFilename[0], szFilename, cchFilename + 1); 1177 1176 1178 1177 *ppRdr = &pRdrFile->Core; -
trunk/kStuff/kRdr/kRdrInternal.h
r3543 r3544 30 30 #include <k/kHlpAssert.h> 31 31 #include <k/kMagics.h> 32 #include <k/kRdrAll.h> 33 #include <k/kErrors.h> 32 34 33 35 #ifdef __cplusplus
Note:
See TracChangeset
for help on using the changeset viewer.