From 98da473fdc7eced1a8efad47320f559b60c012f7 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 8 Nov 2022 19:07:43 +0100 Subject: [PATCH] Run clang-format --- apps/src/screen.c | 10 +++++----- kernel/include/memory/MemoryManager.h | 3 ++- kernel/src/fs/devices/DeviceFS.cpp | 2 +- kernel/src/init/Init.cpp | 9 +++++---- kernel/src/interrupts/IRQ.cpp | 2 +- kernel/src/memory/AddressSpace.cpp | 26 ++++++++++++++++---------- kernel/src/memory/MemoryManager.cpp | 8 +++++--- kernel/src/sys/Syscall.cpp | 4 +++- kernel/src/sys/elf/ELFLoader.cpp | 3 ++- libs/libc/src/sys/ioctl.cpp | 4 ++-- libs/libc/src/sys/mman.cpp | 3 ++- 11 files changed, 44 insertions(+), 30 deletions(-) diff --git a/apps/src/screen.c b/apps/src/screen.c index 60dceed0..7b26ba33 100644 --- a/apps/src/screen.c +++ b/apps/src/screen.c @@ -1,26 +1,26 @@ -#include -#include #include #include +#include +#include int main() { int fd = open("/dev/fb0", O_WRONLY | O_CLOEXEC); - if(fd < 0) + if (fd < 0) { perror("open"); return 1; } int fb_width = ioctl(fd, FB_GET_WIDTH); - if(fb_width < 0) + if (fb_width < 0) { perror("ioctl(FB_GET_WIDTH)"); return 1; } int fb_height = ioctl(fd, FB_GET_HEIGHT); - if(fb_height < 0) + if (fb_height < 0) { perror("ioctl(FB_GET_HEIGHT)"); return 1; diff --git a/kernel/include/memory/MemoryManager.h b/kernel/include/memory/MemoryManager.h index cb5ece3e..c6cd4b37 100644 --- a/kernel/include/memory/MemoryManager.h +++ b/kernel/include/memory/MemoryManager.h @@ -35,5 +35,6 @@ namespace MemoryManager void protect(void* page, uint64_t count, int flags); - void map_several_pages(uint64_t physicalAddress, uint64_t virtualAddress, uint64_t count, int flags = MAP_READ_WRITE); + void map_several_pages(uint64_t physicalAddress, uint64_t virtualAddress, uint64_t count, + int flags = MAP_READ_WRITE); } \ No newline at end of file diff --git a/kernel/src/fs/devices/DeviceFS.cpp b/kernel/src/fs/devices/DeviceFS.cpp index 98de1c09..d98cb00f 100644 --- a/kernel/src/fs/devices/DeviceFS.cpp +++ b/kernel/src/fs/devices/DeviceFS.cpp @@ -1,8 +1,8 @@ #include "fs/devices/DeviceFS.h" #include "fs/devices/Console.h" +#include "fs/devices/Framebuffer.h" #include "fs/devices/Keyboard.h" #include "fs/devices/NullDevice.h" -#include "fs/devices/Framebuffer.h" #include "fs/devices/Random.h" #include "fs/devices/Serial.h" #include "fs/devices/Version.h" diff --git a/kernel/src/init/Init.cpp b/kernel/src/init/Init.cpp index 4b886699..da57cecd 100644 --- a/kernel/src/init/Init.cpp +++ b/kernel/src/init/Init.cpp @@ -10,6 +10,7 @@ #include "memory/MemoryManager.h" #include "memory/PMM.h" #include "memory/VMM.h" +#include "misc/MSR.h" #include "misc/hang.h" #include "rand/Init.h" #include "rand/Mersenne.h" @@ -18,7 +19,6 @@ #include "std/assert.h" #include "std/string.h" #include "utils/Time.h" -#include "misc/MSR.h" extern BOOTBOOT bootboot; extern "C" char environment[4096]; @@ -46,7 +46,8 @@ extern void panic_prepare_keyboard_triple_fault(); static void check_and_enable_nx() { - if(!CPU::has_nx()) { + if (!CPU::has_nx()) + { kerrorln("This machine does not support the NX feature, which is required to continue booting."); kerrorln("On most cases, this means your machine is too old and not supported."); @@ -54,7 +55,7 @@ static void check_and_enable_nx() panic_prepare_keyboard_triple_fault(); - while(1) halt(); + while (1) halt(); } kdbgln("nx supported"); @@ -63,7 +64,7 @@ static void check_and_enable_nx() uint64_t value = efer.read(); - if(value & NO_EXECUTE_ENABLED) + if (value & NO_EXECUTE_ENABLED) { kdbgln("nx already enabled"); return; diff --git a/kernel/src/interrupts/IRQ.cpp b/kernel/src/interrupts/IRQ.cpp index 438fa83f..5dcf7d21 100644 --- a/kernel/src/interrupts/IRQ.cpp +++ b/kernel/src/interrupts/IRQ.cpp @@ -1,8 +1,8 @@ #define MODULE "irq" #include "interrupts/IRQ.h" -#include "fs/devices/Keyboard.h" #include "fs/devices/Console.h" +#include "fs/devices/Keyboard.h" #include "io/IO.h" #include "io/PIC.h" #include "log/Log.h" diff --git a/kernel/src/memory/AddressSpace.cpp b/kernel/src/memory/AddressSpace.cpp index 2a499bbf..c3c4468b 100644 --- a/kernel/src/memory/AddressSpace.cpp +++ b/kernel/src/memory/AddressSpace.cpp @@ -26,7 +26,8 @@ void AddressSpace::destroy() if (!pdp_pde.present) continue; if (pdp_pde.larger_pages) { - if(pdp_pde.owned_by_task) { + if (pdp_pde.owned_by_task) + { pages_freed++; PMM::free_page((void*)pdp_pde.get_address()); } @@ -39,7 +40,8 @@ void AddressSpace::destroy() if (!pd_pde.present) continue; if (pd_pde.larger_pages) { - if(pd_pde.owned_by_task) { + if (pd_pde.owned_by_task) + { pages_freed++; PMM::free_page((void*)pd_pde.get_address()); } @@ -52,7 +54,8 @@ void AddressSpace::destroy() if (!pt_pde.present) continue; if (pt_pde.larger_pages) { - if(pt_pde.owned_by_task) { + if (pt_pde.owned_by_task) + { pages_freed++; PMM::free_page((void*)pt_pde.get_address()); } @@ -91,7 +94,8 @@ void AddressSpace::clear() if (!pdp_pde.present) continue; if (pdp_pde.larger_pages) { - if(pdp_pde.owned_by_task) { + if (pdp_pde.owned_by_task) + { pages_freed++; PMM::free_page((void*)pdp_pde.get_address()); } @@ -104,7 +108,8 @@ void AddressSpace::clear() if (!pd_pde.present) continue; if (pd_pde.larger_pages) { - if(pd_pde.owned_by_task) { + if (pd_pde.owned_by_task) + { pages_freed++; PMM::free_page((void*)pd_pde.get_address()); } @@ -117,7 +122,8 @@ void AddressSpace::clear() if (!pt_pde.present) continue; if (pt_pde.larger_pages) { - if(pt_pde.owned_by_task) { + if (pt_pde.owned_by_task) + { pages_freed++; PMM::free_page((void*)pt_pde.get_address()); } @@ -168,7 +174,7 @@ AddressSpace AddressSpace::clone() // FIXME: Add out-of-memory checks to this fu if (!pdp_pde.present) continue; if (pdp_pde.larger_pages) { - if(!pdp_pde.owned_by_task) + if (!pdp_pde.owned_by_task) { memcpy(&cloned_pdp_pde, &pdp_pde, sizeof(PageDirectoryEntry)); continue; @@ -197,7 +203,7 @@ AddressSpace AddressSpace::clone() // FIXME: Add out-of-memory checks to this fu if (!pd_pde.present) continue; if (pd_pde.larger_pages) { - if(!pd_pde.owned_by_task) + if (!pd_pde.owned_by_task) { memcpy(&cloned_pd_pde, &pd_pde, sizeof(PageDirectoryEntry)); continue; @@ -226,7 +232,7 @@ AddressSpace AddressSpace::clone() // FIXME: Add out-of-memory checks to this fu if (!pt_pde.present) continue; if (pt_pde.larger_pages) { - if(!pt_pde.owned_by_task) + if (!pt_pde.owned_by_task) { memcpy(&cloned_pt_pde, &pt_pde, sizeof(PageDirectoryEntry)); continue; @@ -252,7 +258,7 @@ AddressSpace AddressSpace::clone() // FIXME: Add out-of-memory checks to this fu { PageDirectoryEntry& pde = pt->entries[l]; PageDirectoryEntry& cloned_pde = cloned_pt->entries[l]; - if(!pde.owned_by_task) + if (!pde.owned_by_task) { memcpy(&cloned_pde, &pde, sizeof(PageDirectoryEntry)); continue; diff --git a/kernel/src/memory/MemoryManager.cpp b/kernel/src/memory/MemoryManager.cpp index f52d3865..a78df587 100644 --- a/kernel/src/memory/MemoryManager.cpp +++ b/kernel/src/memory/MemoryManager.cpp @@ -7,8 +7,8 @@ #include "memory/MemoryManager.h" #include "memory/PMM.h" #include "memory/VMM.h" -#include "std/assert.h" #include "misc/utils.h" +#include "std/assert.h" void MemoryManager::init() { @@ -25,8 +25,10 @@ extern char end_of_kernel_data[1]; void MemoryManager::protect_kernel_sections() { - protect(start_of_kernel_rodata, Utilities::get_blocks_from_size(PAGE_SIZE, end_of_kernel_rodata - start_of_kernel_rodata), 0); - protect(start_of_kernel_data, Utilities::get_blocks_from_size(PAGE_SIZE, end_of_kernel_data - start_of_kernel_data), MAP_READ_WRITE); + protect(start_of_kernel_rodata, + Utilities::get_blocks_from_size(PAGE_SIZE, end_of_kernel_rodata - start_of_kernel_rodata), 0); + protect(start_of_kernel_data, Utilities::get_blocks_from_size(PAGE_SIZE, end_of_kernel_data - start_of_kernel_data), + MAP_READ_WRITE); } void* MemoryManager::get_mapping(void* physicalAddress, int flags) diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index f051a345..f510bfa6 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -16,7 +16,9 @@ void Syscall::entry(Context* context) case SYS_sleep: sys_sleep(context, context->rdi); break; case SYS_write: sys_write(context, (int)context->rdi, context->rsi, (const char*)context->rdx); break; case SYS_getprocid: sys_getprocid(context, (int)context->rdi); break; - case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx, (int)context->r10, (off_t)context->r8); break; + case SYS_mmap: + sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx, (int)context->r10, (off_t)context->r8); + break; case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break; case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi, (mode_t)context->rdx); break; case SYS_read: sys_read(context, (int)context->rdi, context->rsi, (char*)context->rdx); break; diff --git a/kernel/src/sys/elf/ELFLoader.cpp b/kernel/src/sys/elf/ELFLoader.cpp index 80b5a53a..5219d938 100644 --- a/kernel/src/sys/elf/ELFLoader.cpp +++ b/kernel/src/sys/elf/ELFLoader.cpp @@ -119,7 +119,8 @@ ELFImage* ELFLoader::load_elf_from_vfs(VFS::Node* node) int new_flags = MAP_USER | MAP_AS_OWNED_BY_TASK; if (can_write_segment(phdr.p_flags)) new_flags |= MAP_READ_WRITE; - else if (can_execute_segment(phdr.p_flags)) new_flags |= MAP_EXEC; + else if (can_execute_segment(phdr.p_flags)) + new_flags |= MAP_EXEC; MemoryManager::protect(buffer, pages, new_flags); diff --git a/libs/libc/src/sys/ioctl.cpp b/libs/libc/src/sys/ioctl.cpp index 29d7285c..053fb7e6 100644 --- a/libs/libc/src/sys/ioctl.cpp +++ b/libs/libc/src/sys/ioctl.cpp @@ -1,8 +1,8 @@ #include -#include -#include #include #include +#include +#include extern "C" { diff --git a/libs/libc/src/sys/mman.cpp b/libs/libc/src/sys/mman.cpp index 63017015..3a5b6b1a 100644 --- a/libs/libc/src/sys/mman.cpp +++ b/libs/libc/src/sys/mman.cpp @@ -7,7 +7,8 @@ extern "C" // FIXME: Implement a POSIX-compliant mmap. void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset) { - long result = __luna_syscall5(SYS_mmap, (sysarg_t)addr, (sysarg_t)len, (sysarg_t)prot, flags & MAP_ANONYMOUS ? (sysarg_t)-1 : (sysarg_t)fd, (sysarg_t)offset); + long result = __luna_syscall5(SYS_mmap, (sysarg_t)addr, (sysarg_t)len, (sysarg_t)prot, + flags & MAP_ANONYMOUS ? (sysarg_t)-1 : (sysarg_t)fd, (sysarg_t)offset); _RETURN_WITH_MEMORY_ERRNO(result, void*); }