summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2013-11-10 10:26:57 -0700
committerSimon Glass <sjg@chromium.org>2014-01-08 17:24:19 -0700
commit77595c6d9e2c1af9c3b143f496c4c47d0e95a458 (patch)
treefd18c5f9e08c1a556ad703eb1e9b1086164cf8f6 /include
parentf4d8de48f5a2aa1885daa0d425b8c0568a2ccb69 (diff)
downloadu-boot-77595c6d9e2c1af9c3b143f496c4c47d0e95a458.tar.gz
u-boot-77595c6d9e2c1af9c3b143f496c4c47d0e95a458.tar.bz2
u-boot-77595c6d9e2c1af9c3b143f496c4c47d0e95a458.zip
sandbox: Improve/augment memory allocation functions
Implement realloc() and free() for sandbox, by adding a header to each block which contains the block size. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/os.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/os.h b/include/os.h
index 950433daa3..1575a96922 100644
--- a/include/os.h
+++ b/include/os.h
@@ -107,6 +107,35 @@ void os_tty_raw(int fd);
void *os_malloc(size_t length);
/**
+ * Free memory previous allocated with os_malloc()/os_realloc()
+ *
+ * This returns the memory to the OS.
+ *
+ * \param ptr Pointer to memory block to free
+ */
+void *os_free(void *ptr);
+
+/**
+ * Reallocate previously-allocated memory to increase/decrease space
+ *
+ * This works in a similar way to the C library realloc() function. If
+ * length is 0, then ptr is freed. Otherwise the space used by ptr is
+ * expanded or reduced depending on whether length is larger or smaller
+ * than before.
+ *
+ * If ptr is NULL, then this is similar to calling os_malloc().
+ *
+ * This function may need to move the memory block to make room for any
+ * extra space, in which case the new pointer is returned.
+ *
+ * \param ptr Pointer to memory block to reallocate
+ * \param length New length for memory block
+ * \return pointer to new memory block, or NULL on failure or if length
+ * is 0.
+ */
+void *os_realloc(void *ptr, size_t length);
+
+/**
* Access to the usleep function of the os
*
* \param usec Time to sleep in micro seconds