aboutsummaryrefslogtreecommitdiff
path: root/libs/libc/inc/mem.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libc/inc/mem.h')
-rw-r--r--libs/libc/inc/mem.h70
1 files changed, 51 insertions, 19 deletions
diff --git a/libs/libc/inc/mem.h b/libs/libc/inc/mem.h
index a25feaf..64f74f5 100644
--- a/libs/libc/inc/mem.h
+++ b/libs/libc/inc/mem.h
@@ -5,34 +5,66 @@
#include <def.h>
-// malloc
+/**
+ * malloc
+ */
+
+ATTR((malloc)) ATTR((alloc_size(1))) RET_NONNULL void *_malloc(u32 size);
+
ATTR((malloc))
ATTR((alloc_size(1)))
-INLINE RET_NONNULL void *malloc_debug(u32 size, const char *file, int line, const char *func,
- const char *inp) NONNULL;
+RET_NONNULL void *malloc_debug(u32 size, const char *file, int line, const char *func,
+ const char *inp) NONNULL;
+
+/**
+ * realloc
+ */
+
+ATTR((malloc)) ATTR((alloc_size(2))) void *_realloc(void *ptr, u32 size);
-// realloc
ATTR((malloc))
ATTR((alloc_size(2)))
-INLINE RET_NONNULL void *realloc_debug(void *ptr, u32 size, const char *file, int line,
- const char *func, const char *inp);
+void *realloc_debug(void *ptr, u32 size, const char *file, int line, const char *func,
+ const char *inp0, const char *inp1);
+
+/**
+ * zalloc
+ */
+
+ATTR((malloc)) ATTR((alloc_size(1))) RET_NONNULL void *_zalloc(u32 size);
-// zalloc
ATTR((malloc))
ATTR((alloc_size(1)))
-RET_NONNULL
-INLINE void *zalloc_debug(u32 size, const char *file, int line, const char *func, const char *inp);
+RET_NONNULL void *zalloc_debug(u32 size, const char *file, int line, const char *func,
+ const char *inp) NONNULL;
+
+/**
+ * free
+ */
+
+void _free(void *ptr) NONNULL;
+void free_debug(void *ptr, const char *file, int line, const char *func, const char *inp) NONNULL;
-// free
-INLINE void free_debug(void *ptr, const char *file, int line, const char *func,
- const char *inp) NONNULL;
+/**
+ * Debug wrappers
+ */
-// Debug wrappers
+#if DEBUG_ALLOC
#define realloc(ptr, size) \
- realloc_debug((void *)ptr, (u32)(size), __FILE__, __LINE__, __func__, #size)
+ realloc_debug((void *)ptr, (u32)(size), __FILE__, __LINE__, __func__, #ptr, #size)
#define zalloc(size) zalloc_debug((u32)(size), __FILE__, __LINE__, __func__, #size)
#define malloc(size) malloc_debug((u32)(size), __FILE__, __LINE__, __func__, #size)
#define free(ptr) free_debug((void *)(ptr), __FILE__, __LINE__, __func__, #ptr)
+#else
+#define realloc(ptr, size) _realloc((void *)ptr, (u32)(size))
+#define zalloc(size) _zalloc((u32)(size))
+#define malloc(size) _malloc((u32)(size))
+#define free(ptr) _free((void *)(ptr))
+#endif
+
+/**
+ * Standard memory functions
+ */
void *memcpy(void *dest, const void *src, u32 n) NONNULL;
void *memset(void *dest, u32 val, u32 n) NONNULL;
@@ -41,11 +73,11 @@ s32 memcmp(const void *s1, const void *s2, u32 n) NONNULL;
u8 mememp(const u8 *buf, u32 n) NONNULL;
#ifdef KERNEL
-INLINE void *memcpy_user(void *dest, const void *src, u32 n) NONNULL;
-INLINE void *memset_user(void *dest, u32 val, u32 n) NONNULL;
-INLINE void *memchr_user(void *src, char c, u32 n) NONNULL;
-INLINE s32 memcmp_user(const void *s1, const void *s2, u32 n) NONNULL;
-INLINE u8 mememp_user(const u8 *buf, u32 n) NONNULL;
+void *memcpy_user(void *dest, const void *src, u32 n) NONNULL;
+void *memset_user(void *dest, u32 val, u32 n) NONNULL;
+void *memchr_user(void *src, char c, u32 n) NONNULL;
+s32 memcmp_user(const void *s1, const void *s2, u32 n) NONNULL;
+u8 mememp_user(const u8 *buf, u32 n) NONNULL;
#endif
#endif