typedef __mode_t | mode_t |
typedef __off_t | off_t |
typedef __size_t | size_t |
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. 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.
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). 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.
The protections (region accessibility) are specified in the prot argument by or'ing the following values:
PROT_READ Pages may be read. PROT_WRITE Pages may be written. PROT_EXEC Pages may be executed. PROT_NONE This protection mode is currently not supported.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. Sharing, mapping type and options are specified in the flags argument by or'ing the following values:
MAP_PRIVATE Modifications are private. MAP_SHARED Modifications are shared. MAP_FIXED, MAP_FILE, MAP_ANON, MAP_HASSEMAPHORE, MAP_STACK, MAP_NOSYNC -- These flags are currently not supported.The close system call does not unmap pages, see munmap for further information.
The current design does not allow a process to specify the location of swap space. 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.
/* Detailed description : Example to create a mapped memory to a file region. Precondition : None / #include <unistd.h> #include <stdio.h> #include <sys/mman.h> #include <fcntl.h> int main(void) { int fd = -1; char* mapaddr; int len = getpagesize(); int prot = PROT_WRITE | PROT_READ; if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0){ printf("File open failed"); } mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0); if(mapaddr == MAP_FAILED){ printf("mmap on file failed"); } printf("mmap on file succeeded"); }
See also: mprotect() msync() munmap() getpagesize()
Parameters | |
---|---|
Represents the parameter addr | |
Represents the parameter addr | |
Represents the parameter addr | |
Represents the parameter addr | |
Represents the parameter addr | |
Represents the parameter addr |
IMPORT_C int | mprotect | ( | const void * | , |
size_t | , | |||
int | ||||
) |
The mprotect system call changes the specified pages to have protection prot. Not all implementations will guarantee protection on a page basis; the granularity of protection changes may be as large as an entire region. A region is the virtual address space defined by the start and end addresses of a struct vm_map_entry .
NOTE: This interface is not functionally supported in Symbian OS, only build supported.
IMPORT_C int | msync | ( | void * | , |
size_t | , | |||
int | ||||
) |
MS_ASYNC This flag is currently not supported. MS_SYNC Perform synchronous writes MS_INVALIDATE Invalidate all cached dataThe msync system call writes any modified pages back to the file system. 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:
MS_ASYNC This flag is currently not supported. MS_SYNC Perform synchronous writes MS_INVALIDATE Invalidate all cached data
/* Detailed description: Example to sync changes on mapped memory to file. Precondition: None */ #include <unistd.h> #include <stdio.h> #include <sys/mman.h> #include <fcntl.h> #include <string.h> int main(void) { int fd = -1; char* mapaddr; int len = getpagesize(); int prot = PROT_WRITE | PROT_READ; if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0) { printf("File open failed"); } mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0); if(mapaddr == MAP_FAILED) { printf("mmap on file failed"); } strcpy(mapaddr, "This is a write through mapped memory "); if(-1 == msync(mapaddr, len, MS_SYNC)) { printf("Sync on mapped memory to file failed"); } printf("Sync on mapped memory to file succeeded"); }
See also: mlock() mprotect() munmap()
IMPORT_C int | munmap | ( | void * | , |
size_t | ||||
) |
The munmap system call deletes the mappings for the specified address range and causes further references to addresses within the range to generate invalid memory references. The current implementation does not support partial deletion 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.
/* Detailed description: Example to create a mapped memory to a file region. Precondition: None */ #include <unistd.h> #include <stdio.h> #include <sys/mman.h> #include <fcntl.h> int main(void) { int fd = -1; char* mapaddr; int len = getpagesize(); int prot = PROT_WRITE | PROT_READ; if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0){ printf("File open failed"); } mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0); if(mapaddr == MAP_FAILED){ printf("mmap on file failed"); } printf("mmap on file succeeded"); }
IMPORT_C int | shm_open | ( | const char * | , |
int | , | |||
mode_t | ||||
) |
Notes:
1) Mode values for group is ignored.
2) Execute bit is ignored.
3) The name argument pointing to a shared memory object actually does not appear in the file system.
4) Symbian implementation does not distinguish between a name begining with or without a slash character (\).
/* Detailed description : Example to create a shared memory object. Precondition : None / #include <stdio.h> #include <sys/mman.h> #include <fcntl.h> int main(void) { int fd = -1; if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0) { printf("shared memory creation failed"); } printf("shared memory creation succeeded"); return 0; }
See also: shm_unlink() close() read() write() lseek() fstat() fcntl()
Parameters | |
---|---|
For full documentation, see http://www.opengroup.org/onlinepubs/000095399/functions/shm_open.html |
IMPORT_C int | shm_unlink | ( | const char * | ) |
/* Detailed description : Example to unlink a shared memory object. Precondition : None / #include <stdio.h> #include <sys/mman.h> #include <fcntl.h> #include <errno.h> int main(void) { int fd = -1; int ret = 0; if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0) { printf("shared memory creation failed with error %d\n", errno); } printf("shared memory creation succeeded\n"); if((ret = shm_unlink("page")) < 0) { printf("shared memory removal failed with error %d\n", errno); } printf("shared memory removal succeeded\n"); return 0; }
See also: shm_open() close() read() write() lseek() fstat() fcntl()
Parameters | |
---|---|
For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/shm_unlink.html |