efl/src/lib/eina/eina_mmap.h

62 lines
1.9 KiB
C
Raw Normal View History

#ifndef EINA_MMAP_H_
#define EINA_MMAP_H_
/**
* @addtogroup Eina_Mmap_Group Mmap Group
* @ingroup Eina
*
* @brief These functions provide helpers for safe mmap handling.
*
* @{
*
* @since 1.1.0
*/
/**
* @brief Enables or disables safe mmaped IO handling.
*
* @param[in] enabled The enabled state (to enable, pass #EINA_TRUE)
* @return #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
*/
eina: Rename EAPI macro to EINA_API in Eina library Summary: Patch from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))` However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Reviewers: jptiz, lucas, woohyun, vtorri, raster Reviewed By: jptiz, lucas, vtorri Subscribers: ProhtMeyhet, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
EINA_API Eina_Bool
eina_mmap_safety_enabled_set(Eina_Bool enabled);
/**
* @brief Gets the enabled state of mmap safety.
*
* @return 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
*/
eina: Rename EAPI macro to EINA_API in Eina library Summary: Patch from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass `__attribute__ ((visibility ("default")))` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as `__atttribute__((visibility("default")))` However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Reviewers: jptiz, lucas, woohyun, vtorri, raster Reviewed By: jptiz, lucas, vtorri Subscribers: ProhtMeyhet, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12188
2020-11-25 04:35:48 -08:00
EINA_API Eina_Bool
eina_mmap_safety_enabled_get(void);
/**
* @}
*/
#endif