diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-08-30 17:36:09 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-08-30 17:36:09 +0200 |
commit | 22d37d84a7ab0bb4208cdc8828541a30ef0821e2 (patch) | |
tree | f4405e288fc9c37b97c574325245bdb574c4144e /include/slibc-alloc.h | |
parent | add crealloc (diff) | |
download | slibc-22d37d84a7ab0bb4208cdc8828541a30ef0821e2.tar.gz slibc-22d37d84a7ab0bb4208cdc8828541a30ef0821e2.tar.bz2 slibc-22d37d84a7ab0bb4208cdc8828541a30ef0821e2.tar.xz |
add memory allocation functions
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | include/slibc-alloc.h | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/include/slibc-alloc.h b/include/slibc-alloc.h index 0308482..b230f16 100644 --- a/include/slibc-alloc.h +++ b/include/slibc-alloc.h @@ -54,9 +54,12 @@ void secure_free(void*); * @throws EINVAL If `segment` is `NULL`. * @throws EFAULT If `segment` is not a pointer to an allocation * on the heap, or was not allocated with a function - * implemented in slibc. + * implemented in slibc. It is however not guaranteed + * that this will happen, undefined behaviour may be + * invoked instead. */ -size_t allocsize(void*); /* TODO not implemented */ +size_t allocsize(void*) + __GCC_ONLY(__attribute__((warn_unused_result))); /** * Variant of `realloc` that overrides newly allocated space @@ -67,8 +70,53 @@ size_t allocsize(void*); /* TODO not implemented */ * @param ptr The old allocation, see `realloc` for more details. * @param size The new allocation size, see `realloc` for more details. * @return The new allocation, see `realloc` for more details. + * + * @throws ENOMEM The process cannot allocate more memory. + */ +void* crealloc(void*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result))); + +/** + * This function behaves exactly like `realloc`, except it is + * guaranteed to never initialise or errors data. + * + * @param ptr The old allocation, see `realloc` for more details. + * @param size The new allocation size, see `realloc` for more details. + * @return The new allocation, see `realloc` for more details. + * + * @throws ENOMEM The process cannot allocate more memory. + */ +void* fast_realloc(void*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result))); + +/** + * This function behaves exactly like `crealloc`, except it + * does not initialise newly allocated size. + * + * @param ptr The old allocation, see `realloc` for more details. + * @param size The new allocation size, see `realloc` for more details. + * @return The new allocation, see `realloc` for more details. + * + * @throws ENOMEM The process cannot allocate more memory. + */ +void* secure_realloc(void*, size_t) + __GCC_ONLY(__attribute__((warn_unused_result))); + +/** + * This function behaves exactly like `fast_realloc`, except: + * - Its haviour is undefined if `ptr` is `NULL`. + * - Its haviour is undefined `size` equals the old allocation size. + * - Its haviour is undefined if `size` is zero. + * - It will never free `ptr`. + * + * @param ptr The old allocation, see `realloc` for more details. + * @param size The new allocation size, see `realloc` for more details. + * @return The new allocation, see `realloc` for more details. + * + * @throws ENOMEM The process cannot allocate more memory. */ -void* crealloc(void*, size_t); /* TODO not implemented */ +void* naive_realloc(void*, size_t) /* sic! we limit ourself to ASCII */ + __GCC_ONLY(__attribute__((nonnull, warn_unused_result))); /** |