+static bool move;
+#define ALIGN (sizeof(void *)*2)
+
+static void *my_alloc(size_t len)
+{
+ char *ret = malloc(len + ALIGN);
+ memcpy(ret, &len, sizeof(len));
+ return ret + ALIGN;
+}
+
+static void my_free(void *p)
+{
+ if (p)
+ free((char *)p - ALIGN);
+}
+
+static void *my_realloc(void *old, size_t new_size)
+{
+ char *ret;
+
+ /* Test what happens if we always move */
+ if (move) {
+ size_t old_size = *(size_t *)((char *)old - ALIGN);
+ ret = my_alloc(new_size);
+ memcpy(ret, old, old_size > new_size ? new_size : old_size);
+ my_free(old);
+ } else {
+ ret = realloc((char *)old - ALIGN, new_size + ALIGN);
+ memcpy(ret, &new_size, sizeof(new_size));
+ ret += ALIGN;
+ }
+ return ret;
+}
+