summaryrefslogtreecommitdiff
path: root/include/stdlib.h
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-03 16:53:51 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-03 16:54:42 -0400
commit516e920cd96730cf470357aa250636d9d42a849c (patch)
tree16e177ffc8bfed0a86abe46455bcbb37c2dbed6d /include/stdlib.h
parentboot headers moved (diff)
downloadcomus-516e920cd96730cf470357aa250636d9d42a849c.tar.gz
comus-516e920cd96730cf470357aa250636d9d42a849c.tar.bz2
comus-516e920cd96730cf470357aa250636d9d42a849c.zip
memory allocator/pager, plus other stuff
Diffstat (limited to 'include/stdlib.h')
-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 */