home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / 2n02056a < prev    next >
Text File  |  1991-01-02  |  3KB  |  118 lines

  1.  
  2. COMMENT #
  3. ------------------------------------------------------
  4.  
  5.   FILE   -  PFHT.ASM
  6.  
  7.   Determine the number of Process File Handle Table entries
  8.   which are not currently in use.
  9.  
  10.   Written for Microsoft MASM 5.x to interface with
  11.   Microsoft C 5.x.
  12.  
  13.   Module Contents:
  14.         int process_handles_free(void);
  15.  
  16.   NOTE:
  17.     This function makes use of two PSP fields (PFHT_ADDR
  18.     and PFHT_COUNT) which are present only in DOS versions
  19.     3.0 and higher.
  20.  
  21. ------------------------------------------------------
  22. END OF COMMENT #
  23.  
  24. .model small            ;memory model directive
  25.  
  26.  
  27.  
  28. ;                  --- EQUATES ---
  29.  
  30. ; --- an unused PFHT entry will contain 0ffh
  31. FOXES           equ     0ffh
  32.  
  33. ; --- offset within the PSP of the dword pointer to the
  34. ;     PFHT
  35. PFHT_ADDR       equ     34h
  36.  
  37. ; --- offset within the PSP of the word containing the
  38. ;     number of elements in the PFHT
  39. PFHT_COUNT      equ     32h
  40.  
  41.  
  42. ;                  --- DATA ---
  43. .data
  44.  
  45. ; --- declare MSC global variable containing the PSP
  46. ;     segment address
  47. extrn           __psp:word
  48.  
  49.  
  50. ;                  --- CODE ---
  51. .code
  52.  
  53.  
  54. ;------------------------------------------------------
  55. ; int process_handles_free(void);
  56. ;       Sums the number of elements within the Process File
  57. ;       Handle Table which are unused (contain 0ffh).
  58. ;
  59. ; INPUT:    None
  60. ; OUTPUT:   None
  61. ; RETURNS:  Number of file handles not in use in the
  62. ;           Process File Handle Table in the AX register.
  63. ;           All other registers preserved.
  64. ;------------------------------------------------------
  65. public _process_handles_free
  66. _process_handles_free proc
  67.         push    ds
  68.         push    si
  69.         push    bx
  70.         push    cx
  71.  
  72. ; --- zero out the unused counter
  73.         xor     bx,bx
  74.  
  75. ; -- obtain the segment address of the psp
  76.         mov     ax,DGROUP
  77.         mov     ds,ax
  78. assume ds:dgroup
  79.         mov     ax,[__psp]
  80.         mov     ds,ax
  81. assume ds:nothing
  82.  
  83. ; --- address the PFHT count and load cx with its value
  84.         mov     si,PFHT_COUNT
  85.         mov     cx,word ptr [si]
  86.  
  87. ; --- address the pointer to the PFHT and load ds:si with
  88. ;     the dword pointer found
  89.         mov     si,PFHT_ADDR
  90.         lds     si,[si]
  91.  
  92. ; --- setup ah for comparison to an unused entry in the
  93. ;     PFHT
  94.         mov     ah,FOXES
  95.  
  96. ; --- examine each element in the PFHT.  if it contains
  97. ;     0ffh it is unused so increment the unused count.
  98. pfht_loop:
  99.         lodsb                   ;get an elements content
  100.         xor     al,ah           ;is it unused
  101.         jnz     not_empty       ;no, take the jump
  102.         inc     bx              ;yes, inc the count
  103. not_empty:
  104.         loop    pfht_loop       ;go back for another
  105.  
  106. ; --- move the total into ax for return to caller
  107.         mov     ax,bx
  108.  
  109.         pop     cx
  110.         pop     bx
  111.         pop     si
  112.         pop     ds
  113.         ret
  114. _process_handles_free endp
  115.  
  116. end
  117.  
  118.