summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/stdlib.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index 6a2051d..1455a1f 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -11,6 +11,8 @@
#include <stddef.h>
+#define PAGE_SIZE 4096
+
/**
* converts single digit int to base 36
* @param i - int
@@ -194,4 +196,59 @@ extern unsigned int bound(unsigned int min, unsigned int value,
*/
extern void delay(int count);
+/**
+ * Allocates size_t bytes in memory
+ *
+ * @param size - the amount of bytes to allocate
+ * @returns the address allocated or NULL on failure
+ */
+extern void *malloc(size_t size);
+
+/**
+ * Rellocates a given allocated ptr to a new size of bytes in memory.
+ * If ptr is NULL it will allocate new memory.
+ *
+ * @param ptr - the pointer to reallocate
+ * @param size - the amount of bytes to reallocate to
+ * @returns the address allocated or NULL on failure
+ */
+extern void *realloc(void *ptr, size_t size);
+
+/**
+ * Frees an allocated pointer in memory
+ *
+ * @param ptr - the pointer to free
+ */
+extern void free(void *ptr);
+
+/**
+ * Allocate a single page of memory
+ *
+ * @returns the address allocated or NULL on failure
+ */
+extern void *alloc_page(void);
+
+/**
+ * Allocate size_t amount of contiguous virtual pages
+ *
+ * @param count - the number of pages to allocate
+ * @returns the address allocated or NULL on failure
+ */
+extern void *alloc_pages(size_t count);
+
+/**
+ * Free allocated pages.
+ *
+ * @param ptr - the pointer provided by alloc_page or alloc_pages
+ */
+extern void free_pages(void *ptr);
+
+/**
+ * Abort the current process with a given message.
+ *
+ * @param format - the format string
+ * @param ... - variable args for the format
+ */
+__attribute__((noreturn)) extern void panic(const char *format, ...);
+
#endif /* stlib.h */