aboutsummaryrefslogtreecommitdiffstats
path: root/src/slibc-alloc.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-10-31 05:01:07 +0100
committerMattias Andrée <maandree@operamail.com>2015-10-31 05:01:07 +0100
commit1cf6842543cbbea5564d2908791f3251c60f3d73 (patch)
tree2e71adc36358b7acccecf8ece8de99400ae3d8a3 /src/slibc-alloc.c
parentupdate todo (diff)
downloadslibc-1cf6842543cbbea5564d2908791f3251c60f3d73.tar.gz
slibc-1cf6842543cbbea5564d2908791f3251c60f3d73.tar.bz2
slibc-1cf6842543cbbea5564d2908791f3251c60f3d73.tar.xz
doc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/slibc-alloc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/slibc-alloc.c b/src/slibc-alloc.c
index 604eff1..a7ae30a 100644
--- a/src/slibc-alloc.c
+++ b/src/slibc-alloc.c
@@ -25,8 +25,31 @@
+/**
+ * Get the alignment-shift of a pointer.
+ *
+ * @param p:void* The pointer.
+ * @return :size_t The number of bytes added for alignment.
+ * This excludes the information this macro
+ * reads, and the storage of the allocation-size.
+ */
#define __ALIGN(p) (*(size_t*)(((char*)(p)) - sizeof(size_t)))
+
+/**
+ * Get the allocated pointer from a returned pointer.
+ *
+ * @param p:void* The pointer returned by a `malloc`-family function.
+ * @return The pointer allocated by a `malloc`-family function.
+ */
#define PURE_ALLOC(p) (((char*)(p)) - (__ALIGN(p) + 2 * sizeof(size_t)))
+
+/**
+ * Get the real allocation is of a pointer, including
+ * the size of the metadata storage and the alignment-padding.
+ *
+ * @param p:void* The pointer.
+ * @return :size_t The real allocation size of the pointer.
+ */
#define PURE_SIZE(p) (*(size_t*)PURE_ALLOC(p) + 2 * sizeof(size_t))