home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / ISREMOVE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.0 KB  |  106 lines

  1. /**
  2. *
  3. * Name        isremove -- Remove resident program
  4. *
  5. * Synopsis    ercode = isremove(psp_seg);
  6. *
  7. *        int     ercode   Error code from DOS function 0x49:
  8. *                  0 if okay, nonzero if error.
  9. *        unsigned psp_seg  Segment of Program Segment Prefix
  10. *                  of resident program.
  11. *
  12. * Description    This function removes from memory a program that has
  13. *        previously terminated and stayed resident via ISRESEXT.
  14. *
  15. *        WARNING:  Any interrupt vectors or chained interrupt
  16. *        service that invoke any portion of the resident program
  17. *        MUST be re-vectored or otherwise disabled BEFORE the
  18. *        program is removed.  Serious problems may result
  19. *        otherwise.
  20. *
  21. * Method    This function works by following the chain of DOS memory
  22. *        control blocks via MMCTRL.  The control blocks are
  23. *        located at increasing memory addresses, so we begin
  24. *        searching at the first memory control block, as reported
  25. *        by MMFIRST.  For each control block that belongs to
  26. *        psp_seg, we free the associated memory block via DOS
  27. *        function 0x49.    All memory blocks belonging to the
  28. *        specified program are freed, regardless of their
  29. *        location.
  30. *
  31. * Results    ercode          Error code from DOS function 0x49.
  32. *
  33. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
  34. *
  35. **/
  36.  
  37. #include <dos.h>              /* For intdosx(), REGS, and     */
  38.                       /* SREGS.               */
  39.  
  40. #include <bintrupt.h>
  41.  
  42. static int mm_free(unsigned);          /* Internal function (see       */
  43.                       /* below).              */
  44.  
  45. int isremove(psp_seg)
  46. unsigned psp_seg;
  47. {
  48.     unsigned memblock,nextblock;
  49.     int      result;
  50.     MEMCTRL  ctlblock;
  51.  
  52.     result = 9;               /* In case first block address  */
  53.                       /* is bad, return 9 (Invalid    */
  54.                       /* memory block).           */
  55.  
  56.     /* Begin memory block search at first memory block.           */
  57.  
  58.     for (memblock  = mmfirst();
  59.      memblock != 0;
  60.      memblock  = nextblock)
  61.     {
  62.     if (   9 != mmctrl(memblock,&ctlblock,&nextblock)
  63.                           /* If block okay    */
  64.         && ctlblock.owner_psp == psp_seg)      /* and belongs to   */
  65.     {                      /*   psp_seg,       */
  66.         result = mm_free(memblock);     /* then free the block.   */
  67.         if (result != 0)
  68.         break;                /* Quit if error.          */
  69.     }
  70.     }
  71.  
  72.     return result;
  73. }
  74.  
  75. /**
  76. *
  77. * Name        mm_free -- Release an allocated memory block
  78. *
  79. * Synopsis    ercode = mm_free(seg);
  80. *
  81. *        int ercode      Returned error code (0 if okay).
  82. *        unsigned seg      Segment address of memory block.
  83. *
  84. * Description    This function frees memory blocks that have been
  85. *        allocated by DOS function 0x48.  The segment address
  86. *        given must be associated with a previously allocated
  87. *        block.
  88. *
  89. * Returns    ercode          DOS function return code.
  90. *
  91. **/
  92.  
  93. static int mm_free(seg)
  94. unsigned seg;
  95. {
  96.     union  REGS regs;
  97.     struct SREGS sregs;
  98.  
  99.     regs.h.ah = 0x49;
  100.     sregs.es  = seg;
  101.     intdosx(®s,®s,&sregs);
  102.  
  103.     return ((regs.x.cflag) ? (regs.h.al)    /* Nonzero error code.    */
  104.                : (0));        /* Success:  return 0.    */
  105. }
  106.