aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2021-02-16 22:33:42 +0100
committerMarvin Borner2021-02-16 22:33:42 +0100
commit392b0ff1fcc52c189f131c71ea2a969d1b8c5690 (patch)
tree22cc9e27c09cb9887ca6972e07602070cda25451
parent1287f9dfe987f0456e4fb0741385d5f0278ef53b (diff)
Okay!
-rw-r--r--apps/exec.c1
-rw-r--r--apps/wm.c3
-rw-r--r--kernel/features/proc.c2
-rw-r--r--kernel/inc/proc.h4
-rw-r--r--libc/inc/sys.h2
-rw-r--r--libgui/gfx.c4
-rw-r--r--libgui/gui.c12
-rw-r--r--libgui/msg.c10
8 files changed, 22 insertions, 16 deletions
diff --git a/apps/exec.c b/apps/exec.c
index 8e3bf95..ae7ca35 100644
--- a/apps/exec.c
+++ b/apps/exec.c
@@ -46,6 +46,7 @@ void on_submit(struct gui_event_keyboard *event, struct element *elem)
int main()
{
+ log("exec loaded\n");
struct element *root = gui_init("Exec", WIDTH, HEIGHT, COLOR_BLACK);
struct element *input =
gui_add_text_input(root, 0, 0, 100, FONT_32, COLOR_WHITE, COLOR_BLACK);
diff --git a/apps/wm.c b/apps/wm.c
index bcb3e71..3c952c8 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -311,6 +311,8 @@ int main(int argc, char **argv)
err(1, "POLL ERROR!\n");
}
+ assert(msg.magic == MSG_MAGIC);
+
switch (msg.type) {
case GFX_NEW_CONTEXT: {
struct context *ctx = msg.data;
@@ -340,6 +342,7 @@ int main(int argc, char **argv)
redraw_focused();
break;
default:
+ log("Unknown WM request %d\n", msg.type);
break;
}
};
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index fdf509c..74fa5d4 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -341,7 +341,7 @@ s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struct devic
return count;
} else if (!memcmp(path, "msg", 4)) {
if (stack_empty(p->messages)) {
- return 0; // This shouldn't happen
+ return -1; // This shouldn't happen
} else {
u8 *msg = stack_pop(p->messages);
if (!msg)
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index cb583d6..a727210 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -17,7 +17,7 @@
#define GDT_USER_CODE_OFFSET 0x1b // User code segment offset in GDT (with ring3 mask)
#define GDT_USER_DATA_OFFSET 0x23 // User data segment offset in GDT (with ring3 mask)
-#define PROC_MAX_WAIT_IDS 128
+#define PROC_MAX_WAIT_IDS 16
#define PROC_WAIT_MAGIC 0x00528491
#define STREAM_MAX_SIZE 4096
@@ -34,7 +34,7 @@ struct proc_wait_identifier {
};
struct proc_wait {
- struct proc_wait_identifier ids[PROC_MAX_WAIT_IDS]; // dev_id
+ struct proc_wait_identifier ids[PROC_MAX_WAIT_IDS];
u32 id_cnt;
};
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index e7fdcf0..aead212 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -90,7 +90,6 @@ static inline u32 getpid()
return buf;
}
-#include <mem.h>
#include <print.h>
#include <str.h>
static inline u32 pidof(const char *name)
@@ -109,6 +108,7 @@ static inline u32 pidof(const char *name)
}
// Simple read wrapper
+#include <mem.h>
static inline void *sread(const char *path)
{
struct stat s = { 0 };
diff --git a/libgui/gfx.c b/libgui/gfx.c
index d3a66f2..a6e23e6 100644
--- a/libgui/gfx.c
+++ b/libgui/gfx.c
@@ -100,8 +100,8 @@ static void draw_rectangle(struct context *ctx, int x1, int y1, int x2, int y2,
struct context *gfx_new_ctx(struct context *ctx)
{
struct message msg = { 0 };
- msg_send(pidof(WM_PATH), GFX_NEW_CONTEXT, ctx);
- msg_receive(&msg);
+ assert(msg_send(pidof(WM_PATH), GFX_NEW_CONTEXT, ctx) > 0);
+ assert(msg_receive(&msg) > 0);
memcpy(ctx, msg.data, sizeof(*ctx));
return ctx;
}
diff --git a/libgui/gui.c b/libgui/gui.c
index 052a07b..8eb7ce9 100644
--- a/libgui/gui.c
+++ b/libgui/gui.c
@@ -23,8 +23,7 @@ static struct window windows[MAX_WINDOWS] = { 0 };
static struct window *new_window(const char *title, int x, int y, u32 width, u32 height, int flags)
{
- if (window_count + 1 >= MAX_WINDOWS)
- return NULL;
+ assert(window_count + 1 <= MAX_WINDOWS);
struct window *win = &windows[window_count + 1];
win->ctx = malloc(sizeof(*win->ctx));
@@ -200,7 +199,6 @@ static int absolute_y_off(struct element *elem)
struct context *gui_get_context(int x, int y, u32 width, u32 height)
{
- log("GET CONTEXT: %dx%d\n", width, height);
struct context *ctx = malloc(sizeof(*ctx));
ctx->pid = getpid();
ctx->x = x;
@@ -535,10 +533,7 @@ void gui_event_loop(struct element *container)
struct message msg = { 0 };
struct element *focused = NULL;
while (1) {
- /* if (!msg_receive(&msg)) { */
- yield();
- continue;
- /* } */
+ assert(msg_receive(&msg) > 0);
switch (msg.type) {
case GUI_KILL: {
@@ -591,6 +586,9 @@ void gui_event_loop(struct element *container)
gui_sync_window(container->window_id);
break;
}
+ default: {
+ log("Unknown GUI request %d\n", msg.type);
+ }
}
}
diff --git a/libgui/msg.c b/libgui/msg.c
index bf3d28c..4576a5f 100644
--- a/libgui/msg.c
+++ b/libgui/msg.c
@@ -5,19 +5,23 @@
#include <print.h>
#include <sys.h>
+static struct message msg_buf = { 0 };
+
int msg_send(u32 pid, enum message_type type, void *data)
{
assert((signed)pid != -1);
char path[32] = { 0 };
sprintf(path, "/proc/%d/msg", pid);
- struct message msg = { .magic = MSG_MAGIC, .src = getpid(), .type = type, .data = data };
- return write(path, &msg, 0, sizeof(msg));
+ msg_buf.magic = MSG_MAGIC;
+ msg_buf.src = getpid();
+ msg_buf.type = type;
+ msg_buf.data = data;
+ return write(path, &msg_buf, 0, sizeof(msg_buf));
}
int msg_receive(struct message *msg)
{
int ret = read("/proc/self/msg", msg, 0, sizeof(*msg));
- assert(msg->magic == MSG_MAGIC); // TODO: Remove? (Many >0 checks are needed)
if (msg->magic == MSG_MAGIC && ret == sizeof(*msg))
return ret;
else