Mmap Group
Eina

These functions provide helpers for safe mmap handling. More...

## Functions

EINA_API Eina_Bool | eina_mmap_safety_enabled_set (Eina_Bool enabled)
| Enables or disables safe mmaped IO handling.
EINA_API Eina_Bool | eina_mmap_safety_enabled_get (void)
| Gets the enabled state of mmap safety.

## Detailed Description

These functions provide helpers for safe mmap handling.

Since
  1.1.0

## Function Documentation

## eina_mmap_safety_enabled_set()

EINA_API Eina_Bool eina_mmap_safety_enabled_set | ( | Eina_Bool | enabled | ) |

Enables or disables safe mmaped IO handling.

Parameters

  [in] | enabled | The enabled state (to enable, pass EINA_TRUE)

Returns
  EINA_TRUE on success, EINA_FALSE on failure.

This enables (if possible on your platform) a signal handler for SIGBUS, that replaces the "bad page" with a page of 0's (from /dev/zero) if a SIGBUS occurs. This allows for safe mmap() of files that may truncate or from files on devices with IO errors. Normally these cases will result in a SIGBUS being delivered (and termination of your process), but when "mmap safety" is enabled, this will not occur. Instead a page of bytes of the value 0 will replace the "bad page", allowing the process to continue and allow its own parsing error detection to safely abort the operation without the process falling apart.

If you disable mmap safety, the SIGBUS handler will be restored to its default handler. Note that eina_file_map_all() and eina_file_map_new() will automatically enable mmap safety as they provide an mmaped file IO layer, and rely on mmap to not fail for any part of the file.

If you set up your own SIGBUS handler, then this will effectively disable the safe mmap handling and make you liable to crashing on IO to or from such "damaged files" that would take down your process.

Since
  1.1.0

References eina_cpu_page_size(), EINA_FALSE, eina_file_close_on_exec(), EINA_LOG_COLOR_DEFAULT, eina_log_domain_register(), EINA_LOG_ERR, and EINA_TRUE.

Referenced by eina_file_map_all(), and eina_file_map_new().

## eina_mmap_safety_enabled_get()

EINA_API Eina_Bool eina_mmap_safety_enabled_get | ( | void |  | ) |

Gets the enabled state of mmap safety.

Returns
  The safety state (EINA_TRUE if enabled)

This returns the mmap safety state set by eina_mmap_safety_enabled_set(). See eina_mmap_safety_enabled_set() for more information.

Since
  1.1.0