First public contribution.
1 /** @file ../include/sys/mman.h
6 /** @fn mmap(void *, size_t len, int prot, int flags, int fildes, off_t offset)
7 @param # Represents the parameter addr
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.
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.
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.
22 The protections (region accessibility) are specified in the prot argument by or'ing the following values:
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.
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:
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.
38 The close system call does not unmap pages, see munmap for further information.
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.
45 /* Detailed description : Example to create a mapped memory to a file region.
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");
61 mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
62 if(mapaddr == MAP_FAILED){
63 printf("mmap on file failed");
65 printf("mmap on file succeeded");
79 /** @fn mmap64(void *, size_t len, int prot, int flags, int fildes, off64_t offset)
80 @param # Represents the parameter addr
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.
89 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
97 /** @fn mprotect(const void *addr, size_t len, int 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.
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 .
110 NOTE: This interface is not functionally supported in Symbian OS,
111 only build supported.
120 @externallyDefinedApi
123 /** @fn msync(void *addr, size_t len, int flags)
127 @return Upon successful completion msync() returns 0; otherwise, it returns -1 and
128 sets errno to indicate the error.
132 This flag is currently not supported.
134 Perform synchronous writes
136 Invalidate all cached data
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:
142 MS_ASYNC This flag is currently not supported. MS_SYNC Perform synchronous writes MS_INVALIDATE Invalidate all cached data
147 * Detailed description: Example to sync changes on mapped memory to file.
153 #include <sys/mman.h>
160 int len = getpagesize();
161 int prot = PROT_WRITE | PROT_READ;
162 if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0)
164 printf("File open failed");
166 mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
167 if(mapaddr == MAP_FAILED)
169 printf("mmap on file failed");
171 strcpy(mapaddr, "This is a write through mapped memory ");
172 if(-1 == msync(mapaddr, len, MS_SYNC))
174 printf("Sync on mapped memory to file failed");
176 printf("Sync on mapped memory to file succeeded");
188 @externallyDefinedApi
192 /** @fn munmap(void *addr, size_t len)
195 @return Upon successful completion munmap() returns 0; otherwise, it returns -1 and
196 sets errno to indicate the error.
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.
206 * Detailed description: Example to create a mapped memory to a file region.
212 #include <sys/mman.h>
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");
223 mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
224 if(mapaddr == MAP_FAILED){
225 printf("mmap on file failed");
227 printf("mmap on file succeeded");
234 @externallyDefinedApi
238 /** @fn shm_open(const char *name, int oflag, mode_t mode)
243 For full documentation, see http://www.opengroup.org/onlinepubs/000095399/functions/shm_open.html
247 1) Mode values for group is ignored.
249 2) Execute bit is ignored.
251 3) The name argument pointing to a shared memory object actually does not appear in the file system.
253 4) Symbian implementation does not distinguish between a name begining with or without a slash character (\).
257 /* Detailed description : Example to create a shared memory object.
258 * Precondition : None
261 #include <sys/mman.h>
266 if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0)
268 printf("shared memory creation failed");
270 printf("shared memory creation succeeded");
284 @externallyDefinedApi
288 /** @fn shm_unlink(const char *name)
291 For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/shm_unlink.html
295 /* Detailed description : Example to unlink a shared memory object.
296 * Precondition : None
299 #include <sys/mman.h>
306 if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0)
308 printf("shared memory creation failed with error %d\n", errno);
310 printf("shared memory creation succeeded\n");
311 if((ret = shm_unlink("page")) < 0)
313 printf("shared memory removal failed with error %d\n", errno);
315 printf("shared memory removal succeeded\n");
329 @externallyDefinedApi
336 Protections are chosen from these bits, or-ed together. no permissions.
339 @externallyDefinedApi
345 Protections are chosen from these bits, or-ed together. pages can be read.
348 @externallyDefinedApi
354 Protections are chosen from these bits, or-ed together. pages can be written.
357 @externallyDefinedApi
363 Protections are chosen from these bits, or-ed together. pages can be executed.
366 @externallyDefinedApi
375 @externallyDefinedApi
384 @externallyDefinedApi
390 map addr must be exactly as requested.
393 @externallyDefinedApi
399 msync() flags. msync synchronously.
402 @externallyDefinedApi
408 msync() flags. return immediately.
411 @externallyDefinedApi
415 /** @def MS_INVALIDATE
417 msync() flags. invalidate all cached data.
420 @externallyDefinedApi