- Timestamp:
- Apr 9, 2001, 10:50:16 PM (24 years ago)
- Location:
- trunk/src/helpers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh2.c
r56 r57 810 810 *@@changed V0.9.1 (2000-02-13) [umoeller]: fixed 32-bits flag 811 811 *@@changed V0.9.7 (2000-12-20) [lafaix]: fixed ulNewHeaderOfs 812 *@@changed V0.9.10 (2001-04-08) [umoeller]: now setting ppExec only if NO_ERROR is returned 812 813 */ 813 814 … … 819 820 ULONG ulAction = 0; 820 821 HFILE hFile; 822 PEXECUTABLE pExec = NULL; 821 823 822 824 if (!ppExec) 823 825 return (ERROR_INVALID_PARAMETER); 824 826 825 *ppExec = (PEXECUTABLE)malloc(sizeof(EXECUTABLE));826 if (!( *ppExec))827 pExec = (PEXECUTABLE)malloc(sizeof(EXECUTABLE)); 828 if (!(pExec)) 827 829 return (ERROR_NOT_ENOUGH_MEMORY); 828 830 829 memset( (*ppExec), 0, sizeof(EXECUTABLE));831 memset(pExec, 0, sizeof(EXECUTABLE)); 830 832 831 833 if (!(arc = DosOpen((PSZ)pcszExecutable, … … 850 852 851 853 // read old DOS EXE header 852 (*ppExec)->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));853 if (!( (*ppExec)->pDosExeHeader))854 pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER)); 855 if (!(pExec->pDosExeHeader)) 854 856 arc = ERROR_NOT_ENOUGH_MEMORY; 855 857 else … … 862 864 &ulLocal))) // out: new offset 863 865 && (!(arc = DosRead(hFile, 864 (*ppExec)->pDosExeHeader,866 pExec->pDosExeHeader, 865 867 sizeof(DOSEXEHEADER), 866 &( (*ppExec)->cbDosExeHeader))))868 &(pExec->cbDosExeHeader)))) 867 869 ) 868 870 { 869 871 // now check if we really have a DOS header 870 if ( (*ppExec)->pDosExeHeader->usDosExeID != 0x5a4d)872 if (pExec->pDosExeHeader->usDosExeID != 0x5a4d) 871 873 arc = ERROR_INVALID_EXE_SIGNATURE; 872 874 else 873 875 { 874 876 // we have a DOS header: 875 if ( (*ppExec)->pDosExeHeader->usRelocTableOfs < 0x40)877 if (pExec->pDosExeHeader->usRelocTableOfs < 0x40) 876 878 { 877 879 // neither LX nor PE nor NE: 878 (*ppExec)->ulOS = EXEOS_DOS3;879 (*ppExec)->ulExeFormat = EXEFORMAT_OLDDOS;880 pExec->ulOS = EXEOS_DOS3; 881 pExec->ulExeFormat = EXEFORMAT_OLDDOS; 880 882 } 881 883 else … … 886 888 887 889 if ( (!(arc = DosSetFilePtr(hFile, 888 (*ppExec)->pDosExeHeader->ulNewHeaderOfs,890 pExec->pDosExeHeader->ulNewHeaderOfs, 889 891 FILE_BEGIN, 890 892 &ulLocal))) … … 900 902 // reset file ptr 901 903 DosSetFilePtr(hFile, 902 (*ppExec)->pDosExeHeader->ulNewHeaderOfs,904 pExec->pDosExeHeader->ulNewHeaderOfs, 903 905 FILE_BEGIN, 904 906 &ulLocal); … … 907 909 { 908 910 // New Executable: 909 (*ppExec)->ulExeFormat = EXEFORMAT_NE;911 pExec->ulExeFormat = EXEFORMAT_NE; 910 912 // allocate NE header 911 (*ppExec)->pNEHeader = (PNEHEADER)malloc(sizeof(NEHEADER));912 if (!( (*ppExec)->pNEHeader))913 pExec->pNEHeader = (PNEHEADER)malloc(sizeof(NEHEADER)); 914 if (!(pExec->pNEHeader)) 913 915 arc = ERROR_NOT_ENOUGH_MEMORY; 914 916 else 915 917 // read in NE header 916 918 if (!(arc = DosRead(hFile, 917 (*ppExec)->pNEHeader,919 pExec->pNEHeader, 918 920 sizeof(NEHEADER), 919 &( (*ppExec)->cbNEHeader))))920 if ( (*ppExec)->cbNEHeader == sizeof(NEHEADER))921 pbCheckOS = &( (*ppExec)->pNEHeader->bTargetOS);921 &(pExec->cbNEHeader)))) 922 if (pExec->cbNEHeader == sizeof(NEHEADER)) 923 pbCheckOS = &(pExec->pNEHeader->bTargetOS); 922 924 } 923 925 else if ( (memcmp(achNewHeaderType, "LX", 2) == 0) … … 927 929 { 928 930 // OS/2 Linear Executable: 929 (*ppExec)->ulExeFormat = EXEFORMAT_LX;931 pExec->ulExeFormat = EXEFORMAT_LX; 930 932 // allocate LX header 931 (*ppExec)->pLXHeader = (PLXHEADER)malloc(sizeof(LXHEADER));932 if (!( (*ppExec)->pLXHeader))933 pExec->pLXHeader = (PLXHEADER)malloc(sizeof(LXHEADER)); 934 if (!(pExec->pLXHeader)) 933 935 arc = ERROR_NOT_ENOUGH_MEMORY; 934 936 else 935 937 // read in LX header 936 938 if (!(arc = DosRead(hFile, 937 (*ppExec)->pLXHeader,939 pExec->pLXHeader, 938 940 sizeof(LXHEADER), 939 &( (*ppExec)->cbLXHeader))))940 if ( (*ppExec)->cbLXHeader == sizeof(LXHEADER))941 pbCheckOS = (PBYTE)(&( (*ppExec)->pLXHeader->usTargetOS));941 &(pExec->cbLXHeader)))) 942 if (pExec->cbLXHeader == sizeof(LXHEADER)) 943 pbCheckOS = (PBYTE)(&(pExec->pLXHeader->usTargetOS)); 942 944 } 943 945 else if (memcmp(achNewHeaderType, "PE", 2) == 0) 944 946 { 945 (*ppExec)->ulExeFormat = EXEFORMAT_PE;946 (*ppExec)->ulOS = EXEOS_WIN32;947 (*ppExec)->f32Bits = TRUE;947 pExec->ulExeFormat = EXEFORMAT_PE; 948 pExec->ulOS = EXEOS_WIN32; 949 pExec->f32Bits = TRUE; 948 950 949 951 // can't parse this yet … … 959 961 { 960 962 case NEOS_OS2: 961 (*ppExec)->ulOS = EXEOS_OS2;962 if ( (*ppExec)->ulExeFormat == EXEFORMAT_LX)963 (*ppExec)->f32Bits = TRUE;963 pExec->ulOS = EXEOS_OS2; 964 if (pExec->ulExeFormat == EXEFORMAT_LX) 965 pExec->f32Bits = TRUE; 964 966 break; 965 967 966 968 case NEOS_WIN16: 967 (*ppExec)->ulOS = EXEOS_WIN16;969 pExec->ulOS = EXEOS_WIN16; 968 970 break; 969 971 970 972 case NEOS_DOS4: 971 (*ppExec)->ulOS = EXEOS_DOS4;973 pExec->ulOS = EXEOS_DOS4; 972 974 break; 973 975 974 976 case NEOS_WIN386: 975 (*ppExec)->ulOS = EXEOS_WIN386;976 (*ppExec)->f32Bits = TRUE;977 pExec->ulOS = EXEOS_WIN386; 978 pExec->f32Bits = TRUE; 977 979 break; 978 980 } … … 981 983 } 982 984 } // end if (!(arc = DosSetFilePtr(hFile, 983 } // end if (*ppExec)->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));985 } // end if pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER)); 984 986 985 987 // store exec's HFILE 986 (*ppExec)->hfExe = hFile;988 pExec->hfExe = hFile; 987 989 } // end if (!(arc = DosOpen((PSZ)pcszExecutable, 988 990 989 991 if (arc != NO_ERROR) 990 992 // error: clean up 991 doshExecClose(*ppExec); 993 doshExecClose(pExec); 994 else 995 *ppExec = pExec; 992 996 993 997 return (arc); … … 3005 3009 *@@added V0.9.0 [umoeller] 3006 3010 *@@changed V0.9.9 (2001-04-07) [umoeller]: added transparent LVM support; changed prototype 3007 *@@changed V0.9.9 (2001-04-07) [umoeller]: added memory leaks on errors3011 *@@changed V0.9.9 (2001-04-07) [umoeller]: fixed memory leaks on errors 3008 3012 */ 3009 3013 -
trunk/src/helpers/procstat.c
r44 r57 84 84 * 85 85 *@@added V0.9.3 (2000-05-05) [umoeller] 86 */ 87 88 PQPROCSTAT16 prc16GetInfo(APIRET *parc) // out: error, ptr can be NULL 86 *@@changed V0.9.10 (2001-04-08) [umoeller]: this returned != NULL even though item was freed, fixed 87 *@@changed V0.9.10 (2001-04-08) [umoeller]: now using DosAllocMem, raised bufsize, changed prototype 88 */ 89 90 APIRET prc16GetInfo(PQPROCSTAT16 *ppps) // out: error, ptr can be NULL 89 91 { 90 92 APIRET arc = NO_ERROR; 91 PQPROCSTAT16 pps = (PQPROCSTAT16)malloc(0x8000); 93 PQPROCSTAT16 pps = NULL; 94 95 /* PQPROCSTAT16 pps = (PQPROCSTAT16)malloc(0x8000); 92 96 if (!pps) 93 97 arc = ERROR_NOT_ENOUGH_MEMORY; 94 else 95 { 96 arc = DosQProcStatus(pps, 0x8000); 97 if (arc != NO_ERROR) 98 free(pps); 99 } 100 101 if (parc) 102 *parc = arc; 103 104 return (pps); 98 else */ 99 100 if (!ppps) 101 return (ERROR_INVALID_PARAMETER); 102 103 // changed allocation V0.9.10 (2001-04-08) [umoeller]: 104 // malloc didn't guarantee that the object did not 105 // cross a 64K boundary, which could cause DosQProcStat 106 // to fail... 107 #define BUF_SIZE 0xFFFF // raised from 0x8000 108 109 if (!(arc = DosAllocMem((VOID**)&pps, 110 BUF_SIZE, 111 PAG_READ | PAG_WRITE | PAG_COMMIT 112 | OBJ_TILE // 16-bit compatible, ignored really 113 ))) 114 { 115 if (arc = DosQProcStatus(pps, BUF_SIZE)) 116 { 117 // error: 118 DosFreeMem(pps); // V0.9.10 (2001-04-08) [umoeller] 119 120 // and even worse, I forgot to set the return ptr 121 // to NULL, so this was freed twice... I guess 122 // this produced the crashes in WarpIN with the 123 // KILLPROCESS attribute... V0.9.10 (2001-04-08) [umoeller] 124 pps = NULL; 125 } 126 } 127 128 *ppps = pps; 129 130 return (arc); 105 131 } 106 132 … … 110 136 * 111 137 *@@added V0.9.3 (2000-05-05) [umoeller] 112 */ 113 114 VOID prc16FreeInfo(PQPROCSTAT16 pInfo) 115 { 116 if (pInfo) 117 free(pInfo); 138 *@@changed V0.9.10 (2001-04-08) [umoeller]: now using DosFreeMem 139 */ 140 141 APIRET prc16FreeInfo(PQPROCSTAT16 pInfo) 142 { 143 if (!pInfo) 144 return ERROR_INVALID_PARAMETER; 145 146 return DosFreeMem(pInfo); 118 147 } 119 148 … … 476 505 *@@added V0.9.1 (2000-02-12) [umoeller] 477 506 *@@changed V0.9.3 (2000-05-01) [umoeller]: now using DosAllocMem 507 *@@changed V0.9.10 (2001-04-08) [umoeller]: fixed second QuerySysState param 478 508 */ 479 509 480 510 PQTOPLEVEL32 prc32GetInfo(APIRET *parc) // out: error, ptr can be NULL 481 511 { 482 #define BUFSIZE 128000l512 #define BUFSIZE (256 * 1024) // 128000l 483 513 PCHAR pBuf = NULL; // (PCHAR)malloc(BUFSIZE); 484 514 … … 489 519 if (pBuf) 490 520 { 491 APIRET arc = DosQuerySysState(0x1f, 492 0, 0, 0, 521 APIRET arc = DosQuerySysState(QS32_SUPPORTED, 522 QS32_SUPPORTED, // this was missing 523 // V0.9.10 (2001-04-08) [umoeller] 524 0, 0, 493 525 (PCHAR)pBuf, 494 526 BUFSIZE); … … 528 560 { 529 561 PQPROCESS32 pProcThis = pInfo->pProcessData; 530 while (pProcThis && pProcThis-> rectype == 1)562 while (pProcThis && pProcThis->ulRecType == 1) 531 563 { 532 564 int i; … … 561 593 } 562 594 563 if (pProcThis-> rectype == 1)595 if (pProcThis->ulRecType == 1) 564 596 return (pProcThis); 565 597 else … … 578 610 */ 579 611 580 PQS EMA32prc32FindSem16(PQTOPLEVEL32 pInfo, // in: as returned by prc32GetInfo612 PQS32SEM16 prc32FindSem16(PQTOPLEVEL32 pInfo, // in: as returned by prc32GetInfo 581 613 USHORT usSemID) // in: as in QPROCESS32.pausSem16 582 614 { 583 PQSEM16STRUC32 pSemData = pInfo->pSem16Data; 584 PQSEMA32 pSemThis = &pSemData->sema; 585 ULONG i = 0; 615 PQS32SEM16HEAD pSemHead = pInfo->pSem16Data; 616 PQS32SEM16 // pSemThis = &pSemData->sema; 617 pSemThis = &pSemHead->Sem16Rec; 618 ULONG i = 0; 586 619 587 620 while (pSemThis) 588 621 { 589 _Pmpf(("prc32FindSem16: found usIndex 0x%lX", pSemThis->usIndex)); 590 if (/* pSemThis->usIndex */ i == usSemID) 622 if (i == usSemID) 591 623 return (pSemThis); 592 624 … … 610 642 */ 611 643 612 PQS EM32STRUC32 prc32FindSem32(PQTOPLEVEL32 pInfo, // in: as returned by prc32GetInfo613 644 PQS32SEM32 prc32FindSem32(PQTOPLEVEL32 pInfo, // in: as returned by prc32GetInfo 645 USHORT usSemID) // in: as in QPROCESS32.pausSem16 614 646 { 615 647 // PQSEM32STRUC32 pSemThis = pInfo->pSem32Data; … … 687 719 PQFILEDATA32 pFile = pInfo->pFileData; 688 720 while ( (pFile) 689 && (pFile-> rectype == 8) // this is necessary, we'll crash otherwise!!721 && (pFile->ulRecType == 8) // this is necessary, we'll crash otherwise!! 690 722 ) 691 723 { 692 if (pFile->filedata->sfn == usFileID) 724 ULONG ul; 725 // for some reason, there is an array in the file struct, 726 // so search the array for the SFN 727 for (ul = 0; 728 ul < pFile->ulCFiles; 729 ul++) 730 { 731 if (pFile->paFiles[ul].usSFN == usFileID) 693 732 return (pFile); 733 } 694 734 695 735 pFile = pFile->pNext;
Note:
See TracChangeset
for help on using the changeset viewer.