parent
7addaa1eb4
commit
0b30e759ed
|
@ -25,12 +25,12 @@
|
||||||
* bytes of the value 0 will replace the "bad page", allowing the process
|
* 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
|
* to continue and allow its own parsing error detection to safely abort
|
||||||
* the operation without the process falling apart.
|
* the operation without the process falling apart.
|
||||||
*
|
*
|
||||||
* If you disable mmap safety, the SIGBUS handler will be restored to its
|
* 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()
|
* 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
|
* 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.
|
* 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
|
* 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
|
* the safe mmap handling and make you liable to crashes on IO to or from
|
||||||
* such "damaged files" that would take down your process.
|
* such "damaged files" that would take down your process.
|
||||||
|
|
|
@ -84,7 +84,7 @@ _eina_mmap_safe_sigbus(int sig __UNUSED__,
|
||||||
if (siginfo->si_code == BUS_ADRALN)
|
if (siginfo->si_code == BUS_ADRALN)
|
||||||
{
|
{
|
||||||
ERR("Unaligned memory access. SIGBUS!!!");
|
ERR("Unaligned memory access. SIGBUS!!!");
|
||||||
errno = perrno;
|
errno = perrno;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
/* send this to stderr - not eina_log. Specifically want this on stderr */
|
/* send this to stderr - not eina_log. Specifically want this on stderr */
|
||||||
|
@ -96,17 +96,17 @@ _eina_mmap_safe_sigbus(int sig __UNUSED__,
|
||||||
/* mmap a pzge of zero's from /dev/zero in there */
|
/* mmap a pzge of zero's from /dev/zero in there */
|
||||||
if (mmap(addr, _eina_mmap_pagesize,
|
if (mmap(addr, _eina_mmap_pagesize,
|
||||||
PROT_READ | PROT_WRITE | PROT_EXEC,
|
PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||||
MAP_PRIVATE | MAP_FIXED,
|
MAP_PRIVATE | MAP_FIXED,
|
||||||
_eina_mmap_zero_fd, 0) == MAP_FAILED)
|
_eina_mmap_zero_fd, 0) == MAP_FAILED)
|
||||||
{
|
{
|
||||||
/* mmap of /dev/zero failed :( */
|
/* mmap of /dev/zero failed :( */
|
||||||
perror("mmap");
|
perror("mmap");
|
||||||
ERR("Failed to mmap() /dev/zero in place of page. SIGBUS!!!");
|
ERR("Failed to mmap() /dev/zero in place of page. SIGBUS!!!");
|
||||||
errno = perrno;
|
errno = perrno;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
/* restore previous errno */
|
/* restore previous errno */
|
||||||
errno = perrno;
|
errno = perrno;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -130,16 +130,16 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled)
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled = !!enabled;
|
enabled = !!enabled;
|
||||||
|
|
||||||
if (mmap_safe == enabled) return mmap_safe;
|
if (mmap_safe == enabled) return mmap_safe;
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
/* find out system page size the cleanest way we can */
|
/* find out system page size the cleanest way we can */
|
||||||
#ifdef _SC_PAGESIZE
|
#ifdef _SC_PAGESIZE
|
||||||
_eina_mmap_pagesize = sysconf(_SC_PAGESIZE);
|
_eina_mmap_pagesize = sysconf(_SC_PAGESIZE);
|
||||||
if (_eina_mmap_pagesize <= 0) return EINA_FALSE;
|
if (_eina_mmap_pagesize <= 0) return EINA_FALSE;
|
||||||
#else
|
#else
|
||||||
|
@ -169,7 +169,7 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled)
|
||||||
}
|
}
|
||||||
mmap_safe = enabled;
|
mmap_safe = enabled;
|
||||||
return mmap_safe;
|
return mmap_safe;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
|
|
Loading…
Reference in New Issue