mirror of
https://github.com/matrix-construct/construct
synced 2024-06-11 14:38:57 +02:00
ircd::allocator: Add mprotect(2) wrappings.
This commit is contained in:
parent
55004f054a
commit
271214ff70
|
@ -51,6 +51,9 @@ namespace ircd::allocator
|
|||
size_t prefetch(const const_buffer &);
|
||||
size_t evict(const const_buffer &);
|
||||
|
||||
void protect(const const_buffer &, const bool = true);
|
||||
void readonly(const mutable_buffer &, const bool = true);
|
||||
|
||||
std::unique_ptr<char, decltype(&std::free)>
|
||||
aligned_alloc(const size_t &align, const size_t &size);
|
||||
}
|
||||
|
|
|
@ -135,6 +135,36 @@ catch(const std::exception &e)
|
|||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ircd::allocator::readonly(const mutable_buffer &buf,
|
||||
const bool enable)
|
||||
{
|
||||
const int prot
|
||||
{
|
||||
enable?
|
||||
PROT_READ:
|
||||
PROT_READ|PROT_WRITE
|
||||
};
|
||||
|
||||
void *const ptr(mutable_cast(data(buf)));
|
||||
sys::call(::mprotect, ptr, size(buf), prot);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::allocator::protect(const const_buffer &buf,
|
||||
const bool enable)
|
||||
{
|
||||
const int prot
|
||||
{
|
||||
enable?
|
||||
PROT_NONE:
|
||||
PROT_READ|PROT_WRITE
|
||||
};
|
||||
|
||||
void *const ptr(mutable_cast(data(buf)));
|
||||
sys::call(::mprotect, ptr, size(buf), prot);
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::allocator::evict(const const_buffer &buf)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue