msync()
Synchronize memory with physical storage
Synopsis:
#include <sys/mman.h>
int msync( void * addr,
size_t len,
int flags );
Arguments:
- addr
- The beginning of the range of addresses that you want to synchronize.
- len
- The length of the range of addresses, in bytes.
- flags
- A bitwise inclusive OR of one or more of the following flags:
- MS_ASYNC — perform asynchronous writes if possible. In this release of QNX OS, this flag behaves the same as MS_SYNC, which is allowed by POSIX.
- MS_CACHE_ONLY (QNX OS extension) — have the function flush or invalidate the data cache (via the MS_ASYNC, MS_SYNC, or MS_INVALIDATE flags), instead of the POSIX standard behavior.
- MS_INVALIDATE — invalidate cached data. This flag invalidates all cached copies of mapped data that are inconsistent with the permanent storage locations such that subsequent references obtain data that were consistent with these locations sometime between the call to msync() and the first subsequent memory reference to the data.
- MS_INVALIDATE_ICACHE (QNX OS extension) — if you're dynamically modifying code, use this flag to make sure that the new code is what will be executed.
- MS_CLEAN_ONLY (QNX OS extension) — operate only on clean pages.
- MS_SYNC — perform synchronous writes.
The function doesn't return until all write operations are completed.
Note:This flag isn't POSIX-compliant for memory-mapped files (see below). For such files, the MS_SYNC flag offers backwards compatibility when calling msync() to ensure consistency of data between mapped memory I/O and file I/O (i.e., POSIX read/write).
- MS_SYNC_FULL — perform synchronous writes. The function doesn't return until all write operations are completed as defined for synchronized I/O data integrity completion. This flag ensures compliance with the POSIX definition of MS_SYNC for memory-mapped files.
Note:You can specify at most one of MS_ASYNC, MS_SYNC, and MS_SYNC_FULL.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The msync() function writes all modified data to permanent storage locations, if any, in those whole pages containing any part of the calling process's address space starting at addr and continuing for len bytes. This function is used with memory-mapped files, hardware mappings, and DMA-safe mappings. If no such storage exists, msync() need not have any effect. If requested, msync() invalidates cached copies of data.
For mappings to files, this function can be called with MS_SYNC_FULL set to ensure that all write operations are completed as defined for synchronized I/O data integrity completion as though a call to fsync() were made.
If you call msync() on MAP_PRIVATE mappings, no modified data get written to the underlying object and no such data are made visible to other processes.
If msync() causes any write to a file, the file's st_ctime and st_mtime fields are marked for update.
Returns:
- 0
- Success.
- -1
- An error occurred (errno is set).
Errors:
- EBUSY
- Some or all of the addresses in the range starting at addr and continuing for len bytes are locked, and MS_INVALIDATE is specified.
- EINTR
- The call was interrupted by a signal.
- EINVAL
- The flags value is invalid.
- ENOMEM
- The addresses in the range starting at addr and continuing for len bytes are outside the range allowed for the address space of a process or specify one or more pages that aren't mapped.
Examples:
See the entry for mmap().
Classification:
Safety: | |
---|---|
Cancellation point | Yes |
Signal handler | Yes |
Thread | Yes |