home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / mc454src.zip / mc-4.5.4.src / os2emx / doc / mmap.txt < prev    next >
Encoding:
Text File  |  1999-01-04  |  7.5 KB  |  170 lines

  1.                   Memory Mapped Files Emulation Layer v1.00
  2.                   (c) 1998 Maurilio Longo - md2520@mclink.it
  3.  
  4.                                    - * -
  5.  
  6. This is a brief document about mmap.dll, if you don't know what memory mapped
  7. files are then this .dll is not for you :-)
  8.  
  9. This .dll is freeware (you can use and redistribute it whitout any charge) but
  10. I retain all rights upon it. Standard disclaimer applies :-) i.e. I'm not
  11. responsible for any damages arising from its use or misuse.
  12.  
  13.                            USE IT AT YOUR OWN RISK.
  14.  
  15. This .dll provides ANSI C compliant mmap() services to OS/2 processes. It is
  16. intended as a tool for programmers porting unix software to OS/2 and / or for
  17. programmers developing native OS/2 programs.
  18.  
  19. It is already used on mSLQ 2 (actually it was developed for mSQL 2). You can find
  20. more info about mSQL at this address: http://blnet.com/msqlpc/
  21.  
  22.  
  23. In this package you'll find several files:
  24.  
  25. mmap.dll    :  the emulation layer, it should go on a directory listed on your
  26.                LIBPATH;
  27. mmap.lib    :  import library for OMF linker (like link386.exe);
  28. mmap.a      :  import library for EMX/GCC ld.exe (a.out format);
  29. mman.h      :  include file for C programmers;
  30. mmap.txt    :  this text file you're already reading :-)
  31.  
  32.  
  33. Since it is an *emulation* of mmap() services it has a few restrictions/limits
  34. that you should be aware of and care:
  35.  
  36. 1) You can have only one mapped region per file, this is a limit which will be
  37.    rised on a future release.
  38.  
  39. 2) You cannot share a mapped region between processes (or address spaces), this
  40.    is a permanent restriction arising from the fact that mmap.dll runs with
  41.    user privileges and needs to be able to commit / decommit memory pages.
  42.  
  43. 3) It suports a maximum of 64 threads per process accessing mmap() services.
  44.    This limit can be changed but, at the moment, there is no reason to increase
  45.    it. If you need to use more than 64 threads, please let me know.
  46.  
  47. 4) You cannot mmap() more than 300 / 350 Mb per process, this is a limit of
  48.    OS/2 which should be rised in the upcoming OS/2 5. This version of mmap.dll
  49.    can handle a maximum of 2Gb of mapped memory per process.
  50.  
  51. 5) All standard flags of mman.h are defined but not used. You cannot protect or
  52.    lock memory regions and you should not rely on access flags. All mapped pages
  53.    are read only until a write access occurs. This is a permanent restriction.
  54.  
  55. 6) msync() is always synchronous and should be called from time to time to
  56.    sync modified pages to disk. If you never call it syncing will be done at
  57.    the time of munmap() call.
  58.  
  59. 7) There is a non-standard constant MS_MUNMAP (0x10) which is used by munmap()
  60.    to signal to msync() that it has been called by munmap(). This makes msync()
  61.    faster.
  62.  
  63. 8) There is a non-standard function merror() which returns last error of calling
  64.    thread (and resets it).
  65.  
  66. 9) I've only tested it with OS/2 Warp 4 (ita, fp 6) but it should work with
  67.    OS/2 Warp 3 as well. If you can test it with OS/2 2 or OS/2 Warp Server
  68.    (Standard or Advanced) please let me know whether it works.
  69.  
  70.  
  71. The mmap() emulation dll exports the following functions (here listed using 
  72. pascal notation since this library has been developed with VirtualPascal/2 v1.1):
  73.  
  74. Type
  75.    caddr_t  =  Pointer;             // C types for mmap functions
  76.    off_t    =  longint;
  77.    size_t   =  longint;
  78.    int      =  longint;
  79.  
  80. // Returns size in bytes of a memory page
  81. function getpagesize: int;
  82.  
  83. // Stub function, returns -1 and sets merror to EAGAIN
  84. function mprotect(pAddr: caddr_t;  cbLen, fProtection: int): int;
  85.  
  86. // Stub function, returns -1 and sets merror to EAGAIN
  87. function mlockall(fFlags: int): int;
  88.  
  89. // Maps a file to a range of addresses in memory.
  90. // pAddr must be 0, otherwise call fails
  91. // cbLen is dimension of region of file to map
  92. // fProtection is here only for compatibility, all pages are readonly and become read/write after a
  93. //             write access to them
  94. // hFile is the handle of mapping file; only one mapping region is available as of version 1.0 of mmap.dll
  95. // cbOffest position in file from which mapping starts
  96. // if something goes wrong it returns -1 and sets merror to appropriate error code
  97. function mmap(pAddr: caddr_t; cbLen: size_t; fProtection, fFlags, hFile: int; cbOffset: off_t): caddr_t;
  98.  
  99. // Synchronizes pages accessed with a write operation to file, after synchronization pages are converted to
  100. // readonly access; pages with readonly access are decomitted.
  101. // It accepts starting address and len of a mapped region. fFlags is not used but for value
  102. // MS_UNMAP which tells msync that is being called by munmap and so decommitting of readonly pages
  103. // is not necessary.
  104. function msync(pAddr: caddr_t; cbLen: size_t; fFlags: int): int;
  105.  
  106. // Stub function, always returns 0
  107. function munlockall: int;
  108.  
  109. // Unmaps a previously mapped region and syncs it to file if necessary
  110. function munmap(pAddr: caddr_t; cbLen: size_t): int;
  111.  
  112. // Returns, and clears, last error of calling thread
  113. function merror: int;
  114.  
  115.  
  116. merror() returns last error occurred to calling thread and clears it; defined
  117. errors are as follows:
  118.  
  119. EPERM          =     1;              // Operation not permitted
  120. EIO            =     5;              // Input/output error
  121. ENXIO          =     6;              // Device not configured
  122. EBADF          =     9;              // Bad file descriptor
  123. ENOMEM         =     12;             // Cannot allocate memory
  124. EACCES         =     13;             // Permission denied
  125. EBUSY          =     16;             // Device busy
  126. ENODEV         =     19;             // Operation not supported by device
  127. EINVAL         =     22;             // Invalid argument
  128. EMFILE         =     24;             // Too many open files
  129. EAGAIN         =     35;             // Resource temporarily unavailable
  130.  
  131.  
  132. This library defines standard flags for mmap(), msync() and munmap() but does
  133. not use them; so you should not rely on them but at the same time they are
  134. reserved for future use.
  135.  
  136. HAVE_MSYNC     =     1;          // msync available
  137. PROT_READ      =     $0001;      // read only access - not used
  138. PROT_WRITE     =     $0002;      // write access     - not used
  139. PROT_EXEC      =     $0004;      // execute access   - not used
  140. PROT_NONE      =     $0000;      // no access        - not used
  141.  
  142. MAP_SHARED     =     1;          // shared mapping   - not supported
  143. MAP_PRIVATE    =     2;          // private mapping  - all mappings are private only
  144. MAP_FIXED      =     $10;        // fixed address    - not supported
  145.  
  146. MCL_CURRENT    =     $1;         // locking options not supported
  147. MCL_FUTURE     =     $2;
  148.  
  149. MS_ASYNC       =     $1;         // all syncing is synchronous so it is not used
  150. MS_INVALIDATE  =     $2;         //                  - not supported
  151. MS_MUNMAP      =     $10;        // Used by munmap() when calling msync()
  152.  
  153.  
  154. It's possible to set an environment variable to force the mmap.dll to show infos 
  155. about its inner workings. To enable this capability use
  156.  
  157. SET MMAPDLL=DEBUG
  158.  
  159. before starting any process which will use mmap() services.
  160.  
  161. It's possible to find a more detailed documentation about memory mapped files
  162. at this address http://hots.stsci.edu/man/man2/mmap.html but please bear in
  163. mind that those are pages about linux / freebsd memory mapped services so they
  164. list capabilities and functions not available with my emulation.
  165.  
  166. Ok, that's all. Please bear with my poor english and happy mmaping :-)) I'd like
  167. to be informed if you decide to use my library in a program of yours.
  168. Postcards are always wellcome :-)).
  169.  
  170.