summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/arch/i386/mmu.c8
-rw-r--r--kernel/cpu/syscall.c1
-rw-r--r--kernel/drivers/keyboard.c22
-rw-r--r--kernel/fs/shm.c9
-rw-r--r--kernel/fs/vfs.c4
-rw-r--r--kernel/fs/vfs.h1
-rw-r--r--kernel/includes/syscalls.h3
-rw-r--r--kernel/kmalloc.c2
-rw-r--r--kernel/process.s2
-rw-r--r--kernel/sched/scheduler.c11
-rw-r--r--kernel/syscalls/munmap.c6
-rw-r--r--userland/irc/irc.c3
-rw-r--r--userland/libc/Makefile4
-rw-r--r--userland/libc/include/sys/mman.h1
-rw-r--r--userland/libc/include/syscall.h1
-rw-r--r--userland/libc/sys/mman/munmap.c6
-rw-r--r--userland/libgui/libgui.c13
-rw-r--r--userland/libgui/libgui.h7
-rw-r--r--userland/terminal/term.c14
-rw-r--r--userland/windowserver/Makefile5
-rw-r--r--userland/windowserver/ws.c136
-rw-r--r--userland/windowserver/ws.h1
23 files changed, 171 insertions, 91 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 71ea761..0b59509 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -1,6 +1,6 @@
CC="i686-sb-gcc"
AS="i686-sb-as"
-OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o ipc.o syscalls/ipc.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o lib/list.o cpu/arch_inst.o cpu/int_syscall.o queue.o syscalls/queue.o
+OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o syscalls/open.o syscalls/write.o syscalls/pwrite.o ipc.o syscalls/ipc.o syscalls/port.o syscalls/map_frames.o syscalls/virtual_to_physical.o syscalls/install_irq.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o lib/list.o cpu/arch_inst.o cpu/int_syscall.o queue.o syscalls/queue.o syscalls/munmap.o
CFLAGS = -std=c99 -Ofast -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
#CFLAGS = -std=c99 -Ofast -flto -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
#CFLAGS = -std=c99 -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
diff --git a/kernel/arch/i386/mmu.c b/kernel/arch/i386/mmu.c
index 8761dd8..9b63a9a 100644
--- a/kernel/arch/i386/mmu.c
+++ b/kernel/arch/i386/mmu.c
@@ -156,11 +156,11 @@ void write_to_frame(u32 frame_address, u8 on) {
num_allocated_frames++;
tmp_small_frames[INDEX_FROM_BIT(frame)] |=
((u32)0x1 << OFFSET_FROM_BIT(frame));
- return;
+ } else {
+ num_allocated_frames--;
+ tmp_small_frames[INDEX_FROM_BIT(frame)] &=
+ ~((u32)0x1 << OFFSET_FROM_BIT(frame));
}
- num_allocated_frames--;
- tmp_small_frames[INDEX_FROM_BIT(frame)] &=
- ~((u32)0x1 << OFFSET_FROM_BIT(frame));
}
PageDirectory *get_active_pagedirectory(void) {
diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c
index 6b260d3..7734f4e 100644
--- a/kernel/cpu/syscall.c
+++ b/kernel/cpu/syscall.c
@@ -205,6 +205,7 @@ int (*syscall_functions[])() = {
(void(*))syscall_queue_create,
(void(*))syscall_queue_add,
(void(*))syscall_queue_wait,
+ (void(*))syscall_munmap,
};
void int_syscall(reg_t *r);
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index 24ebbb0..fe4fe16 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -155,26 +155,10 @@ void int_keyboard(reg_t *frame) {
ev.mode |= is_alt_down << 1;
ev.mode |= is_ctrl_down << 2;
fifo_object_write((u8 *)&ev, 0, sizeof(ev), keyboard_fifo);
- kb_inode->has_data = keyboard_fifo->has_data;
-}
-
-#define PS2_WAIT_RECV \
- { \
- for (;;) { \
- u8 status = inb(PS2_REG_STATUS); \
- if (status & 0x1) \
- break; \
- } \
- }
-
-#define PS2_WAIT_SEND \
- { \
- for (;;) { \
- u8 status = inb(PS2_REG_STATUS); \
- if (!(status & (0x1 << 1))) \
- break; \
- } \
+ if (kb_inode) {
+ kb_inode->has_data = keyboard_fifo->has_data;
}
+}
void install_keyboard(void) {
keyboard_fifo = create_fifo_object();
diff --git a/kernel/fs/shm.c b/kernel/fs/shm.c
index e0c0211..9215b24 100644
--- a/kernel/fs/shm.c
+++ b/kernel/fs/shm.c
@@ -55,9 +55,10 @@ vfs_vm_object_t *shm_get_vm_object(u64 length, u64 offset, vfs_fd_t *fd) {
int shm_ftruncate(vfs_fd_t *fd, size_t length) {
vfs_vm_object_t *p = fd->inode->internal_object;
p->size = length;
- p->virtual_object = ksbrk(length);
+ p->real_pointer = krealloc(p->real_pointer, length + 0x2000);
+ p->virtual_object = align_page(p->real_pointer);
int n = (uintptr_t)align_page((void *)(u32)length) / 0x1000;
- p->object = kmalloc(sizeof(void *) * n);
+ p->object = krealloc(p->object, sizeof(void *) * n);
for (int i = 0; i < n; i++) {
p->object[i] =
(void *)(get_page(p->virtual_object + (i * 0x1000), NULL, 0, 0)->frame *
@@ -73,9 +74,7 @@ int shm_open(const char *name, int oflag, mode_t mode) {
if (!internal_object) {
// if (!(oflag & O_CREAT))
// return -EMFILE;
- internal_object = kmalloc(sizeof(vfs_vm_object_t));
- internal_object->object = NULL;
- internal_object->size = 0;
+ internal_object = kcalloc(1, sizeof(vfs_vm_object_t));
hashmap_add_entry(shared_memory_objects, name, internal_object, NULL, 0);
}
diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c
index 6a8dfd1..143dc9d 100644
--- a/kernel/fs/vfs.c
+++ b/kernel/fs/vfs.c
@@ -379,6 +379,10 @@ vfs_vm_object_t *vfs_get_vm_object(int fd, u64 length, u64 offset) {
if (!vfs_fd) {
return NULL;
}
+ assert(vfs_fd->inode);
+ if(!vfs_fd->inode->get_vm_object) {
+ return NULL;
+ }
vfs_vm_object_t *r = vfs_fd->inode->get_vm_object(length, offset, vfs_fd);
return r;
}
diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h
index bee3179..74e5bf4 100644
--- a/kernel/fs/vfs.h
+++ b/kernel/fs/vfs.h
@@ -29,6 +29,7 @@ typedef struct vfs_mounts vfs_mounts_t;
#define FS_TYPE_LINK 7
struct vfs_vm_object {
+ void *real_pointer;
void *virtual_object;
void **object;
u64 size;
diff --git a/kernel/includes/syscalls.h b/kernel/includes/syscalls.h
index a0be694..cd49a1b 100644
--- a/kernel/includes/syscalls.h
+++ b/kernel/includes/syscalls.h
@@ -1,4 +1,5 @@
#include <fs/vfs.h>
+#include <queue.h>
#include <signal.h>
#include <socket.h>
#include <stddef.h>
@@ -6,7 +7,6 @@
#include <time.h>
#include <typedefs.h>
#include <types.h>
-#include <queue.h>
void syscall_outw(u16 port, u16 word);
u32 syscall_inl(u16 port);
@@ -68,6 +68,7 @@ typedef struct SYS_MMAP_PARAMS {
} __attribute__((packed)) SYS_MMAP_PARAMS;
void *syscall_mmap(SYS_MMAP_PARAMS *args);
+int syscall_munmap(void *addr, size_t length);
#ifndef MSLEEP_H
#define MSLEEP_H
void syscall_msleep(u32 ms);
diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c
index f75ab33..48fb4c7 100644
--- a/kernel/kmalloc.c
+++ b/kernel/kmalloc.c
@@ -184,7 +184,7 @@ void *krealloc(void *ptr, size_t size) {
size_t l = get_mem_size(ptr);
size_t to_copy = min(l, size);
memcpy(rc, ptr, to_copy);
- // kfree(ptr);
+ kfree(ptr);
return rc;
}
diff --git a/kernel/process.s b/kernel/process.s
index 934d627..ed87959 100644
--- a/kernel/process.s
+++ b/kernel/process.s
@@ -101,8 +101,6 @@ insert_eip_on_stack:
# WARNING: Caller is expected to disable IRQs before calling, and enable IRQs again after function returns
switch_to_task:
-# cli
-
# Save previous task's state
# Notes:
diff --git a/kernel/sched/scheduler.c b/kernel/sched/scheduler.c
index e202be2..ebf2c32 100644
--- a/kernel/sched/scheduler.c
+++ b/kernel/sched/scheduler.c
@@ -535,6 +535,17 @@ void *create_physical_mapping(void **physical_addresses, size_t length) {
return rc;
}
+int munmap(void *addr, size_t length) {
+ for (int i = 0; i < 100; i++) {
+ MemoryMap *m = current_task->maps[i];
+ if (addr == m->u_address) {
+ current_task->maps[i] = NULL;
+ return 0;
+ }
+ }
+ return 0;
+}
+
void *mmap(void *addr, size_t length, int prot, int flags, int fd,
size_t offset) {
(void)addr;
diff --git a/kernel/syscalls/munmap.c b/kernel/syscalls/munmap.c
new file mode 100644
index 0000000..82f7918
--- /dev/null
+++ b/kernel/syscalls/munmap.c
@@ -0,0 +1,6 @@
+#include <sched/scheduler.h>
+#include <syscalls.h>
+
+int syscall_munmap(void *addr, size_t length) {
+return munmap(addr, length);
+}
diff --git a/userland/irc/irc.c b/userland/irc/irc.c
index 297c332..6bdbce5 100644
--- a/userland/irc/irc.c
+++ b/userland/irc/irc.c
@@ -259,7 +259,8 @@ void handle_msg(struct irc_server *server, struct sv msg) {
sb_append_sv(&user_list_message, channel);
sb_append(&user_list_message, ": ");
sb_append_sv(&user_list_message, command_parameters);
- irc_add_message(server, channel, C_TO_SV("*"), SB_TO_SV(user_list_message));
+ irc_add_message(server, channel, C_TO_SV("*"),
+ SB_TO_SV(user_list_message));
sb_free(&user_list_message);
}
}
diff --git a/userland/libc/Makefile b/userland/libc/Makefile
index 62d4973..c818200 100644
--- a/userland/libc/Makefile
+++ b/userland/libc/Makefile
@@ -2,8 +2,8 @@ CC="i686-sb-gcc"
AR="i686-sb-ar"
AS="i686-sb-as"
#CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
-CFLAGS = -ggdb -ffreestanding -Ofast -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
-OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o
+CFLAGS = -ggdb -ffreestanding -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type
+OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o
all: libc.a
%.o: %.c
diff --git a/userland/libc/include/sys/mman.h b/userland/libc/include/sys/mman.h
index 7dfe29a..7cba68f 100644
--- a/userland/libc/include/sys/mman.h
+++ b/userland/libc/include/sys/mman.h
@@ -12,4 +12,5 @@
void *mmap(void *addr, size_t length, int prot, int flags, int fd,
size_t offset);
+int munmap(void *addr, size_t length);
#endif
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index d89ead5..e375079 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -60,6 +60,7 @@
#define SYS_QUEUE_CREATE 49
#define SYS_QUEUE_ADD 50
#define SYS_QUEUE_WAIT 51
+#define SYS_MUNMAP 52
int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
uint32_t esi, uint32_t edi);
diff --git a/userland/libc/sys/mman/munmap.c b/userland/libc/sys/mman/munmap.c
new file mode 100644
index 0000000..940ea46
--- /dev/null
+++ b/userland/libc/sys/mman/munmap.c
@@ -0,0 +1,6 @@
+#include <sys/mman.h>
+#include <syscall.h>
+
+int munmap(void *addr, size_t length) {
+ RC_ERRNO(syscall(SYS_MUNMAP, addr, length,0, 0, 0));
+}
diff --git a/userland/libgui/libgui.c b/userland/libgui/libgui.c
index a344778..2a8361d 100644
--- a/userland/libgui/libgui.c
+++ b/userland/libgui/libgui.c
@@ -256,6 +256,19 @@ void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev)) {
}
}
+void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy) {
+ ftruncate(w->bitmap_fd, sx * sy * sizeof(uint32_t));
+ w->sx = sx;
+ w->sy = sy;
+ char buffer[sizeof(uint8_t) + sizeof(uint32_t) * 2];
+ uint8_t l = 2;
+ memcpy(buffer, &l, sizeof(l));
+ memcpy(buffer + sizeof(uint8_t), &sx, sizeof(sx));
+ memcpy(buffer + sizeof(uint8_t) + sizeof(uint32_t), &sy, sizeof(sy));
+ int len = sizeof(uint8_t) + sizeof(uint32_t) * 2;
+ write(w->ws_socket, buffer, len);
+}
+
GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy) {
GUI_Window *w = malloc(sizeof(GUI_Window));
if (!w)
diff --git a/userland/libgui/libgui.h b/userland/libgui/libgui.h
index cb8d9a7..1c3ac95 100644
--- a/userland/libgui/libgui.h
+++ b/userland/libgui/libgui.h
@@ -5,6 +5,7 @@
#define WINDOWSERVER_EVENT_KEYPRESS 0
#define WINDOWSERVER_EVENT_WINDOW_EXIT 1
+#define WINDOWSERVER_EVENT_WINDOW_RESIZE 2
typedef struct {
int ws_socket;
@@ -25,7 +26,10 @@ struct KEY_EVENT {
typedef struct {
int type;
- struct KEY_EVENT ev;
+ union {
+ struct KEY_EVENT ev;
+ int vector[2];
+ };
} WS_EVENT;
GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy);
@@ -35,4 +39,5 @@ void GUI_OverwriteFont(GUI_Window *w, uint32_t px, uint32_t py,
const uint32_t color);
void GUI_ClearScreen(GUI_Window *w, uint32_t color);
void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev));
+void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy);
#endif
diff --git a/userland/terminal/term.c b/userland/terminal/term.c
index b734bb5..4824a59 100644
--- a/userland/terminal/term.c
+++ b/userland/terminal/term.c
@@ -100,6 +100,8 @@ void newtty(void) {
openpty(&m, &s, NULL, NULL, NULL);
int pid = fork();
if (0 == pid) {
+ close(global_w->ws_socket);
+ close(global_w->bitmap_fd);
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
@@ -242,6 +244,18 @@ void run() {
if (0 >= (rc = read(global_w->ws_socket, &e, sizeof(e)))) {
continue;
}
+ if (WINDOWSERVER_EVENT_WINDOW_EXIT == e.type) {
+ close(global_w->ws_socket);
+ exit(0);
+ return;
+ }
+// if (WINDOWSERVER_EVENT_WINDOW_RESIZE == e.type) {
+// GUI_Resize(global_w, e.vector[0], e.vector[1]);
+// continue;
+// }
+ if (WINDOWSERVER_EVENT_KEYPRESS != e.type) {
+ continue;
+ }
if (1 == e.ev.release) {
continue;
}
diff --git a/userland/windowserver/Makefile b/userland/windowserver/Makefile
index 0adbdaa..d267350 100644
--- a/userland/windowserver/Makefile
+++ b/userland/windowserver/Makefile
@@ -1,6 +1,5 @@
CC="i686-sb-gcc"
-#CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -mgeneral-regs-only -Wimplicit-fallthrough
-CFLAGS = -ggdb -ffreestanding -Ofast -Wall -Wextra -pedantic -mgeneral-regs-only -Wimplicit-fallthrough
+CFLAGS = -ggdb -O0 -Wall -Wextra -Wimplicit-fallthrough
BIN=ws
LIB=-lgcc
INC=-I../libgui/
@@ -14,4 +13,4 @@ clean:
rm $(OBJ) ws
$(BIN): $(OBJ)
- $(CC) -flto -o $(BIN) $(CFLAGS) $(OBJ) $(LIB)
+ $(CC) -o $(BIN) $(CFLAGS) $(OBJ) $(LIB)
diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c
index ceb4f64..6d01048 100644
--- a/userland/windowserver/ws.c
+++ b/userland/windowserver/ws.c
@@ -3,6 +3,7 @@
#include "font.h"
#include <assert.h>
#include <fcntl.h>
+#include <math.h>
#include <poll.h>
#include <socket.h>
#include <stddef.h>
@@ -15,12 +16,46 @@
#define WINDOW_SERVER_SOCKET "/windowserver"
+#define RET_CLICKED(_x, _y, _sx, _sy, _id) \
+ if (contains(_x, _y, _sx, _sy, mouse_x, mouse_y)) { \
+ if (mouse_left_down) { \
+ active_id = _id; \
+ } else if (mouse_left_up) { \
+ if (_id == active_id) { \
+ return 1; \
+ } \
+ } \
+ } else { \
+ if (_id == active_id && mouse_left_up) { \
+ active_id = -1; \
+ } \
+ } \
+ return 0;
+
+// Taken from drivers/keyboard.c
+struct KEY_EVENT {
+ char c;
+ uint8_t mode; // (shift (0 bit)) (alt (1 bit))
+ uint8_t release; // 0 pressed, 1 released
+};
+
+typedef struct {
+ int type;
+ union {
+ struct KEY_EVENT ev;
+ int vector[2];
+ };
+} WS_EVENT;
+
WINDOW *window;
int mouse_x = 0;
int mouse_y = 0;
-int mouse_down = 0;
-int mouse_up = 0;
+int mouse_left_down = 0;
+int mouse_left_up = 0;
+int mouse_right_down = 0;
+int mouse_right_up = 0;
+
int active_id = -1;
int ui_id = 0;
@@ -37,13 +72,6 @@ uint64_t mouse_fd_poll;
void draw(void);
-// Taken from drivers/keyboard.c
-struct KEY_EVENT {
- char c;
- uint8_t mode; // (shift (0 bit)) (alt (1 bit))
- uint8_t release; // 0 pressed, 1 released
-};
-
int create_socket(void) {
struct sockaddr_un address;
int fd = socket(AF_UNIX, 0, 0);
@@ -216,14 +244,27 @@ void parse_window_event(WINDOW *w) {
int bitmap_fd = shm_open(bitmap_name, O_RDWR, O_CREAT);
create_window(w, bitmap_fd, e.px, e.py, e.sx, e.sy);
draw();
+ return;
+ }
+ if (2 == event_type) {
+ uint32_t vec[2];
+ for (; 0 == read(w->fd, vec, sizeof(vec));)
+ ;
+ void *rc =
+ mmap(NULL, vec[0] * vec[1] * sizeof(uint32_t), 0, 0, w->bitmap_fd, 0);
+ if ((void *)-1 == rc) {
+ return;
+ }
+ w->sx = vec[0];
+ w->sy = vec[1];
+ w->buffer_sx = vec[0];
+ w->buffer_sy = vec[1];
+ munmap(w->bitmap_ptr, 0);
+ w->bitmap_ptr = rc;
+ return;
}
}
-typedef struct {
- int type;
- struct KEY_EVENT ev;
-} WS_EVENT;
-
void send_key_event_to_window(struct KEY_EVENT ev) {
WS_EVENT e = {
.type = 0,
@@ -309,6 +350,14 @@ struct mouse_event {
uint8_t y;
};
+void send_resize(WINDOW *w, int x, int y) {
+ WS_EVENT e = {
+ .type = WINDOWSERVER_EVENT_WINDOW_RESIZE,
+ .vector = {x, y},
+ };
+ write(w->fd, &e, sizeof(e));
+}
+
void parse_mouse_event(int fd) {
int16_t xc = 0;
int16_t yc = 0;
@@ -346,12 +395,20 @@ void parse_mouse_event(int fd) {
if (mouse_y < 0) {
mouse_y = 0;
}
- if (mouse_down && !left_button) {
- mouse_up = 1;
+ if (mouse_left_down && !left_button) {
+ mouse_left_up = 1;
+ } else {
+ mouse_left_up = 0;
+ }
+
+ if (mouse_right_down && !right_button) {
+ mouse_right_up = 1;
} else {
- mouse_up = 0;
+ mouse_right_up = 0;
}
- mouse_down = left_button;
+ mouse_right_down = right_button;
+
+ mouse_left_down = left_button;
if (middle_button) {
if (main_display.active_window) {
main_display.active_window->x += xc;
@@ -360,10 +417,13 @@ void parse_mouse_event(int fd) {
&main_display.active_window->y);
}
}
- if (right_button) {
+ if (mouse_right_down) {
if (main_display.active_window) {
- main_display.active_window->sx += xc;
- main_display.active_window->sy -= yc;
+ int new_sx = main_display.active_window->sx + xc;
+ int new_sy = main_display.active_window->sy - yc;
+ new_sx = max(0, new_sx);
+ new_sy = max(0, new_sy);
+ send_resize(main_display.active_window, new_sx, new_sy);
}
}
draw();
@@ -474,20 +534,7 @@ int draw_button(DISPLAY *disp, int x, int y, int sx, int sy, uint32_t border,
draw_rectangle(disp, x + 1, y + 1, sx, sy, filled);
draw_outline(disp, x, y, sx, sy, 1, border);
- if (contains(x, y, sx, sy, mouse_x, mouse_y)) {
- if (mouse_down) {
- active_id = id;
- } else if (mouse_up) {
- if (id == active_id) {
- return 1;
- }
- }
- } else {
- if (id == active_id && mouse_up) {
- active_id = -1;
- }
- }
- return 0;
+ RET_CLICKED(x, y, sx, sy, id)
}
int draw_window(DISPLAY *disp, WINDOW *w, int id) {
@@ -542,20 +589,7 @@ int draw_window(DISPLAY *disp, WINDOW *w, int id) {
}
}
- if (contains(px, py, sx, sy, mouse_x, mouse_y)) {
- if (mouse_down) {
- active_id = id;
- } else if (mouse_up) {
- if (id == active_id) {
- return 1;
- }
- }
- } else {
- if (id == active_id && mouse_up) {
- active_id = -1;
- }
- }
- return 0;
+ RET_CLICKED(x, y, sx, sy, id)
}
void update_display(const DISPLAY *disp) {
@@ -647,8 +681,8 @@ void draw(void) {
}
}
if (ui_state) {
- mouse_down = 0;
- mouse_up = 0;
+ mouse_left_down = 0;
+ mouse_left_up = 0;
ui_state = 0;
draw();
} else {
diff --git a/userland/windowserver/ws.h b/userland/windowserver/ws.h
index 9978b9c..f76523d 100644
--- a/userland/windowserver/ws.h
+++ b/userland/windowserver/ws.h
@@ -5,6 +5,7 @@
#define WINDOWSERVER_EVENT_KEYPRESS 0
#define WINDOWSERVER_EVENT_WINDOW_EXIT 1
+#define WINDOWSERVER_EVENT_WINDOW_RESIZE 2
typedef struct {
int fd;