2011-07-04 02:29:59 -07:00
|
|
|
#ifndef EINA_MMAP_H_
|
|
|
|
#define EINA_MMAP_H_
|
|
|
|
|
|
|
|
/**
|
2011-07-15 11:37:44 -07:00
|
|
|
* @addtogroup Eina_Mmap_Group Mmap Group
|
2011-07-04 02:29:59 -07:00
|
|
|
*
|
|
|
|
* @brief These functions provide helpers for safe mmap handling
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @since 1.1.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable or disable safe mmaped IO handling
|
|
|
|
*
|
2012-05-29 23:55:31 -07:00
|
|
|
* @param enabled The enabled state (to enable, pass #EINA_TRUE)
|
2012-04-04 20:52:51 -07:00
|
|
|
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
|
2011-07-04 02:29:59 -07:00
|
|
|
*
|
|
|
|
* This enables (if possible on your platform) a signal handler for
|
2012-04-04 21:24:36 -07:00
|
|
|
* SIGBUS, that replaces the "bad page" with a page of 0's (from /dev/zero)
|
2011-07-04 02:29:59 -07:00
|
|
|
* 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
|
2012-04-04 09:48:23 -07:00
|
|
|
* in a SIGBUS being delivered (and termination of your process), but
|
2011-07-04 02:29:59 -07:00
|
|
|
* 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.
|
2011-08-16 02:08:02 -07:00
|
|
|
*
|
2011-07-04 02:29:59 -07:00
|
|
|
* 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.
|
2011-08-16 02:08:02 -07:00
|
|
|
*
|
2011-07-04 02:29:59 -07:00
|
|
|
* If you set up your own SIGBUS handler, then this will effectively disable
|
|
|
|
* the safe mmap handling and make you liable to crashes on IO to or from
|
|
|
|
* such "damaged files" that would take down your process.
|
|
|
|
*
|
|
|
|
* @since 1.1.0
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
eina_mmap_safety_enabled_set(Eina_Bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the enabled state of mmap safety.
|
|
|
|
*
|
2012-05-29 23:55:31 -07:00
|
|
|
* @return The safety state (#EINA_TRUE if enabled)
|
2011-07-04 02:29:59 -07:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
eina_mmap_safety_enabled_get(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
#endif
|