Run clang-format

This commit is contained in:
apio 2022-11-08 19:07:43 +01:00
parent 0c1ffedd3f
commit 98da473fdc
11 changed files with 44 additions and 30 deletions

View File

@ -1,26 +1,26 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main() int main()
{ {
int fd = open("/dev/fb0", O_WRONLY | O_CLOEXEC); int fd = open("/dev/fb0", O_WRONLY | O_CLOEXEC);
if(fd < 0) if (fd < 0)
{ {
perror("open"); perror("open");
return 1; return 1;
} }
int fb_width = ioctl(fd, FB_GET_WIDTH); int fb_width = ioctl(fd, FB_GET_WIDTH);
if(fb_width < 0) if (fb_width < 0)
{ {
perror("ioctl(FB_GET_WIDTH)"); perror("ioctl(FB_GET_WIDTH)");
return 1; return 1;
} }
int fb_height = ioctl(fd, FB_GET_HEIGHT); int fb_height = ioctl(fd, FB_GET_HEIGHT);
if(fb_height < 0) if (fb_height < 0)
{ {
perror("ioctl(FB_GET_HEIGHT)"); perror("ioctl(FB_GET_HEIGHT)");
return 1; return 1;

View File

@ -35,5 +35,6 @@ namespace MemoryManager
void protect(void* page, uint64_t count, int flags); 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);
} }

View File

@ -1,8 +1,8 @@
#include "fs/devices/DeviceFS.h" #include "fs/devices/DeviceFS.h"
#include "fs/devices/Console.h" #include "fs/devices/Console.h"
#include "fs/devices/Framebuffer.h"
#include "fs/devices/Keyboard.h" #include "fs/devices/Keyboard.h"
#include "fs/devices/NullDevice.h" #include "fs/devices/NullDevice.h"
#include "fs/devices/Framebuffer.h"
#include "fs/devices/Random.h" #include "fs/devices/Random.h"
#include "fs/devices/Serial.h" #include "fs/devices/Serial.h"
#include "fs/devices/Version.h" #include "fs/devices/Version.h"

View File

@ -10,6 +10,7 @@
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "memory/PMM.h" #include "memory/PMM.h"
#include "memory/VMM.h" #include "memory/VMM.h"
#include "misc/MSR.h"
#include "misc/hang.h" #include "misc/hang.h"
#include "rand/Init.h" #include "rand/Init.h"
#include "rand/Mersenne.h" #include "rand/Mersenne.h"
@ -18,7 +19,6 @@
#include "std/assert.h" #include "std/assert.h"
#include "std/string.h" #include "std/string.h"
#include "utils/Time.h" #include "utils/Time.h"
#include "misc/MSR.h"
extern BOOTBOOT bootboot; extern BOOTBOOT bootboot;
extern "C" char environment[4096]; extern "C" char environment[4096];
@ -46,7 +46,8 @@ extern void panic_prepare_keyboard_triple_fault();
static void check_and_enable_nx() 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("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."); 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(); panic_prepare_keyboard_triple_fault();
while(1) halt(); while (1) halt();
} }
kdbgln("nx supported"); kdbgln("nx supported");
@ -63,7 +64,7 @@ static void check_and_enable_nx()
uint64_t value = efer.read(); uint64_t value = efer.read();
if(value & NO_EXECUTE_ENABLED) if (value & NO_EXECUTE_ENABLED)
{ {
kdbgln("nx already enabled"); kdbgln("nx already enabled");
return; return;

View File

@ -1,8 +1,8 @@
#define MODULE "irq" #define MODULE "irq"
#include "interrupts/IRQ.h" #include "interrupts/IRQ.h"
#include "fs/devices/Keyboard.h"
#include "fs/devices/Console.h" #include "fs/devices/Console.h"
#include "fs/devices/Keyboard.h"
#include "io/IO.h" #include "io/IO.h"
#include "io/PIC.h" #include "io/PIC.h"
#include "log/Log.h" #include "log/Log.h"

View File

@ -26,7 +26,8 @@ void AddressSpace::destroy()
if (!pdp_pde.present) continue; if (!pdp_pde.present) continue;
if (pdp_pde.larger_pages) if (pdp_pde.larger_pages)
{ {
if(pdp_pde.owned_by_task) { if (pdp_pde.owned_by_task)
{
pages_freed++; pages_freed++;
PMM::free_page((void*)pdp_pde.get_address()); PMM::free_page((void*)pdp_pde.get_address());
} }
@ -39,7 +40,8 @@ void AddressSpace::destroy()
if (!pd_pde.present) continue; if (!pd_pde.present) continue;
if (pd_pde.larger_pages) if (pd_pde.larger_pages)
{ {
if(pd_pde.owned_by_task) { if (pd_pde.owned_by_task)
{
pages_freed++; pages_freed++;
PMM::free_page((void*)pd_pde.get_address()); PMM::free_page((void*)pd_pde.get_address());
} }
@ -52,7 +54,8 @@ void AddressSpace::destroy()
if (!pt_pde.present) continue; if (!pt_pde.present) continue;
if (pt_pde.larger_pages) if (pt_pde.larger_pages)
{ {
if(pt_pde.owned_by_task) { if (pt_pde.owned_by_task)
{
pages_freed++; pages_freed++;
PMM::free_page((void*)pt_pde.get_address()); PMM::free_page((void*)pt_pde.get_address());
} }
@ -91,7 +94,8 @@ void AddressSpace::clear()
if (!pdp_pde.present) continue; if (!pdp_pde.present) continue;
if (pdp_pde.larger_pages) if (pdp_pde.larger_pages)
{ {
if(pdp_pde.owned_by_task) { if (pdp_pde.owned_by_task)
{
pages_freed++; pages_freed++;
PMM::free_page((void*)pdp_pde.get_address()); PMM::free_page((void*)pdp_pde.get_address());
} }
@ -104,7 +108,8 @@ void AddressSpace::clear()
if (!pd_pde.present) continue; if (!pd_pde.present) continue;
if (pd_pde.larger_pages) if (pd_pde.larger_pages)
{ {
if(pd_pde.owned_by_task) { if (pd_pde.owned_by_task)
{
pages_freed++; pages_freed++;
PMM::free_page((void*)pd_pde.get_address()); PMM::free_page((void*)pd_pde.get_address());
} }
@ -117,7 +122,8 @@ void AddressSpace::clear()
if (!pt_pde.present) continue; if (!pt_pde.present) continue;
if (pt_pde.larger_pages) if (pt_pde.larger_pages)
{ {
if(pt_pde.owned_by_task) { if (pt_pde.owned_by_task)
{
pages_freed++; pages_freed++;
PMM::free_page((void*)pt_pde.get_address()); 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.present) continue;
if (pdp_pde.larger_pages) 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)); memcpy(&cloned_pdp_pde, &pdp_pde, sizeof(PageDirectoryEntry));
continue; 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.present) continue;
if (pd_pde.larger_pages) 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)); memcpy(&cloned_pd_pde, &pd_pde, sizeof(PageDirectoryEntry));
continue; 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.present) continue;
if (pt_pde.larger_pages) 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)); memcpy(&cloned_pt_pde, &pt_pde, sizeof(PageDirectoryEntry));
continue; continue;
@ -252,7 +258,7 @@ AddressSpace AddressSpace::clone() // FIXME: Add out-of-memory checks to this fu
{ {
PageDirectoryEntry& pde = pt->entries[l]; PageDirectoryEntry& pde = pt->entries[l];
PageDirectoryEntry& cloned_pde = cloned_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)); memcpy(&cloned_pde, &pde, sizeof(PageDirectoryEntry));
continue; continue;

View File

@ -7,8 +7,8 @@
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "memory/PMM.h" #include "memory/PMM.h"
#include "memory/VMM.h" #include "memory/VMM.h"
#include "std/assert.h"
#include "misc/utils.h" #include "misc/utils.h"
#include "std/assert.h"
void MemoryManager::init() void MemoryManager::init()
{ {
@ -25,8 +25,10 @@ extern char end_of_kernel_data[1];
void MemoryManager::protect_kernel_sections() 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_rodata,
protect(start_of_kernel_data, Utilities::get_blocks_from_size(PAGE_SIZE, end_of_kernel_data - start_of_kernel_data), MAP_READ_WRITE); 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) void* MemoryManager::get_mapping(void* physicalAddress, int flags)

View File

@ -16,7 +16,9 @@ void Syscall::entry(Context* context)
case SYS_sleep: sys_sleep(context, context->rdi); break; 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_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_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_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_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; case SYS_read: sys_read(context, (int)context->rdi, context->rsi, (char*)context->rdx); break;

View File

@ -119,7 +119,8 @@ ELFImage* ELFLoader::load_elf_from_vfs(VFS::Node* node)
int new_flags = MAP_USER | MAP_AS_OWNED_BY_TASK; int new_flags = MAP_USER | MAP_AS_OWNED_BY_TASK;
if (can_write_segment(phdr.p_flags)) new_flags |= MAP_READ_WRITE; 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); MemoryManager::protect(buffer, pages, new_flags);

View File

@ -1,8 +1,8 @@
#include <luna/syscall.h> #include <luna/syscall.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h> #include <stdint.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
extern "C" extern "C"
{ {

View File

@ -7,7 +7,8 @@ extern "C"
// FIXME: Implement a POSIX-compliant mmap. // FIXME: Implement a POSIX-compliant mmap.
void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset) 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*); _RETURN_WITH_MEMORY_ERRNO(result, void*);
} }