- Timestamp:
- Jan 22, 2001, 9:06:38 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/api/api.cpp
r4998 r5008 1 /* $Id: api.cpp,v 1. 3 2001-01-21 07:52:46bird Exp $1 /* $Id: api.cpp,v 1.4 2001-01-22 08:06:38 bird Exp $ 2 2 * 3 3 * API Overload Init and Helper Function. … … 38 38 #include "options.h" 39 39 #include "locks.h" 40 41 40 #include "sprintf.h" 41 42 43 /******************************************************************************* 44 * Defined Constants And Macros * 45 *******************************************************************************/ 46 #if 1//ndef RING0 47 #include <stdio.h> 48 #define IOSftClose(hFile) DosClose(hFile) 49 #define rmalloc malloc 50 #define realloc realloc 51 #define rfree free 52 #undef kprintf 53 #define kprintf(a) printf a 54 #endif 42 55 43 56 … … 82 95 APIRET apiGetProccessName(PSZ pszName); 83 96 APIRET apiGetModuleName(PSZ pszName, USHORT usCS, ULONG ulEIP); 97 #if 1 //ndef RING0 98 APIRET apiWriteIniFile(PSZ pszIniFile); 99 APIRET apiWriteMasks(SFN sfn, PULONG poff, PMASKARRAY pMasks, PSZ pszType, BOOL fEnabled); 100 APIRET apiWriteLine(SFN sfn, PULONG poff, PSZ pszString); 101 #endif 84 102 85 103 … … 125 143 if (pszNewFile) 126 144 { 127 ULONG cbRead ;145 ULONG cbRead = cbFile; 128 146 129 147 rc = IOSftReadAt(sfn, &cbRead, pszNewFile, 0UL, 0UL); … … 232 250 ? &paNewApiData[iApi].ModuleInc 233 251 : &paNewApiData[iApi].ModuleExc; /* default */ 252 if (strstr(pszLine, "DIS")) 253 paNewApiData[iApi].fEnabled = FALSE; 234 254 } 235 255 else … … 270 290 * If we were successfull we'll replace the existing api data with 271 291 * the data we've just read. 272 * (TODO: Not sure (ie. quite sure) if we need some kind of serialization here...)273 292 * If not we'll free any used memory before returning failure. 274 293 */ … … 395 414 396 415 /** 416 * Sort the entire api data structure. 417 * @param paApiData Pointer to api data to sort. 418 * @sketch Loop thru all entries and sort all four mask arrays. 419 * @status completely implemented. 420 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 421 * @remark See apiSortMaskArray. 422 */ 423 void apiSortApiData(PAPIDATAENTRY paApiData) 424 { 425 int i; 426 427 for (i = 0; i < API_CENTRIES; i++) 428 { 429 apiSortMaskArray(&paApiData[i].ProcessInc); 430 apiSortMaskArray(&paApiData[i].ProcessExc); 431 apiSortMaskArray(&paApiData[i].ModuleInc); 432 apiSortMaskArray(&paApiData[i].ModuleExc); 433 } 434 } 435 436 437 /** 438 * Sorts the content of an mask array. 439 * Duplicates are removed. 440 * @param pMasks Pointer to a mask array structure. 441 * @sketch Use bouble sort. 442 * @status partially implemented. 443 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 444 * @remark Duplicate submasks aren't tested for. 445 * example: "DOSCALL1.DLL" is equal to "DOS*" 446 */ 447 void apiSortMaskArray(PMASKARRAY pMasks) 448 { 449 int i; 450 PSZ pszTmp; 451 452 do 453 { 454 for (i = 1, pszTmp = NULL; i < pMasks->cMasks; i++) 455 { 456 int iDiff = strcmp(pMasks->papszMasks[i], pMasks->papszMasks[i-1]); 457 if (iDiff == 0) 458 { /* remove entry */ 459 memmove(&pMasks->papszMasks[i], &pMasks->papszMasks[i+1], 460 (pMasks->cMasks - i - 1) * sizeof(pMasks->papszMasks[0])); 461 i--; 462 } 463 else if (iDiff < 0) 464 { /* Swap entries. */ 465 PSZ pszTmp = pMasks->papszMasks[i]; 466 pMasks->papszMasks[i] = pMasks->papszMasks[i-1]; 467 pMasks->papszMasks[i-1] = pszTmp; 468 } 469 } 470 } while (pszTmp != NULL); 471 } 472 473 474 /** 397 475 * Frees internal data in a api data structure. 398 476 * @param paApiData Pointer to api data table. … … 419 497 } 420 498 421 422 /** 423 * Sort the entire api data structure. 424 * @param paApiData Pointer to api data to sort. 425 * @sketch Loop thru all entries and sort all four mask arrays. 499 #if 1 //ndef RING0 500 /** 501 * Write the internal data to a fresh ini file. 502 * This is a service routine used by the configuration program. 503 * @returns OS/2 return code. 504 * @param pszIniFile Pointer to the name of the ini file. 505 * @sketch 506 * @status 507 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 508 * @remark 509 */ 510 APIRET apiWriteIniFile(PSZ pszIniFile) 511 { 512 SFN sfn; 513 APIRET rc; 514 515 516 rc = IOSftOpen(pszIniFile, 517 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS, 518 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_WRITEONLY, 519 (PSFN)SSToDS(&sfn), 520 NULL); 521 if (rc == NO_ERROR) 522 { 523 int i; 524 ULONG off = 0; 525 PULONG poff = (PULONG)SSToDS(&off); 526 char sz[80]; 527 PSZ psz = (PSZ)SSToDS(&sz[0]); 528 529 for (i = 0; i < API_CENTRIES; i++) 530 { 531 sprintf(psz, "[%d]", i); 532 if ((rc = apiWriteLine(sfn, poff, psz)) != NO_ERROR) 533 break; 534 535 rc = apiWriteMasks(sfn, poff, &aApiData[i].ProcessExc, "Process Exclude", aApiData[i].fEnabled); 536 if (rc != NO_ERROR) 537 break; 538 539 if (aApiData[i].ProcessInc.cMasks) 540 { 541 rc = apiWriteMasks(sfn, poff, &aApiData[i].ProcessInc, "Process Include", TRUE); 542 if (rc != NO_ERROR) 543 break; 544 } 545 546 if (aApiData[i].ModuleExc.cMasks) 547 { 548 rc = apiWriteMasks(sfn, poff, &aApiData[i].ModuleExc, "Module Exclude", TRUE); 549 if (rc != NO_ERROR) 550 break; 551 } 552 553 if (aApiData[i].ModuleInc.cMasks) 554 { 555 rc = apiWriteMasks(sfn, poff, &aApiData[i].ModuleInc, "Module Include", TRUE); 556 if (rc != NO_ERROR) 557 break; 558 } 559 rc = apiWriteLine(sfn, poff, ""); 560 } 561 562 IOSftClose(sfn); 563 } 564 else 565 kprintf(("apiWriteIniFile: Failed open %s for write. rc=%d\n", pszIniFile, rc)); 566 567 return rc; 568 } 569 570 571 /** 572 * Writes the content of a mask array to the ini file. 573 * @returns OS/2 return code. 574 * @param sfn File handle. (sfn = System File Number) 575 * @param poff Pointer to the file offset variable. 576 * (We're required to keep track of the current offset due to 577 * the IOSftWriteAt function.) 578 * @param pMasks Pointer to the mask array struct to be written to file. 579 * @param pszType Type string for these masks. 580 * @param fEnabled If the api entry is enabled or not. 426 581 * @status completely implemented. 427 582 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 428 * @remark See apiSortMaskArray. 429 */ 430 void apiSortApiData(PAPIDATAENTRY paApiData) 431 { 432 int i; 433 434 for (i = 0; i < API_CENTRIES; i++) 435 { 436 apiSortMaskArray(&paApiData[i].ProcessInc); 437 apiSortMaskArray(&paApiData[i].ProcessExc); 438 apiSortMaskArray(&paApiData[i].ModuleInc); 439 apiSortMaskArray(&paApiData[i].ModuleExc); 440 } 441 } 442 443 444 /** 445 * Sorts the content of an mask array. 446 * Duplicates are removed. 447 * @param pMasks Pointer to a mask array structure. 448 * @sketch Use bouble sort. 449 * @status partially implemented. 450 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 451 * @remark Duplicate submasks aren't tested for. 452 * example: "DOSCALL1.DLL" is equal to "DOS*" 453 */ 454 void apiSortMaskArray(PMASKARRAY pMasks) 455 { 456 int i; 457 PSZ pszTmp; 458 459 do 460 { 461 for (i = 1, pszTmp = NULL; i < pMasks->cMasks; i++) 462 { 463 int iDiff = strcmp(pMasks->papszMasks[i], pMasks->papszMasks[i-1]); 464 if (iDiff == 0) 465 { /* remove entry */ 466 memmove(&pMasks->papszMasks[i], &pMasks->papszMasks[i+1], 467 (pMasks->cMasks - i - 1) * sizeof(pMasks->papszMasks[0])); 468 i--; 469 } 470 else if (iDiff < 0) 471 { /* Swap entries. */ 472 PSZ pszTmp = pMasks->papszMasks[i]; 473 pMasks->papszMasks[i] = pMasks->papszMasks[i-1]; 474 pMasks->papszMasks[i-1] = pszTmp; 475 } 476 } 477 } while (pszTmp != NULL); 478 } 479 583 */ 584 APIRET apiWriteMasks(SFN sfn, PULONG poff, PMASKARRAY pMasks, PSZ pszType, BOOL fEnabled) 585 { 586 char sz[48]; 587 PSZ psz = (PSZ)SSToDS(&sz[0]); 588 APIRET rc = NO_ERROR; 589 int i; 590 591 if (fEnabled) 592 sprintf(psz, "Type=%s", pszType); 593 else 594 sprintf(psz, "Type=%s Disabled", pszType); 595 rc = apiWriteLine(sfn, poff, psz); 596 if (rc != NO_ERROR) 597 return rc; 598 599 for (i = 0, rc = NO_ERROR; rc == NO_ERROR && i < pMasks->cMasks; i++) 600 rc = apiWriteLine(sfn, poff, pMasks->papszMasks[i]); 601 602 return rc; 603 } 604 605 606 /** 607 * Writes a string to the file and advances to the next line. 608 * @returns OS/2 return code. 609 * @param sfn File handle. (sfn = System File Number) 610 * @param poff Pointer to the file offset variable. 611 * (We're required to keep track of the current offset due to 612 * the IOSftWriteAt function.) 613 * @param pszString String to be written. 614 * @status completely implemented. 615 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 616 */ 617 APIRET apiWriteLine(SFN sfn, PULONG poff, PSZ pszString) 618 { 619 ULONG cb = strlen(pszString); 620 APIRET rc; 621 622 rc = IOSftWriteAt(sfn, &cb, pszString, 0UL, *poff); 623 if (rc == NO_ERROR) 624 { 625 *poff += cb; 626 cb = 2; 627 rc = IOSftWriteAt(sfn, &cb, "\r\n", 0UL, *poff); 628 if (rc == NO_ERROR) 629 *poff += cb; 630 } 631 632 return rc; 633 } 634 635 636 /** 637 * Opens a given file. 638 * @returns NO_ERROR on success. OS/2 error code on error. 639 * @param pszFilename Pointer to filename. 640 * @param flOpenFlags Open flags. (similar to DosOpen) 641 * @param flOpenMode Open mode flags. (similar to DosOpen) 642 * @param phFile Pointer to filehandle. 643 * @param pulsomething 16-bit near (?) pointer to a variable - unknown. NULL is allowed. EA? 644 */ 645 APIRET KRNLCALL IOSftOpen( 646 PSZ pszFilename, 647 ULONG flOpenFlags, 648 ULONG flOpenMode, 649 PSFN phFile, 650 PULONG pulsomething 651 ) 652 { 653 APIRET rc; 654 ULONG ulAction = 0; 655 656 rc = DosOpen(pszFilename, phFile, &ulAction, 0, 0, flOpenFlags, flOpenMode, NULL); 657 658 pulsomething = pulsomething; 659 return rc; 660 } 661 662 /** 663 * Read at a given offset in the a file. 664 * @returns NO_ERROR on success. OS/2 error code on error. 665 * @param hFile File handle - System File Number. 666 * @param pcbActual Pointer to variable which upon input holds the number 667 * of bytes to read, on output the actual number of bytes read. 668 * @param pvBuffer Pointer to the read buffer. 669 * @param flFlags Read flags? 670 * @param ulOffset File offset to read from. (0=start of file) 671 */ 672 APIRET KRNLCALL IOSftReadAt( 673 SFN hFile, 674 PULONG pcbActual, 675 PVOID pvBuffer, 676 ULONG flFlags, 677 ULONG ulOffset) 678 { 679 APIRET rc; 680 ULONG ul; 681 rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ul); 682 if (rc == NO_ERROR) 683 rc = DosRead(hFile, pvBuffer, *pcbActual, pcbActual); 684 flFlags = flFlags; 685 return rc; 686 } 687 688 689 /** 690 * Write at a given offset in the a file. 691 * @returns NO_ERROR on success. OS/2 error code on error. 692 * @param hFile File handle - System File Number. 693 * @param pcbActual Pointer to variable which upon input holds the number 694 * of bytes to write, on output the actual number of bytes write. 695 * @param pvBuffer Pointer to the write buffer. 696 * @param flFlags Read flags? 697 * @param ulOffset File offset to write from. (0=start of file) 698 */ 699 APIRET KRNLCALL IOSftWriteAt( 700 SFN hFile, 701 PULONG pcbActual, 702 PVOID pvBuffer, 703 ULONG flFlags, 704 ULONG ulOffset) 705 { 706 APIRET rc; 707 ULONG ul; 708 rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ul); 709 if (rc == NO_ERROR) 710 rc = DosWrite(hFile, pvBuffer, *pcbActual, pcbActual); 711 flFlags = flFlags; 712 return rc; 713 } 714 715 /** 716 * Gets the filesize. 717 * @returns NO_ERROR on success; OS/2 error code on error. 718 * @param hFile File handle - System File Number. 719 * @param pcbFile Pointer to ULONG which will hold the file size upon return. 720 */ 721 APIRET KRNLCALL SftFileSize( 722 SFN hFile, 723 PULONG pcbFile) 724 { 725 FILESTATUS3 fsts3; 726 APIRET rc; 727 728 rc = DosQueryFileInfo(hFile, FIL_STANDARD, &fsts3, sizeof(fsts3)); 729 if (rc == NO_ERROR) 730 *pcbFile = fsts3.cbFile; 731 return rc; 732 } 733 734 #endif 480 735 481 736 /** … … 496 751 497 752 753 #ifdef RING0 498 754 /** 499 755 * Get the current process executable name. … … 673 929 674 930 675 676 931 /** 677 932 * Init The Api Overloading SubSystem. … … 690 945 return rc; 691 946 } 692 947 #endif 948
Note:
See TracChangeset
for help on using the changeset viewer.