Changeset 4164 for trunk/src/win32k/dev32/d32init.c
- Timestamp:
- Sep 2, 2000, 11:08:23 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/dev32/d32init.c
r3485 r4164 1 /* $Id: d32init.c,v 1. 19 2000-05-03 10:46:06bird Exp $1 /* $Id: d32init.c,v 1.20 2000-09-02 21:07:57 bird Exp $ 2 2 * 3 3 * d32init.c - 32-bits init routines. … … 14 14 #define MAXSIZE_PROLOG 0x18 /* Note that this must be synced with */ 15 15 /* the one used in calltab.asm. */ 16 #define static /* just to make all symbols visible in the kernel debugger. */17 16 #if 0 /* Enable this to have extra debug logging. */ 18 17 #define kprintf2(a) kprintf … … 24 23 #define INCL_NOPMAPI 25 24 #define LDR_INCL_INITONLY 25 #define INCL_OS2KRNL_ALL 26 26 27 27 /******************************************************************************* … … 32 32 #include <string.h> 33 33 34 #include "devSegDf.h" 34 35 #include "OS2Krnl.h" 35 36 #include "options.h" … … 44 45 #include "ldrCalls.h" 45 46 #include "macros.h" 47 #include "errors.h" 48 49 #ifdef R3TST 50 #include "test.h" 51 #endif 46 52 47 53 … … 53 59 static char * apszInfoLevel[] = {"INFOLEVEL_QUIET", "INFOLEVEL_ERROR", "INFOLEVEL_WARNING", "INFOLEVEL_INFO", "INFOLEVEL_INFOALL", "!invalid!"}; 54 60 #endif 55 staticPMTE pKrnlMTE = NULL;56 staticPSMTE pKrnlSMTE = NULL;57 staticPOTE pKrnlOTE = NULL;61 PMTE pKrnlMTE = NULL; 62 PSMTE pKrnlSMTE = NULL; 63 POTE pKrnlOTE = NULL; 58 64 59 65 … … 61 67 * Internal Functions * 62 68 *******************************************************************************/ 63 static ULONG readnum(const char *pszNum); 64 _Inline int ModR_M_32bit(char bModRM); 65 static int interpretFunctionProlog32(char *pach, BOOL fOverload); 66 static int interpretFunctionProlog16(char *pach, BOOL fOverload); 67 static int ImportTabInit(void); 69 ULONG readnum(const char *pszNum); 70 _Inline int ModR_M_32bit(char bModRM); 71 _Inline int ModR_M_16bit(char bModRM); 72 int interpretFunctionProlog32(char *pach, BOOL fOverload); 73 int interpretFunctionProlog16(char *pach, BOOL fOverload); 74 int importTabInit(void); 75 #ifdef R3TST 76 PMTE GetOS2KrnlMTETst(void); 77 void R3TstFixImportTab(void); 78 #endif 79 PSZ SECCALL nopSecPathFromSFN(SFN hFile); 80 68 81 69 82 … … 78 91 /* extern(s) located in mytkExecPgm.asm */ 79 92 extern char mytkExecPgm; 80 81 82 #ifndef DEBUGR3 93 extern char mytkStartProcess; 94 95 83 96 /** 84 97 * Ring-0, 32-bit, init function. … … 118 131 { 119 132 case 'c': 120 case 'C': /* -C[1|2] - com-port no, def:-C2 */ 121 switch (pszTmp[1]) 122 { 123 case '1': 124 options.usCom = OUTPUT_COM1; 125 break; 126 127 case '2': 128 default: 129 options.usCom = OUTPUT_COM2; 130 } 133 case 'C': /* -C[1|2] or -Com:[1|2] - com-port no, def:-C2 */ 134 pszTmp2 = strpbrk(pszTmp, ":=/- "); 135 if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '=')) 136 pszTmp2++; 137 else 138 pszTmp2 = pszTmp + 1; 139 options.usCom = (USHORT)(*pszTmp2 == '1' ? OUTPUT_COM1 : OUTPUT_COM2); 131 140 break; 132 141 … … 134 143 case 'E':/* ELF */ 135 144 pszTmp2 = strpbrk(pszTmp, ":=/- "); 136 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1145 if (pszTmp2 != NULL 137 146 && (pszTmp2[1] == 'N' ||pszTmp2[1] == 'n' || pszTmp2[1] == 'D' || pszTmp2[1] == 'd') 138 147 ) … … 145 154 case 'H': /* Heap options */ 146 155 pszTmp2 = strpbrk(pszTmp, ":=/- "); 147 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1 148 && (*pszTmp2 == ':' || *pszTmp2 == '=')) 156 if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '=')) 149 157 { 150 158 ul = readnum(pszTmp2 + 1); … … 159 167 break; 160 168 169 case 'j': 170 case 'J': /* -Java:<Yes|No> */ 171 pszTmp2 = strpbrk(pszTmp, ":=/- "); 172 options.fJava = 173 pszTmp2 != NULL 174 && (int)(pszTmp2-pszTmp) < cch-1 175 && (*pszTmp2 == ':' || *pszTmp2 == '=') 176 && (pszTmp2[1] == 'Y' || pszTmp2[1] == 'y'); 177 break; 178 161 179 case 'l': 162 180 case 'L': /* -L[..]<:|=| >[<Y..|E..| > | <N..|D..>] */ 163 181 pszTmp2 = strpbrk(pszTmp, ":=/- "); 164 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1165 && (pszTmp2[1] == ' N' ||pszTmp2[1] == 'n' || pszTmp2[1] == 'D' || pszTmp2[1] == 'd')182 if (pszTmp2 != NULL 183 && (pszTmp2[1] == 'Y' ||pszTmp2[1] == 'y' || pszTmp2[1] == 'E' || pszTmp2[1] == 'e') 166 184 ) 185 options.fLogging = TRUE; 186 else 167 187 options.fLogging = FALSE; 168 else169 options.fLogging = TRUE;170 188 break; 171 189 … … 178 196 case 'P': /* PE */ 179 197 pszTmp2 = strpbrk(pszTmp, ":=/- "); 180 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1 181 && (*pszTmp2 == ':' || *pszTmp2 == '=')) 198 if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '=')) 182 199 { 183 pszTmp ++;184 if (strnicmp(pszTmp , "pe2lx", 5) == 0)200 pszTmp2++; 201 if (strnicmp(pszTmp2, "pe2lx", 5) == 0) 185 202 options.fPE = FLAGS_PE_PE2LX; 186 else if (strnicmp(pszTmp , "pe", 2) == 0)203 else if (strnicmp(pszTmp2, "pe", 2) == 0) 187 204 options.fPE = FLAGS_PE_PE; 188 else if (strnicmp(pszTmp , "mixed", 2) == 0)205 else if (strnicmp(pszTmp2, "mixed", 2) == 0) 189 206 options.fPE = FLAGS_PE_MIXED; 190 else if (strnicmp(pszTmp , "not", 2) == 0)207 else if (strnicmp(pszTmp2, "not", 2) == 0) 191 208 options.fPE = FLAGS_PE_NOT; 192 209 else … … 203 220 204 221 case 'r': 205 case 'R': /* ResHeap options */222 case 'R': /* ResHeap options or REXX option */ 206 223 pszTmp2 = strpbrk(pszTmp, ":=/- "); 207 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1 208 && (*pszTmp2 == ':' || *pszTmp2 == '=')) 209 { 210 ul = readnum(pszTmp2 + 1); 211 if (ul > 0x1000UL && ul < 0x700000UL) /* 4KB < ul < 7MB */ 224 if ( (pszTmp[1] == 'E' || pszTmp[1] == 'e') 225 && (pszTmp[2] == 'X' || pszTmp[2] == 'x')) 226 { /* REXX */ 227 options.fREXXScript = 228 pszTmp2 != NULL 229 && (int)(pszTmp2-pszTmp) < cch-1 230 && (*pszTmp2 == ':' || *pszTmp2 == '=') 231 && (pszTmp2[1] == 'Y' || pszTmp2[1] == 'y'); 232 } 233 else 234 { /* ResHeap options */ 235 if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '=')) 212 236 { 213 if (strnicmp(pszTmp, "resheapm", 8) == 0) 214 options.cbResHeapMax = ul; 215 else 216 options.cbResHeapInit = ul; 237 ul = readnum(pszTmp2 + 1); 238 if (ul > 0x1000UL && ul < 0x700000UL) /* 4KB < ul < 7MB */ 239 { 240 if (strnicmp(pszTmp, "resheapm", 8) == 0) 241 options.cbResHeapMax = ul; 242 else 243 options.cbResHeapInit = ul; 244 } 217 245 } 218 246 } … … 222 250 case 'S': /* Sym:<filename> or Script:<Yes|No> or Smp */ 223 251 /* SMP kernel */ 224 if (pszTmp[1] == 'm' || pszTmp[1] == 'M') 225 options.fKernel = KF_SMP; 226 else 252 pszTmp2 = strpbrk(pszTmp, ":=/- "); 253 if (pszTmp[1] == 'c' || pszTmp[1] == 'C') 227 254 { 228 if (pszTmp[1] == 'c' || pszTmp[1] == 'C') 229 { 230 pszTmp2 = strpbrk(pszTmp, ":=/- "); 231 options.fScript = pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1 232 && (*pszTmp2 == ':' || *pszTmp2 == '=') 233 && (pszTmp2[1] == 'Y' || pszTmp2[1] == 'y'); 234 } 235 } 236 break; 237 238 case 'u': 239 case 'U': /* UNI kernel */ 240 options.fKernel = KF_UNI; 255 options.fUNIXScript = 256 pszTmp2 != NULL 257 && (int)(pszTmp2-pszTmp) < cch-1 258 && (*pszTmp2 == ':' || *pszTmp2 == '=') 259 && (pszTmp2[1] == 'Y' || pszTmp2[1] == 'y'); 260 } 241 261 break; 242 262 … … 247 267 248 268 case 'w': 249 case 'W': 269 case 'W': /* ModuleBase info level; -W<n> or -Warning:<n> */ 250 270 if (pszTmp[1] >= '0' && pszTmp[1] <= '4') 251 271 options.ulInfoLevel = pszTmp[1] - '0'; … … 253 273 { 254 274 pszTmp2 = strpbrk(pszTmp, ":=/- "); 255 if (pszTmp2 != NULL && (int)(pszTmp2-pszTmp) < cch-1 256 && (*pszTmp2 == ':' || *pszTmp2 == '=') 257 && pszTmp2[1] >= '0' && pszTmp2[1] <= '4' 258 ) 259 options.ulInfoLevel = pszTmp2[1] - '0'; 275 if (pszTmp2 != NULL && (*pszTmp2 == ':' || *pszTmp2 == '=')) 276 pszTmp2++; 277 else 278 pszTmp2 = pszTmp + 1; 279 280 if (*pszTmp2 >= '0' && *pszTmp2 <= '4') 281 options.ulInfoLevel = *pszTmp2 - '0'; 260 282 } 261 283 break; … … 270 292 if (options.cbResHeapInit > options.cbResHeapMax) 271 293 options.cbResHeapMax = options.cbResHeapInit; 272 273 /* Transfer version and build number from 16-bit probkrnl.c */274 options.ulBuild = _usBuild;275 options.usVerMajor = _usVerMajor;276 options.usVerMinor = _usVerMinor;277 294 278 295 /* Log option summary */ … … 288 305 else 289 306 kprintf(("\tlogging disabled\n")); 290 kprintf(("\tCom port no.% d\n", options.usCom));291 292 kprintf(("\tKernel: v er%d.%d build %d type %s\n",307 kprintf(("\tCom port no.%03xh\n", options.usCom)); 308 309 kprintf(("\tKernel: v%d.%d build %d type ", 293 310 options.usVerMajor, 294 311 options.usVerMinor, 295 options.ulBuild, 296 (options.fKernel & KF_SMP) ? "SMP" : "UNI" 297 )); 298 kprintf(("\tfPE=%d (%s)\n", options.fPE, apszPE[MIN(options.fPE, 5)])); 312 options.ulBuild)); 313 if (options.fKernel & KF_SMP) 314 kprintf(("SMP ")); 315 else if (options.fKernel & KF_W4) 316 kprintf(("W4 ")); 317 else 318 kprintf(("UNI ")); 319 if (options.fKernel & KF_DEBUG) 320 kprintf(("DEBUG\n")); 321 else 322 kprintf(("\n")); 323 324 kprintf(("\tfPE=%d (%s)\n", options.fPE, apszPE[MIN(options.fPE, 5)])); 299 325 kprintf(("\tulInfoLevel=%d (%s)\n", options.ulInfoLevel, apszInfoLevel[MIN(options.ulInfoLevel, 5)])); 300 kprintf(("\tfElf=%d\n", options.fElf)); 301 kprintf(("\tfScript=%d\n", options.fScript)); 302 kprintf(("\tfNoLoader=%d\n", options.fNoLoader)); 326 kprintf(("\tfElf=%d\n", options.fElf)); 327 kprintf(("\tfUNIXScript=%d\n", options.fUNIXScript)); 328 kprintf(("\tfREXXScript=%d\n", options.fREXXScript)); 329 kprintf(("\tfJAVA=%d\n", options.fJava)); 330 kprintf(("\tfNoLoader=%d\n", options.fNoLoader)); 303 331 kprintf(("\tcbSwpHeapInit=0x%08x cbSwpHeapMax=0x%08x\n", 304 332 options.cbSwpHeapInit, options.cbSwpHeapMax)); 305 333 kprintf(("\tcbResHeapInit=0x%08x cbResHeapMax=0x%08x\n", 306 options.cb SwpHeapInit, options.cbSwpHeapMax));334 options.cbResHeapInit, options.cbResHeapMax)); 307 335 kprintf(("Options - Summary - End\n")); 308 336 #endif /* debug */ … … 325 353 /* functionoverrides */ 326 354 if (!options.fNoLoader) 327 if ( ImportTabInit() != NO_ERROR)355 if (importTabInit() != NO_ERROR) 328 356 return STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL; 329 357 … … 369 397 * @author knut st. osmundsen 370 398 */ 371 staticULONG readnum(const char *pszNum)399 ULONG readnum(const char *pszNum) 372 400 { 373 401 ULONG ulRet = 0; … … 428 456 429 457 /* Find the kernel OTE table */ 458 #ifndef R3TST 430 459 pKrnlMTE = GetOS2KrnlMTE(); 460 #else 461 pKrnlMTE = GetOS2KrnlMTETst(); 462 #endif 431 463 if (pKrnlMTE != NULL) 432 464 { … … 461 493 * Search for internal revision stuff in the two first objects. 462 494 */ 463 pKrnlInfo->u sBuild = 0;464 for (i = 0; i < 2 && pKrnlInfo->u sBuild == 0; i++)495 pKrnlInfo->ulBuild = 0; 496 for (i = 0; i < 2 && pKrnlInfo->ulBuild == 0; i++) 465 497 { 466 498 const char *psz = (const char*)pKrnlOTE[i].ote_base; 467 const char *pszEnd = psz + pKrnlOTE[i].ote_size ;468 469 while (psz + 100< pszEnd)499 const char *pszEnd = psz + pKrnlOTE[i].ote_size - 50; /* Last possible search position. */ 500 501 while (psz < pszEnd) 470 502 { 471 503 if (strncmp(psz, "Internal revision ", 18) == 0 && (psz[18] >= '0' && psz[18] <= '9')) 472 504 { 473 505 int j; 474 kprintf2(("Get OTEs32: found internal revision: '%s'\n", psz));506 kprintf2(("GetKernelInfo32: found internal revision: '%s'\n", psz)); 475 507 476 508 /* skip to end of "Internal revision " string. */ … … 481 513 { 482 514 if (*psz != '.') 483 pKrnlInfo->u sBuild = (unsigned short)(pKrnlInfo->usBuild * 10 + (*psz - '0'));515 pKrnlInfo->ulBuild = (unsigned short)(pKrnlInfo->ulBuild * 10 + (*psz - '0')); 484 516 psz++; 485 517 } 486 518 487 519 /* Check if build number seems valid. */ 488 if ( !(pKrnlInfo->usBuild >= 8254 && pKrnlInfo->usBuild < 8383) /* Warp 3 fp 32 -> fp 60 */ 489 && !(pKrnlInfo->usBuild >= 9023 && pKrnlInfo->usBuild <= 9036) /* Warp 4 GA -> fp 12 */ 490 && !(pKrnlInfo->usBuild >= 14039 && pKrnlInfo->usBuild < 14080) /* Warp 4.5 GA -> fp 40 */ 520 if ( !(pKrnlInfo->ulBuild >= 8254 && pKrnlInfo->ulBuild < 8383) /* Warp 3 fp 32 -> fp 60 */ 521 && !(pKrnlInfo->ulBuild >= 9023 && pKrnlInfo->ulBuild <= 9036) /* Warp 4 GA -> fp 12 */ 522 && !(pKrnlInfo->ulBuild >= 14039 && pKrnlInfo->ulBuild < 14080) /* Warp 4.5 GA -> fp 40 */ 523 && !(pKrnlInfo->ulBuild >= 6600 && pKrnlInfo->ulBuild <= 6678) /* Warp 2.1x fix?? (just for fun!) */ 491 524 ) 492 525 { 493 kprintf(("Get OTEs32: info summary: Build %d is invalid - invalid fixpack?\n", pKrnlInfo->usBuild));494 usRc = 6;526 kprintf(("GetKernelInfo32: info summary: Build %d is invalid - invalid fixpack?\n", pKrnlInfo->ulBuild)); 527 usRc = ERROR_D32_INVALID_BUILD; 495 528 break; 496 529 } … … 500 533 || (psz[0] == '_' && (psz[1] == 'S' || psz[1] == 's')) /* _SMP */ 501 534 ) 502 pKrnlInfo->fchType = TYPE_SMP; 503 else if (psz[0] == '_' && psz[1] == 'W' && psz[2] == '4') /* _W4 */ 504 pKrnlInfo->fchType = TYPE_W4; 535 pKrnlInfo->fKernel = KF_SMP; 505 536 else 506 pKrnlInfo->fchType = TYPE_UNI; 537 if (*psz != ',' 538 && ( (psz[0] == '_' && psz[1] == 'W' && psz[2] == '4') /* _W4 */ 539 || (psz[1] == '_' && psz[2] == 'W' && psz[3] == '4') /* A_W4 */ 540 || (psz[0] == '_' && psz[1] == 'U' && psz[2] == 'N' && psz[3] == 'I' && psz[4] == '4') /* _UNI4 */ 541 || (psz[1] == '_' && psz[2] == 'U' && psz[3] == 'N' && psz[4] == 'I' && psz[5] == '4') /* A_UNI4 */ 542 ) 543 ) 544 pKrnlInfo->fKernel = KF_W4 | KF_UNI; 545 else 546 pKrnlInfo->fKernel = KF_UNI; 507 547 508 548 509 549 /* Check if its a debug kernel (look for DEBUG at start of object 3-5) */ 510 550 j = 3; 511 pKrnlInfo->fDebug = FALSE;512 551 while (j < 5) 513 552 { … … 520 559 && strncmp((char*)pKrnlOTE[j].ote_base, "DEBUG", 5) == 0) 521 560 { 522 pKrnlInfo->f Debug = TRUE;561 pKrnlInfo->fKernel |= KF_DEBUG; 523 562 break; 524 563 } … … 527 566 528 567 /* Display info */ 529 kprintf(("Get OTEs32: info summary: Build %d, fchType=%d, fDebug=%d\n",530 pKrnlInfo->u sBuild, pKrnlInfo->fchType, pKrnlInfo->fDebug));568 kprintf(("GetKernelInfo32: info summary: Build %d, fKernel=%d\n", 569 pKrnlInfo->ulBuild, pKrnlInfo->fKernel)); 531 570 532 571 /* Break out */ … … 540 579 541 580 /* Set error code if not found */ 542 if (pKrnlInfo->u sBuild == 0)581 if (pKrnlInfo->ulBuild == 0) 543 582 { 544 usRc = 5;545 kprintf(("Get OTEs32: Internal revision was not found!\n"));583 usRc = ERROR_D32_BUILD_INFO_NOT_FOUND; 584 kprintf(("GetKernelInfo32: Internal revision was not found!\n")); 546 585 } 547 586 } 548 587 else 549 usRc = 4;588 usRc = ERROR_D32_NO_OBJECT_TABLE; 550 589 } 551 590 else 552 usRc = 3;591 usRc = ERROR_D32_TOO_MANY_OBJECTS; 553 592 } 554 593 else 555 usRc = 2;594 usRc = ERROR_D32_NO_SWAPMTE; 556 595 } 557 596 else 558 usRc = 1; 559 560 561 if (usRc != 0) 562 kprintf(("GetOTEs32: failed. usRc = %d\n", usRc)); 597 usRc = ERROR_D32_GETOS2KRNL_FAILED; 598 599 if (usRc != NO_ERROR) 600 kprintf(("GetKernelInfo32: failed. usRc = %d\n", usRc)); 563 601 564 602 return (USHORT)(usRc | (usRc != NO_ERROR ? STATUS_DONE | STERR : STATUS_DONE)); 565 603 } 566 #endif /* !DEBUGR3*/567 604 568 605 … … 575 612 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 576 613 */ 577 _Inlineint ModR_M_32bit(char bModRM)614 int ModR_M_32bit(char bModRM) 578 615 { 579 616 if ((bModRM & 0xc0) == 0x80 /* ex. mov ax,[ebp+11145543h] */ 580 617 || ((bModRM & 0xc0) == 0 && (bModRM & 0x07) == 5)) /* ex. mov ebp,[0ff231234h] */ 581 618 { /* 32-bit displacement */ 582 return 5; 619 return 5 + ((bModRM & 0x7) == 0x4); // + SIB 620 } 621 else if ((bModRM & 0xc0) == 0x40) /* ex. mov ecx,[esi]+4fh */ 622 { /* 8-bit displacement */ 623 return 2 + ((bModRM & 0x7) == 0x4); // + SIB 624 } 625 /* no displacement (only /r byte) */ 626 return 1; 627 } 628 629 630 /** 631 * Functions which cacluates the instructionsize given a ModR/M byte. 632 * @returns Number of bytes to add to cb and pach. 633 * @param bModRM ModR/M byte. 634 * @status completely implemented. 635 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 636 */ 637 int ModR_M_16bit(char bModRM) 638 { 639 if ((bModRM & 0xc0) == 0x80 /* ex. mov ax,[ebp+11145543h] */ 640 || ((bModRM & 0xc0) == 0 && (bModRM & 0x07) == 5)) /* ex. mov ebp,[0ff231234h] */ 641 { /* 16-bit displacement */ 642 return 4; 583 643 } 584 644 else if ((bModRM & 0xc0) == 0x40) /* ex. mov ecx,[esi]+4fh */ … … 603 663 * FALSE: Function is to be imported. 604 664 */ 605 staticint interpretFunctionProlog32(char *pach, BOOL fOverload)665 int interpretFunctionProlog32(char *pach, BOOL fOverload) 606 666 { 607 667 int cb = -3; 608 609 668 kprintf2(("interpretFunctionProlog32(0x%08x, %d):\n" 610 669 "\t%02x %02x %02x %02x - %02x %02x %02x %02x\n" … … 630 689 * push ebp 631 690 * or 691 * mov ecx, r/m32 692 * or 693 * jmp dword 694 * or 695 * sub esp, imm8 696 * or 697 * call ptr16:32 698 * or 699 * enter imm16, imm8 (2.1x) 700 * or 701 * mov eax, imm32 (2.1x) 702 * <anything> 703 * or 704 * xor r32, r/m32 705 * or 632 706 * mov eax, msoff32 633 707 * 634 708 */ 635 if ((pach[0] == 0x55 && (pach[1] == 0x8b || pach[1] == 0xa1)) /* t wo first prologs */709 if ((pach[0] == 0x55 && (pach[1] == 0x8b || pach[1] == 0xa1)) /* the two first prologs */ 636 710 || 637 (pach[0] == 0xB8 && (pach[5] == 0xEB || pach[5] == 0x55 ) && !fOverload) /* two next prologs */ 711 (pach[0] == 0xB8 && (pach[5] == 0xEB || pach[5] == 0x55) && !fOverload) /* the two next prologs */ 712 || 713 (pach[0] == 0x8B && !fOverload) /* the next prolog */ 714 || 715 (pach[0] == 0xFF && !fOverload) /* the next prolog */ 716 || 717 (pach[0] == 0x83 && !fOverload) /* the next prolog */ 718 || 719 (pach[0] == 0x9a && !fOverload) /* the next prolog */ 720 || 721 (pach[0] == 0xc8) /* the next prolog */ 722 || 723 (pach[0] == 0xB8 && !fOverload) /* the next prolog */ 724 || 725 (pach[0] == 0x33 && !fOverload) /* the next prolog */ 638 726 || 639 727 (pach[0] == 0xa1 && !fOverload) /* last prolog */ 640 728 ) 641 729 { 642 BOOL fForce; 730 BOOL fForce = FALSE; 731 int cbWord = 4; 643 732 cb = 0; 644 733 while (cb < 5 || fForce) /* 5 is the size of a jump instruction. */ 645 734 { 646 735 int cb2; 736 if (!fForce && cbWord != 4) 737 cbWord = 4; 647 738 fForce = FALSE; 648 739 switch (*pach) … … 656 747 case 0x65: /* gs segment override */ 657 748 fForce = TRUE; 749 break; 750 751 case 0x66: /* 16 bit */ 752 fForce = TRUE; 753 cbWord = 2; 658 754 break; 659 755 … … 703 799 case 0xa1: /* mov eax, moffs16 */ 704 800 case 0xa3: /* mov moffs16, eax */ 705 pach += 4;706 cb += 4;801 pach += cbWord; 802 cb += cbWord; 707 803 break; 708 804 … … 722 818 case 0x8b: /* mov /r */ 723 819 case 0x8d: /* lea /r */ 724 if ((pach[1] & 0x7) == 4 && (pach[1] & 0xc0) != 0xc0) /* invalid instruction!?! */725 return -1;726 820 cb += cb2 = ModR_M_32bit(pach[1]); 727 821 pach += cb2; … … 751 845 ) 752 846 { 753 cb += cb2 = 4 + ModR_M_32bit(pach[1]); /* 4 is the size of the imm32*/847 cb += cb2 = cbWord + ModR_M_32bit(pach[1]); /* cbWord is the size of the imm32/imm16 */ 754 848 pach += cb2; 755 849 } … … 759 853 return -2; 760 854 } 855 break; 856 857 case 0x9a: /* call ptr16:32 */ 858 cb += cb2 = 6; 859 pach += cb2; 860 break; 861 862 case 0xc8: /* enter imm16, imm8 */ 863 cb += cb = 3; 864 pach += cb2; 865 break; 866 867 /* 868 * jmp /digit 869 */ 870 case 0xff: 871 cb += cb2 = cbWord + ModR_M_32bit(pach[1]); /* cbWord is the size of the imm32/imm16 */ 872 pach += cb2; 761 873 break; 762 874 … … 771 883 else 772 884 { 773 kprintf(("interpretFunctionProlog32: unknown prolog start. 0x%x 0x%x 0x%x\n", pach[0], pach[1], pach[2])); 885 kprintf(("interpretFunctionProlog32: unknown prolog start. 0x%x 0x%x 0x%x 0x%x 0x%x\n", 886 pach[0], pach[1], pach[2], pach[3], pach[4])); 774 887 cb = 0; 775 888 } … … 787 900 * FALSE: Function is to be imported. 788 901 */ 789 staticint interpretFunctionProlog16(char *pach, BOOL fOverload)902 int interpretFunctionProlog16(char *pach, BOOL fOverload) 790 903 { 791 904 int cb = -7; … … 809 922 while (cb < 8 || fForce) /* 8 is the size of a 66h prefixed far jump instruction. */ 810 923 { 924 int cb2; 811 925 fForce = FALSE; 812 926 switch (*pach) 813 927 { 928 case 0x06: /* push es */ 929 case 0x0e: /* push cs */ 930 case 0x1e: /* push ds */ 931 case 0x16: /* push ss */ 932 break; 933 814 934 case 0x0f: /* push gs and push fs */ 815 935 if (pach[1] != 0xA0 && pach[1] != 0xA8) … … 888 1008 break; 889 1009 1010 /* complex sized instruction - "/5 ib" */ 1011 case 0x80: /* 5: sub r/m8, imm8 7: cmp r/m8, imm8 */ 1012 case 0x83: /* 5: sub r/m16, imm8 7: cmp r/m16, imm8 */ 1013 if ((pach[1] & 0x38) == (5<<3) 1014 || (pach[1] & 0x38) == (7<<3) 1015 ) 1016 { 1017 cb += cb2 = 1 + ModR_M_16bit(pach[1]); /* 1 is the size of the imm8 */ 1018 pach += cb2; 1019 } 1020 else 1021 { 1022 kprintf(("interpretFunctionProlog16: unknown instruction (-3) 0x%x 0x%x 0x%x\n", pach[0], pach[1], pach[2])); 1023 return -3; 1024 } 1025 break; 1026 1027 890 1028 default: 891 1029 kprintf(("interpretFunctionProlog16: unknown instruction 0x%x 0x%x 0x%x\n", pach[0], pach[1], pach[2])); … … 904 1042 905 1043 906 #ifndef DEBUGR3907 1044 /** 908 1045 * Verifies the aImportTab. … … 913 1050 USHORT _loadds _Far32 _Pascal VerifyImportTab32(void) 914 1051 { 915 int i; 916 int cb; 917 int cbmin; 1052 USHORT usRc; 1053 int i; 1054 int cb; 1055 int cbmin; 918 1056 919 1057 /* VerifyImporTab32 is called before the initroutine! */ … … 921 1059 922 1060 /* Check that pKrnlOTE is set */ 923 if (GetKernelInfo32(NULL) != NO_ERROR) 924 return STATUS_DONE | STERR | 1; 1061 usRc = GetKernelInfo32(NULL); 1062 if (usRc != NO_ERROR) 1063 return (USHORT)(STATUS_DONE | STERR | (usRc & STECODE)); 925 1064 926 1065 /* … … 933 1072 */ 934 1073 kprintf2(("VerifyImportTab32: procedure no.%d is being checked: %s addr=0x%08x iObj=%d offObj=%d\n", 935 i, & _aImportTab[i].achName[0], _aImportTab[i].ulAddress,936 _aImportTab[i].iObject, _aImportTab[i].offObject));1074 i, &aImportTab[i].achName[0], aImportTab[i].ulAddress, 1075 aImportTab[i].iObject, aImportTab[i].offObject)); 937 1076 938 1077 /* Verify that it is found */ 939 if (!_aImportTab[i].fFound) 940 { 941 kprintf(("VerifyImportTab32: procedure no.%d was not fFound!\n", i)); 942 return STATUS_DONE | STERR | 2; 1078 if (!aImportTab[i].fFound) 1079 { 1080 if (aImportTab[i].fType & EPT_NOT_REQ) 1081 continue; 1082 else 1083 { 1084 kprintf(("VerifyImportTab32: procedure no.%d was not fFound!\n", i)); 1085 return STATUS_DONE | STERR | ERROR_D32_PROC_NOT_FOUND; 1086 } 943 1087 } 944 1088 945 1089 /* Verify read/writeable. */ 946 if ( _aImportTab[i].iObject >= pKrnlSMTE->smte_objcnt /* object index valid? */947 || _aImportTab[i].ulAddress < pKrnlOTE[_aImportTab[i].iObject].ote_base/* address valid? */948 || _aImportTab[i].ulAddress + 16 > (pKrnlOTE[_aImportTab[i].iObject].ote_base +949 pKrnlOTE[ _aImportTab[i].iObject].ote_size) /* address valid? */950 || _aImportTab[i].ulAddress - _aImportTab[i].offObject951 != pKrnlOTE[ _aImportTab[i].iObject].ote_base /* offObject ok? */1090 if (aImportTab[i].iObject >= pKrnlSMTE->smte_objcnt /* object index valid? */ 1091 || aImportTab[i].ulAddress < pKrnlOTE[aImportTab[i].iObject].ote_base /* address valid? */ 1092 || aImportTab[i].ulAddress + 16 > (pKrnlOTE[aImportTab[i].iObject].ote_base + 1093 pKrnlOTE[aImportTab[i].iObject].ote_size) /* address valid? */ 1094 || aImportTab[i].ulAddress - aImportTab[i].offObject 1095 != pKrnlOTE[aImportTab[i].iObject].ote_base /* offObject ok? */ 952 1096 ) 953 1097 { 954 1098 kprintf(("VerifyImportTab32: procedure no.%d has an invalid address or object number.!\n" 955 1099 " %s addr=0x%08x iObj=%d offObj=%d\n", 956 i, & _aImportTab[i].achName[0], _aImportTab[i].ulAddress,957 _aImportTab[i].iObject, _aImportTab[i].offObject));958 return STATUS_DONE | STERR | 3;1100 i, &aImportTab[i].achName[0], aImportTab[i].ulAddress, 1101 aImportTab[i].iObject, aImportTab[i].offObject)); 1102 return STATUS_DONE | STERR | ERROR_D32_INVALID_OBJ_OR_ADDR; 959 1103 } 960 1104 961 1105 962 963 if ( _aImportTab[i].ulAddress < 0xffe00000UL)1106 #ifndef R3TST 1107 if (aImportTab[i].ulAddress < 0xff400000UL) 964 1108 { 965 1109 kprintf(("VerifyImportTab32: procedure no.%d has an invalid address, %#08x!\n", 966 i, _aImportTab[i].ulAddress));967 return STATUS_DONE | STERR | 4;1110 i, aImportTab[i].ulAddress)); 1111 return STATUS_DONE | STERR | ERROR_D32_INVALID_ADDRESS; 968 1112 } 969 970 switch (_aImportTab[i].fType & ~EPT_BIT_MASK) 1113 #endif 1114 1115 switch (aImportTab[i].fType & ~(EPT_BIT_MASK | EPT_NOT_REQ)) 971 1116 { 972 1117 case EPT_PROC: … … 975 1120 * Verify known function prolog. 976 1121 */ 977 if (EPT32BitEntry( _aImportTab[i]))1122 if (EPT32BitEntry(aImportTab[i])) 978 1123 { 979 cb = interpretFunctionProlog32((char*) _aImportTab[i].ulAddress,980 _aImportTab[i].fType == EPT_PROC32);1124 cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, 1125 aImportTab[i].fType == EPT_PROC32); 981 1126 cbmin = 5; /* Size of the jump instruction */ 982 1127 } 983 1128 else 984 1129 { 985 cb = interpretFunctionProlog16((char*) _aImportTab[i].ulAddress,986 _aImportTab[i].fType == EPT_PROC16);1130 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, 1131 aImportTab[i].fType == EPT_PROC16); 987 1132 cbmin = 7; /* Size of the far jump instruction */ 988 1133 } … … 991 1136 * Check result of the function prolog interpretations. 992 1137 */ 993 if (cb <= 0 &&cb + cbmin >= MAXSIZE_PROLOG)1138 if (cb <= 0 || cb + cbmin >= MAXSIZE_PROLOG) 994 1139 { /* failed, too small or too large. */ 995 kprintf(("VerifyImportTab32: verify failed for procedure no.%d (c d=%d)\n", i, cb));996 return STATUS_DONE | STERR | 5;1140 kprintf(("VerifyImportTab32: verify failed for procedure no.%d (cb=%d)\n", i, cb)); 1141 return STATUS_DONE | STERR | ERROR_D32_TOO_INVALID_PROLOG; 997 1142 } 998 1143 break; … … 1003 1148 1004 1149 default: 1005 kprintf(("VerifyImportTab32: only EPT_PROC isimplemented\n",i));1150 kprintf(("VerifyImportTab32: invalid type/type not implemented\n",i)); 1006 1151 Int3(); /* temporary fix! */ 1007 return STATUS_DONE | STERR | 6;1152 return STATUS_DONE | STERR | ERROR_D32_NOT_IMPLEMENTED; 1008 1153 } 1009 1154 } … … 1017 1162 * @returns NO_ERROR on success. !0 on error. 1018 1163 */ 1019 staticint importTabInit(void)1164 int importTabInit(void) 1020 1165 { 1021 /* This table must be updated with the overloading functions. */ 1166 /* This table must be updated with the overloading functions. 1167 * It should also hold NOP functions for functions which are of the 1168 * not required type. 1169 */ 1022 1170 static unsigned auFuncs[NBR_OF_KRNLIMPORTS] = 1023 1171 { 1024 (unsigned)myldrRead, 1025 (unsigned)myldrOpen, 1026 (unsigned)myldrClose, 1027 (unsigned)myLDRQAppType, 1028 (unsigned)myldrEnum32bitRelRecs, 1029 0, 1030 0, 1031 0, 1032 0, 1033 0, 1034 0, 1035 0, 1036 0, 1037 (unsigned)&mytkExecPgm, 1038 0, 1039 0, 1040 0, 1041 0 1172 (unsigned)myldrRead, /* 0 */ 1173 (unsigned)myldrOpen, /* 1 */ 1174 (unsigned)myldrClose, /* 2 */ 1175 (unsigned)myLDRQAppType, /* 3 */ 1176 (unsigned)myldrEnum32bitRelRecs,/* 4 */ 1177 0, /* 5 */ 1178 0, /* 6 */ 1179 0, /* 7 */ 1180 0, /* 8 */ 1181 0, /* 9 */ 1182 0, /* 10 */ 1183 0, /* 11 */ 1184 0, /* 12 */ 1185 (unsigned)&mytkExecPgm, /* 13 */ 1186 (unsigned)&mytkStartProcess, /* 14 */ 1187 0, /* 15 */ 1188 0, /* 16 */ 1189 0, /* 17 */ 1190 0, /* 18 */ 1191 0, /* 19 */ 1192 (unsigned)myldrOpenPath, /* 20 */ 1193 0, /* 21 */ 1194 0, /* 22 */ 1195 0, /* 23 */ 1196 0, /* 24 */ 1197 0, /* 25 */ 1198 0, /* 26 */ 1199 0, /* 27 */ 1200 0, /* 28 */ 1201 0, /* 29 */ 1202 0, /* 30 */ 1203 0, /* 31 */ 1204 0, /* 32 */ 1205 0, /* 33 */ 1206 0, /* 34 */ 1207 0, /* 35 */ 1208 0, /* 36 */ 1209 0, /* 37 */ 1210 0, /* 38 */ 1211 0, /* 39 */ 1212 0, /* 40 */ 1213 (unsigned)nopSecPathFromSFN, /* 41 */ 1042 1214 }; 1043 1044 1215 int i; 1045 1216 int cb; 1046 1217 int cbmin; 1218 1219 #ifdef R3TST 1220 R3TstFixImportTab(); 1221 #endif 1047 1222 1048 1223 /* … … 1052 1227 { 1053 1228 /* EPT_VARIMPORTs are skipped */ 1054 if (( _aImportTab[i].fType & ~EPT_BIT_MASK) == EPT_VARIMPORT)1229 if ((aImportTab[i].fType & ~EPT_BIT_MASK) == EPT_VARIMPORT) 1055 1230 continue; 1056 1057 if (EPT32BitEntry(_aImportTab[i])) 1058 { 1059 cb = interpretFunctionProlog32((char*)_aImportTab[i].ulAddress, _aImportTab[i].fType == EPT_PROC32); 1231 /* EPT_NOT_REQ which is not found are set pointing to the nop function provided. */ 1232 if (!aImportTab[i].fFound && (aImportTab[i].fType & EPT_NOT_REQ)) 1233 { 1234 aImportTab[i].ulAddress = auFuncs[i]; 1235 continue; 1236 } 1237 1238 if (EPT32BitEntry(aImportTab[i])) 1239 { 1240 cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, aImportTab[i].fType == EPT_PROC32); 1060 1241 cbmin = 5; /* Size of the jump instruction */ 1061 1242 } 1062 1243 else 1063 1244 { 1064 cb = interpretFunctionProlog16((char*) _aImportTab[i].ulAddress, _aImportTab[i].fType == EPT_PROC16);1245 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, aImportTab[i].fType == EPT_PROC16); 1065 1246 cbmin = 7; /* Size of the far jump instruction */ 1066 1247 } … … 1068 1249 { 1069 1250 kprintf(("ImportTabInit: Verify failed for procedure no.%d, cb=%d\n", i, cb)); 1070 return 1;1251 return ERROR_D32_VERIFY_FAILED; 1071 1252 } 1072 1253 } … … 1077 1258 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 1078 1259 { 1079 switch ( _aImportTab[i].fType)1260 switch (aImportTab[i].fType & ~EPT_NOT_REQ) 1080 1261 { 1081 1262 /* … … 1087 1268 case EPT_PROC32: 1088 1269 { 1089 cb = interpretFunctionProlog32((char*) _aImportTab[i].ulAddress, TRUE);1090 _aImportTab[i].cbProlog = (char)cb;1270 cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, TRUE); 1271 aImportTab[i].cbProlog = (char)cb; 1091 1272 if (cb >= 5 && cb + 5 < MAXSIZE_PROLOG) /* 5(1st): size of jump instruction in the function prolog which jumps to my overloading function */ 1092 1273 { /* 5(2nd): size of jump instruction which jumps back to the original function after executing the prolog copied to the callTab entry for this function. */ … … 1094 1275 * Copy function prolog which will be overwritten by the jmp to calltabl. 1095 1276 */ 1096 memcpy(callTab[i], (void*) _aImportTab[i].ulAddress, (size_t)cb);1277 memcpy(callTab[i], (void*)aImportTab[i].ulAddress, (size_t)cb); 1097 1278 1098 1279 /* … … 1102 1283 */ 1103 1284 callTab[i][cb] = 0xE9; /* jmp */ 1104 *(unsigned long*)(void*)&callTab[i][cb+1] = _aImportTab[i].ulAddress + cb - (unsigned long)&callTab[i][cb+5];1285 *(unsigned long*)(void*)&callTab[i][cb+1] = aImportTab[i].ulAddress + cb - (unsigned long)&callTab[i][cb+5]; 1105 1286 1106 1287 /* 1107 1288 * Jump from original function to my function - an cli(?) could be needed here 1108 1289 */ 1109 *(char*) _aImportTab[i].ulAddress = 0xE9; /* jmp */1110 *(unsigned long*)( _aImportTab[i].ulAddress + 1) = auFuncs[i] - (_aImportTab[i].ulAddress + 5);1290 *(char*)aImportTab[i].ulAddress = 0xE9; /* jmp */ 1291 *(unsigned long*)(aImportTab[i].ulAddress + 1) = auFuncs[i] - (aImportTab[i].ulAddress + 5); 1111 1292 } 1112 1293 else 1113 1294 { /* !fatal! - this could never happen really... */ 1114 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when rehooking it!\n", i));1295 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when rehooking it!\n", i)); 1115 1296 Int3(); /* ipe - later! */ 1116 return 1;1297 return ERROR_D32_VERIFY_FAILED; 1117 1298 } 1118 1299 break; … … 1129 1310 Int3(); 1130 1311 1131 cb = interpretFunctionProlog16((char*) _aImportTab[i].ulAddress, TRUE);1132 _aImportTab[i].cbProlog = (char)cb;1312 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, TRUE); 1313 aImportTab[i].cbProlog = (char)cb; 1133 1314 if (cb >= 8 && cb + 7 < MAXSIZE_PROLOG) /* 8: size of a 16:32 jump which jumps to my overloading function (prefixed with 66h in a 16-bit segment) */ 1134 1315 { /* 7: size of a 16:32 jump which is added to the call tab */ … … 1136 1317 * Copy function prolog which is to be overwritten. 1137 1318 */ 1138 memcpy(callTab[i], (void*) _aImportTab[i].ulAddress, (size_t)cb);1319 memcpy(callTab[i], (void*)aImportTab[i].ulAddress, (size_t)cb); 1139 1320 1140 1321 /* … … 1143 1324 */ 1144 1325 callTab[i][cb] = 0xEA; /* jmp far ptr */ 1145 *(unsigned long*)(void*)&callTab[i][cb+1] = _aImportTab[i].offObject;1146 *(unsigned short*)(void*)&callTab[i][cb+5] = _aImportTab[i].usSel;1326 *(unsigned long*)(void*)&callTab[i][cb+1] = aImportTab[i].offObject; 1327 *(unsigned short*)(void*)&callTab[i][cb+5] = aImportTab[i].usSel; 1147 1328 1148 1329 /* … … 1150 1331 * 0x66 0xEA <four byte target address> <two byte target selector> 1151 1332 */ 1152 *(char*)( _aImportTab[i].ulAddress ) = 0x66; /* operandsize prefix */1153 *(char*)( _aImportTab[i].ulAddress + 1) = 0xEA; /* jmp far ptr */1154 *(unsigned long*)( _aImportTab[i].ulAddress + 2) = auFuncs[i]; /* FIXME? */1155 *(unsigned short*)( _aImportTab[i].ulAddress + 6) = _R0FlatCS16; /* FIXME */1333 *(char*)(aImportTab[i].ulAddress ) = 0x66; /* operandsize prefix */ 1334 *(char*)(aImportTab[i].ulAddress + 1) = 0xEA; /* jmp far ptr */ 1335 *(unsigned long*)(aImportTab[i].ulAddress + 2) = auFuncs[i]; /* FIXME? */ 1336 *(unsigned short*)(aImportTab[i].ulAddress + 6) = _R0FlatCS16; /* FIXME */ 1156 1337 } 1157 1338 else 1158 1339 { /* !fatal! - this could never happen really... */ 1159 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when rehooking it!\n", i));1340 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when rehooking it!\n", i)); 1160 1341 Int3(); /* ipe - later! */ 1161 return 1;1342 return ERROR_D32_VERIFY_FAILED; 1162 1343 } 1163 1344 break; … … 1171 1352 case EPT_PROCIMPORT32: 1172 1353 { 1173 cb = interpretFunctionProlog32((char*) _aImportTab[i].ulAddress, FALSE);1174 _aImportTab[i].cbProlog = (char)cb;1354 cb = interpretFunctionProlog32((char*)aImportTab[i].ulAddress, FALSE); 1355 aImportTab[i].cbProlog = (char)cb; 1175 1356 if (cb > 0) /* Since no prolog part is copied to the function table, it's ok as long as the prolog has been recognzied. */ 1176 1357 { … … 1181 1362 */ 1182 1363 callTab[i][0] = 0xE9; /* jmp */ 1183 *(unsigned*)(void*)&callTab[i][1] = _aImportTab[i].ulAddress - (unsigned)&callTab[i][5];1364 *(unsigned*)(void*)&callTab[i][1] = aImportTab[i].ulAddress - (unsigned)&callTab[i][5]; 1184 1365 } 1185 1366 else 1186 1367 { /* !fatal! - this should never really happen... */ 1187 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when importing it!\n", i));1368 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when importing it!\n", i)); 1188 1369 Int3(); /* ipe - later! */ 1189 return 1;1370 return ERROR_D32_VERIFY_FAILED; 1190 1371 } 1191 1372 break; … … 1199 1380 case EPT_PROCIMPORT16: 1200 1381 { 1201 cb = interpretFunctionProlog16((char*) _aImportTab[i].ulAddress, FALSE);1202 _aImportTab[i].cbProlog = (char)cb;1382 cb = interpretFunctionProlog16((char*)aImportTab[i].ulAddress, FALSE); 1383 aImportTab[i].cbProlog = (char)cb; 1203 1384 if (cb > 0) /* Since no prolog part is copied to the function table, it's ok as long as the prolog has been recognzied. */ 1204 1385 { … … 1208 1389 */ 1209 1390 callTab[i][0] = 0xEA; /* jmp far ptr */ 1210 *(unsigned long*)(void*)&callTab[i][1] = _aImportTab[i].offObject;1211 *(unsigned short*)(void*)&callTab[i][5] = _aImportTab[i].usSel;1391 *(unsigned long*)(void*)&callTab[i][1] = aImportTab[i].offObject; 1392 *(unsigned short*)(void*)&callTab[i][5] = aImportTab[i].usSel; 1212 1393 } 1213 1394 else 1214 1395 { /* !fatal! - this should never really happen... */ 1215 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when importing it!\n", i));1396 kprintf(("ImportTabInit: FATAL verify failed for procedure no.%d when importing it!\n", i)); 1216 1397 Int3(); /* ipe - later! */ 1217 return 1;1398 return ERROR_D32_VERIFY_FAILED; 1218 1399 } 1219 1400 break; … … 1231 1412 case EPT_VARIMPORT32: 1232 1413 case EPT_VARIMPORT16: 1233 _aImportTab[i].cbProlog = (char)0;1234 *(unsigned long*)(void*)&callTab[i][0] = _aImportTab[i].ulAddress;1235 *(unsigned long*)(void*)&callTab[i][4] = _aImportTab[i].offObject;1236 *(unsigned short*)(void*)&callTab[i][8] = _aImportTab[i].usSel;1237 *(unsigned short*)(void*)&callTab[i][0xa] = (unsigned short) _aImportTab[i].offObject;1238 *(unsigned short*)(void*)&callTab[i][0xc] = _aImportTab[i].usSel;1414 aImportTab[i].cbProlog = (char)0; 1415 *(unsigned long*)(void*)&callTab[i][0] = aImportTab[i].ulAddress; 1416 *(unsigned long*)(void*)&callTab[i][4] = aImportTab[i].offObject; 1417 *(unsigned short*)(void*)&callTab[i][8] = aImportTab[i].usSel; 1418 *(unsigned short*)(void*)&callTab[i][0xa] = (unsigned short)aImportTab[i].offObject; 1419 *(unsigned short*)(void*)&callTab[i][0xc] = aImportTab[i].usSel; 1239 1420 break; 1240 1421 … … 1242 1423 kprintf(("ImportTabInit: unsupported type. (procedure no.%d, cb=%d)\n", i, cb)); 1243 1424 Int3(); /* ipe - later! */ 1244 return 1;1425 return ERROR_D32_VERIFY_FAILED; 1245 1426 } /* switch - type */ 1246 1427 } /* for */ … … 1248 1429 return NO_ERROR; 1249 1430 } 1250 #endif /* !DEBUGR3 */ 1251 1252 1253 1254 1255 /******************************************************************************* 1256 * Ring-3 Debug Stuff 1257 *******************************************************************************/ 1258 #ifdef DEBUGR3 1259 #include <stdio.h> 1260 1261 void main(void) 1431 1432 1433 #ifdef R3TST 1434 /** 1435 * Creates a fake kernel MTE, SMTE and OTE for use while testing in Ring3. 1436 * @returns Pointer to the fake kernel MTE. 1437 * @status completely implemented. 1438 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1439 */ 1440 PMTE GetOS2KrnlMTETst(void) 1262 1441 { 1263 char ach_ldrRead[] = { 1264 0x55, 0x8b, 0xec, 0x8d, 0x65, 0xf8, 0x53, 0x56, 1265 0x57, 0x33, 0xd2, 0x42, 0x89, 0x55, 0xf8, 0x38, 1266 0x35, 0xce, 0x70, 0x00, 0x00, 0x75, 0x4d, 0x8b, 1267 0x55, 0x08, 0x66, 0x83, 0xfa, 0xff, 0x74, 0x62 1268 }; 1269 char ach_ldrOpen[] = { 1270 0x55, 0x8b, 0xec, 0x33, 0xc0, 0x38, 0x05, 0xce, 1271 0x70, 0x00, 0x00, 0x75, 0x4b, 0x50, 0xff, 0x75, 1272 0x08, 0x6a, 0x01, 0x68, 0xa3, 0x00, 0x00, 0x00, 1273 0xff, 0x75, 0x0c, 0xff, 0x15, 0xc4, 0xc1, 0x0d 1274 }; 1275 char ach_ldrClose[] = { 1276 0x55, 0x8b, 0xec, 0x33, 0xc0, 0x38, 0x05, 0xce, 1277 0x70, 0x00, 0x00, 0x75, 0x13, 0x8b, 0x55, 0x08, 1278 0x0f, 0xb7, 0xd2, 0x66, 0x83, 0xfa, 0xff, 0x74, 1279 0x07, 0x52, 0xff, 0x15, 0xcc, 0xc1, 0x0d, 0x00 1280 }; 1281 char ach_LDRQAppType[] = { 1282 0x55, 0x8b, 0x0d, 0xa0, 0x0a, 0x00, 0x00, 0x8b, 1283 0xec, 0x83, 0xec, 0x3c, 0x53, 0x81, 0xc1, 0x24, 1284 0x06, 0x00, 0x00, 0x57, 0x56, 0x6a, 0xff, 0x66, 1285 0xc7, 0x45, 0xc6, 0x00, 0x00, 0x51, 0xe8, 0x38 1286 }; 1287 char ach_ldrEnum32bitRelRecs[] = { 1288 0x55, 0xa1, 0xe8, 0xcf, 0x0d, 0x00, 0x8b, 0xec, 1289 0x83, 0xec, 0x5c, 0x53, 0x8b, 0x55, 0x08, 0x57, 1290 0x56, 0x8b, 0x52, 0x04, 0xf6, 0x40, 0x04, 0x80, 1291 0x89, 0x55, 0xfc, 0x0f, 0x84, 0x10, 0x01, 0x00 1292 }; 1293 char ach_IOSftOpen[] = { 1294 0x55, 0x8b, 0xec, 0x8d, 0xa5, 0xa0, 0xfe, 0xff, 1295 0xff, 0xf6, 0x05, 0x95, 0x2d, 0x00, 0x00, 0x80, 1296 0x74, 0x13, 0x66, 0x68, 0x50, 0x30, 0xff, 0x75, 1297 0x08, 0x6a, 0x3c, 0x6a, 0x06, 0xe8, 0x5a, 0x03 1298 }; 1299 char ach_IOSftClose[] = { 1300 0x55, 0x8b, 0xec, 0x8d, 0xa5, 0x28, 0xff, 0xff, 1301 0xff, 0xf6, 0x05, 0x95, 0x2d, 0x00, 0x00, 0x80, 1302 0x74, 0x16, 0x50, 0x66, 0x68, 0x51, 0x30, 0x8b, 1303 0x45, 0x08, 0x50, 0x6a, 0x0c, 0x6a, 0x06, 0xe8 1304 }; 1305 char ach_IOSftTransPath[] = { 1306 0x55, 0x8b, 0xec, 0x8d, 0xa5, 0xd8, 0xfd, 0xff, 1307 0xff, 0x53, 0x56, 0x57, 0x1e, 0x06, 0xa1, 0xa4, 1308 0x0a, 0x00, 0x00, 0x66, 0x8d, 0x9d, 0xe2, 0xfe, 1309 0xff, 0xff, 0x66, 0x89, 0x98, 0xf6, 0x01, 0x00 1310 }; 1311 char ach_IOSftReadAt[] = { 1312 0xb8, 0xc4, 0x68, 0x14, 0x00, 0xeb, 0x05, 0xb8, 1313 0xcc, 0x68, 0x14, 0x00, 0x55, 0x8b, 0xec, 0x8d, 1314 0xa5, 0x20, 0xff, 0xff, 0xff, 0xf6, 0x05, 0x95, 1315 0x2d, 0x00, 0x00, 0x80, 0x74, 0x28, 0x50, 0x66 1316 }; 1317 char ach_IOSftWriteAt[] = { 1318 0xb8, 0xcc, 0x68, 0x14, 0x00, 0x55, 0x8b, 0xec, 1319 0x8d, 0xa5, 0x20, 0xff, 0xff, 0xff, 0xf6, 0x05, 1320 0x95, 0x2d, 0x00, 0x00, 0x80, 0x74, 0x28, 0x50, 1321 0x66, 0x68, 0x52, 0x30, 0x8b, 0x45, 0x08, 0x25 1322 }; 1323 char ach_SftFileSize[] = { 1324 0x55, 0x8b, 0xec, 0x8d, 0xa5, 0x28, 0xff, 0xff, 1325 0xff, 0x57, 0x56, 0x53, 0xc6, 0x85, 0x2b, 0xff, 1326 0xff, 0xff, 0x00, 0x8b, 0x35, 0xa4, 0x0a, 0x00, 1327 0x00, 0xf6, 0x46, 0x04, 0x01, 0x74, 0x0a, 0x80 1328 }; 1329 char ach_VMAllocMem[] = { 1330 0xa1, 0xe8, 0xcf, 0x0d, 0x00, 0x55, 0x8b, 0xec, 1331 0x83, 0xec, 0x44, 0x53, 0x57, 0xf6, 0x40, 0x04, 1332 0x80, 0x56, 0x0f, 0x84, 0x34, 0x01, 0x00, 0x00, 1333 0xf6, 0x00, 0x40, 0x74, 0x44, 0xa1, 0xcc, 0x02 1334 }; 1335 char ach_VMGetOwner[] = { 1336 0x55, 0x8b, 0xec, 0x83, 0xec, 0x30, 0x57, 0x66, 1337 0x8b, 0x4d, 0x08, 0x66, 0x89, 0x4d, 0xd8, 0xf6, 1338 0xc1, 0x04, 0x75, 0x39, 0x80, 0x3d, 0x40, 0x8c, 1339 0x00, 0x00, 0x00, 0x74, 0x07, 0xa1, 0xac, 0x0a 1340 }; 1341 char achg_tkExecPgm[] = { 1342 0x55, 0x8b, 0xec, 0x8d, 0x65, 0xa4, 0x66, 0x89, 1343 0x5d, 0xf4, 0x66, 0x8c, 0x45, 0xf6, 0x66, 0x89, 1344 0x55, 0xfc, 0x66, 0x8c, 0x5d, 0xfe, 0x66, 0x89, 1345 0x75, 0xf0, 0x66, 0x89, 0x7d, 0xf2, 0xc7, 0x45 1346 }; 1347 char achf_FuStrLenZ[] = { 1348 0x6a, 0x02, 0x52, 0x66, 0x55, 0x0f, 0xa8, 0x68, 1349 0x0c, 0x00, 0x0f, 0xa9, 0x65, 0x67, 0x66, 0x8b, 1350 0x2d, 0xa8, 0x0a, 0x00, 0x00, 0x65, 0x67, 0xff, 1351 0xb5, 0xb4, 0x1f, 0x00, 0x00, 0x65, 0x67, 0x66 1352 }; 1353 char achf_FuStrLen[] = { 1354 0x6a, 0x02, 0x52, 0x66, 0x55, 0x0f, 0xa8, 0x68, 1355 0x0c, 0x00, 0x0f, 0xa9, 0x65, 0x67, 0x66, 0x8b, 1356 0x2d, 0xa8, 0x0a, 0x00, 0x00, 0x65, 0x67, 0xff, 1357 0xb5, 0xb4, 0x1f, 0x00, 0x00, 0x65, 0x67, 0x66 1358 }; 1359 char achf_FuBuff[] = { 1360 0x6a, 0x02, 0x52, 0x66, 0x55, 0x0f, 0xa8, 0x68, 1361 0x0c, 0x00, 0x0f, 0xa9, 0x65, 0x67, 0x66, 0x8b, 1362 0x2d, 0xa8, 0x0a, 0x00, 0x00, 0x65, 0x67, 0xff, 1363 0xb5, 0xb4, 0x1f, 0x00, 0x00, 0x65, 0x67, 0x66 1364 }; 1365 char achf_VMObjHandleInfo[] = { 1366 0x55, 0x8B, 0x0D, 0x9C, 0xBF, 0x0D, 0x00, 0x8B, 1367 0xEC, 0x83, 0xEC, 0x0C, 0x53, 0x57, 0x8D, 0x55, 1368 0xF8 1369 }; 1370 1371 1372 char *aProcs[] = 1442 static MTE KrnlMTE; 1443 static SMTE KrnlSMTE; 1444 1445 KrnlMTE.mte_swapmte = &KrnlSMTE; 1446 KrnlSMTE.smte_objtab = &aKrnlOTE[0]; 1447 KrnlSMTE.smte_objcnt = cObjectsFake; 1448 1449 return &KrnlMTE; 1450 } 1451 1452 /** 1453 * -Ring-3 testing- 1454 * Changes the entries in aImportTab to point to their fake equivalents. 1455 * @returns void 1456 * @param void 1457 * @status completely implemented. 1458 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1459 * @remark Called before the aImportTab array is used/verified. 1460 */ 1461 VOID R3TstFixImportTab(VOID) 1462 { 1463 struct _TstFaker 1373 1464 { 1374 ach_ldrRead , 1375 ach_ldrOpen , 1376 ach_ldrClose , 1377 ach_LDRQAppType , 1378 ach_ldrEnum32bitRelRecs, 1379 ach_IOSftOpen , 1380 ach_IOSftClose , 1381 ach_IOSftTransPath , 1382 ach_IOSftReadAt , 1383 ach_IOSftWriteAt , 1384 ach_SftFileSize , 1385 ach_VMAllocMem , 1386 ach_VMGetOwner , 1387 achg_tkExecPgm , 1388 achf_FuStrLenZ , 1389 achf_FuStrLen , 1390 achf_FuBuff , 1391 achf_VMObjHandleInfo , 1392 NULL 1465 unsigned uAddress; 1466 int fObj; /* 1 = CODE32, 2 = CODE16, 3 = DATA32, 4 = DATA16 */ 1467 } 1468 aTstFakers[NBR_OF_KRNLIMPORTS] = 1469 { 1470 {(unsigned)fakeldrRead, 1}, 1471 {(unsigned)fakeldrOpen, 1}, 1472 {(unsigned)fakeldrClose, 1}, 1473 {(unsigned)fakeLDRQAppType, 1}, 1474 {(unsigned)fakeldrEnum32bitRelRecs, 1}, 1475 {(unsigned)fakeIOSftOpen, 1}, 1476 {(unsigned)fakeIOSftClose, 1}, 1477 {(unsigned)fakeIOSftTransPath, 1}, 1478 {(unsigned)fakeIOSftReadAt, 1}, 1479 {(unsigned)fakeIOSftWriteAt, 1}, 1480 {(unsigned)fakeSftFileSize, 1}, 1481 {(unsigned)fakeVMAllocMem, 1}, 1482 {(unsigned)fakeVMGetOwner, 1}, 1483 {(unsigned)fakeg_tkExecPgm, 1}, 1484 {(unsigned)fake_tkStartProcess, 1}, 1485 {(unsigned)fakef_FuStrLenZ, 2}, 1486 {(unsigned)fakef_FuStrLen, 2}, 1487 {(unsigned)fakef_FuBuff, 2}, 1488 {(unsigned)fakeVMObjHandleInfo, 1}, 1489 {(unsigned)fakeldrASMpMTEFromHandle,1}, 1490 {(unsigned)fakeldrOpenPath, 1}, 1491 {(unsigned)fakeLDRClearSem, 1}, 1492 {(unsigned)fakeldrFindModule, 1}, 1493 {(unsigned)fakeKSEMRequestMutex, 1}, 1494 {(unsigned)fakeKSEMReleaseMutex, 1}, 1495 {(unsigned)fakeKSEMQueryMutex, 1}, 1496 {(unsigned)fakeKSEMInit, 1}, 1497 {(unsigned)&fakeLDRSem, 3}, 1498 {(unsigned)&fakeLDRLibPath, 3}, 1499 {(unsigned)fakeTKSuBuff, 1}, 1500 {(unsigned)fakeTKFuBuff, 1}, 1501 {(unsigned)fakeTKFuBufLen, 1}, 1502 {(unsigned)fakeldrValidateMteHandle,1}, 1503 {(unsigned)&fakepTCBCur, 4}, 1504 {(unsigned)&fakepPTDACur, 4}, 1505 {(unsigned)&fakeptda_start, 4}, 1506 {(unsigned)&fakeptda_environ, 4}, 1507 {(unsigned)&fakeptda_ptdasem, 4}, 1508 {(unsigned)&fakeptda_module, 4}, 1509 {(unsigned)&fakeptda_pBeginLIBPATH, 4}, 1510 {(unsigned)&fakeldrpFileNameBuf, 3}, 1511 {(unsigned)&fakeSecPathFromSFN, 3} 1393 1512 }; 1394 1513 int i; 1395 1514 1396 /* loop thru procs */ 1397 for (i = 0; aProcs[i] != NULL; i++) 1515 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 1398 1516 { 1399 unsigned cb; 1400 printf("Proc.no.%i\n", i); 1401 if (i < 14 || i > 16) 1402 cb = interpretFunctionProlog32(aProcs[i], i < 5 || i == 13); 1403 else 1404 cb = interpretFunctionProlog16(aProcs[i], FALSE); 1405 printf(" cb=%d\n\n", cb); 1406 } 1517 switch (aImportTab[i].fType) 1518 { 1519 case EPT_PROC32: 1520 if (aTstFakers[i].fObj != 1) 1521 kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (PROC32)\n", i)); 1522 break; 1523 case EPT_PROCIMPORT32: 1524 if (aTstFakers[i].fObj != 1) 1525 kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (PROCIMPORT32)\n", i)); 1526 break; 1527 case EPT_PROCIMPORT16: 1528 if (aTstFakers[i].fObj != 2) 1529 kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (PROCIMPORT16)\n", i)); 1530 break; 1531 case EPT_VARIMPORT32: 1532 case EPT_VARIMPORT16: 1533 if (aTstFakers[i].fObj != 3 && aTstFakers[i].fObj != 4) 1534 kprintf(("R3TstFixImportTab: invalid segment config for entry %i. (VARIMPORT32/16)\n", i)); 1535 break; 1536 } /* switch - type */ 1537 1538 aImportTab[i].ulAddress = aTstFakers[i].uAddress; 1539 switch (aTstFakers[i].fObj) 1540 { 1541 case 1: 1542 aImportTab[i].usSel = GetSelectorCODE32(); 1543 aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&CODE32START; 1544 break; 1545 case 2: 1546 aImportTab[i].usSel = GetSelectorCODE16(); 1547 aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&CODE16START; 1548 break; 1549 case 3: 1550 aImportTab[i].usSel = GetSelectorDATA32(); 1551 aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&DATA32START; 1552 break; 1553 case 4: 1554 aImportTab[i].usSel = GetSelectorDATA16(); 1555 aImportTab[i].offObject = aTstFakers[i].uAddress - (unsigned)&DATA16START; 1556 break; 1557 default: 1558 kprintf(("R3TstFixImportTab: invalid segment config for entry %i.\n", i)); 1559 } 1560 } /* for */ 1407 1561 } 1408 1562 #endif 1563 1564 /** 1565 * Dummy nop function if SecPathFromSFN isn't found. 1566 */ 1567 PSZ SECCALL nopSecPathFromSFN(SFN hFile) 1568 { 1569 NOREF(hFile); 1570 return NULL; 1571 }
Note:
See TracChangeset
for help on using the changeset viewer.