Bug 592194 - Fix missing _SC_PAGE_SIZE macro
Autoconfiscate a simple call to mprotect() even more.
This commit is contained in:
parent
3c69bd46e2
commit
4ff2a58952
|
@ -234,30 +234,27 @@ hb_blob_is_writeable (hb_blob_t *blob)
|
|||
return mode == HB_MEMORY_MODE_WRITEABLE;
|
||||
}
|
||||
|
||||
hb_bool_t
|
||||
hb_blob_try_writeable_inplace (hb_blob_t *blob)
|
||||
|
||||
static hb_bool_t
|
||||
_try_make_writeable_inplace_unix_locked (hb_blob_t *blob)
|
||||
{
|
||||
hb_memory_mode_t mode;
|
||||
|
||||
if (HB_OBJECT_IS_INERT (blob))
|
||||
return FALSE;
|
||||
|
||||
hb_mutex_lock (blob->lock);
|
||||
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITEABLE) {
|
||||
unsigned int pagesize, mask, length;
|
||||
#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT)
|
||||
unsigned int pagesize = -1, mask, length;
|
||||
const char *addr;
|
||||
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: making writeable\n", blob, __FUNCTION__);
|
||||
#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
|
||||
pagesize = (unsigned int) sysconf (_SC_PAGE_SIZE);
|
||||
#elif defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
|
||||
pagesize = (unsigned int) sysconf (_SC_PAGESIZE);
|
||||
#elif defined(HAVE_GETPAGESIZE)
|
||||
pagesize = (unsigned int) getpagesize ();
|
||||
#endif
|
||||
pagesize = (unsigned int) sysconf(_SC_PAGE_SIZE);
|
||||
|
||||
if ((unsigned int) -1 == pagesize) {
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: %s\n", blob, __FUNCTION__, strerror (errno));
|
||||
fprintf (stderr, "%p %s: failed to get pagesize: %s\n", blob, __FUNCTION__, strerror (errno));
|
||||
#endif
|
||||
goto done;
|
||||
return FALSE;
|
||||
}
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: pagesize is %u\n", blob, __FUNCTION__, pagesize);
|
||||
|
@ -275,22 +272,51 @@ hb_blob_try_writeable_inplace (hb_blob_t *blob)
|
|||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: %s\n", blob, __FUNCTION__, strerror (errno));
|
||||
#endif
|
||||
goto done;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
blob->mode = HB_MEMORY_MODE_WRITEABLE;
|
||||
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: successfully made [%p..%p] (%d bytes) writeable\n",
|
||||
blob, __FUNCTION__,
|
||||
addr, addr+length, length);
|
||||
#endif
|
||||
}
|
||||
#else /* !HAVE_SYS_MMAN_H */
|
||||
#warning "No way to make readonly memory writeable. This is suboptimal."
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
hb_bool_t
|
||||
hb_blob_try_writeable_inplace (hb_blob_t *blob)
|
||||
{
|
||||
hb_memory_mode_t mode;
|
||||
|
||||
if (HB_OBJECT_IS_INERT (blob))
|
||||
return FALSE;
|
||||
|
||||
hb_mutex_lock (blob->lock);
|
||||
|
||||
if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITEABLE) {
|
||||
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: making writeable\n", blob, __FUNCTION__);
|
||||
#endif
|
||||
|
||||
done:
|
||||
if (_try_make_writeable_inplace_unix_locked (blob)) {
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: making writeable -> succeeded\n", blob, __FUNCTION__);
|
||||
#endif
|
||||
blob->mode = HB_MEMORY_MODE_WRITEABLE;
|
||||
} else {
|
||||
#if HB_DEBUG
|
||||
fprintf (stderr, "%p %s: making writeable -> FAILED\n", blob, __FUNCTION__);
|
||||
#endif
|
||||
/* Failed to make writeable inplace, mark that */
|
||||
blob->mode = HB_MEMORY_MODE_READONLY;
|
||||
}
|
||||
}
|
||||
|
||||
mode = blob->mode;
|
||||
|
||||
hb_mutex_unlock (blob->lock);
|
||||
|
|
Loading…
Reference in New Issue