os/ossrv/genericopenlibs/openenvcore/include/sys/mman.dosc
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /** @file  ../include/sys/mman.h
     2 @internalComponent
     3 */
     4 
     5 
     6 /** @fn  mmap(void *, size_t len, int prot, int flags, int fildes, off_t offset)
     7 @param # Represents the parameter addr
     8 @param len
     9 @param prot
    10 @param flags
    11 @param fildes
    12 @param offset
    13 @return   Upon successful completion, mmap returns a pointer to the mapped region.
    14 Otherwise, a value of MAP_FAILED is returned and errno is set to indicate the error.
    15 
    16 The  mmap system call causes the pages starting at  addr and continuing for at most  len bytes to be mapped from the object described by  fildes, starting at byte offset  offset. 
    17 If  len is not a multiple of the pagesize, the mapped region may extend past the specified range. Any such extension beyond the end of the mapped object will be zero-filled.
    18 
    19 If addr is non-zero, it is used as a hint to the system. (As a convenience to the system, the actual address of the region may differ from the address supplied).
    20 If addr is zero, an address will be selected by the system. The actual starting address of the region is returned. A successful mmap deletes any previous mapping in the allocated address range.
    21 
    22 The protections (region accessibility) are specified in the prot argument by or'ing the following values:
    23 
    24 @code
    25 PROT_READ 	Pages may be read.
    26 PROT_WRITE 	Pages may be written.
    27 PROT_EXEC 	Pages may be executed.
    28 PROT_NONE 	This protection mode is currently not supported.
    29 @endcode
    30 The flags argument specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references. 
    31 Sharing, mapping type and options are specified in the flags argument by or'ing the following values:
    32 
    33 @code
    34 MAP_PRIVATE 	Modifications are private.
    35 MAP_SHARED 	Modifications are shared.
    36 MAP_FIXED, MAP_FILE, MAP_ANON, MAP_HASSEMAPHORE, MAP_STACK, MAP_NOSYNC -- These flags are currently not supported.
    37 @endcode
    38 The close system call does not unmap pages, see munmap for further information.
    39 
    40 The current design does not allow a process to specify the location of swap space. 
    41 In the future we may define an additional mapping type, MAP_SWAP, in which the file descriptor argument specifies a file or device to which swapping should be done.
    42 
    43 Examples:
    44 @code
    45 /* Detailed description  : Example to create a mapped memory to a file region.
    46  * Precondition : None              
    47  * /
    48 #include <unistd.h>
    49 #include <stdio.h>
    50 #include <sys/mman.h>
    51 #include <fcntl.h>
    52 int main(void)
    53 {
    54     int fd = -1;
    55     char* mapaddr;
    56     int len = getpagesize();
    57     int prot = PROT_WRITE | PROT_READ;
    58     if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0){
    59         printf("File open failed");
    60     }
    61     mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
    62     if(mapaddr == MAP_FAILED){
    63         printf("mmap on file failed");
    64     }
    65     printf("mmap on file succeeded");
    66 }
    67 
    68 @endcode
    69 @see mprotect()
    70 @see msync()
    71 @see munmap()
    72 @see getpagesize()
    73  
    74 
    75 @publishedAll
    76 @externallyDefinedApi
    77 */
    78 
    79 /** @fn  mmap64(void *, size_t len, int prot, int flags, int fildes, off64_t offset)
    80 @param # Represents the parameter addr
    81 @param len
    82 @param prot
    83 @param flags
    84 @param fildes
    85 @param offset
    86 @return   Upon successful completion, mmap64 returns a pointer to the mapped region.
    87 Otherwise, a value of MAP_FAILED is returned and errno is set to indicate the error.
    88 
    89 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
    90 
    91 @see mmap()
    92  
    93 @publishedAll
    94 @externallyDefinedApi
    95 */
    96 
    97 /** @fn  mprotect(const void *addr, size_t len, int prot)
    98 @param addr
    99 @param len
   100 @param prot
   101 @return   Upon successful completion, mprotect returns the value 0 if successful; otherwise the
   102 value -1 is returned and the global variable errno is set to indicate the error.
   103 
   104   The mprotect system call
   105 changes the specified pages to have protection prot. Not all implementations will guarantee protection on a page basis;
   106 the granularity of protection changes may be as large as an entire region.
   107 A region is the virtual address space defined by the start
   108 and end addresses of a struct vm_map_entry .
   109 
   110  NOTE: This interface is not functionally supported in Symbian OS, 
   111   only build supported.
   112 
   113 @see msync()
   114 @see munmap()
   115 
   116 
   117  
   118 
   119 @publishedAll
   120 @externallyDefinedApi
   121 */
   122 
   123 /** @fn  msync(void *addr, size_t len, int flags)
   124 @param addr
   125 @param len
   126 @param flags
   127 @return   Upon successful completion msync() returns 0; otherwise, it returns -1 and 
   128 sets errno to indicate the error.
   129 
   130 @code
   131  MS_ASYNC
   132   This flag is currently not supported.
   133  MS_SYNC
   134   Perform synchronous writes
   135  MS_INVALIDATE
   136   Invalidate all cached data
   137 
   138 @endcode
   139   The msync system call writes any modified pages back to the file system. 
   140 If len is non-zero only those pages containing addr and len-1 succeeding locations will be examined. The flags argument may be specified as follows:
   141 
   142  MS_ASYNC  This flag is currently not supported. MS_SYNC  Perform synchronous writes MS_INVALIDATE  Invalidate all cached data
   143 
   144 Examples:
   145 @code
   146 /*
   147 * Detailed description: Example to sync changes on mapped memory to file.
   148 * Precondition: None
   149 *               
   150 */
   151 #include <unistd.h>
   152 #include <stdio.h>
   153 #include <sys/mman.h>
   154 #include <fcntl.h>
   155 #include <string.h>
   156 int main(void)
   157 {
   158     int fd = -1;
   159     char* mapaddr;
   160     int len = getpagesize();
   161     int prot = PROT_WRITE | PROT_READ;
   162     if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0)
   163     {
   164          printf("File open failed");
   165     }
   166     mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
   167     if(mapaddr == MAP_FAILED)
   168     {
   169          printf("mmap on file failed");
   170     }
   171     strcpy(mapaddr, "This is a write through mapped memory ");
   172     if(-1 == msync(mapaddr, len, MS_SYNC))
   173     {
   174         printf("Sync on mapped memory to file failed");
   175     }
   176     printf("Sync on mapped memory to file succeeded");
   177 }
   178 
   179 @endcode
   180 @see mlock()
   181 @see mprotect()
   182 @see munmap()
   183 
   184 
   185  
   186 
   187 @publishedAll
   188 @externallyDefinedApi
   189 */
   190 
   191 
   192 /** @fn  munmap(void *addr, size_t len)
   193 @param addr
   194 @param len
   195 @return   Upon successful completion munmap() returns 0; otherwise, it returns -1 and 
   196 sets errno to indicate the error.
   197 
   198   The munmap system call deletes the mappings for the specified address range 
   199 and causes further references to addresses within the range to generate invalid 
   200 memory references. The current implementation does not support partial deletion 
   201 of mapped memory, i.e if offset to offset+len section of memory was mapped using mmap the entire section of memory offset+len will be deleted.
   202 
   203 Examples:
   204 @code
   205 /*
   206 * Detailed description: Example to create a mapped memory to a file region.
   207 * Precondition: None
   208 *               
   209 */
   210 #include <unistd.h>
   211 #include <stdio.h>
   212 #include <sys/mman.h>
   213 #include <fcntl.h>
   214 int main(void)
   215 {
   216     int fd = -1;
   217     char* mapaddr;
   218     int len = getpagesize();
   219     int prot = PROT_WRITE | PROT_READ;
   220     if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0){
   221         printf("File open failed");
   222     }
   223     mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
   224     if(mapaddr == MAP_FAILED){
   225         printf("mmap on file failed");
   226     }
   227     printf("mmap on file succeeded");
   228 }
   229 
   230 @endcode
   231  
   232 
   233 @publishedAll
   234 @externallyDefinedApi
   235 */
   236 
   237 
   238 /** @fn  shm_open(const char *name, int oflag, mode_t mode)
   239 @param name
   240 @param oflag
   241 @param mode
   242 
   243 For full documentation, see http://www.opengroup.org/onlinepubs/000095399/functions/shm_open.html 
   244 
   245 Notes:
   246 
   247  1) Mode values for group is ignored. 
   248 
   249  2) Execute bit is ignored.
   250 
   251  3) The name argument pointing to a shared memory object actually does not appear in the file system.
   252 
   253  4) Symbian implementation does not distinguish between a name begining with or without a slash character (\).
   254 
   255 Examples:
   256 @code
   257 /* Detailed description  : Example to create a shared memory object.
   258  * Precondition : None              
   259  * /
   260 #include <stdio.h>
   261 #include <sys/mman.h>
   262 #include <fcntl.h>
   263 int main(void)
   264     {
   265     int fd = -1;
   266     if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0)
   267 	{
   268 	printf("shared memory creation failed");
   269 	}
   270     printf("shared memory creation succeeded");
   271     return 0;
   272     }
   273 
   274 @endcode
   275 @see shm_unlink()
   276 @see close()
   277 @see read()
   278 @see write()
   279 @see lseek()
   280 @see fstat()
   281 @see fcntl()
   282 
   283 @publishedAll
   284 @externallyDefinedApi
   285 */
   286 
   287 
   288 /** @fn  shm_unlink(const char *name)
   289 @param name
   290 
   291 For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/shm_unlink.html
   292 
   293 Examples:
   294 @code
   295 /* Detailed description  : Example to unlink a shared memory object.
   296  * Precondition : None              
   297  * /
   298 #include <stdio.h>
   299 #include <sys/mman.h>
   300 #include <fcntl.h>
   301 #include <errno.h>
   302 int main(void)
   303     {
   304     int fd = -1;
   305     int ret = 0;
   306     if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0)
   307 	{
   308 	printf("shared memory creation failed with error %d\n", errno);
   309 	}
   310     printf("shared memory creation succeeded\n");
   311     if((ret = shm_unlink("page")) < 0)
   312 	{
   313 	printf("shared memory removal failed with error %d\n", errno);
   314 	}
   315     printf("shared memory removal succeeded\n");
   316     return 0;
   317     }
   318 
   319 @endcode
   320 @see shm_open()
   321 @see close()
   322 @see read()
   323 @see write()
   324 @see lseek()
   325 @see fstat()
   326 @see fcntl()
   327 
   328 @publishedAll
   329 @externallyDefinedApi
   330 */
   331 
   332 
   333 
   334 /** @def PROT_NONE
   335 
   336 Protections are chosen from these bits, or-ed together. no permissions.
   337 
   338 @publishedAll
   339 @externallyDefinedApi
   340 */
   341 
   342 
   343 /** @def PROT_READ
   344 
   345 Protections are chosen from these bits, or-ed together. pages can be read.
   346 
   347 @publishedAll
   348 @externallyDefinedApi
   349 */
   350 
   351 
   352 /** @def PROT_WRITE
   353 
   354 Protections are chosen from these bits, or-ed together. pages can be written.
   355 
   356 @publishedAll
   357 @externallyDefinedApi
   358 */
   359 
   360 
   361 /** @def PROT_EXEC	
   362 
   363 Protections are chosen from these bits, or-ed together. pages can be executed.
   364 
   365 @publishedAll
   366 @externallyDefinedApi
   367 */
   368 
   369 
   370 /** @def MAP_SHARED
   371 
   372 share changes
   373 
   374 @publishedAll
   375 @externallyDefinedApi
   376 */
   377 
   378 
   379 /** @def MAP_PRIVATE
   380 
   381 changes are private
   382 
   383 @publishedAll
   384 @externallyDefinedApi
   385 */
   386 
   387 
   388 /** @def MAP_FIXED
   389 
   390 map addr must be exactly as requested.
   391 
   392 @publishedAll
   393 @externallyDefinedApi
   394 */
   395 
   396 
   397 /** @def MS_SYNC	
   398 
   399 msync() flags. msync synchronously.
   400 
   401 @publishedAll
   402 @externallyDefinedApi
   403 */
   404 
   405 
   406 /** @def MS_ASYNC
   407 
   408 msync() flags. return immediately.
   409 
   410 @publishedAll
   411 @externallyDefinedApi
   412 */
   413 
   414 
   415 /** @def MS_INVALIDATE
   416 
   417 msync() flags. invalidate all cached data.
   418 
   419 @publishedAll
   420 @externallyDefinedApi
   421 */
   422 
   423 
   424 
   425 
   426 
   427 
   428 
   429 
   430 
   431 
   432