// MIT License, Copyright (c) 2021 Marvin Borner #include #include #include #include #include res msg_send(u32 pid, enum message_type type, void *data, u32 size) { assert((signed)pid != -1 && size >= sizeof(struct message_header)); char path[32] = { 0 }; snprintf(path, sizeof(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; }