Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]

#include <mman.h>
Link against: libc.lib

PROT_NONE

Interface status: externallyDefinedApi

PROT_NONE 0x00

Description

Protections are chosen from these bits, or-ed together. no permissions.

[Top]


PROT_READ

Interface status: externallyDefinedApi

PROT_READ 0x01

Description

Protections are chosen from these bits, or-ed together. pages can be read.

[Top]


PROT_WRITE

Interface status: externallyDefinedApi

PROT_WRITE 0x02

Description

Protections are chosen from these bits, or-ed together. pages can be written.

[Top]


PROT_EXEC

Interface status: externallyDefinedApi

PROT_EXEC 0x04

Description

Protections are chosen from these bits, or-ed together. pages can be executed.

[Top]


MAP_SHARED

Interface status: externallyDefinedApi

MAP_SHARED 0x0001

Description

share changes

[Top]


MAP_PRIVATE

Interface status: externallyDefinedApi

MAP_PRIVATE 0x0002

Description

changes are private

[Top]


MAP_FIXED

Interface status: externallyDefinedApi

MAP_FIXED 0x0010

Description

map addr must be exactly as requested.

[Top]


MS_SYNC

Interface status: externallyDefinedApi

MS_SYNC 0x0000

Description

msync(void *,size_t,int)msync(void *,size_t,int) flags. msync synchronously.

[Top]


MS_ASYNC

Interface status: externallyDefinedApi

MS_ASYNC 0x0001

Description

msync(void *,size_t,int)msync(void *,size_t,int) flags. return immediately.

[Top]


MS_INVALIDATE

Interface status: externallyDefinedApi

MS_INVALIDATE 0x0002

Description

msync(void *,size_t,int)msync(void *,size_t,int) flags. invalidate all cached data.

[Top]


mmap(void *,size_t,int,int,int,off_t)

Interface status: externallyDefinedApi

IMPORT_C void* mmap(void *, size_t, int, int, int, off_t);

Description

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.

Examples:

/* 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");
}

Parameters

void *

Represents the parameter addr

size_tsize_t

int

int

int

off_toff_t

See also:

[Top]


mprotect(const void *,size_t,int)

Interface status: externallyDefinedApi

IMPORT_C int mprotect(const void *, size_t, int);

Description

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.

Parameters

const void *

size_tsize_t

int

Return value

int

Upon successful completion, mprotect returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

See also:

[Top]


msync(void *,size_t,int)

Interface status: externallyDefinedApi

IMPORT_C int msync(void *, size_t, int);

Description

 MS_ASYNC
  This flag is currently not supported.
 MS_SYNC
  Perform synchronous writes
 MS_INVALIDATE
  Invalidate all cached data

The 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

Examples:

/*
 Detailed description: Example to sync changes on mapped memory to file.
 Precondition: None
               
*/
# 133 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 134 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 135 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 136 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 137 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
int main(void)
{
    int fd = -1;
    char* mapaddr;
    int len = getpagesize();
    int prot =  0x02  |  0x01 ;
    if((fd = open("C:\Test.txt",  0x0002  |  0x0200 , 0666) ) < 0)
    {
         printf("File open failed");
    }
    mapaddr = (char*)mmap((void*)0, len, prot,  0x0001 , fd, 0);
    if(mapaddr ==  ((void *)-1) )
    {
         printf("mmap on file failed");
    }
    strcpy(mapaddr, "This is a write through mapped memory ");
    if(-1 == msync(mapaddr, len,  0x0000 ))
    {
        printf("Sync on mapped memory to file failed");
    }
    printf("Sync on mapped memory to file succeeded");
}

Parameters

void *

size_tsize_t

int

Return value

int

Upon successful completion msync(void *,size_t,int)msync(void *,size_t,int) returns 0; otherwise, it returns -1 and sets errno to indicate the error.

See also:

[Top]


munmap(void *,size_t)

Interface status: externallyDefinedApi

IMPORT_C int munmap(void *, size_t);

Description

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.

Examples:

/*
 Detailed description: Example to create a mapped memory to a file region.
 Precondition: None
               
*/
# 192 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 193 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 194 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
# 195 "d:/EPOC/release/9.4/common/generic/openenv/core/include/sys/mman.dosc" 2
int main(void)
{
    int fd = -1;
    char* mapaddr;
    int len = getpagesize();
    int prot =  0x02  |  0x01 ;
    if((fd = open("C:\Test.txt",  0x0002  |  0x0200 , 0666) ) < 0){
        printf("File open failed");
    }
    mapaddr = (char*)mmap((void*)0, len, prot,  0x0001 , fd, 0);
    if(mapaddr ==  ((void *)-1) ){
        printf("mmap on file failed");
    }
    printf("mmap on file succeeded");
}

Parameters

void *

size_tsize_t

Return value

int

Upon successful completion munmap(void *,size_t)munmap(void *,size_t) returns 0; otherwise, it returns -1 and sets errno to indicate the error.