From d143fec0d146ef0463b18cfd76ef094c81ac8250 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 18 Jul 2024 14:45:16 -0700 Subject: [PATCH] fix mmap error case --- project.4coder | 4 +++- src/os/core/linux/os_core_linux.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/project.4coder b/project.4coder index 9584f3ae..c3bac732 100644 --- a/project.4coder +++ b/project.4coder @@ -49,7 +49,8 @@ commands = { //.win = "build rdi_from_pdb rdi_dump && pushd build && rdi_from_pdb --pdb:mule_main.pdb --out:mule_main.rdi && rdi_dump mule_main.rdi > mule_main.dump && popd", //.win = "build raddbg telemetry", - .win = "build ryan_scratch", + //.win = "build ryan_scratch", + .win = "wsl ./build.sh ryan_scratch", .linux = "", .out = "*compilation*", .footer_panel = true, @@ -69,6 +70,7 @@ commands = { // .win = "pushd build && raddbg.exe --user:local_dev.raddbg_user --project:local_dev.raddbg_project && popd", .win = "pushd build && ryan_scratch.exe && popd", + .win = "wsl ./build/ryan_scratch", .linux = "", .out = "*compilation*", .footer_panel = true, diff --git a/src/os/core/linux/os_core_linux.c b/src/os/core/linux/os_core_linux.c index 2220b63e..dd9c4f4f 100644 --- a/src/os/core/linux/os_core_linux.c +++ b/src/os/core/linux/os_core_linux.c @@ -162,6 +162,10 @@ internal void * os_reserve(U64 size) { void *result = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if(result == MAP_FAILED) + { + result = 0; + } return result; } @@ -191,6 +195,10 @@ internal void * os_reserve_large(U64 size) { void *result = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0); + if(result == MAP_FAILED) + { + result = 0; + } return result; } @@ -497,6 +505,10 @@ os_file_map_view_open(OS_Handle map, OS_AccessFlags flags, Rng1U64 range) if(flags & OS_AccessFlag_Read) { prot_flags |= PROT_READ; } int map_flags = MAP_PRIVATE; void *base = mmap(0, dim_1u64(range), prot_flags, map_flags, fd, range.min); + if(base == MAP_FAILED) + { + base = 0; + } return base; } @@ -637,6 +649,10 @@ os_shared_memory_view_open(OS_Handle handle, Rng1U64 range) if(os_handle_match(handle, os_handle_zero())){return 0;} int id = (int)handle.u64[0]; void *base = mmap(0, dim_1u64(range), PROT_READ|PROT_WRITE, MAP_SHARED, id, range.min); + if(base == MAP_FAILED) + { + base = 0; + } return base; }