diff options
Diffstat (limited to 'libs/libgui/msg.c')
-rw-r--r-- | libs/libgui/msg.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libs/libgui/msg.c b/libs/libgui/msg.c new file mode 100644 index 0000000..73af242 --- /dev/null +++ b/libs/libgui/msg.c @@ -0,0 +1,31 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include <assert.h> +#include <errno.h> +#include <libgui/msg.h> +#include <print.h> +#include <sys.h> + +res msg_send(u32 pid, enum message_type type, void *data, u32 size) +{ + if (!data) + return -EFAULT; + assert((signed)pid != -1 && size >= sizeof(struct message_header)); + char path[32] = { 0 }; + sprintf(path, "/proc/%d/msg", pid); + struct message_header *header = data; + header->magic = MSG_MAGIC; + header->src = getpid(); + header->type = type; + return write(path, data, 0, size); +} + +res msg_receive(void *buf, u32 size) +{ + int ret = read("/proc/self/msg", buf, 0, size); + struct message_header *header = buf; + if (header->magic == MSG_MAGIC) + return ret; + else + return -1; +} |