+ sodium_alloc_overhead()

This commit is contained in:
Frank Denis 2017-08-02 12:34:56 +02:00
parent 23c36615cd
commit c5b61d8129
4 changed files with 17 additions and 0 deletions

View File

@ -487,6 +487,7 @@ _randombytes_set_implementation 0 0
_randombytes_stir 1 1
_randombytes_uniform 1 1
_sodium_add 0 0
_sodium_alloc_overhead 0 0
_sodium_allocarray 0 0
_sodium_bin2hex 1 1
_sodium_compare 0 0

View File

@ -120,6 +120,9 @@ int sodium_mprotect_readonly(void *ptr);
SODIUM_EXPORT
int sodium_mprotect_readwrite(void *ptr);
SODIUM_EXPORT
size_t sodium_alloc_overhead(size_t size);
/* -------- */
int _sodium_alloc_init(void);

View File

@ -702,3 +702,13 @@ sodium_mprotect_readwrite(void *ptr)
{
return _sodium_mprotect(ptr, _mprotect_readwrite);
}
size_t
sodium_alloc_overhead(size_t size)
{
#ifndef HAVE_ALIGNED_MALLOC
return unprotected_size == (size_t) 0U;
#else
return _page_round((sizeof canary) + size) + page_size * (size_t) 3U;
#endif
}

View File

@ -37,6 +37,9 @@ main(void)
void * buf;
size_t size;
assert(sodium_alloc_overhead((size_t) 0U) !=
sodium_alloc_overhead((size_t) 65537U));
#ifdef SIGSEGV
signal(SIGSEGV, segv_handler);
#endif