Synesis Software

mmap() API
[Synesis Software UNIX Emulation for Win32]


Detailed Description

This API provides facilities for manipulating memory-mapped files.


Defines

#define PROT_READ   (UNIXEM_PROT_READ)
#define PROT_WRITE   (UNIXEM_PROT_WRITE)
#define PROT_EXEC   (UNIXEM_PROT_EXEC)
#define PROT_NONE   (UNIXEM_PROT_NONE)
#define MAP_PRIVATE   (UNIXEM_MAP_PRIVATE)
#define MAP_ANONYMOUS   (UNIXEM_MAP_ANONYMOUS)
#define MAP_FIXED   (UNIXEM_MAP_FIXED)
#define MAP_FAILED   (UNIXEM_MAP_FAILED)
#define UNIXEM_PROT_READ   (0x01)
#define UNIXEM_PROT_WRITE   (0x02)
#define UNIXEM_PROT_EXEC   (0x04)
#define UNIXEM_PROT_NONE   (0x00)
#define UNIXEM_MAP_PRIVATE   (0x02)
#define UNIXEM_MAP_ANONYMOUS   (0x20)
#define UNIXEM_MAP_FIXED   (0x10)
#define UNIXEM_MAP_FAILED   ((void*)~0)

Functions

void * mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 Maps a file into memory, and returns a pointer to it.
int munmap (void *addr, size_t len)
 Deletes a mapped region.
int msync (void *addr, size_t len, int flags)
 Writes any dirty pages within the given range to disk.
void * unixem_mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 Maps a file into memory, and returns a pointer to it.
int unixem_munmap (void *addr, size_t len)
 Deletes a mapped region.
int unixem_msync (void *addr, size_t len, int flags)
 Writes any dirty pages within the given range to disk.


Define Documentation

#define MAP_ANONYMOUS   (UNIXEM_MAP_ANONYMOUS)

Ignore fd and offset parameters

#define MAP_FAILED   (UNIXEM_MAP_FAILED)

Returned from mmap() when the mapping fails

#define MAP_FIXED   (UNIXEM_MAP_FIXED)

Interpret addr exactly

#define MAP_PRIVATE   (UNIXEM_MAP_PRIVATE)

Changes are private

#define PROT_EXEC   (UNIXEM_PROT_EXEC)

page can be executed

#define PROT_NONE   (UNIXEM_PROT_NONE)

page can not be accessed

#define PROT_READ   (UNIXEM_PROT_READ)

page can be read

#define PROT_WRITE   (UNIXEM_PROT_WRITE)

page can be written

#define UNIXEM_MAP_ANONYMOUS   (0x20)

Ignore fd and offset parameters

Referenced by unixem_mmap().

#define UNIXEM_MAP_FAILED   ((void*)~0)

Returned from mmap() when the mapping fails

Referenced by unixem_mmap(), unixem_msync(), and unixem_munmap().

#define UNIXEM_MAP_FIXED   (0x10)

Interpret addr exactly

Referenced by unixem_mmap().

#define UNIXEM_MAP_PRIVATE   (0x02)

Changes are private

#define UNIXEM_PROT_EXEC   (0x04)

page can be executed

#define UNIXEM_PROT_NONE   (0x00)

page can not be accessed

#define UNIXEM_PROT_READ   (0x01)

page can be read

#define UNIXEM_PROT_WRITE   (0x02)

page can be written


Function Documentation

void* mmap ( void *  addr,
size_t  len,
int  prot,
int  flags,
int  fd,
off_t  offset 
)

Maps a file into memory, and returns a pointer to it.

Parameters:
addr Suggested address for the mapping
len The number of bytes in the mapped region. The combination of len and offset must not exceed the length of the mapped file
prot Either PROT_NONE, or a combination of the other PROT_* flags
flags One of MAP_PRIVATE, MAP_ANONYMOUS or MAP_FIXED.
fd The file descriptor of the file to map, or -1 to allocate an anonymous map
offset The offset within the file to start the mapped region
Return values:
pointer to mapped region if successful
MAP_FAILED if failed
Note:
The current implementation supports the following three modes: 1. Read-only file; 2. Read-write file; 3. Anonymous Read-write block of system paging file.

This is a macro, which resolves to unixem_mmap()

int msync ( void *  addr,
size_t  len,
int  flags 
)

Writes any dirty pages within the given range to disk.

Parameters:
addr The base address of the mapped region
len The length of the mapped region to flush to disk. Will be rounded up to next page boundary.
flags Ignored
Note:
This is a macro, which resolves to unixem_msync()

int munmap ( void *  addr,
size_t  len 
)

Deletes a mapped region.

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.

Parameters:
addr The base address of the mapped region to unmap
len The length of the mapped region. Ignore in the Win32 implementation
Return values:
0 if successful
-1 if failed
Note:
This is a macro, which resolves to unixem_munmap()

void* unixem_mmap ( void *  addr,
size_t  len,
int  prot,
int  flags,
int  fd,
off_t  offset 
)

Maps a file into memory, and returns a pointer to it.

Parameters:
addr Suggested address for the mapping
len The number of bytes in the mapped region. The combination of len and offset must not exceed the length of the mapped file
prot Either PROT_NONE, or a combination of the other PROT_* flags
flags One of MAP_PRIVATE, MAP_ANONYMOUS or MAP_FIXED.
fd The file descriptor of the file to map, or -1 to allocate an anonymous map
offset The offset within the file to start the mapped region
Return values:
pointer to mapped region if successful
MAP_FAILED if failed
Note:
The current implementation supports the following three modes: 1. Read-only file; 2. Read-write file; 3. Anonymous Read-write block of system paging file.

References unixem_internal_Windows_HANDLE_from_file_handle(), UNIXEM_MAP_ANONYMOUS, UNIXEM_MAP_FAILED, and UNIXEM_MAP_FIXED.

int unixem_msync ( void *  addr,
size_t  len,
int  flags 
)

Writes any dirty pages within the given range to disk.

Parameters:
addr The base address of the mapped region
len The length of the mapped region to flush to disk. Will be rounded up to next page boundary.
flags Ignored

References UNIXEM_MAP_FAILED.

int unixem_munmap ( void *  addr,
size_t  len 
)

Deletes a mapped region.

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.

Parameters:
addr The base address of the mapped region to unmap
len The length of the mapped region. Ignore in the Win32 implementation
Return values:
0 if successful
-1 if failed

References UNIXEM_MAP_FAILED.


UNIX Emulation for Win32 Libraries documentation © Synesis Software Pty Ltd, 2002-2010