aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--apps/link.ld15
-rw-r--r--apps/wm.c3
-rw-r--r--kernel/features/load.c1
-rw-r--r--kernel/main.c2
-rw-r--r--libc/inc/def.h2
-rw-r--r--libc/mem.c2
-rw-r--r--libc/print.c14
-rw-r--r--libc/sanitize.c31
-rwxr-xr-xrun2
10 files changed, 50 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 0a59189..ba1a348 100644
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,11 @@
CFLAGS_OPTIMIZATION = -finline -finline-functions -Ofast
CFLAGS_WARNINGS = -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=2 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wlogical-op -Wunreachable-code -Wundef -Wold-style-definition -pedantic-errors
-CFLAGS_DEFAULT = $(CFLAGS_WARNINGS) $(CFLAGS_OPTIMIZATION) -std=c99 -m32 -nostdlib -nostdinc -fno-builtin -fno-profile-generate -fno-omit-frame-pointer -fno-common -fno-asynchronous-unwind-tables -mno-red-zone
+CFLAGS_DEFAULT = $(CFLAGS_WARNINGS) $(CFLAGS_OPTIMIZATION) -std=c99 -m32 -nostdlib -nostdinc -fno-builtin -fno-profile-generate -fno-omit-frame-pointer -fno-common -fno-asynchronous-unwind-tables -mno-red-zone -mno-80387 -mno-mmx -mno-sse -mno-sse2 # Everything after -fno-builtin is optional
all: compile
-debug: CFLAGS_DEFAULT += -Wno-error -ggdb3 -s -fstack-protector-all #-fsanitize=undefined
+debug: CFLAGS_DEFAULT += -Wno-error -ggdb3 -s -fstack-protector-all -fsanitize=undefined
debug: compile
export
diff --git a/apps/link.ld b/apps/link.ld
index 2b9599a..781e38d 100644
--- a/apps/link.ld
+++ b/apps/link.ld
@@ -8,27 +8,24 @@ SECTIONS
. = 0x00000000;
.text : {
+ code = .;
*(.text)
- }
-
- .rodata : {
*(.rodata)
+ . = ALIGN(4096);
}
- . = ALIGN(4096);
-
.data : {
+ data = .;
*(.data)
+ . = ALIGN(4096);
}
- . = ALIGN(4096);
-
.bss : {
+ bss = .;
*(.bss)
+ . = ALIGN(4096);
}
- . = ALIGN(4096);
-
_GLOBAL_OFFSET_TABLE_ = .;
. = ALIGN(4096);
diff --git a/apps/wm.c b/apps/wm.c
index abbb2bd..a9f22d5 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -251,6 +251,9 @@ static void handle_event_keyboard(struct event_keyboard *event)
else if (event->scancode == KEY_LEFTCTRL || event->scancode == KEY_RIGHTCTRL)
special_keys.ctrl ^= 1;
+ if (event->scancode > KEYMAP_LENGTH)
+ return;
+
char ch;
if (special_keys.shift)
ch = keymap->shift_map[event->scancode];
diff --git a/kernel/features/load.c b/kernel/features/load.c
index 9024c82..8a4aae3 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -17,7 +17,6 @@ void proc_load(struct proc *proc, void *data)
int bin_load(const char *path, struct proc *proc)
{
- // TODO: Remove hardcoded filesize
struct stat s = { 0 };
vfs_stat(path, &s);
char *data = malloc(s.size);
diff --git a/kernel/main.c b/kernel/main.c
index 2112541..6be31bd 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -26,7 +26,7 @@ void kernel_main(struct vid_info *vid_info)
serial_print("\nKernel was compiled at " __TIME__ " on " __DATE__ "\n");
serial_print("Serial connected.\n");
- heap_init(0x00f00000 + rand());
+ heap_init(0x00f00000);
boot_passed = vid_info;
diff --git a/libc/inc/def.h b/libc/inc/def.h
index 8ff6d81..c8b9dbf 100644
--- a/libc/inc/def.h
+++ b/libc/inc/def.h
@@ -25,6 +25,8 @@ typedef unsigned long long u64;
#define UNUSED(a) ((void)(a))
+#define NO_SANITIZE __attribute__((no_sanitize("undefined")))
+
#define EOF (-1)
#define NULL ((void *)0)
diff --git a/libc/mem.c b/libc/mem.c
index 7e9590a..971315a 100644
--- a/libc/mem.c
+++ b/libc/mem.c
@@ -291,8 +291,10 @@ void heap_init(u32 start)
heap.end = (u32)start + HEAP_INIT_SIZE;
}
+#define ALIGN sizeof(long)
static void *_malloc(u32 size)
{
+ size = ((size + ALIGN - 1) / ALIGN) * ALIGN; // Alignment
u32 index = bin_index(size);
struct h_bin *temp = (struct h_bin *)&heap.bins[index];
struct h_node *found = node_best_fit(temp, size);
diff --git a/libc/print.c b/libc/print.c
index 3f6c1cd..ef51e1f 100644
--- a/libc/print.c
+++ b/libc/print.c
@@ -3,6 +3,7 @@
#include <arg.h>
#include <assert.h>
#include <conv.h>
+#include <cpu.h>
#include <def.h>
#include <mem.h>
#include <serial.h>
@@ -217,14 +218,17 @@ int print(const char *str)
void panic(const char *format, ...)
{
+ char buf[1024] = { 0 };
va_list ap;
va_start(ap, format);
+ vsprintf(buf, format, ap);
+ va_end(ap);
#ifdef kernel
- vprintf(format, ap);
+ print(buf);
+ loop();
#else
- vfprintf(PATH_ERR, format, ap);
+ err(1, buf);
#endif
- va_end(ap);
-
- assert(0);
+ while (1)
+ ;
}
diff --git a/libc/sanitize.c b/libc/sanitize.c
index d4eed01..983b10f 100644
--- a/libc/sanitize.c
+++ b/libc/sanitize.c
@@ -26,6 +26,7 @@ void __stack_chk_fail_local(void)
/**
* UBSan
+ * TODO: Fix san-paths for userspace (maybe due to -fPIE?)
*/
#define is_aligned(value, alignment) !(value & (alignment - 1))
@@ -45,7 +46,7 @@ struct type_descriptor {
struct type_mismatch {
struct source_location location;
struct type_descriptor *type;
- u32 alignment;
+ u8 alignment;
u8 type_check_kind;
};
@@ -132,7 +133,8 @@ void __ubsan_handle_divrem_overflow(struct overflow *data, void *left, void *rig
UNUSED(left);
UNUSED(right);
struct source_location *loc = &data->location;
- panic("%s:%d: UBSAN: divrem-overflow\n", loc->file, loc->line);
+ panic("%s:%d: UBSAN: divrem-overflow (probably div-by-zero) [type: %s]\n", loc->file,
+ loc->line, data->type->name);
}
void __ubsan_handle_out_of_bounds(struct out_of_bounds *data, void *value);
@@ -146,16 +148,31 @@ void __ubsan_handle_out_of_bounds(struct out_of_bounds *data, void *value)
void __ubsan_handle_type_mismatch_v1(struct type_mismatch *data, u32 ptr);
void __ubsan_handle_type_mismatch_v1(struct type_mismatch *data, u32 ptr)
{
+ static const char *kinds[] = {
+ "Load of",
+ "Store to",
+ "Reference binding to",
+ "Member access within",
+ "Member call on",
+ "Constructor call on",
+ "Downcast of",
+ "Downcast of",
+ "Upcast of",
+ "Cast to virtual base of",
+ "Nonnull binding to",
+ "Dynamic operation on",
+ };
+
struct source_location *loc = &data->location;
const char *msg = "";
if (ptr == 0) {
- msg = "Null pointer access";
+ msg = "null pointer";
} else if (data->alignment != 0 && is_aligned(ptr, data->alignment))
- msg = "Misaligned memory access";
+ msg = "misaligned memory address";
else
- msg = "Insufficient space";
- panic("%s:%d: UBSAN: type-mismatch-v1: %s [type: %s]\n", loc->file, loc->line, msg,
- data->type->name);
+ msg = "address with insufficient space";
+ panic("%s:%d: UBSAN: %s %s [type: %s; addr: 0x%x; align: %d]\n", loc->file, loc->line,
+ kinds[data->type_check_kind], msg, data->type->name, ptr, data->alignment);
}
void __ubsan_handle_alignment_assumption(void);
diff --git a/run b/run
index d406a43..2201570 100755
--- a/run
+++ b/run
@@ -23,7 +23,7 @@ mode="${1}"
no_ask="${2}"
# TODO: Support q35 chipset ('-machine q35')
-# TODO: Support -enable-kvm: GPF due to some malloc bug?!
+# TODO: Support -enable-kvm: GPF?!
qemu_with_flags() {
network="rtl8139"
qemu-system-i386 -d guest_errors -cpu max -no-reboot -vga std -rtc base=localtime -m 256M -netdev user,id=net0,hostfwd=tcp:127.0.0.1:8000-10.0.2.15:8000 -device $network,netdev=net0 -object filter-dump,id=dump,netdev=net0,file=dump.pcap "$@"