home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n10 / gmmfsrc.exe / GMMF.H < prev    next >
C/C++ Source or Header  |  1995-10-01  |  4KB  |  114 lines

  1. /*****************************************************************************
  2. Module name: GMMF.h
  3. Written by: Jeffrey Richter
  4. Purpose: Function prototypes for using growable memory-mapped files.
  5. *****************************************************************************/
  6.  
  7.  
  8. // If you application runs on Windows NT only, uncomment the line below.
  9. // If you rapplication runs on both Windows 95 and Windows NT, leave the line
  10. // below commented out.
  11. //#define GMMF_WINNT_ONLY
  12.  
  13.  
  14. //////////////////////////////////////////////////////////////////////////////
  15.  
  16.  
  17. // Opaque data structure initialized by GMMF_Create and used by 
  18. // GMMF_ExcFilter and GMMF_Close.
  19. typedef struct {
  20.    DWORD    cbFileSizeMax; // Max size that file can grow to
  21.    DWORD    cbFileGrowInc; // File grows by this increment
  22.    DWORD    cbOverrunBuf;  // Reserved area to catch file overflow
  23.    HANDLE   hFile;         // File object
  24.    HANDLE   hFileMap;      // File-mapping object
  25.    PBYTE    pbFile;        // Address to start of file
  26.  
  27. #ifndef GMMF_WINNT_ONLY
  28.    HANDLE   hFileMapRes;   // Used to reserve address space
  29. #endif
  30. } GMMF, *PGMMF;
  31.  
  32.  
  33. //////////////////////////////////////////////////////////////////////////////
  34.  
  35.  
  36. // Creates a GMMF and places it in the process's address space.  Note that the
  37. // cbFIleSizeMax and cbFileSizeInc values are rounded up to an even 
  38. // allocation-granularity boundary.  The return value is the address of the
  39. // GMMF or NULL if the GMMF could not be created.
  40. PVOID WINAPI GMMF_Create (PGMMF pgmmf, HANDLE hFile, DWORD cbFileSizeMax, 
  41.    DWORD cbFileGrowInc, DWORD cbOverrunBuf);
  42.  
  43.  
  44. //////////////////////////////////////////////////////////////////////////////
  45.  
  46.  
  47. // SEH Exception filter used to grow the GMMF.
  48. long WINAPI GMMF_ExcFilter (PEXCEPTION_POINTERS pexp, PGMMF pgmmf);
  49.  
  50. //////////////////////////////////////////////////////////////////////////////
  51.  
  52.  
  53. // Closes a GMMF and truncates the file to the specified size.
  54. void WINAPI GMMF_Close (PGMMF pgmmf, DWORD cbDiskFile);
  55.  
  56.  
  57. //////////////////////////////////////////////////////////////////////////////
  58.  
  59.  
  60. // Useful macro for creating our own software exception codes
  61. #define MAKESOFTWAREEXCEPTION(Severity, Facility, Exception) \
  62.    ((DWORD) ( \
  63.    /* Severity code */     (Severity  <<  0) |     \
  64.    /* MS(0) or Cust(1) */  (1         << 29) |     \
  65.    /* Reserved(0) */       (0         << 28) |     \
  66.    /* Facility code */     (Facility  << 16) |     \
  67.    /* Exception code */    (Exception <<  0)))
  68.  
  69.  
  70. //////////////////////////////////////////////////////////////////////////////
  71.  
  72.  
  73. // GMMF software exceptions thrown when problems arise.
  74. #define FACILITY_GMMF            0
  75.  
  76.  
  77. // GMMF_DISKFULL_EXCEPTION is thrown by GMMF_ExcFilter if the GMMF cannot be
  78. // grown because the user is out of disk space.
  79. #define EXCEPTION_GMMF_DISKFULL      \
  80.    MAKESOFTWAREEXCEPTION(ERROR_SEVERITY_ERROR, FACILITY_GMMF, 1)
  81.  
  82.  
  83. // GMMF_CORRUPTEDRGN_EXCEPTION is thrown by GMMF_Create or GMMF_ExcFilter if 
  84. // the memory address region containing the GMMF is corrupted due to other
  85. // threads pre-empting the GMMF thread and manipulating the address space.
  86. #define EXCEPTION_GMMF_CORRUPTEDRGN  \
  87.    MAKESOFTWAREEXCEPTION(ERROR_SEVERITY_ERROR, FACILITY_GMMF, 2)
  88.  
  89.  
  90. // GMMF_WRITEPASTMAX_EXCEPTION is thrown by GMMF_ExcFilter if your code 
  91. // attempts to write past the GMMF into the overrun buffer.
  92. #define EXCEPTION_GMMF_WRITEPASTMAX  \
  93.    MAKESOFTWAREEXCEPTION(ERROR_SEVERITY_WARNING, FACILITY_GMMF, 3)
  94.  
  95.  
  96. //////////////////////////////////////////////////////////////////////////////
  97.  
  98.  
  99. // Returns TRUE if Val is between Low and High inclusively.
  100. #define InRange(Low, Val, High)  (((Low) <= (Val)) && ((Val) <= (High)))
  101.  
  102.  
  103. //////////////////////////////////////////////////////////////////////////////
  104.  
  105.  
  106. // Rounds Val down to the nearest Gran
  107. #define RoundDown(Val, Gran)     ((Val) / (Gran) * (Gran))
  108.  
  109. // Rounds Val up to the nearest Gran
  110. #define RoundUp(Val, Gran)       (((Val) + (Gran) - 1) / (Gran) * (Gran))
  111.  
  112.  
  113. //////////////////////////////// End of File /////////////////////////////////
  114.