aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/inc/mem.h10
-rw-r--r--libc/inc/sys.h9
-rw-r--r--libc/mem.c17
3 files changed, 23 insertions, 13 deletions
diff --git a/libc/inc/mem.h b/libc/inc/mem.h
index 4750efb..a01c9a2 100644
--- a/libc/inc/mem.h
+++ b/libc/inc/mem.h
@@ -10,14 +10,14 @@ void free_debug(void *ptr, const char *file, int line, const char *func, const c
#define malloc(size) malloc_debug(size, __FILE__, __LINE__, __func__, #size)
#define free(ptr) free_debug(ptr, __FILE__, __LINE__, __func__, #ptr)
-// Huh
+/* void *_malloc(u32 size); */
+/* void _free(void *ptr); */
+/* #define malloc(size) _malloc(size) */
+/* #define free(ptr) _free(ptr) */
+
#ifdef kernel
void heap_init(u32 start);
-/* void *malloc(u32 size); */
-/* void free(void *ptr); */
#elif defined(userspace)
-/* void *malloc(u32 size); */
-/* void free(void *ptr); */
#else
#error "No lib target specified. Please use -Dkernel or -Duserspace"
#endif
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index 3145432..c846b4b 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -98,14 +98,13 @@ int sysv(enum sys num, ...);
#define event_unregister(id) sys1(SYS_UNREGISTER, (int)(id))
#define msg_send(pid, type, msg) sys3(SYS_SEND, (int)(pid), (int)(type), (int)(msg))
-#define msg_receive() (struct message *)sys0(SYS_RECEIVE)
+#define msg_receive(buf) (struct message *)sys1(SYS_RECEIVE, (int)(buf))
#define getpid() (int)sys0(SYS_GETPID)
-static inline struct message *msg_receive_loop()
+static inline struct message *msg_receive_loop(struct message *buf)
{
- struct message *msg;
- while (!(msg = msg_receive()))
+ while (!msg_receive(&buf))
yield();
- return msg;
+ return buf;
}
// Simple read wrapper
diff --git a/libc/mem.c b/libc/mem.c
index 0c0ad4d..17703d5 100644
--- a/libc/mem.c
+++ b/libc/mem.c
@@ -347,13 +347,24 @@ void _free(void *ptr)
void *malloc_debug(u32 size, const char *file, int line, const char *func, const char *inp)
{
- printf("MALLOC:\t%s:%d: %s: %dB (%s)\n", file, line, func, size, inp);
- return _malloc(size);
+ void *ret = _malloc(size);
+#ifdef kernel
+ printf("K");
+#else
+ printf("U");
+#endif
+ printf("MALLOC\t%s:%d: %s: 0x%x %dB (%s)\n", file, line, func, ret, size, inp);
+ return ret;
}
void free_debug(void *ptr, const char *file, int line, const char *func, const char *inp)
{
- printf("FREE:\t%s:%d: %s: 0x%x (%s)\n", file, line, func, ptr, inp);
+#ifdef kernel
+ printf("K");
+#else
+ printf("U");
+#endif
+ printf("FREE\t%s:%d: %s: 0x%x (%s)\n", file, line, func, ptr, inp);
if (ptr)
_free(ptr);
}