diff options
author | Anton Kling <anton@kling.gg> | 2024-04-15 23:47:25 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-04-16 00:02:23 +0200 |
commit | efe10908766d96974c008a6a8f124916fdca7a14 (patch) | |
tree | 69f90dc3c01d32d63a38ab50f61268b1ac06dc97 /userland | |
parent | 62ba2a9ab01e5f2a9b1cd325af8d3112702b7713 (diff) |
Kernel: Improve "out of memory" error handling
It can now boot with fairly low memory while not crashing and instead
gracefully failing the operation. Userland still does not properly
handle errors.
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libgui/libgui.c | 5 | ||||
-rw-r--r-- | userland/windowserver/ws.c | 3 |
2 files changed, 3 insertions, 5 deletions
diff --git a/userland/libgui/libgui.c b/userland/libgui/libgui.c index f7a8079..07edbdd 100644 --- a/userland/libgui/libgui.c +++ b/userland/libgui/libgui.c @@ -308,10 +308,7 @@ GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy) { ftruncate(w->bitmap_fd, MAX_WINDOW_SIZE * sizeof(uint32_t)); void *rc = mmap(NULL, MAX_WINDOW_SIZE * sizeof(uint32_t), 0, 0, w->bitmap_fd, 0); - if (!((int)rc >= 0)) { - printf("rc: %x\n", rc); - assert(0); - } + assert(rc != (void *)(-1)); w->bitmap_ptr = rc; // Send the request to the windowserver diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c index 6d01048..11efa59 100644 --- a/userland/windowserver/ws.c +++ b/userland/windowserver/ws.c @@ -103,6 +103,7 @@ void setup_display(DISPLAY *disp, const char *path, uint64_t size) { ; } disp->true_buffer = mmap(NULL, size, 0, 0, disp->vga_fd, 0); + assert(disp->true_buffer != (void *)(-1)); disp->back_buffer = malloc(size + 0x1000); disp->window = window; @@ -110,7 +111,7 @@ void setup_display(DISPLAY *disp, const char *path, uint64_t size) { assert(disp->wallpaper_fd >= 0); ftruncate(disp->wallpaper_fd, size); void *rc = mmap(NULL, size, 0, 0, disp->wallpaper_fd, 0); - assert(rc); + assert(rc != (void *)(-1)); disp->wallpaper_buffer = rc; for (int i = 0; i < disp->size / disp->bpp; i++) { uint32_t *p = disp->wallpaper_buffer + i * sizeof(uint32_t); |