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