From bc951ca565d137b2d1bd158e5473bd42cf568d10 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Jun 2019 11:43:58 +0200 Subject: [PATCH] Kernel: Run clang-format on everything. --- Kernel/Devices/BXVGADevice.cpp | 45 +++-- Kernel/Devices/DebugLogDevice.cpp | 1 - Kernel/Devices/Device.cpp | 4 +- Kernel/Devices/DiskDevice.cpp | 1 - Kernel/Devices/DiskPartition.cpp | 3 +- Kernel/Devices/FileBackedDiskDevice.cpp | 1 - Kernel/Devices/FullDevice.cpp | 3 +- Kernel/Devices/IDEDiskDevice.cpp | 191 ++++++++++---------- Kernel/Devices/KeyboardDevice.cpp | 175 ++++++++++++++---- Kernel/Devices/NullDevice.cpp | 1 - Kernel/Devices/PCSpeaker.cpp | 2 +- Kernel/Devices/PS2MouseDevice.cpp | 21 ++- Kernel/Devices/RandomDevice.cpp | 1 - Kernel/Devices/ZeroDevice.cpp | 1 - Kernel/File.cpp | 1 - Kernel/FileSystem/Custody.cpp | 7 +- Kernel/FileSystem/DevPtsFS.cpp | 6 +- Kernel/FileSystem/Ext2FileSystem.cpp | 57 +++--- Kernel/FileSystem/FIFO.cpp | 8 +- Kernel/FileSystem/FileDescription.cpp | 4 +- Kernel/FileSystem/FileSystem.cpp | 5 +- Kernel/FileSystem/Inode.cpp | 4 +- Kernel/FileSystem/InodeFile.cpp | 4 +- Kernel/FileSystem/ProcFS.cpp | 108 ++++++------ Kernel/FileSystem/SyntheticFileSystem.cpp | 22 +-- Kernel/FileSystem/VirtualFileSystem.cpp | 15 +- Kernel/IRQHandler.cpp | 3 +- Kernel/KParams.h | 1 + Kernel/KSyms.cpp | 5 +- Kernel/Net/E1000NetworkAdapter.cpp | 142 +++++++-------- Kernel/Net/IPv4Socket.cpp | 26 +-- Kernel/Net/LocalSocket.cpp | 6 +- Kernel/Net/NetworkAdapter.cpp | 12 +- Kernel/Net/NetworkTask.cpp | 67 +++---- Kernel/Net/Routing.cpp | 2 +- Kernel/Net/Socket.cpp | 6 +- Kernel/Net/TCPSocket.cpp | 15 +- Kernel/Net/UDPSocket.cpp | 11 +- Kernel/PCI.cpp | 54 +++--- Kernel/PIC.cpp | 18 +- Kernel/Process.cpp | 107 +++++------ Kernel/ProcessTracer.cpp | 4 +- Kernel/RTC.cpp | 13 +- Kernel/Scheduler.cpp | 27 ++- Kernel/SharedMemory.cpp | 6 +- Kernel/StdLib.cpp | 38 ++-- Kernel/Syscall.cpp | 16 +- Kernel/Syscall.h | 2 +- Kernel/TTY/MasterPTY.cpp | 2 +- Kernel/TTY/TTY.cpp | 27 ++- Kernel/TTY/VirtualConsole.cpp | 89 +++++++--- Kernel/Thread.cpp | 67 ++++--- Kernel/VM/MemoryManager.cpp | 36 ++-- Kernel/VM/PageDirectory.cpp | 4 +- Kernel/VM/PhysicalPage.cpp | 2 +- Kernel/VM/RangeAllocator.cpp | 10 +- Kernel/VM/Region.cpp | 22 +-- Kernel/VM/Region.h | 1 + Kernel/VM/VMObject.cpp | 9 +- Kernel/i386.cpp | 205 +++++++++++----------- Kernel/i8253.cpp | 5 +- Kernel/init.cpp | 56 +++--- Kernel/kmalloc.cpp | 23 +-- 63 files changed, 974 insertions(+), 856 deletions(-) diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index e8ad647c32..1b3ba22ef4 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -1,29 +1,29 @@ #include #include #include -#include #include +#include #include -#define VBE_DISPI_IOPORT_INDEX 0x01CE -#define VBE_DISPI_IOPORT_DATA 0x01CF +#define VBE_DISPI_IOPORT_INDEX 0x01CE +#define VBE_DISPI_IOPORT_DATA 0x01CF -#define VBE_DISPI_INDEX_ID 0x0 -#define VBE_DISPI_INDEX_XRES 0x1 -#define VBE_DISPI_INDEX_YRES 0x2 -#define VBE_DISPI_INDEX_BPP 0x3 -#define VBE_DISPI_INDEX_ENABLE 0x4 -#define VBE_DISPI_INDEX_BANK 0x5 -#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6 -#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7 -#define VBE_DISPI_INDEX_X_OFFSET 0x8 -#define VBE_DISPI_INDEX_Y_OFFSET 0x9 -#define VBE_DISPI_DISABLED 0x00 -#define VBE_DISPI_ENABLED 0x01 -#define VBE_DISPI_LFB_ENABLED 0x40 +#define VBE_DISPI_INDEX_ID 0x0 +#define VBE_DISPI_INDEX_XRES 0x1 +#define VBE_DISPI_INDEX_YRES 0x2 +#define VBE_DISPI_INDEX_BPP 0x3 +#define VBE_DISPI_INDEX_ENABLE 0x4 +#define VBE_DISPI_INDEX_BANK 0x5 +#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6 +#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7 +#define VBE_DISPI_INDEX_X_OFFSET 0x8 +#define VBE_DISPI_INDEX_Y_OFFSET 0x9 +#define VBE_DISPI_DISABLED 0x00 +#define VBE_DISPI_ENABLED 0x01 +#define VBE_DISPI_LFB_ENABLED 0x40 -#define BXVGA_DEV_IOCTL_SET_Y_OFFSET 1982 -#define BXVGA_DEV_IOCTL_SET_RESOLUTION 1985 +#define BXVGA_DEV_IOCTL_SET_Y_OFFSET 1982 +#define BXVGA_DEV_IOCTL_SET_RESOLUTION 1985 struct BXVGAResolution { int width; int height; @@ -75,7 +75,7 @@ dword BXVGADevice::find_framebuffer_address() static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 }; static const PCI::ID virtualbox_vga_id = { 0x80ee, 0xbeef }; dword framebuffer_address = 0; - PCI::enumerate_all([&framebuffer_address] (const PCI::Address& address, PCI::ID id) { + PCI::enumerate_all([&framebuffer_address](const PCI::Address& address, PCI::ID id) { if (id == bochs_vga_id || id == virtualbox_vga_id) { framebuffer_address = PCI::get_BAR0(address) & 0xfffffff0; kprintf("BXVGA: framebuffer @ P%x\n", framebuffer_address); @@ -95,11 +95,10 @@ KResultOr BXVGADevice::mmap(Process& process, FileDescription&, LinearA move(vmo), 0, "BXVGA Framebuffer", - prot - ); + prot); kprintf("BXVGA: %s(%u) created Region{%p} with size %u for framebuffer P%x with laddr L%x\n", - process.name().characters(), process.pid(), - region, region->size(), framebuffer_address().as_ptr(), region->laddr().get()); + process.name().characters(), process.pid(), + region, region->size(), framebuffer_address().as_ptr(), region->laddr().get()); ASSERT(region); return region; } diff --git a/Kernel/Devices/DebugLogDevice.cpp b/Kernel/Devices/DebugLogDevice.cpp index 838101dda4..da6720f139 100644 --- a/Kernel/Devices/DebugLogDevice.cpp +++ b/Kernel/Devices/DebugLogDevice.cpp @@ -25,4 +25,3 @@ ssize_t DebugLogDevice::write(FileDescription&, const byte* data, ssize_t data_s IO::out8(0xe9, data[i]); return data_size; } - diff --git a/Kernel/Devices/Device.cpp b/Kernel/Devices/Device.cpp index 24a5274456..601ff9fa71 100644 --- a/Kernel/Devices/Device.cpp +++ b/Kernel/Devices/Device.cpp @@ -3,8 +3,8 @@ #include Device::Device(unsigned major, unsigned minor) - : m_major(major) - , m_minor(minor) + : m_major(major) + , m_minor(minor) { VFS::the().register_device({}, *this); } diff --git a/Kernel/Devices/DiskDevice.cpp b/Kernel/Devices/DiskDevice.cpp index b3a63b2a56..ce131307ca 100644 --- a/Kernel/Devices/DiskDevice.cpp +++ b/Kernel/Devices/DiskDevice.cpp @@ -27,4 +27,3 @@ bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in) ASSERT(end_block <= 0xffffffff); return write_blocks(first_block, end_block - first_block, in); } - diff --git a/Kernel/Devices/DiskPartition.cpp b/Kernel/Devices/DiskPartition.cpp index 413e1cb0a4..34ebf00ea5 100644 --- a/Kernel/Devices/DiskPartition.cpp +++ b/Kernel/Devices/DiskPartition.cpp @@ -8,7 +8,8 @@ Retained DiskPartition::create(Retained&& device, uns } DiskPartition::DiskPartition(Retained&& device, unsigned block_offset) - : m_device(move(device)), m_block_offset(block_offset) + : m_device(move(device)) + , m_block_offset(block_offset) { } diff --git a/Kernel/Devices/FileBackedDiskDevice.cpp b/Kernel/Devices/FileBackedDiskDevice.cpp index 6e936fb778..b56aaff6d6 100644 --- a/Kernel/Devices/FileBackedDiskDevice.cpp +++ b/Kernel/Devices/FileBackedDiskDevice.cpp @@ -79,4 +79,3 @@ const char* FileBackedDiskDevice::class_name() const { return "FileBackedDiskDevice"; } - diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index fd4403d1ce..6198c174a6 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -1,7 +1,7 @@ #include "FullDevice.h" -#include #include #include +#include FullDevice::FullDevice() : CharacterDevice(1, 7) @@ -30,4 +30,3 @@ ssize_t FullDevice::write(FileDescription&, const byte*, ssize_t size) return 0; return -ENOSPC; } - diff --git a/Kernel/Devices/IDEDiskDevice.cpp b/Kernel/Devices/IDEDiskDevice.cpp index 436891da61..4c50915e61 100644 --- a/Kernel/Devices/IDEDiskDevice.cpp +++ b/Kernel/Devices/IDEDiskDevice.cpp @@ -1,81 +1,81 @@ #include #include -#include -#include -#include #include #include +#include +#include +#include //#define DISK_DEBUG #define IRQ_FIXED_DISK 14 -#define ATA_SR_BSY 0x80 -#define ATA_SR_DRDY 0x40 -#define ATA_SR_DF 0x20 -#define ATA_SR_DSC 0x10 -#define ATA_SR_DRQ 0x08 -#define ATA_SR_CORR 0x04 -#define ATA_SR_IDX 0x02 -#define ATA_SR_ERR 0x01 +#define ATA_SR_BSY 0x80 +#define ATA_SR_DRDY 0x40 +#define ATA_SR_DF 0x20 +#define ATA_SR_DSC 0x10 +#define ATA_SR_DRQ 0x08 +#define ATA_SR_CORR 0x04 +#define ATA_SR_IDX 0x02 +#define ATA_SR_ERR 0x01 -#define ATA_ER_BBK 0x80 -#define ATA_ER_UNC 0x40 -#define ATA_ER_MC 0x20 -#define ATA_ER_IDNF 0x10 -#define ATA_ER_MCR 0x08 -#define ATA_ER_ABRT 0x04 -#define ATA_ER_TK0NF 0x02 -#define ATA_ER_AMNF 0x01 +#define ATA_ER_BBK 0x80 +#define ATA_ER_UNC 0x40 +#define ATA_ER_MC 0x20 +#define ATA_ER_IDNF 0x10 +#define ATA_ER_MCR 0x08 +#define ATA_ER_ABRT 0x04 +#define ATA_ER_TK0NF 0x02 +#define ATA_ER_AMNF 0x01 -#define ATA_CMD_READ_PIO 0x20 -#define ATA_CMD_READ_PIO_EXT 0x24 -#define ATA_CMD_READ_DMA 0xC8 -#define ATA_CMD_READ_DMA_EXT 0x25 -#define ATA_CMD_WRITE_PIO 0x30 -#define ATA_CMD_WRITE_PIO_EXT 0x34 -#define ATA_CMD_WRITE_DMA 0xCA -#define ATA_CMD_WRITE_DMA_EXT 0x35 -#define ATA_CMD_CACHE_FLUSH 0xE7 -#define ATA_CMD_CACHE_FLUSH_EXT 0xEA -#define ATA_CMD_PACKET 0xA0 -#define ATA_CMD_IDENTIFY_PACKET 0xA1 -#define ATA_CMD_IDENTIFY 0xEC +#define ATA_CMD_READ_PIO 0x20 +#define ATA_CMD_READ_PIO_EXT 0x24 +#define ATA_CMD_READ_DMA 0xC8 +#define ATA_CMD_READ_DMA_EXT 0x25 +#define ATA_CMD_WRITE_PIO 0x30 +#define ATA_CMD_WRITE_PIO_EXT 0x34 +#define ATA_CMD_WRITE_DMA 0xCA +#define ATA_CMD_WRITE_DMA_EXT 0x35 +#define ATA_CMD_CACHE_FLUSH 0xE7 +#define ATA_CMD_CACHE_FLUSH_EXT 0xEA +#define ATA_CMD_PACKET 0xA0 +#define ATA_CMD_IDENTIFY_PACKET 0xA1 +#define ATA_CMD_IDENTIFY 0xEC -#define ATAPI_CMD_READ 0xA8 -#define ATAPI_CMD_EJECT 0x1B +#define ATAPI_CMD_READ 0xA8 +#define ATAPI_CMD_EJECT 0x1B -#define ATA_IDENT_DEVICETYPE 0 -#define ATA_IDENT_CYLINDERS 2 -#define ATA_IDENT_HEADS 6 -#define ATA_IDENT_SECTORS 12 -#define ATA_IDENT_SERIAL 20 -#define ATA_IDENT_MODEL 54 +#define ATA_IDENT_DEVICETYPE 0 +#define ATA_IDENT_CYLINDERS 2 +#define ATA_IDENT_HEADS 6 +#define ATA_IDENT_SECTORS 12 +#define ATA_IDENT_SERIAL 20 +#define ATA_IDENT_MODEL 54 #define ATA_IDENT_CAPABILITIES 98 -#define ATA_IDENT_FIELDVALID 106 -#define ATA_IDENT_MAX_LBA 120 -#define ATA_IDENT_COMMANDSETS 164 -#define ATA_IDENT_MAX_LBA_EXT 200 +#define ATA_IDENT_FIELDVALID 106 +#define ATA_IDENT_MAX_LBA 120 +#define ATA_IDENT_COMMANDSETS 164 +#define ATA_IDENT_MAX_LBA_EXT 200 -#define IDE_ATA 0x00 -#define IDE_ATAPI 0x01 +#define IDE_ATA 0x00 +#define IDE_ATAPI 0x01 -#define ATA_REG_DATA 0x00 -#define ATA_REG_ERROR 0x01 -#define ATA_REG_FEATURES 0x01 -#define ATA_REG_SECCOUNT0 0x02 -#define ATA_REG_LBA0 0x03 -#define ATA_REG_LBA1 0x04 -#define ATA_REG_LBA2 0x05 -#define ATA_REG_HDDEVSEL 0x06 -#define ATA_REG_COMMAND 0x07 -#define ATA_REG_STATUS 0x07 -#define ATA_REG_SECCOUNT1 0x08 -#define ATA_REG_LBA3 0x09 -#define ATA_REG_LBA4 0x0A -#define ATA_REG_LBA5 0x0B -#define ATA_REG_CONTROL 0x0C -#define ATA_REG_ALTSTATUS 0x0C +#define ATA_REG_DATA 0x00 +#define ATA_REG_ERROR 0x01 +#define ATA_REG_FEATURES 0x01 +#define ATA_REG_SECCOUNT0 0x02 +#define ATA_REG_LBA0 0x03 +#define ATA_REG_LBA1 0x04 +#define ATA_REG_LBA2 0x05 +#define ATA_REG_HDDEVSEL 0x06 +#define ATA_REG_COMMAND 0x07 +#define ATA_REG_STATUS 0x07 +#define ATA_REG_SECCOUNT1 0x08 +#define ATA_REG_LBA3 0x09 +#define ATA_REG_LBA4 0x0A +#define ATA_REG_LBA5 0x0B +#define ATA_REG_CONTROL 0x0C +#define ATA_REG_ALTSTATUS 0x0C #define ATA_REG_DEVADDRESS 0x0D Retained IDEDiskDevice::create() @@ -137,14 +137,14 @@ bool IDEDiskDevice::write_block(unsigned index, const byte* data) static void print_ide_status(byte status) { kprintf("DRQ=%u BSY=%u DRDY=%u DSC=%u DF=%u CORR=%u IDX=%u ERR=%u\n", - (status & ATA_SR_DRQ) != 0, - (status & ATA_SR_BSY) != 0, - (status & ATA_SR_DRDY) != 0, - (status & ATA_SR_DSC) != 0, - (status & ATA_SR_DF) != 0, - (status & ATA_SR_CORR) != 0, - (status & ATA_SR_IDX) != 0, - (status & ATA_SR_ERR) != 0); + (status & ATA_SR_DRQ) != 0, + (status & ATA_SR_BSY) != 0, + (status & ATA_SR_DRDY) != 0, + (status & ATA_SR_DSC) != 0, + (status & ATA_SR_DF) != 0, + (status & ATA_SR_CORR) != 0, + (status & ATA_SR_IDX) != 0, + (status & ATA_SR_ERR) != 0); } bool IDEDiskDevice::wait_for_irq() @@ -184,7 +184,7 @@ void IDEDiskDevice::initialize() { static const PCI::ID piix3_ide_id = { 0x8086, 0x7010 }; static const PCI::ID piix4_ide_id = { 0x8086, 0x7111 }; - PCI::enumerate_all([this] (const PCI::Address& address, PCI::ID id) { + PCI::enumerate_all([this](const PCI::Address& address, PCI::ID id) { if (id == piix3_ide_id || id == piix4_ide_id) { m_pci_address = address; kprintf("PIIX%u IDE device found!\n", id == piix3_ide_id ? 3 : 4); @@ -199,7 +199,8 @@ void IDEDiskDevice::initialize() m_interrupted = false; - while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY); + while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY) + ; enable_irq(); @@ -236,8 +237,7 @@ void IDEDiskDevice::initialize() bbuf.pointer() + 54, m_cylinders, m_heads, - m_sectors_per_track - ); + m_sectors_per_track); // Let's try to set up DMA transfers. if (!m_pci_address.is_null()) { @@ -260,8 +260,8 @@ bool IDEDiskDevice::read_sectors_with_dma(dword lba, word count, byte* outbuf) LOCKER(m_lock); #ifdef DISK_DEBUG dbgprintf("%s(%u): IDEDiskDevice::read_sectors_with_dma (%u x%u) -> %p\n", - current->process().name().characters(), - current->pid(), lba, count, outbuf); + current->process().name().characters(), + current->pid(), lba, count, outbuf); #endif disable_irq(); @@ -286,7 +286,8 @@ bool IDEDiskDevice::read_sectors_with_dma(dword lba, word count, byte* outbuf) m_interrupted = false; enable_irq(); - while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY); + while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY) + ; bool is_slave = false; @@ -337,13 +338,14 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf) LOCKER(m_lock); #ifdef DISK_DEBUG dbgprintf("%s: Disk::read_sectors request (%u sector(s) @ %u)\n", - current->process().name().characters(), - count, - start_sector); + current->process().name().characters(), + count, + start_sector); #endif disable_irq(); - while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY); + while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY) + ; #ifdef DISK_DEBUG kprintf("IDEDiskDevice: Reading %u sector(s) @ LBA %u\n", count, start_sector); @@ -356,7 +358,8 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf) IO::out8(m_io_base + ATA_REG_HDDEVSEL, 0xe0 | ((start_sector >> 24) & 0xf)); // 0xf0 for 2nd device IO::out8(0x3F6, 0x08); - while (!(IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_DRDY)); + while (!(IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_DRDY)) + ; IO::out8(m_io_base + ATA_REG_COMMAND, ATA_CMD_READ_PIO); m_interrupted = false; @@ -381,8 +384,8 @@ bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* in LOCKER(m_lock); #ifdef DISK_DEBUG dbgprintf("%s(%u): IDEDiskDevice::write_sectors_with_dma (%u x%u) <- %p\n", - current->process().name().characters(), - current->pid(), lba, count, inbuf); + current->process().name().characters(), + current->pid(), lba, count, inbuf); #endif disable_irq(); @@ -406,7 +409,8 @@ bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* in m_interrupted = false; enable_irq(); - while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY); + while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY) + ; bool is_slave = false; @@ -455,14 +459,15 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da LOCKER(m_lock); #ifdef DISK_DEBUG dbgprintf("%s(%u): IDEDiskDevice::write_sectors request (%u sector(s) @ %u)\n", - current->process().name().characters(), - current->pid(), - count, - start_sector); + current->process().name().characters(), + current->pid(), + count, + start_sector); #endif disable_irq(); - while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY); + while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY) + ; //dbgprintf("IDEDiskDevice: Writing %u sector(s) @ LBA %u\n", count, start_sector); @@ -476,7 +481,8 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da IO::out8(m_io_base + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_DRQ)); + while (!(IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_DRQ)) + ; byte status = IO::in8(m_io_base + ATA_REG_STATUS); ASSERT(status & ATA_SR_DRQ); @@ -488,7 +494,8 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da disable_irq(); IO::out8(m_io_base + ATA_REG_COMMAND, ATA_CMD_CACHE_FLUSH); - while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY); + while (IO::in8(m_io_base + ATA_REG_STATUS) & ATA_SR_BSY) + ; m_interrupted = false; enable_irq(); wait_for_irq(); diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index 7a8464e598..03fa1b25ec 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -1,24 +1,23 @@ -#include -#include "i386.h" #include "IO.h" #include "PIC.h" +#include "i386.h" +#include +#include #include #include -#include //#define KEYBOARD_DEBUG -#define IRQ_KEYBOARD 1 -#define I8042_BUFFER 0x60 -#define I8042_STATUS 0x64 -#define I8042_ACK 0xFA -#define I8042_BUFFER_FULL 0x01 -#define I8042_WHICH_BUFFER 0x20 -#define I8042_MOUSE_BUFFER 0x20 -#define I8042_KEYBOARD_BUFFER 0x00 +#define IRQ_KEYBOARD 1 +#define I8042_BUFFER 0x60 +#define I8042_STATUS 0x64 +#define I8042_ACK 0xFA +#define I8042_BUFFER_FULL 0x01 +#define I8042_WHICH_BUFFER 0x20 +#define I8042_MOUSE_BUFFER 0x20 +#define I8042_KEYBOARD_BUFFER 0x00 -static char map[0x80] = -{ +static char map[0x80] = { 0, '\033', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08, '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', @@ -26,8 +25,7 @@ static char map[0x80] = 0, 0, 0, ' ' }; -static char shift_map[0x80] = -{ +static char shift_map[0x80] = { 0, '\033', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0x08, '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', @@ -35,24 +33,76 @@ static char shift_map[0x80] = 0, 0, 0, ' ' }; -static KeyCode unshifted_key_map[0x80] = -{ - Key_Invalid, Key_Escape, - Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0, Key_Minus, Key_Equal, Key_Backspace, +static KeyCode unshifted_key_map[0x80] = { + Key_Invalid, + Key_Escape, + Key_1, + Key_2, + Key_3, + Key_4, + Key_5, + Key_6, + Key_7, + Key_8, + Key_9, + Key_0, + Key_Minus, + Key_Equal, + Key_Backspace, Key_Tab, //15 - Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_LeftBracket, Key_RightBracket, - Key_Return, // 28 + Key_Q, + Key_W, + Key_E, + Key_R, + Key_T, + Key_Y, + Key_U, + Key_I, + Key_O, + Key_P, + Key_LeftBracket, + Key_RightBracket, + Key_Return, // 28 Key_Control, // 29 - Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Apostrophe, Key_Backtick, + Key_A, + Key_S, + Key_D, + Key_F, + Key_G, + Key_H, + Key_J, + Key_K, + Key_L, + Key_Semicolon, + Key_Apostrophe, + Key_Backtick, Key_LeftShift, // 42 Key_Backslash, - Key_Z, Key_X, Key_C, Key_V, Key_B, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, + Key_Z, + Key_X, + Key_C, + Key_V, + Key_B, + Key_N, + Key_M, + Key_Comma, + Key_Period, + Key_Slash, Key_RightShift, // 54 Key_Invalid, - Key_Alt, // 56 - Key_Space, // 57 + Key_Alt, // 56 + Key_Space, // 57 Key_Invalid, // 58 - Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, + Key_F1, + Key_F2, + Key_F3, + Key_F4, + Key_F5, + Key_F6, + Key_F7, + Key_F8, + Key_F9, + Key_F10, Key_Invalid, Key_Invalid, // 70 Key_Home, @@ -78,24 +128,76 @@ static KeyCode unshifted_key_map[0x80] = Key_Logo, }; -static KeyCode shifted_key_map[0x100] = -{ - Key_Invalid, Key_Escape, - Key_ExclamationPoint, Key_AtSign, Key_Hashtag, Key_Dollar, Key_Percent, Key_Circumflex, Key_Ampersand, Key_Asterisk, Key_LeftParen, Key_RightParen, Key_Underscore, Key_Plus, Key_Backspace, +static KeyCode shifted_key_map[0x100] = { + Key_Invalid, + Key_Escape, + Key_ExclamationPoint, + Key_AtSign, + Key_Hashtag, + Key_Dollar, + Key_Percent, + Key_Circumflex, + Key_Ampersand, + Key_Asterisk, + Key_LeftParen, + Key_RightParen, + Key_Underscore, + Key_Plus, + Key_Backspace, Key_Tab, - Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_LeftBrace, Key_RightBrace, + Key_Q, + Key_W, + Key_E, + Key_R, + Key_T, + Key_Y, + Key_U, + Key_I, + Key_O, + Key_P, + Key_LeftBrace, + Key_RightBrace, Key_Return, Key_Control, - Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Colon, Key_DoubleQuote, Key_Tilde, + Key_A, + Key_S, + Key_D, + Key_F, + Key_G, + Key_H, + Key_J, + Key_K, + Key_L, + Key_Colon, + Key_DoubleQuote, + Key_Tilde, Key_LeftShift, // 42 Key_Pipe, - Key_Z, Key_X, Key_C, Key_V, Key_B, Key_N, Key_M, Key_LessThan, Key_GreaterThan, Key_QuestionMark, + Key_Z, + Key_X, + Key_C, + Key_V, + Key_B, + Key_N, + Key_M, + Key_LessThan, + Key_GreaterThan, + Key_QuestionMark, Key_RightShift, // 54 Key_Invalid, Key_Alt, - Key_Space, // 57 + Key_Space, // 57 Key_Invalid, // 58 - Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, + Key_F1, + Key_F2, + Key_F3, + Key_F4, + Key_F5, + Key_F6, + Key_F7, + Key_F8, + Key_F9, + Key_F10, Key_Invalid, Key_Invalid, // 70 Key_Home, @@ -163,7 +265,8 @@ void KeyboardDevice::handle_irq() break; } switch (ch) { - case I8042_ACK: break; + case I8042_ACK: + break; default: if (m_modifiers & Mod_Alt) { switch (map[ch]) { diff --git a/Kernel/Devices/NullDevice.cpp b/Kernel/Devices/NullDevice.cpp index c04f84e1ca..1d4cfcdaf6 100644 --- a/Kernel/Devices/NullDevice.cpp +++ b/Kernel/Devices/NullDevice.cpp @@ -34,4 +34,3 @@ ssize_t NullDevice::write(FileDescription&, const byte*, ssize_t buffer_size) { return min(PAGE_SIZE, buffer_size); } - diff --git a/Kernel/Devices/PCSpeaker.cpp b/Kernel/Devices/PCSpeaker.cpp index 347dd33b62..c8c8b883a4 100644 --- a/Kernel/Devices/PCSpeaker.cpp +++ b/Kernel/Devices/PCSpeaker.cpp @@ -1,7 +1,7 @@ #include -#include #include #include +#include void PCSpeaker::tone_on(int frequency) { diff --git a/Kernel/Devices/PS2MouseDevice.cpp b/Kernel/Devices/PS2MouseDevice.cpp index a7f2fe296d..b48b537e8b 100644 --- a/Kernel/Devices/PS2MouseDevice.cpp +++ b/Kernel/Devices/PS2MouseDevice.cpp @@ -1,16 +1,16 @@ #include "PS2MouseDevice.h" #include "IO.h" -#define IRQ_MOUSE 1 -#define I8042_BUFFER 0x60 -#define I8042_STATUS 0x64 -#define I8042_ACK 0xFA -#define I8042_BUFFER_FULL 0x01 -#define I8042_WHICH_BUFFER 0x20 -#define I8042_MOUSE_BUFFER 0x20 -#define I8042_KEYBOARD_BUFFER 0x00 +#define IRQ_MOUSE 1 +#define I8042_BUFFER 0x60 +#define I8042_STATUS 0x64 +#define I8042_ACK 0xFA +#define I8042_BUFFER_FULL 0x01 +#define I8042_WHICH_BUFFER 0x20 +#define I8042_MOUSE_BUFFER 0x20 +#define I8042_KEYBOARD_BUFFER 0x00 -#define PS2MOUSE_GET_DEVICE_ID 0xF2 +#define PS2MOUSE_GET_DEVICE_ID 0xF2 #define PS2MOUSE_SET_SAMPLE_RATE 0xF3 #define PS2MOUSE_INTELLIMOUSE_ID 0x03 @@ -54,8 +54,7 @@ void PS2MouseDevice::handle_irq() m_data[2], (m_data[0] & 1) ? "Left" : "", (m_data[0] & 2) ? "Right" : "", - m_queue.size() - ); + m_queue.size()); #endif parse_data_packet(); }; diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp index 3e3cfdd023..c5ff3f2562 100644 --- a/Kernel/Devices/RandomDevice.cpp +++ b/Kernel/Devices/RandomDevice.cpp @@ -47,4 +47,3 @@ ssize_t RandomDevice::write(FileDescription&, const byte*, ssize_t size) // FIXME: Use input for entropy? I guess that could be a neat feature? return min(PAGE_SIZE, size); } - diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index aa9e98e3a8..e9eed27af0 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -27,4 +27,3 @@ ssize_t ZeroDevice::write(FileDescription&, const byte*, ssize_t size) { return min(PAGE_SIZE, size); } - diff --git a/Kernel/File.cpp b/Kernel/File.cpp index c0e4d37aea..7d4d9c98de 100644 --- a/Kernel/File.cpp +++ b/Kernel/File.cpp @@ -28,4 +28,3 @@ KResultOr File::mmap(Process&, FileDescription&, LinearAddress, size_t, { return KResult(-ENODEV); } - diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp index f70d1a2719..769d4c0de8 100644 --- a/Kernel/FileSystem/Custody.cpp +++ b/Kernel/FileSystem/Custody.cpp @@ -31,9 +31,9 @@ Retained Custody::get_or_create(Custody* parent, const String& name, In if (RetainPtr cached_custody = get_if_cached(parent, name)) { if (&cached_custody->inode() != &inode) { dbgprintf("WTF! cached custody for name '%s' has inode=%s, new inode=%s\n", - name.characters(), - cached_custody->inode().identifier().to_string().characters(), - inode.identifier().to_string().characters()); + name.characters(), + cached_custody->inode().identifier().to_string().characters(), + inode.identifier().to_string().characters()); } ASSERT(&cached_custody->inode() == &inode); return *cached_custody; @@ -83,4 +83,3 @@ void Custody::did_rename(Badge, const String& name) { m_name = name; } - diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index 8e8fd94637..be3a0d6968 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -1,7 +1,7 @@ -#include -#include -#include #include +#include +#include +#include static DevPtsFS* s_the; diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index a17fa9b2df..a32731f5c7 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1,12 +1,12 @@ #include "Ext2FileSystem.h" -#include "ext2_fs.h" -#include "UnixTypes.h" #include "RTC.h" +#include "UnixTypes.h" +#include "ext2_fs.h" #include -#include #include -#include +#include #include +#include //#define EXT2_DEBUG @@ -162,10 +162,10 @@ ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& block_i auto& super_block = this->super_block(); if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&super_block)) - return { }; + return {}; if (inode > super_block.s_inodes_count) - return { }; + return {}; auto& bgd = group_descriptor(group_index_from_inode(inode)); @@ -314,7 +314,7 @@ Vector Ext2FS::block_list_for_inode(const ext2_inode& e2inod if (!blocks_remaining) return list; - auto process_block_array = [&] (unsigned array_block_index, auto&& callback) { + auto process_block_array = [&](unsigned array_block_index, auto&& callback) { if (include_block_list_blocks) callback(array_block_index); auto array_block = read_block(array_block_index); @@ -331,15 +331,15 @@ Vector Ext2FS::block_list_for_inode(const ext2_inode& e2inod } }; - process_block_array(e2inode.i_block[EXT2_IND_BLOCK], [&] (unsigned entry) { + process_block_array(e2inode.i_block[EXT2_IND_BLOCK], [&](unsigned entry) { list.unchecked_append(entry); }); if (!blocks_remaining) return list; - process_block_array(e2inode.i_block[EXT2_DIND_BLOCK], [&] (unsigned entry) { - process_block_array(entry, [&] (unsigned entry) { + process_block_array(e2inode.i_block[EXT2_DIND_BLOCK], [&](unsigned entry) { + process_block_array(entry, [&](unsigned entry) { list.unchecked_append(entry); }); }); @@ -347,9 +347,9 @@ Vector Ext2FS::block_list_for_inode(const ext2_inode& e2inod if (!blocks_remaining) return list; - process_block_array(e2inode.i_block[EXT2_TIND_BLOCK], [&] (unsigned entry) { - process_block_array(entry, [&] (unsigned entry) { - process_block_array(entry, [&] (unsigned entry) { + process_block_array(e2inode.i_block[EXT2_TIND_BLOCK], [&](unsigned entry) { + process_block_array(entry, [&](unsigned entry) { + process_block_array(entry, [&](unsigned entry) { list.unchecked_append(entry); }); }); @@ -468,7 +468,7 @@ RetainPtr Ext2FS::get_inode(InodeIdentifier inode) const unsigned offset; auto block = read_block_containing_inode(inode.index(), block_index, offset); if (!block) - return { }; + return {}; auto it = m_inode_cache.find(inode.index()); if (it != m_inode_cache.end()) @@ -709,13 +709,13 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const String& name, mod LOCKER(m_lock); ASSERT(is_directory()); -//#ifdef EXT2_DEBUG + //#ifdef EXT2_DEBUG dbgprintf("Ext2FS: Adding inode %u with name '%s' to directory %u\n", child_id.index(), name.characters(), index()); -//#endif + //#endif Vector entries; bool name_already_exists = false; - traverse_as_directory([&] (auto& entry) { + traverse_as_directory([&](auto& entry) { if (!strcmp(entry.name, name.characters())) { name_already_exists = true; return false; @@ -755,12 +755,12 @@ KResult Ext2FSInode::remove_child(const String& name) InodeIdentifier child_id { fsid(), child_inode_index }; -//#ifdef EXT2_DEBUG + //#ifdef EXT2_DEBUG dbgprintf("Ext2FS: Removing '%s' in directory %u\n", name.characters(), index()); -//#endif + //#endif Vector entries; - traverse_as_directory([&] (auto& entry) { + traverse_as_directory([&](auto& entry) { if (strcmp(entry.name, name.characters()) != 0) entries.append(entry); return true; @@ -842,7 +842,6 @@ unsigned Ext2FS::inodes_per_group() const unsigned Ext2FS::inode_size() const { return EXT2_INODE_SIZE(&super_block()); - } unsigned Ext2FS::blocks_per_group() const { @@ -868,12 +867,12 @@ Vector Ext2FS::allocate_blocks(GroupIndex group_index, int c LOCKER(m_lock); dbgprintf("Ext2FS: allocate_blocks(group: %u, count: %u)\n", group_index, count); if (count == 0) - return { }; + return {}; auto& bgd = group_descriptor(group_index); if (bgd.bg_free_blocks_count < count) { kprintf("Ext2FS: allocate_blocks can't allocate out of group %u, wanted %u but only %u available\n", group_index, count, bgd.bg_free_blocks_count); - return { }; + return {}; } // FIXME: Implement a scan that finds consecutive blocks if possible. @@ -910,7 +909,7 @@ unsigned Ext2FS::allocate_inode(GroupIndex preferred_group, off_t expected_size) unsigned group_index = 0; - auto is_suitable_group = [this, needed_blocks] (GroupIndex group_index) { + auto is_suitable_group = [this, needed_blocks](GroupIndex group_index) { auto& bgd = group_descriptor(group_index); return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= needed_blocks; }; @@ -1138,7 +1137,7 @@ RetainPtr Ext2FS::create_inode(InodeIdentifier parent_id, const String& n if (!inode_id) { kprintf("Ext2FS: create_inode: allocate_inode failed\n"); error = -ENOSPC; - return { }; + return {}; } auto needed_blocks = ceil_div(size, block_size()); @@ -1146,14 +1145,14 @@ RetainPtr Ext2FS::create_inode(InodeIdentifier parent_id, const String& n if (blocks.size() != needed_blocks) { kprintf("Ext2FS: create_inode: allocate_blocks failed\n"); error = -ENOSPC; - return { }; + return {}; } // Try adding it to the directory first, in case the name is already in use. auto result = parent_inode->add_child({ fsid(), inode_id }, name, to_ext2_file_type(mode)); if (result.is_error()) { error = result; - return { }; + return {}; } // Looks like we're good, time to update the inode bitmap and group+global inode counters. @@ -1211,7 +1210,7 @@ void Ext2FSInode::populate_lookup_cache() const return; HashMap children; - traverse_as_directory([&children] (auto& entry) { + traverse_as_directory([&children](auto& entry) { children.set(String(entry.name, entry.name_length), entry.inode.index()); return true; }); @@ -1229,7 +1228,7 @@ InodeIdentifier Ext2FSInode::lookup(StringView name) auto it = m_lookup_cache.find(name); if (it != m_lookup_cache.end()) return { fsid(), (*it).value }; - return { }; + return {}; } void Ext2FSInode::one_retain_left() diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index e14689e763..32d80804e4 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -1,10 +1,10 @@ +#include +#include #include #include #include #include #include -#include -#include //#define FIFO_DEBUG @@ -34,7 +34,7 @@ Retained FIFO::open_direction(FIFO::Direction direction) { auto descriptor = FileDescription::create(this); attach(direction); - descriptor->set_fifo_direction({ }, direction); + descriptor->set_fifo_direction({}, direction); return descriptor; } @@ -98,7 +98,7 @@ ssize_t FIFO::read(FileDescription&, byte* buffer, ssize_t size) if (!m_writers && m_buffer.is_empty()) return 0; #ifdef FIFO_DEBUG - dbgprintf("fifo: read(%u)\n",size); + dbgprintf("fifo: read(%u)\n", size); #endif ssize_t nread = m_buffer.read(buffer, size); #ifdef FIFO_DEBUG diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index d62e573d3b..38c58cee0f 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -179,7 +179,7 @@ ssize_t FileDescription::get_dir_entries(byte* buffer, ssize_t size) auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate); BufferStream stream(temp_buffer); - VFS::the().traverse_directory_inode(*m_inode, [&stream] (auto& entry) { + VFS::the().traverse_directory_inode(*m_inode, [&stream](auto& entry) { stream << (dword)entry.inode.index(); stream << (byte)entry.file_type; stream << (dword)entry.name_length; @@ -255,7 +255,7 @@ InodeMetadata FileDescription::metadata() const { if (m_inode) return m_inode->metadata(); - return { }; + return {}; } KResultOr FileDescription::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot) diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index a8619bd806..96728554bc 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -1,11 +1,11 @@ #include #include #include -#include #include #include -#include #include +#include +#include static dword s_lastFileSystemID; static HashMap* s_fs_map; @@ -17,7 +17,6 @@ static HashMap& all_fses() return *s_fs_map; } - FS::FS() : m_fsid(++s_lastFileSystemID) { diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 2be2ec2ea6..ef4fbe8207 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -1,7 +1,7 @@ -#include #include -#include +#include #include +#include HashTable& all_inodes() { diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 577dec1a21..48d4be04e8 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include #include #include diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 73aeb43743..ea5825e249 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -1,20 +1,21 @@ #include "ProcFS.h" +#include "Console.h" +#include "KSyms.h" #include "Process.h" +#include "Scheduler.h" +#include "StdLib.h" +#include "i386.h" +#include #include #include #include -#include -#include "StdLib.h" -#include "i386.h" -#include "KSyms.h" -#include "Console.h" -#include "Scheduler.h" #include +#include #include -#include #include -enum ProcParentDirectory { +enum ProcParentDirectory +{ PDI_AbstractRoot = 0, PDI_Root, PDI_Root_sys, @@ -22,7 +23,8 @@ enum ProcParentDirectory { PDI_PID_fd, }; -enum ProcFileType { +enum ProcFileType +{ FI_Invalid = 0, FI_Root = 1, // directory @@ -41,7 +43,7 @@ enum ProcFileType { FI_Root_pci, FI_Root_uptime, FI_Root_self, // symlink - FI_Root_sys, // directory + FI_Root_sys, // directory __FI_Root_End, FI_PID, @@ -54,7 +56,7 @@ enum ProcFileType { FI_PID_fds, FI_PID_exe, // symlink FI_PID_cwd, // symlink - FI_PID_fd, // directory + FI_PID_fd, // directory __FI_PID_End, FI_MaxStaticFileIndex, @@ -183,10 +185,10 @@ ByteBuffer procfs$pid_fds(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); if (process.number_of_open_file_descriptors() == 0) - return { }; + return {}; StringBuilder builder; for (int i = 0; i < process.max_open_file_descriptors(); ++i) { auto* descriptor = process.file_description(i); @@ -201,12 +203,12 @@ ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); int fd = to_fd(identifier); auto* descriptor = process.file_description(fd); if (!descriptor) - return { }; + return {}; return descriptor->absolute_path().to_byte_buffer(); } @@ -214,7 +216,7 @@ ByteBuffer procfs$pid_vm(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); StringBuilder builder; builder.appendf("BEGIN END SIZE COMMIT FLAGS NAME\n"); @@ -238,7 +240,7 @@ ByteBuffer procfs$pid_vm(InodeIdentifier identifier) ByteBuffer procfs$pci(InodeIdentifier) { StringBuilder builder; - PCI::enumerate_all([&builder] (PCI::Address address, PCI::ID id) { + PCI::enumerate_all([&builder](PCI::Address address, PCI::ID id) { builder.appendf("%b:%b.%b %w:%w\n", address.bus(), address.slot(), address.function(), id.vendor_id, id.device_id); }); return builder.to_byte_buffer(); @@ -255,7 +257,7 @@ ByteBuffer procfs$pid_vmo(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); StringBuilder builder; builder.appendf("BEGIN END SIZE NAME\n"); @@ -275,8 +277,7 @@ ByteBuffer procfs$pid_vmo(InodeIdentifier identifier) builder.appendf("P%x%s(%u) ", physical_page ? physical_page->paddr().get() : 0, region->should_cow(i) ? "!" : "", - physical_page ? physical_page->retain_count() : 0 - ); + physical_page ? physical_page->retain_count() : 0); } builder.appendf("\n"); } @@ -287,7 +288,7 @@ ByteBuffer procfs$pid_stack(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); ProcessPagingScope paging_scope(process); struct RecognizedSymbol { @@ -295,7 +296,7 @@ ByteBuffer procfs$pid_stack(InodeIdentifier identifier) const KSym* ksym; }; StringBuilder builder; - process.for_each_thread([&] (Thread& thread) { + process.for_each_thread([&](Thread& thread) { builder.appendf("Thread %d:\n", thread.tid()); Vector recognized_symbols; recognized_symbols.append({ thread.tss().eip, ksymbolicate(thread.tss().eip) }); @@ -326,10 +327,10 @@ ByteBuffer procfs$pid_regs(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); StringBuilder builder; - process.for_each_thread([&] (Thread& thread) { + process.for_each_thread([&](Thread& thread) { builder.appendf("Thread %d:\n", thread.tid()); auto& tss = thread.tss(); builder.appendf("eax: %x\n", tss.eax); @@ -352,7 +353,7 @@ ByteBuffer procfs$pid_exe(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; auto& process = handle->process(); auto* custody = process.executable(); ASSERT(custody); @@ -363,7 +364,7 @@ ByteBuffer procfs$pid_cwd(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); if (!handle) - return { }; + return {}; return handle->process().current_directory().absolute_path().to_byte_buffer(); } @@ -406,7 +407,7 @@ ByteBuffer procfs$mounts(InodeIdentifier) { // FIXME: This is obviously racy against the VFS mounts changing. StringBuilder builder; - VFS::the().for_each_mount([&builder] (auto& mount) { + VFS::the().for_each_mount([&builder](auto& mount) { auto& fs = mount.guest_fs(); builder.appendf("%s @ ", fs.class_name()); if (!mount.host().is_valid()) @@ -425,7 +426,7 @@ ByteBuffer procfs$df(InodeIdentifier) { // FIXME: This is obviously racy against the VFS mounts changing. StringBuilder builder; - VFS::the().for_each_mount([&builder] (auto& mount) { + VFS::the().for_each_mount([&builder](auto& mount) { auto& fs = mount.guest_fs(); builder.appendf("%s,", fs.class_name()); builder.appendf("%u,", fs.total_block_count()); @@ -444,7 +445,7 @@ ByteBuffer procfs$cpuinfo(InodeIdentifier) { CPUID cpuid(0); builder.appendf("cpuid: "); - auto emit_dword = [&] (dword value) { + auto emit_dword = [&](dword value) { builder.appendf("%c%c%c%c", value & 0xff, (value >> 8) & 0xff, @@ -486,7 +487,7 @@ ByteBuffer procfs$cpuinfo(InodeIdentifier) // and verifying that the returned eax>=0x80000004. char buffer[48]; dword* bufptr = reinterpret_cast(buffer); - auto copy_brand_string_part_to_buffer = [&] (dword i) { + auto copy_brand_string_part_to_buffer = [&](dword i) { CPUID cpuid(0x80000002 + i); *bufptr++ = cpuid.eax(); *bufptr++ = cpuid.ebx(); @@ -510,8 +511,7 @@ ByteBuffer procfs$kmalloc(InodeIdentifier) "free: %u\n", kmalloc_sum_eternal, sum_alloc, - sum_free - ); + sum_free); return builder.to_byte_buffer(); } @@ -551,8 +551,7 @@ ByteBuffer procfs$memstat(InodeIdentifier) MM.super_physical_pages_in_existence() - MM.m_free_supervisor_physical_pages.size(), MM.m_free_supervisor_physical_pages.size(), g_kmalloc_call_count, - g_kfree_call_count - ); + g_kfree_call_count); return builder.to_byte_buffer(); } @@ -561,7 +560,7 @@ ByteBuffer procfs$all(InodeIdentifier) InterruptDisabler disabler; auto processes = Process::all_processes(); StringBuilder builder(processes.size() * 80); - auto build_process_line = [&builder] (Process* process) { + auto build_process_line = [&builder](Process* process) { builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u,%u,%s,%u\n", process->pid(), process->main_thread().times_scheduled(), // FIXME(Thread): Bill all scheds to the process @@ -580,8 +579,7 @@ ByteBuffer procfs$all(InodeIdentifier) process->amount_shared(), process->main_thread().ticks(), // FIXME(Thread): Bill all ticks to the process to_string(process->priority()), - process->syscall_count() - ); + process->syscall_count()); }; build_process_line(Scheduler::colonel()); for (auto* process : processes) @@ -601,9 +599,10 @@ ByteBuffer procfs$inodes(InodeIdentifier) } struct SysVariableData final : public ProcFSInodeCustomData { - virtual ~SysVariableData() override { } + virtual ~SysVariableData() override {} - enum Type { + enum Type + { Invalid, Boolean, String, @@ -617,7 +616,7 @@ static ByteBuffer read_sys_bool(InodeIdentifier inode_id) { auto inode_ptr = ProcFS::the().get_inode(inode_id); if (!inode_ptr) - return { }; + return {}; auto& inode = static_cast(*inode_ptr); ASSERT(inode.custom_data()); auto buffer = ByteBuffer::create_uninitialized(2); @@ -637,7 +636,7 @@ static ssize_t write_sys_bool(InodeIdentifier inode_id, const ByteBuffer& data) { auto inode_ptr = ProcFS::the().get_inode(inode_id); if (!inode_ptr) - return { }; + return {}; auto& inode = static_cast(*inode_ptr); ASSERT(inode.custom_data()); if (data.is_empty() || !(data[0] == '0' || data[0] == '1')) @@ -658,7 +657,7 @@ static ByteBuffer read_sys_string(InodeIdentifier inode_id) { auto inode_ptr = ProcFS::the().get_inode(inode_id); if (!inode_ptr) - return { }; + return {}; auto& inode = static_cast(*inode_ptr); ASSERT(inode.custom_data()); auto buffer = ByteBuffer::create_uninitialized(2); @@ -674,7 +673,7 @@ static ssize_t write_sys_string(InodeIdentifier inode_id, const ByteBuffer& data { auto inode_ptr = ProcFS::the().get_inode(inode_id); if (!inode_ptr) - return { }; + return {}; auto& inode = static_cast(*inode_ptr); ASSERT(inode.custom_data()); auto& custom_data = *static_cast(inode.custom_data()); @@ -730,7 +729,7 @@ const char* ProcFS::class_name() const RetainPtr ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, int&) { kprintf("FIXME: Implement ProcFS::create_inode()?\n"); - return { }; + return {}; } RetainPtr ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error) @@ -932,8 +931,7 @@ bool ProcFSInode::traverse_as_directory(Functionprocess(); for (auto& entry : fs().m_entries) { if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) { @@ -1016,7 +1013,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name) } } } - return { }; + return {}; } if (proc_file_type == FI_PID_fd) { @@ -1028,13 +1025,12 @@ InodeIdentifier ProcFSInode::lookup(StringView name) InterruptDisabler disabler; if (auto* process = Process::from_pid(to_pid(identifier()))) fd_exists = process->file_description(name_as_number); - } if (fd_exists) return to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number); } } - return { }; + return {}; } void ProcFSInode::flush_metadata() @@ -1075,7 +1071,7 @@ size_t ProcFSInode::directory_entry_count() const { ASSERT(is_directory()); size_t count = 0; - traverse_as_directory([&count] (const FS::DirectoryEntry&) { + traverse_as_directory([&count](const FS::DirectoryEntry&) { ++count; return true; }); @@ -1099,7 +1095,7 @@ ProcFS::ProcFS() m_entries[FI_Root_all] = { "all", FI_Root_all, procfs$all }; m_entries[FI_Root_memstat] = { "memstat", FI_Root_memstat, procfs$memstat }; m_entries[FI_Root_summary] = { "summary", FI_Root_summary, procfs$summary }; - m_entries[FI_Root_cpuinfo] = { "cpuinfo", FI_Root_cpuinfo, procfs$cpuinfo}; + m_entries[FI_Root_cpuinfo] = { "cpuinfo", FI_Root_cpuinfo, procfs$cpuinfo }; m_entries[FI_Root_inodes] = { "inodes", FI_Root_inodes, procfs$inodes }; m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg }; m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self }; diff --git a/Kernel/FileSystem/SyntheticFileSystem.cpp b/Kernel/FileSystem/SyntheticFileSystem.cpp index 86e2aed130..32b7d07056 100644 --- a/Kernel/FileSystem/SyntheticFileSystem.cpp +++ b/Kernel/FileSystem/SyntheticFileSystem.cpp @@ -1,7 +1,7 @@ -#include -#include -#include #include +#include +#include +#include //#define SYNTHFS_DEBUG @@ -140,13 +140,13 @@ InodeIdentifier SynthFS::root_inode() const RetainPtr SynthFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, off_t size, dev_t, int& error) { - (void) parentInode; - (void) name; - (void) mode; - (void) size; - (void) error; + (void)parentInode; + (void)name; + (void)mode; + (void)size; + (void)error; kprintf("FIXME: Implement SyntheticFileSystem::create_inode().\n"); - return { }; + return {}; } RetainPtr SynthFS::create_directory(InodeIdentifier, const String&, mode_t, int& error) @@ -166,7 +166,7 @@ RetainPtr SynthFS::get_inode(InodeIdentifier inode) const LOCKER(m_lock); auto it = m_inodes.find(inode.index()); if (it == m_inodes.end()) - return { }; + return {}; return (*it).value; } @@ -243,7 +243,7 @@ InodeIdentifier SynthFSInode::lookup(StringView name) if (child->m_name == name) return child->identifier(); } - return { }; + return {}; } void SynthFSInode::flush_metadata() diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 7ae678e6d1..c37f2b87ae 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -1,12 +1,12 @@ #include "VirtualFileSystem.h" -#include #include "FileSystem.h" #include #include #include -#include -#include #include +#include +#include +#include //#define VFS_DEBUG @@ -104,7 +104,7 @@ bool VFS::is_vfs_root(InodeIdentifier inode) const void VFS::traverse_directory_inode(Inode& dir_inode, Function callback) { - dir_inode.traverse_as_directory([&] (const FS::DirectoryEntry& entry) { + dir_inode.traverse_as_directory([&](const FS::DirectoryEntry& entry) { InodeIdentifier resolved_inode; if (auto mount = find_mount_for_host(entry.inode)) resolved_inode = mount->guest(); @@ -586,7 +586,7 @@ String VFS::Mount::absolute_path() const InodeIdentifier VFS::Mount::host() const { if (!m_host_custody) - return { }; + return {}; return m_host_custody->inode().identifier(); } @@ -702,11 +702,10 @@ KResultOr> VFS::resolve_path(StringView path, Custody& base, R // FIXME: We should limit the recursion here and return -ELOOP if it goes to deep. return resolve_path( StringView(symlink_contents.pointer(), - symlink_contents.size()), + symlink_contents.size()), *current_parent, parent_custody, - options - ); + options); } } return custody_chain.last(); diff --git a/Kernel/IRQHandler.cpp b/Kernel/IRQHandler.cpp index fb852a4ae5..69c8c40988 100644 --- a/Kernel/IRQHandler.cpp +++ b/Kernel/IRQHandler.cpp @@ -1,6 +1,6 @@ #include "IRQHandler.h" -#include "i386.h" #include "PIC.h" +#include "i386.h" IRQHandler::IRQHandler(byte irq) : m_irq_number(irq) @@ -22,4 +22,3 @@ void IRQHandler::disable_irq() { PIC::disable(m_irq_number); } - diff --git a/Kernel/KParams.h b/Kernel/KParams.h index 51da17006a..603aedb5d6 100644 --- a/Kernel/KParams.h +++ b/Kernel/KParams.h @@ -13,6 +13,7 @@ public: const String& cmdline() const { return m_cmdline; } String get(const String& key) const; bool has(const String& key) const; + private: String m_cmdline; HashMap m_params; diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index 73816e0d20..34e9156a27 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -1,9 +1,9 @@ #include "KSyms.h" #include "Process.h" #include "Scheduler.h" -#include #include #include +#include static KSym* s_ksyms; dword ksym_lowest_address; @@ -140,7 +140,8 @@ void dump_backtrace() } TemporaryChange change(in_dump_backtrace, true); dword ebp; - asm volatile("movl %%ebp, %%eax":"=a"(ebp)); + asm volatile("movl %%ebp, %%eax" + : "=a"(ebp)); dump_backtrace_impl(ebp, ksyms_ready); } diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index b73ddc70e2..a57e3bf97e 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -1,90 +1,90 @@ +#include #include #include -#include -#define REG_CTRL 0x0000 -#define REG_STATUS 0x0008 -#define REG_EEPROM 0x0014 -#define REG_CTRL_EXT 0x0018 -#define REG_IMASK 0x00D0 -#define REG_RCTRL 0x0100 -#define REG_RXDESCLO 0x2800 -#define REG_RXDESCHI 0x2804 -#define REG_RXDESCLEN 0x2808 -#define REG_RXDESCHEAD 0x2810 -#define REG_RXDESCTAIL 0x2818 -#define REG_TCTRL 0x0400 -#define REG_TXDESCLO 0x3800 -#define REG_TXDESCHI 0x3804 -#define REG_TXDESCLEN 0x3808 -#define REG_TXDESCHEAD 0x3810 -#define REG_TXDESCTAIL 0x3818 -#define REG_RDTR 0x2820 // RX Delay Timer Register -#define REG_RXDCTL 0x3828 // RX Descriptor Control -#define REG_RADV 0x282C // RX Int. Absolute Delay Timer -#define REG_RSRPD 0x2C00 // RX Small Packet Detect Interrupt -#define REG_TIPG 0x0410 // Transmit Inter Packet Gap -#define ECTRL_SLU 0x40 //set link up -#define RCTL_EN (1 << 1) // Receiver Enable -#define RCTL_SBP (1 << 2) // Store Bad Packets -#define RCTL_UPE (1 << 3) // Unicast Promiscuous Enabled -#define RCTL_MPE (1 << 4) // Multicast Promiscuous Enabled -#define RCTL_LPE (1 << 5) // Long Packet Reception Enable -#define RCTL_LBM_NONE (0 << 6) // No Loopback -#define RCTL_LBM_PHY (3 << 6) // PHY or external SerDesc loopback -#define RTCL_RDMTS_HALF (0 << 8) // Free Buffer Threshold is 1/2 of RDLEN -#define RTCL_RDMTS_QUARTER (1 << 8) // Free Buffer Threshold is 1/4 of RDLEN -#define RTCL_RDMTS_EIGHTH (2 << 8) // Free Buffer Threshold is 1/8 of RDLEN -#define RCTL_MO_36 (0 << 12) // Multicast Offset - bits 47:36 -#define RCTL_MO_35 (1 << 12) // Multicast Offset - bits 46:35 -#define RCTL_MO_34 (2 << 12) // Multicast Offset - bits 45:34 -#define RCTL_MO_32 (3 << 12) // Multicast Offset - bits 43:32 -#define RCTL_BAM (1 << 15) // Broadcast Accept Mode -#define RCTL_VFE (1 << 18) // VLAN Filter Enable -#define RCTL_CFIEN (1 << 19) // Canonical Form Indicator Enable -#define RCTL_CFI (1 << 20) // Canonical Form Indicator Bit Value -#define RCTL_DPF (1 << 22) // Discard Pause Frames -#define RCTL_PMCF (1 << 23) // Pass MAC Control Frames -#define RCTL_SECRC (1 << 26) // Strip Ethernet CRC +#define REG_CTRL 0x0000 +#define REG_STATUS 0x0008 +#define REG_EEPROM 0x0014 +#define REG_CTRL_EXT 0x0018 +#define REG_IMASK 0x00D0 +#define REG_RCTRL 0x0100 +#define REG_RXDESCLO 0x2800 +#define REG_RXDESCHI 0x2804 +#define REG_RXDESCLEN 0x2808 +#define REG_RXDESCHEAD 0x2810 +#define REG_RXDESCTAIL 0x2818 +#define REG_TCTRL 0x0400 +#define REG_TXDESCLO 0x3800 +#define REG_TXDESCHI 0x3804 +#define REG_TXDESCLEN 0x3808 +#define REG_TXDESCHEAD 0x3810 +#define REG_TXDESCTAIL 0x3818 +#define REG_RDTR 0x2820 // RX Delay Timer Register +#define REG_RXDCTL 0x3828 // RX Descriptor Control +#define REG_RADV 0x282C // RX Int. Absolute Delay Timer +#define REG_RSRPD 0x2C00 // RX Small Packet Detect Interrupt +#define REG_TIPG 0x0410 // Transmit Inter Packet Gap +#define ECTRL_SLU 0x40 //set link up +#define RCTL_EN (1 << 1) // Receiver Enable +#define RCTL_SBP (1 << 2) // Store Bad Packets +#define RCTL_UPE (1 << 3) // Unicast Promiscuous Enabled +#define RCTL_MPE (1 << 4) // Multicast Promiscuous Enabled +#define RCTL_LPE (1 << 5) // Long Packet Reception Enable +#define RCTL_LBM_NONE (0 << 6) // No Loopback +#define RCTL_LBM_PHY (3 << 6) // PHY or external SerDesc loopback +#define RTCL_RDMTS_HALF (0 << 8) // Free Buffer Threshold is 1/2 of RDLEN +#define RTCL_RDMTS_QUARTER (1 << 8) // Free Buffer Threshold is 1/4 of RDLEN +#define RTCL_RDMTS_EIGHTH (2 << 8) // Free Buffer Threshold is 1/8 of RDLEN +#define RCTL_MO_36 (0 << 12) // Multicast Offset - bits 47:36 +#define RCTL_MO_35 (1 << 12) // Multicast Offset - bits 46:35 +#define RCTL_MO_34 (2 << 12) // Multicast Offset - bits 45:34 +#define RCTL_MO_32 (3 << 12) // Multicast Offset - bits 43:32 +#define RCTL_BAM (1 << 15) // Broadcast Accept Mode +#define RCTL_VFE (1 << 18) // VLAN Filter Enable +#define RCTL_CFIEN (1 << 19) // Canonical Form Indicator Enable +#define RCTL_CFI (1 << 20) // Canonical Form Indicator Bit Value +#define RCTL_DPF (1 << 22) // Discard Pause Frames +#define RCTL_PMCF (1 << 23) // Pass MAC Control Frames +#define RCTL_SECRC (1 << 26) // Strip Ethernet CRC // Buffer Sizes -#define RCTL_BSIZE_256 (3 << 16) -#define RCTL_BSIZE_512 (2 << 16) -#define RCTL_BSIZE_1024 (1 << 16) -#define RCTL_BSIZE_2048 (0 << 16) -#define RCTL_BSIZE_4096 ((3 << 16) | (1 << 25)) -#define RCTL_BSIZE_8192 ((2 << 16) | (1 << 25)) -#define RCTL_BSIZE_16384 ((1 << 16) | (1 << 25)) +#define RCTL_BSIZE_256 (3 << 16) +#define RCTL_BSIZE_512 (2 << 16) +#define RCTL_BSIZE_1024 (1 << 16) +#define RCTL_BSIZE_2048 (0 << 16) +#define RCTL_BSIZE_4096 ((3 << 16) | (1 << 25)) +#define RCTL_BSIZE_8192 ((2 << 16) | (1 << 25)) +#define RCTL_BSIZE_16384 ((1 << 16) | (1 << 25)) // Transmit Command -#define CMD_EOP (1 << 0) // End of Packet -#define CMD_IFCS (1 << 1) // Insert FCS -#define CMD_IC (1 << 2) // Insert Checksum -#define CMD_RS (1 << 3) // Report Status -#define CMD_RPS (1 << 4) // Report Packet Sent -#define CMD_VLE (1 << 6) // VLAN Packet Enable -#define CMD_IDE (1 << 7) // Interrupt Delay Enable +#define CMD_EOP (1 << 0) // End of Packet +#define CMD_IFCS (1 << 1) // Insert FCS +#define CMD_IC (1 << 2) // Insert Checksum +#define CMD_RS (1 << 3) // Report Status +#define CMD_RPS (1 << 4) // Report Packet Sent +#define CMD_VLE (1 << 6) // VLAN Packet Enable +#define CMD_IDE (1 << 7) // Interrupt Delay Enable // TCTL Register -#define TCTL_EN (1 << 1) // Transmit Enable -#define TCTL_PSP (1 << 3) // Pad Short Packets -#define TCTL_CT_SHIFT 4 // Collision Threshold -#define TCTL_COLD_SHIFT 12 // Collision Distance -#define TCTL_SWXOFF (1 << 22) // Software XOFF Transmission -#define TCTL_RTLC (1 << 24) // Re-transmit on Late Collision +#define TCTL_EN (1 << 1) // Transmit Enable +#define TCTL_PSP (1 << 3) // Pad Short Packets +#define TCTL_CT_SHIFT 4 // Collision Threshold +#define TCTL_COLD_SHIFT 12 // Collision Distance +#define TCTL_SWXOFF (1 << 22) // Software XOFF Transmission +#define TCTL_RTLC (1 << 24) // Re-transmit on Late Collision -#define TSTA_DD (1 << 0) // Descriptor Done -#define TSTA_EC (1 << 1) // Excess Collisions -#define TSTA_LC (1 << 2) // Late Collision -#define LSTA_TU (1 << 3) // Transmit Underrun +#define TSTA_DD (1 << 0) // Descriptor Done +#define TSTA_EC (1 << 1) // Excess Collisions +#define TSTA_LC (1 << 2) // Late Collision +#define LSTA_TU (1 << 3) // Transmit Underrun OwnPtr E1000NetworkAdapter::autodetect() { static const PCI::ID qemu_bochs_vbox_id = { 0x8086, 0x100e }; PCI::Address found_address; - PCI::enumerate_all([&] (const PCI::Address& address, PCI::ID id) { + PCI::enumerate_all([&](const PCI::Address& address, PCI::ID id) { if (id == qemu_bochs_vbox_id) { found_address = address; return; @@ -231,7 +231,7 @@ void E1000NetworkAdapter::initialize_rx_descriptors() out32(REG_RXDESCHEAD, 0); out32(REG_RXDESCTAIL, number_of_rx_descriptors - 1); - out32(REG_RCTRL, RCTL_EN| RCTL_SBP| RCTL_UPE | RCTL_MPE | RCTL_LBM_NONE | RTCL_RDMTS_HALF | RCTL_BAM | RCTL_SECRC | RCTL_BSIZE_8192); + out32(REG_RCTRL, RCTL_EN | RCTL_SBP | RCTL_UPE | RCTL_MPE | RCTL_LBM_NONE | RTCL_RDMTS_HALF | RCTL_BAM | RCTL_SECRC | RCTL_BSIZE_8192); } void E1000NetworkAdapter::initialize_tx_descriptors() diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index b09e320409..916abc74d8 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -1,17 +1,17 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define IPV4_SOCKET_DEBUG diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 208348847a..0097e71db4 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -1,8 +1,8 @@ -#include -#include -#include #include #include +#include +#include +#include #include //#define DEBUG_LOCAL_SOCKET diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index a1e5e31c9d..139c5d0ba8 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include static Lockable>& all_adapters() { @@ -81,7 +81,7 @@ ByteBuffer NetworkAdapter::dequeue_packet() { InterruptDisabler disabler; if (m_packet_queue.is_empty()) - return { }; + return {}; return m_packet_queue.take_first(); } diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 55e1357e55..6113d241dd 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -1,18 +1,17 @@ -#include -#include +#include #include +#include +#include +#include #include -#include -#include #include #include -#include -#include #include +#include +#include +#include +#include #include -#include -#include - //#define ETHERNET_DEBUG #define IPV4_DEBUG @@ -36,7 +35,7 @@ Lockable>& arp_table() class CombinedPacketQueueAlarm : public Alarm { public: - CombinedPacketQueueAlarm() { } + CombinedPacketQueueAlarm() {} virtual bool is_ringing() const override { @@ -61,7 +60,7 @@ void NetworkTask_main() if (adapter) adapter->set_ipv4_address(IPv4Address(192, 168, 5, 2)); - auto dequeue_packet = [&] () -> ByteBuffer { + auto dequeue_packet = [&]() -> ByteBuffer { auto packet = LoopbackAdapter::the().dequeue_packet(); if (!packet.is_null()) { dbgprintf("Receive loopback packet (%d bytes)\n", packet.size()); @@ -69,7 +68,7 @@ void NetworkTask_main() } if (adapter && adapter->has_queued_packets()) return adapter->dequeue_packet(); - return { }; + return {}; }; CombinedPacketQueueAlarm queue_alarm; @@ -91,8 +90,7 @@ void NetworkTask_main() eth.source().to_string().characters(), eth.destination().to_string().characters(), eth.ether_type(), - packet.size() - ); + packet.size()); #endif switch (eth.ether_type()) { @@ -117,15 +115,13 @@ void handle_arp(const EthernetFrameHeader& eth, int frame_size) if (packet.hardware_type() != 1 || packet.hardware_address_length() != sizeof(MACAddress)) { kprintf("handle_arp: Hardware type not ethernet (%w, len=%u)\n", packet.hardware_type(), - packet.hardware_address_length() - ); + packet.hardware_address_length()); return; } if (packet.protocol_type() != EtherType::IPv4 || packet.protocol_address_length() != sizeof(IPv4Address)) { kprintf("handle_arp: Protocol type not IPv4 (%w, len=%u)\n", packet.hardware_type(), - packet.protocol_address_length() - ); + packet.protocol_address_length()); return; } @@ -135,8 +131,7 @@ void handle_arp(const EthernetFrameHeader& eth, int frame_size) packet.sender_hardware_address().to_string().characters(), packet.sender_protocol_address().to_string().characters(), packet.target_hardware_address().to_string().characters(), - packet.target_protocol_address().to_string().characters() - ); + packet.target_protocol_address().to_string().characters()); #endif if (packet.operation() == ARPOperation::Request) { @@ -144,7 +139,7 @@ void handle_arp(const EthernetFrameHeader& eth, int frame_size) if (auto* adapter = NetworkAdapter::from_ipv4_address(packet.target_protocol_address())) { // We do! kprintf("handle_arp: Responding to ARP request for my IPv4 address (%s)\n", - adapter->ipv4_address().to_string().characters()); + adapter->ipv4_address().to_string().characters()); ARPPacket response; response.set_operation(ARPOperation::Response); response.set_target_hardware_address(packet.sender_hardware_address()); @@ -183,8 +178,7 @@ void handle_ipv4(const EthernetFrameHeader& eth, int frame_size) #ifdef IPV4_DEBUG kprintf("handle_ipv4: source=%s, target=%s\n", packet.source().to_string().characters(), - packet.destination().to_string().characters() - ); + packet.destination().to_string().characters()); #endif switch ((IPv4Protocol)packet.protocol()) { @@ -210,8 +204,7 @@ void handle_icmp(const EthernetFrameHeader& eth, int frame_size) ipv4_packet.source().to_string().characters(), ipv4_packet.destination().to_string().characters(), icmp_header.type(), - icmp_header.code() - ); + icmp_header.code()); #endif { @@ -231,10 +224,9 @@ void handle_icmp(const EthernetFrameHeader& eth, int frame_size) if (icmp_header.type() == ICMPType::EchoRequest) { auto& request = reinterpret_cast(icmp_header); kprintf("handle_icmp: EchoRequest from %s: id=%u, seq=%u\n", - ipv4_packet.source().to_string().characters(), - (word)request.identifier, - (word)request.sequence_number - ); + ipv4_packet.source().to_string().characters(), + (word)request.identifier, + (word)request.sequence_number); size_t icmp_packet_size = ipv4_packet.payload_size(); auto buffer = ByteBuffer::create_zeroed(icmp_packet_size); auto& response = *(ICMPEchoPacket*)buffer.pointer(); @@ -267,8 +259,7 @@ void handle_udp(const EthernetFrameHeader& eth, int frame_size) udp_packet.source_port(), ipv4_packet.destination().to_string().characters(), udp_packet.destination_port(), - udp_packet.length() - ); + udp_packet.length()); #endif auto socket = UDPSocket::from_port(udp_packet.destination_port()); @@ -308,8 +299,7 @@ void handle_tcp(const EthernetFrameHeader& eth, int frame_size) tcp_packet.has_syn() ? "SYN" : "", tcp_packet.has_ack() ? "ACK" : "", tcp_packet.window_size(), - payload_size - ); + payload_size); #endif auto socket = TCPSocket::from_port(tcp_packet.destination_port()); @@ -350,12 +340,11 @@ void handle_tcp(const EthernetFrameHeader& eth, int frame_size) socket->set_ack_number(tcp_packet.sequence_number() + payload_size); kprintf("Got packet with ack_no=%u, seq_no=%u, payload_size=%u, acking it with new ack_no=%u, seq_no=%u\n", - tcp_packet.ack_number(), - tcp_packet.sequence_number(), - payload_size, - socket->ack_number(), - socket->sequence_number() - ); + tcp_packet.ack_number(), + tcp_packet.sequence_number(), + payload_size, + socket->ack_number(), + socket->sequence_number()); socket->send_tcp_packet(TCPFlags::ACK); if (payload_size != 0) diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 9561fd9249..b2c3d8a782 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -1,5 +1,5 @@ -#include #include +#include NetworkAdapter* adapter_for_route_to(const IPv4Address& ipv4_address) { diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index ee4a78c473..149a9442e0 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -1,9 +1,9 @@ #include -#include -#include #include -#include +#include +#include #include +#include #include KResultOr> Socket::create(int domain, int type, int protocol) diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index fe60425fd3..b0570c402d 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -1,9 +1,9 @@ -#include -#include +#include #include #include +#include +#include #include -#include Lockable>& TCPSocket::sockets_by_port() { @@ -20,14 +20,13 @@ TCPSocketHandle TCPSocket::from_port(word port) LOCKER(sockets_by_port().lock()); auto it = sockets_by_port().resource().find(port); if (it == sockets_by_port().resource().end()) - return { }; + return {}; socket = (*it).value; ASSERT(socket); } return { move(socket) }; } - TCPSocket::TCPSocket(int protocol) : IPv4Socket(SOCK_STREAM, protocol) { @@ -102,14 +101,14 @@ void TCPSocket::send_tcp_packet(word flags, const void* payload, int payload_siz tcp_packet.has_syn() ? "SYN" : "", tcp_packet.has_ack() ? "ACK" : "", tcp_packet.sequence_number(), - tcp_packet.ack_number() - ); + tcp_packet.ack_number()); adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, move(buffer)); } NetworkOrdered TCPSocket::compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket& packet, word payload_size) { - struct [[gnu::packed]] PseudoHeader { + struct [[gnu::packed]] PseudoHeader + { IPv4Address source; IPv4Address destination; byte zero; diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index ee3597e386..6ae66cfb09 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -1,9 +1,9 @@ -#include -#include -#include -#include #include +#include #include +#include +#include +#include Lockable>& UDPSocket::sockets_by_port() { @@ -20,14 +20,13 @@ UDPSocketHandle UDPSocket::from_port(word port) LOCKER(sockets_by_port().lock()); auto it = sockets_by_port().resource().find(port); if (it == sockets_by_port().resource().end()) - return { }; + return {}; socket = (*it).value; ASSERT(socket); } return { move(socket) }; } - UDPSocket::UDPSocket(int protocol) : IPv4Socket(SOCK_DGRAM, protocol) { diff --git a/Kernel/PCI.cpp b/Kernel/PCI.cpp index 2b22cf75c6..2b7e66aab7 100644 --- a/Kernel/PCI.cpp +++ b/Kernel/PCI.cpp @@ -1,32 +1,32 @@ -#include #include +#include -#define PCI_VENDOR_ID 0x00 // word -#define PCI_DEVICE_ID 0x02 // word -#define PCI_COMMAND 0x04 // word -#define PCI_STATUS 0x06 // word -#define PCI_REVISION_ID 0x08 // byte -#define PCI_PROG_IF 0x09 // byte -#define PCI_SUBCLASS 0x0a // byte -#define PCI_CLASS 0x0b // byte -#define PCI_CACHE_LINE_SIZE 0x0c // byte -#define PCI_LATENCY_TIMER 0x0d // byte -#define PCI_HEADER_TYPE 0x0e // byte -#define PCI_BIST 0x0f // byte -#define PCI_BAR0 0x10 // dword -#define PCI_BAR1 0x14 // dword -#define PCI_BAR2 0x18 // dword -#define PCI_BAR3 0x1C // dword -#define PCI_BAR4 0x20 // dword -#define PCI_BAR5 0x24 // dword -#define PCI_INTERRUPT_LINE 0x3C // byte -#define PCI_SECONDARY_BUS 0x19 // byte -#define PCI_HEADER_TYPE_DEVICE 0 -#define PCI_HEADER_TYPE_BRIDGE 1 -#define PCI_TYPE_BRIDGE 0x0604 -#define PCI_ADDRESS_PORT 0xCF8 -#define PCI_VALUE_PORT 0xCFC -#define PCI_NONE 0xFFFF +#define PCI_VENDOR_ID 0x00 // word +#define PCI_DEVICE_ID 0x02 // word +#define PCI_COMMAND 0x04 // word +#define PCI_STATUS 0x06 // word +#define PCI_REVISION_ID 0x08 // byte +#define PCI_PROG_IF 0x09 // byte +#define PCI_SUBCLASS 0x0a // byte +#define PCI_CLASS 0x0b // byte +#define PCI_CACHE_LINE_SIZE 0x0c // byte +#define PCI_LATENCY_TIMER 0x0d // byte +#define PCI_HEADER_TYPE 0x0e // byte +#define PCI_BIST 0x0f // byte +#define PCI_BAR0 0x10 // dword +#define PCI_BAR1 0x14 // dword +#define PCI_BAR2 0x18 // dword +#define PCI_BAR3 0x1C // dword +#define PCI_BAR4 0x20 // dword +#define PCI_BAR5 0x24 // dword +#define PCI_INTERRUPT_LINE 0x3C // byte +#define PCI_SECONDARY_BUS 0x19 // byte +#define PCI_HEADER_TYPE_DEVICE 0 +#define PCI_HEADER_TYPE_BRIDGE 1 +#define PCI_TYPE_BRIDGE 0x0604 +#define PCI_ADDRESS_PORT 0xCF8 +#define PCI_VALUE_PORT 0xCFC +#define PCI_NONE 0xFFFF namespace PCI { diff --git a/Kernel/PIC.cpp b/Kernel/PIC.cpp index 31094849c7..11840dc0b0 100644 --- a/Kernel/PIC.cpp +++ b/Kernel/PIC.cpp @@ -1,17 +1,17 @@ -#include -#include "i386.h" -#include "IO.h" #include "PIC.h" #include "Assertions.h" +#include "IO.h" +#include "i386.h" +#include // The slave 8259 is connected to the master's IRQ2 line. // This is really only to enhance clarity. -#define SLAVE_INDEX 2 +#define SLAVE_INDEX 2 -#define PIC0_CTL 0x20 -#define PIC0_CMD 0x21 -#define PIC1_CTL 0xA0 -#define PIC1_CMD 0xA1 +#define PIC0_CTL 0x20 +#define PIC0_CMD 0x21 +#define PIC1_CTL 0xA0 +#define PIC1_CMD 0xA1 #ifdef DEBUG_PIC static bool initialized; @@ -74,7 +74,7 @@ void initialize() /* ICW4 (set x86 mode) */ IO::out8(PIC0_CMD, 0x01); - IO::out8(PIC1_CMD, 0x01 ); + IO::out8(PIC1_CMD, 0x01); // Mask -- start out with all IRQs disabled. IO::out8(PIC0_CMD, 0xff); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 40a280c4c1..3725c1ffcc 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1,31 +1,31 @@ -#include #include "Process.h" -#include "kmalloc.h" -#include "StdLib.h" -#include "i386.h" -#include -#include -#include -#include -#include "i8253.h" -#include "RTC.h" -#include -#include -#include -#include "Syscall.h" -#include "Scheduler.h" -#include #include "KSyms.h" -#include -#include -#include +#include "RTC.h" +#include "Scheduler.h" +#include "StdLib.h" +#include "Syscall.h" +#include "i386.h" +#include "i8253.h" +#include "kmalloc.h" #include +#include +#include #include #include -#include -#include +#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include //#define DEBUG_POLL_SELECT //#define DEBUG_IO @@ -299,7 +299,7 @@ int Process::do_exec(String path, Vector arguments, Vector envir // FIXME(Thread): Kill any threads the moment we commit to the exec(). if (thread_count() != 1) { dbgprintf("Gonna die because I have many threads! These are the threads:\n"); - for_each_thread([] (Thread& thread) { + for_each_thread([](Thread& thread) { dbgprintf("Thread{%p}: TID=%d, PID=%d\n", &thread, thread.tid(), thread.pid()); return IterationDecision::Continue; }); @@ -307,7 +307,6 @@ int Process::do_exec(String path, Vector arguments, Vector envir ASSERT_NOT_REACHED(); } - auto parts = path.split('/'); if (parts.is_empty()) return -ENOENT; @@ -349,7 +348,7 @@ int Process::do_exec(String path, Vector arguments, Vector envir auto old_regions = move(m_regions); m_regions.append(*region); loader = make(region->laddr().as_ptr()); - loader->map_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable, bool is_executable, const String& name) { + loader->map_section_hook = [&](LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable, bool is_executable, const String& name) { ASSERT(size); ASSERT(alignment == PAGE_SIZE); int prot = 0; @@ -359,10 +358,10 @@ int Process::do_exec(String path, Vector arguments, Vector envir prot |= PROT_WRITE; if (is_executable) prot |= PROT_EXEC; - (void) allocate_region_with_vmo(laddr, size, vmo.copy_ref(), offset_in_image, String(name), prot); + (void)allocate_region_with_vmo(laddr, size, vmo.copy_ref(), offset_in_image, String(name), prot); return laddr.as_ptr(); }; - loader->alloc_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) { + loader->alloc_section_hook = [&](LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) { ASSERT(size); ASSERT(alignment == PAGE_SIZE); int prot = 0; @@ -370,7 +369,7 @@ int Process::do_exec(String path, Vector arguments, Vector envir prot |= PROT_READ; if (is_writable) prot |= PROT_WRITE; - (void) allocate_region(laddr, size, String(name), prot); + (void)allocate_region(laddr, size, String(name), prot); return laddr.as_ptr(); }; bool success = loader->load(); @@ -406,7 +405,7 @@ int Process::do_exec(String path, Vector arguments, Vector envir auto& daf = m_fds[i]; if (daf.descriptor && daf.flags & FD_CLOEXEC) { daf.descriptor->close(); - daf = { }; + daf = {}; } } @@ -636,7 +635,7 @@ Process::~Process() m_main_thread = nullptr; Vector my_threads; - for_each_thread([&my_threads] (auto& thread) { + for_each_thread([&my_threads](auto& thread) { my_threads.append(&thread); return IterationDecision::Continue; }); @@ -973,7 +972,7 @@ int Process::sys$close(int fd) if (!descriptor) return -EBADF; int rc = descriptor->close(); - m_fds[fd] = { }; + m_fds[fd] = {}; return rc; } @@ -1006,8 +1005,8 @@ int Process::sys$access(const char* pathname, int mode) int Process::sys$fcntl(int fd, int cmd, dword arg) { - (void) cmd; - (void) arg; + (void)cmd; + (void)arg; dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg); auto* descriptor = file_description(fd); if (!descriptor) @@ -1183,7 +1182,7 @@ int Process::sys$killpg(int pgrp, int signum) { if (signum < 1 || signum >= 32) return -EINVAL; - (void) pgrp; + (void)pgrp; ASSERT_NOT_REACHED(); } @@ -1387,7 +1386,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) { dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options); // FIXME: Respect options - (void) options; + (void)options; if (wstatus) if (!validate_write_typed(wstatus)) return -EFAULT; @@ -1405,7 +1404,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) if (waitee == -1) { pid_t reaped_pid = 0; InterruptDisabler disabler; - for_each_child([&reaped_pid, &exit_status] (Process& process) { + for_each_child([&reaped_pid, &exit_status](Process& process) { if (process.is_dead()) { reaped_pid = process.pid(); exit_status = reap(process); @@ -1442,8 +1441,8 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) return current->m_waitee_pid; } - -enum class KernelMemoryCheckResult { +enum class KernelMemoryCheckResult +{ NotInsideKernelMemory, AccessGranted, AccessDenied @@ -1556,7 +1555,7 @@ pid_t Process::sys$setsid() { InterruptDisabler disabler; bool found_process_with_same_pgid_as_my_pid = false; - Process::for_each_in_pgrp(pid(), [&] (auto&) { + Process::for_each_in_pgrp(pid(), [&](auto&) { found_process_with_same_pgid_as_my_pid = true; return false; }); @@ -1781,7 +1780,7 @@ int Process::sys$select(const Syscall::SC_select_params* params) current->m_select_has_timeout = false; } - auto transfer_fds = [&] (auto* fds, auto& vector) -> int { + auto transfer_fds = [&](auto* fds, auto& vector) -> int { vector.clear_with_capacity(); if (!fds) return 0; @@ -1809,7 +1808,7 @@ int Process::sys$select(const Syscall::SC_select_params* params) current->block(Thread::State::BlockedSelect); int marked_fd_count = 0; - auto mark_fds = [&] (auto* fds, auto& vector, auto should_mark) { + auto mark_fds = [&](auto* fds, auto& vector, auto should_mark) { if (!fds) return; FD_ZERO(fds); @@ -1820,8 +1819,8 @@ int Process::sys$select(const Syscall::SC_select_params* params) } } }; - mark_fds(params->readfds, current->m_select_read_fds, [] (auto& descriptor) { return descriptor.can_read(); }); - mark_fds(params->writefds, current->m_select_write_fds, [] (auto& descriptor) { return descriptor.can_write(); }); + mark_fds(params->readfds, current->m_select_read_fds, [](auto& descriptor) { return descriptor.can_read(); }); + mark_fds(params->writefds, current->m_select_write_fds, [](auto& descriptor) { return descriptor.can_write(); }); // FIXME: We should also mark params->exceptfds as appropriate. return marked_fd_count; } @@ -1998,7 +1997,7 @@ void Process::die() { InterruptDisabler disabler; - for_each_thread([] (Thread& thread) { + for_each_thread([](Thread& thread) { if (thread.state() != Thread::State::Dead) thread.set_state(Thread::State::Dying); return IterationDecision::Continue; @@ -2189,7 +2188,7 @@ ssize_t Process::sys$recvfrom(const Syscall::SC_recvfrom_params* params) if (!validate_write(addr, *addr_length)) return -EFAULT; } else if (addr) { - return -EINVAL; + return -EINVAL; } auto* descriptor = file_description(sockfd); if (!descriptor) @@ -2504,7 +2503,7 @@ int Process::sys$create_shared_buffer(pid_t peer_pid, int size, void** buffer) shared_buffer->m_pid1_region->set_shared(true); *buffer = shared_buffer->m_pid1_region->laddr().as_ptr(); #ifdef SHARED_BUFFER_DEBUG - kprintf("%s(%u): Created shared buffer %d (%u bytes, vmo is %u) for sharing with %d\n", name().characters(), pid(),shared_buffer_id, size, shared_buffer->size(), peer_pid); + kprintf("%s(%u): Created shared buffer %d (%u bytes, vmo is %u) for sharing with %d\n", name().characters(), pid(), shared_buffer_id, size, shared_buffer->size(), peer_pid); #endif shared_buffers().resource().set(shared_buffer_id, move(shared_buffer)); return shared_buffer_id; @@ -2573,10 +2572,14 @@ int Process::sys$get_shared_buffer_size(int shared_buffer_id) const char* to_string(Process::Priority priority) { switch (priority) { - case Process::IdlePriority: return "Idle"; - case Process::LowPriority: return "Low"; - case Process::NormalPriority: return "Normal"; - case Process::HighPriority: return "High"; + case Process::IdlePriority: + return "Idle"; + case Process::LowPriority: + return "Low"; + case Process::NormalPriority: + return "Normal"; + case Process::HighPriority: + return "High"; } kprintf("to_string(Process::Priority): Invalid priority: %u\n", priority); ASSERT_NOT_REACHED(); @@ -2602,14 +2605,14 @@ void Process::send_signal(byte signal, Process* sender) int Process::thread_count() const { int count = 0; - for_each_thread([&count] (auto&) { + for_each_thread([&count](auto&) { ++count; return IterationDecision::Continue; }); return count; } -int Process::sys$create_thread(int(*entry)(void*), void* argument) +int Process::sys$create_thread(int (*entry)(void*), void* argument) { if (!validate_read((const void*)entry, sizeof(void*))) return -EFAULT; @@ -2648,7 +2651,7 @@ int Process::sys$donate(int tid) return -EINVAL; InterruptDisabler disabler; Thread* beneficiary = nullptr; - for_each_thread([&] (Thread& thread) { + for_each_thread([&](Thread& thread) { if (thread.tid() == tid) { beneficiary = &thread; return IterationDecision::Abort; diff --git a/Kernel/ProcessTracer.cpp b/Kernel/ProcessTracer.cpp index 66aeb8ac49..33cbf79966 100644 --- a/Kernel/ProcessTracer.cpp +++ b/Kernel/ProcessTracer.cpp @@ -1,15 +1,13 @@ -#include #include +#include ProcessTracer::ProcessTracer(pid_t pid) : m_pid(pid) { - } ProcessTracer::~ProcessTracer() { - } void ProcessTracer::did_syscall(dword function, dword arg1, dword arg2, dword arg3, dword result) diff --git a/Kernel/RTC.cpp b/Kernel/RTC.cpp index 3c9f38b967..e64fcd884b 100644 --- a/Kernel/RTC.cpp +++ b/Kernel/RTC.cpp @@ -7,7 +7,7 @@ namespace RTC { static time_t s_boot_time; void initialize() -{ +{ byte cmos_mode = CMOS::read(0x0b); cmos_mode |= 2; // 24 hour mode cmos_mode |= 4; // No BCD mode @@ -116,12 +116,11 @@ time_t now() ASSERT(year >= 2018); return days_in_years_since_epoch(year - 1) * 86400 - + days_in_months_since_start_of_year(month - 1, year) * 86400 - + (day - 1) * 86400 - + hour * 3600 - + minute * 60 - + second; + + days_in_months_since_start_of_year(month - 1, year) * 86400 + + (day - 1) * 86400 + + hour * 3600 + + minute * 60 + + second; } } - diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 8c4b4fa167..fccb5585f2 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -4,8 +4,8 @@ #include "i8253.h" #include #include -#include #include +#include //#define LOG_EVERY_CONTEXT_SWITCH //#define SCHEDULER_DEBUG @@ -72,7 +72,7 @@ bool Scheduler::pick_next() auto now_usec = now.tv_usec; // Check and unblock threads whose wait conditions have been met. - Thread::for_each_nonrunnable([&] (Thread& thread) { + Thread::for_each_nonrunnable([&](Thread& thread) { auto& process = thread.process(); if (thread.state() == Thread::BlockedSleep) { @@ -82,7 +82,7 @@ bool Scheduler::pick_next() } if (thread.state() == Thread::BlockedWait) { - process.for_each_child([&] (Process& child) { + process.for_each_child([&](Process& child) { if (!child.is_dead()) return true; if (thread.waitee_pid() == -1 || thread.waitee_pid() == child.pid()) { @@ -180,7 +180,7 @@ bool Scheduler::pick_next() return IterationDecision::Continue; }); - Process::for_each([&] (Process& process) { + Process::for_each([&](Process& process) { if (process.is_dead()) { if (current != &process.main_thread() && (!process.ppid() || !Process::from_pid(process.ppid()))) { auto name = process.name(); @@ -199,7 +199,7 @@ bool Scheduler::pick_next() // Dispatch any pending signals. // FIXME: Do we really need this to be a separate pass over the process list? - Thread::for_each_living([] (Thread& thread) { + Thread::for_each_living([](Thread& thread) { if (!thread.has_unmasked_pending_signals()) return true; // FIXME: It would be nice if the Scheduler didn't have to worry about who is "current" @@ -289,12 +289,12 @@ bool Scheduler::yield() { InterruptDisabler disabler; ASSERT(current); -// dbgprintf("%s(%u:%u) yield()\n", current->process().name().characters(), current->pid(), current->tid()); + // dbgprintf("%s(%u:%u) yield()\n", current->process().name().characters(), current->pid(), current->tid()); if (!pick_next()) return false; -// dbgprintf("yield() jumping to new process: sel=%x, %s(%u:%u)\n", current->far_ptr().selector, current->process().name().characters(), current->pid(), current->tid()); + // dbgprintf("yield() jumping to new process: sel=%x, %s(%u:%u)\n", current->far_ptr().selector, current->process().name().characters(), current->pid(), current->tid()); switch_now(); return true; } @@ -312,9 +312,7 @@ void Scheduler::switch_now() descriptor.type = 9; flush_gdt(); asm("sti\n" - "ljmp *(%%eax)\n" - ::"a"(¤t->far_ptr()) - ); + "ljmp *(%%eax)\n" ::"a"(¤t->far_ptr())); } bool Scheduler::context_switch(Thread& thread) @@ -333,9 +331,9 @@ bool Scheduler::context_switch(Thread& thread) #ifdef LOG_EVERY_CONTEXT_SWITCH dbgprintf("Scheduler: %s(%u:%u) -> %s(%u:%u) %w:%x\n", - current->process().name().characters(), current->process().pid(), current->tid(), - thread.process().name().characters(), thread.process().pid(), thread.tid(), - thread.tss().cs, thread.tss().eip); + current->process().name().characters(), current->process().pid(), current->tid(), + thread.process().name().characters(), thread.process().pid(), thread.tid(), + thread.tss().cs, thread.tss().eip); #endif } @@ -456,6 +454,5 @@ void Scheduler::timer_tick(RegisterDump& regs) asm( "pushf\n" "orl $0x00004000, (%esp)\n" - "popf\n" - ); + "popf\n"); } diff --git a/Kernel/SharedMemory.cpp b/Kernel/SharedMemory.cpp index 5f4e54c4dd..cfd84587db 100644 --- a/Kernel/SharedMemory.cpp +++ b/Kernel/SharedMemory.cpp @@ -1,8 +1,8 @@ -#include -#include +#include #include #include -#include +#include +#include Lockable>>& shared_memories() { diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index af9eacaab7..a7e649f57d 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -1,4 +1,3 @@ -#include #include "Assertions.h" #include "kmalloc.h" #include @@ -22,17 +21,14 @@ void* memcpy(void* dest_ptr, const void* src_ptr, size_t n) "rep movsl\n" : "=S"(src), "=D"(dest) : "S"(src), "D"(dest), "c"(size_ts) - : "memory" - ); + : "memory"); n -= size_ts * sizeof(size_t); if (n == 0) return dest_ptr; } asm volatile( - "rep movsb\n" - :: "S"(src), "D"(dest), "c"(n) - : "memory" - ); + "rep movsb\n" ::"S"(src), "D"(dest), "c"(n) + : "memory"); return dest_ptr; } @@ -41,18 +37,19 @@ void* memmove(void* dest, const void* src, size_t n) if (dest < src) return memcpy(dest, src, n); - byte *pd = (byte*)dest; - const byte *ps = (const byte*)src; + byte* pd = (byte*)dest; + const byte* ps = (const byte*)src; for (pd += n, ps += n; n--;) *--pd = *--ps; return dest; } -char* strcpy(char* dest, const char *src) +char* strcpy(char* dest, const char* src) { auto* dest_ptr = dest; auto* src_ptr = src; - while ((*dest_ptr++ = *src_ptr++) != '\0'); + while ((*dest_ptr++ = *src_ptr++) != '\0') + ; return dest; } @@ -61,7 +58,7 @@ char* strncpy(char* dest, const char* src, size_t n) size_t i; for (i = 0; i < n && src[i] != '\0'; ++i) dest[i] = src[i]; - for ( ; i < n; ++i) + for (; i < n; ++i) dest[i] = '\0'; return dest; } @@ -79,24 +76,22 @@ void* memset(void* dest_ptr, int c, size_t n) "rep stosl\n" : "=D"(dest) : "D"(dest), "c"(size_ts), "a"(expanded_c) - : "memory" - ); + : "memory"); n -= size_ts * sizeof(size_t); if (n == 0) return dest_ptr; } asm volatile( "rep stosb\n" - : "=D" (dest), "=c" (n) - : "0" (dest), "1" (n), "a" (c) - : "memory" - ); + : "=D"(dest), "=c"(n) + : "0"(dest), "1"(n), "a"(c) + : "memory"); return dest_ptr; } char* strrchr(const char* str, int ch) { - char *last = nullptr; + char* last = nullptr; char c; for (; (c = *str); ++str) { if (c == ch) @@ -113,7 +108,7 @@ size_t strlen(const char* str) return len; } -int strcmp(const char *s1, const char *s2) +int strcmp(const char* s1, const char* s2) { for (; *s1 == *s2; ++s1, ++s2) { if (*s1 == 0) @@ -122,7 +117,7 @@ int strcmp(const char *s1, const char *s2) return *(const byte*)s1 < *(const byte*)s2 ? -1 : 1; } -char* strdup(const char *str) +char* strdup(const char* str) { size_t len = strlen(str); char* new_str = (char*)kmalloc(len + 1); @@ -145,5 +140,4 @@ int memcmp(const void* v1, const void* v2, size_t n) { ASSERT_NOT_REACHED(); } - } diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index 9d11d369da..fffe38ff52 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -1,9 +1,9 @@ -#include "i386.h" -#include "Process.h" -#include "Syscall.h" -#include "Console.h" -#include "Scheduler.h" +#include +#include #include +#include +#include +#include extern "C" void syscall_trap_entry(RegisterDump&); extern "C" void syscall_trap_handler(); @@ -34,8 +34,7 @@ asm( " popw %es\n" " popw %ds\n" " popa\n" - " iret\n" -); + " iret\n"); namespace Syscall { @@ -259,7 +258,7 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, case Syscall::SC_setsockopt: return current->process().sys$setsockopt((const SC_setsockopt_params*)arg1); case Syscall::SC_create_thread: - return current->process().sys$create_thread((int(*)(void*))arg1, (void*)arg2); + return current->process().sys$create_thread((int (*)(void*))arg1, (void*)arg2); case Syscall::SC_rename: return current->process().sys$rename((const char*)arg1, (const char*)arg2); case Syscall::SC_shm_open: @@ -303,4 +302,3 @@ void syscall_trap_entry(RegisterDump& regs) tracer->did_syscall(function, arg1, arg2, arg3, regs.eax); current->process().big_lock().unlock(); } - diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 147abcb0e8..4290283b23 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -108,7 +108,7 @@ __ENUMERATE_SYSCALL(getpeername) \ __ENUMERATE_SYSCALL(sched_setparam) \ __ENUMERATE_SYSCALL(sched_getparam) \ - __ENUMERATE_SYSCALL(fchown) \ + __ENUMERATE_SYSCALL(fchown) namespace Syscall { diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index c3eb39b0b1..b709fe7ebc 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -1,6 +1,6 @@ #include "MasterPTY.h" -#include "SlavePTY.h" #include "PTYMultiplexer.h" +#include "SlavePTY.h" #include #include #include diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index eb82d6f720..7f5b892d7f 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -1,5 +1,5 @@ -#include #include "Process.h" +#include #include #include #include @@ -80,7 +80,7 @@ void TTY::generate_signal(int signal) return; dbgprintf("%s: Send signal %d to everyone in pgrp %d\n", tty_name().characters(), signal, pgid()); InterruptDisabler disabler; // FIXME: Iterate over a set of process handles instead? - Process::for_each_in_pgrp(pgid(), [&] (auto& process) { + Process::for_each_in_pgrp(pgid(), [&](auto& process) { dbgprintf("%s: Send signal %d to %d\n", tty_name().characters(), signal, process.pid()); process.send_signal(signal, nullptr); return true; @@ -94,21 +94,18 @@ void TTY::set_termios(const termios& t) tty_name().characters(), should_echo_input(), should_generate_signals(), - in_canonical_mode() - ); + in_canonical_mode()); dbgprintf("%s set_termios: ECHOE=%u, ECHOK=%u, ECHONL=%u\n", - tty_name().characters(), - (m_termios.c_lflag & ECHOE) != 0, - (m_termios.c_lflag & ECHOK) != 0, - (m_termios.c_lflag & ECHONL) != 0 - ); + tty_name().characters(), + (m_termios.c_lflag & ECHOE) != 0, + (m_termios.c_lflag & ECHOK) != 0, + (m_termios.c_lflag & ECHONL) != 0); dbgprintf("%s set_termios: ISTRIP=%u, ICRNL=%u, INLCR=%u, IGNCR=%u\n", - tty_name().characters(), - (m_termios.c_iflag & ISTRIP) != 0, - (m_termios.c_iflag & ICRNL) != 0, - (m_termios.c_iflag & INLCR) != 0, - (m_termios.c_iflag & IGNCR) != 0 - ); + tty_name().characters(), + (m_termios.c_iflag & ISTRIP) != 0, + (m_termios.c_iflag & ICRNL) != 0, + (m_termios.c_iflag & INLCR) != 0, + (m_termios.c_iflag & IGNCR) != 0); } int TTY::ioctl(FileDescription&, unsigned request, unsigned arg) diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index c4e3f9eb1a..8a8a28ac04 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -1,8 +1,8 @@ #include "VirtualConsole.h" -#include "kmalloc.h" -#include "i386.h" #include "IO.h" #include "StdLib.h" +#include "i386.h" +#include "kmalloc.h" #include static byte* s_vga_buffer; @@ -128,7 +128,8 @@ inline bool is_valid_final_character(byte ch) return ch >= 0x40 && ch <= 0x7e; } -enum class VGAColor : byte { +enum class VGAColor : byte +{ Black = 0, Blue, Green, @@ -147,7 +148,8 @@ enum class VGAColor : byte { White, }; -enum class ANSIColor : byte { +enum class ANSIColor : byte +{ Black = 0, Red, Green, @@ -169,22 +171,38 @@ enum class ANSIColor : byte { static inline VGAColor ansi_color_to_vga(ANSIColor color) { switch (color) { - case ANSIColor::Black: return VGAColor::Black; - case ANSIColor::Red: return VGAColor::Red; - case ANSIColor::Brown: return VGAColor::Brown; - case ANSIColor::Blue: return VGAColor::Blue; - case ANSIColor::Magenta: return VGAColor::Magenta; - case ANSIColor::Green: return VGAColor::Green; - case ANSIColor::Cyan: return VGAColor::Cyan; - case ANSIColor::LightGray: return VGAColor::LightGray; - case ANSIColor::DarkGray: return VGAColor::DarkGray; - case ANSIColor::BrightRed: return VGAColor::BrightRed; - case ANSIColor::BrightGreen: return VGAColor::BrightGreen; - case ANSIColor::Yellow: return VGAColor::Yellow; - case ANSIColor::BrightBlue: return VGAColor::BrightBlue; - case ANSIColor::BrightMagenta: return VGAColor::BrightMagenta; - case ANSIColor::BrightCyan: return VGAColor::BrightCyan; - case ANSIColor::White: return VGAColor::White; + case ANSIColor::Black: + return VGAColor::Black; + case ANSIColor::Red: + return VGAColor::Red; + case ANSIColor::Brown: + return VGAColor::Brown; + case ANSIColor::Blue: + return VGAColor::Blue; + case ANSIColor::Magenta: + return VGAColor::Magenta; + case ANSIColor::Green: + return VGAColor::Green; + case ANSIColor::Cyan: + return VGAColor::Cyan; + case ANSIColor::LightGray: + return VGAColor::LightGray; + case ANSIColor::DarkGray: + return VGAColor::DarkGray; + case ANSIColor::BrightRed: + return VGAColor::BrightRed; + case ANSIColor::BrightGreen: + return VGAColor::BrightGreen; + case ANSIColor::Yellow: + return VGAColor::Yellow; + case ANSIColor::BrightBlue: + return VGAColor::BrightBlue; + case ANSIColor::BrightMagenta: + return VGAColor::BrightMagenta; + case ANSIColor::BrightCyan: + return VGAColor::BrightCyan; + case ANSIColor::White: + return VGAColor::White; } ASSERT_NOT_REACHED(); return VGAColor::LightGray; @@ -317,14 +335,29 @@ void VirtualConsole::execute_escape_sequence(byte final) params.append(value); } switch (final) { - case 'A': escape$A(params); break; - case 'D': escape$D(params); break; - case 'H': escape$H(params); break; - case 'J': escape$J(params); break; - case 'm': escape$m(params); break; - case 's': escape$s(params); break; - case 'u': escape$u(params); break; - default: break; + case 'A': + escape$A(params); + break; + case 'D': + escape$D(params); + break; + case 'H': + escape$H(params); + break; + case 'J': + escape$J(params); + break; + case 'm': + escape$m(params); + break; + case 's': + escape$s(params); + break; + case 'u': + escape$u(params); + break; + default: + break; } m_parameters.clear(); diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 0d53125938..4eea311a05 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -1,7 +1,7 @@ -#include -#include -#include #include +#include +#include +#include #include #include @@ -145,24 +145,42 @@ void Thread::sleep(dword ticks) const char* to_string(Thread::State state) { switch (state) { - case Thread::Invalid: return "Invalid"; - case Thread::Runnable: return "Runnable"; - case Thread::Running: return "Running"; - case Thread::Dying: return "Dying"; - case Thread::Dead: return "Dead"; - case Thread::Stopped: return "Stopped"; - case Thread::Skip1SchedulerPass: return "Skip1"; - case Thread::Skip0SchedulerPasses: return "Skip0"; - case Thread::BlockedSleep: return "Sleep"; - case Thread::BlockedWait: return "Wait"; - case Thread::BlockedRead: return "Read"; - case Thread::BlockedWrite: return "Write"; - case Thread::BlockedSignal: return "Signal"; - case Thread::BlockedSelect: return "Select"; - case Thread::BlockedLurking: return "Lurking"; - case Thread::BlockedConnect: return "Connect"; - case Thread::BlockedReceive: return "Receive"; - case Thread::BlockedSnoozing: return "Snoozing"; + case Thread::Invalid: + return "Invalid"; + case Thread::Runnable: + return "Runnable"; + case Thread::Running: + return "Running"; + case Thread::Dying: + return "Dying"; + case Thread::Dead: + return "Dead"; + case Thread::Stopped: + return "Stopped"; + case Thread::Skip1SchedulerPass: + return "Skip1"; + case Thread::Skip0SchedulerPasses: + return "Skip0"; + case Thread::BlockedSleep: + return "Sleep"; + case Thread::BlockedWait: + return "Wait"; + case Thread::BlockedRead: + return "Read"; + case Thread::BlockedWrite: + return "Write"; + case Thread::BlockedSignal: + return "Signal"; + case Thread::BlockedSelect: + return "Select"; + case Thread::BlockedLurking: + return "Lurking"; + case Thread::BlockedConnect: + return "Connect"; + case Thread::BlockedReceive: + return "Receive"; + case Thread::BlockedSnoozing: + return "Snoozing"; } kprintf("to_string(Thread::State): Invalid state: %u\n", state); ASSERT_NOT_REACHED(); @@ -185,7 +203,7 @@ void Thread::finalize_dying_threads() Vector dying_threads; { InterruptDisabler disabler; - for_each_in_state(Thread::State::Dying, [&] (Thread& thread) { + for_each_in_state(Thread::State::Dying, [&](Thread& thread) { dying_threads.append(&thread); }); } @@ -236,7 +254,8 @@ ShouldUnblockThread Thread::dispatch_one_pending_signal() return dispatch_signal(signal); } -enum class DefaultSignalAction { +enum class DefaultSignalAction +{ Terminate, Ignore, DumpCore, @@ -490,7 +509,7 @@ void Thread::make_userspace_stack_for_main_thread(Vector arguments, Vect push_value_on_stack(0); } -void Thread::make_userspace_stack_for_secondary_thread(void *argument) +void Thread::make_userspace_stack_for_secondary_thread(void* argument) { auto* region = m_process.allocate_region(LinearAddress(), default_userspace_stack_size, String::format("Stack (Thread %d)", tid())); ASSERT(region); diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index b147bbfc06..4ba87d0d79 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -1,11 +1,11 @@ -#include -#include +#include "CMOS.h" +#include "Process.h" +#include "StdLib.h" +#include "i386.h" #include #include -#include "i386.h" -#include "StdLib.h" -#include "Process.h" -#include "CMOS.h" +#include +#include //#define MM_DEBUG //#define PAGE_FAULT_DEBUG @@ -96,12 +96,12 @@ void MemoryManager::initialize_paging() dbgprintf("MM: Installing page directory\n"); #endif - asm volatile("movl %%eax, %%cr3"::"a"(kernel_page_directory().cr3())); + asm volatile("movl %%eax, %%cr3" ::"a"(kernel_page_directory().cr3())); asm volatile( "movl %%cr0, %%eax\n" "orl $0x80000001, %%eax\n" - "movl %%eax, %%cr0\n" - :::"%eax", "memory"); + "movl %%eax, %%cr0\n" :: + : "%eax", "memory"); #ifdef MM_DEBUG dbgprintf("MM: Paging initialized.\n"); @@ -302,7 +302,6 @@ bool MemoryManager::copy_on_write(Region& region, unsigned page_index_in_region) return true; } - bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_region) { ASSERT(region.page_directory()); @@ -416,7 +415,7 @@ RetainPtr MemoryManager::allocate_physical_page(ShouldZeroFill sho if (1 > m_free_physical_pages.size()) { kprintf("FUCK! No physical pages available.\n"); ASSERT_NOT_REACHED(); - return { }; + return {}; } #ifdef MM_DEBUG dbgprintf("MM: allocate_physical_page vending P%x (%u remaining)\n", m_free_physical_pages.last()->paddr().get(), m_free_physical_pages.size()); @@ -436,7 +435,7 @@ RetainPtr MemoryManager::allocate_supervisor_physical_page() if (1 > m_free_supervisor_physical_pages.size()) { kprintf("FUCK! No physical pages available.\n"); ASSERT_NOT_REACHED(); - return { }; + return {}; } #ifdef MM_DEBUG dbgprintf("MM: allocate_supervisor_physical_page vending P%x (%u remaining)\n", m_free_supervisor_physical_pages.last()->paddr().get(), m_free_supervisor_physical_pages.size()); @@ -451,21 +450,24 @@ void MemoryManager::enter_process_paging_scope(Process& process) ASSERT(current); InterruptDisabler disabler; current->tss().cr3 = process.page_directory().cr3(); - asm volatile("movl %%eax, %%cr3"::"a"(process.page_directory().cr3()):"memory"); + asm volatile("movl %%eax, %%cr3" ::"a"(process.page_directory().cr3()) + : "memory"); } void MemoryManager::flush_entire_tlb() { asm volatile( "mov %%cr3, %%eax\n" - "mov %%eax, %%cr3\n" - ::: "%eax", "memory" - ); + "mov %%eax, %%cr3\n" :: + : "%eax", "memory"); } void MemoryManager::flush_tlb(LinearAddress laddr) { - asm volatile("invlpg %0": :"m" (*(char*)laddr.get()) : "memory"); + asm volatile("invlpg %0" + : + : "m"(*(char*)laddr.get()) + : "memory"); } void MemoryManager::map_for_kernel(LinearAddress laddr, PhysicalAddress paddr) diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index 0d7c948818..ad27ac77bc 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include static const dword userspace_range_base = 0x01000000; static const dword kernelspace_range_base = 0xc0000000; diff --git a/Kernel/VM/PhysicalPage.cpp b/Kernel/VM/PhysicalPage.cpp index 459fde5c60..0ffa91bafd 100644 --- a/Kernel/VM/PhysicalPage.cpp +++ b/Kernel/VM/PhysicalPage.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include Retained PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor) diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp index f077ff7383..199a73f5ad 100644 --- a/Kernel/VM/RangeAllocator.cpp +++ b/Kernel/VM/RangeAllocator.cpp @@ -1,6 +1,6 @@ +#include #include #include -#include //#define VRA_DEBUG @@ -33,7 +33,7 @@ Vector Range::carve(const Range& taken) { Vector parts; if (taken == *this) - return { }; + return {}; if (taken.base() > base()) parts.append({ base(), taken.base().get() - base().get() }); if (taken.end() < end()) @@ -79,7 +79,7 @@ Range RangeAllocator::allocate_anywhere(size_t size) return allocated_range; } kprintf("VRA: Failed to allocate anywhere: %u\n", size); - return { }; + return {}; } Range RangeAllocator::allocate_specific(LinearAddress base, size_t size) @@ -101,7 +101,7 @@ Range RangeAllocator::allocate_specific(LinearAddress base, size_t size) return allocated_range; } kprintf("VRA: Failed to allocate specific range: %x(%u)\n", base.get(), size); - return { }; + return {}; } void RangeAllocator::deallocate(Range range) @@ -121,7 +121,7 @@ void RangeAllocator::deallocate(Range range) sort_and_merge: // FIXME: We don't have to sort if we insert at the right position immediately. - quick_sort(m_available_ranges.begin(), m_available_ranges.end(), [] (auto& a, auto& b) { + quick_sort(m_available_ranges.begin(), m_available_ranges.end(), [](auto& a, auto& b) { return a.base() < b.base(); }); diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 15fddd0a5f..2de4b0913b 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -1,8 +1,8 @@ -#include -#include -#include #include #include +#include +#include +#include Region::Region(const Range& range, String&& n, byte access, bool cow) : m_range(range) @@ -72,10 +72,10 @@ Retained Region::clone() if (m_shared || (is_readable() && !is_writable())) { #ifdef MM_DEBUG dbgprintf("%s<%u> Region::clone(): sharing %s (L%x)\n", - current->process().name().characters(), - current->pid(), - m_name.characters(), - laddr().get()); + current->process().name().characters(), + current->pid(), + m_name.characters(), + laddr().get()); #endif // Create a new region backed by the same VMObject. return adopt(*new Region(m_range, m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_access)); @@ -83,10 +83,10 @@ Retained Region::clone() #ifdef MM_DEBUG dbgprintf("%s<%u> Region::clone(): cowing %s (L%x)\n", - current->process().name().characters(), - current->pid(), - m_name.characters(), - laddr().get()); + current->process().name().characters(), + current->pid(), + m_name.characters(), + laddr().get()); #endif // Set up a COW region. The parent (this) region becomes COW as well! m_cow_map.fill(true); diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index 76c6645f3e..3d9477ca04 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -10,6 +10,7 @@ class VMObject; class Region : public Retainable { friend class MemoryManager; + public: enum Access { diff --git a/Kernel/VM/VMObject.cpp b/Kernel/VM/VMObject.cpp index 45cce32da0..0c6b8d8442 100644 --- a/Kernel/VM/VMObject.cpp +++ b/Kernel/VM/VMObject.cpp @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include Retained VMObject::create_file_backed(RetainPtr&& inode) { @@ -59,7 +59,6 @@ VMObject::VMObject(PhysicalAddress paddr, size_t size) ASSERT(m_physical_pages.size() == page_count()); } - VMObject::VMObject(RetainPtr&& inode) : m_inode(move(inode)) { @@ -113,7 +112,7 @@ void VMObject::inode_size_changed(Badge, size_t old_size, size_t new_size } // FIXME: Consolidate with inode_contents_changed() so we only do a single walk. - for_each_region([] (Region& region) { + for_each_region([](Region& region) { ASSERT(region.page_directory()); MM.remap_region(*region.page_directory(), region); }); @@ -165,7 +164,7 @@ void VMObject::inode_contents_changed(Badge, off_t offset, ssize_t size, #endif // FIXME: Consolidate with inode_size_changed() so we only do a single walk. - for_each_region([] (Region& region) { + for_each_region([](Region& region) { ASSERT(region.page_directory()); MM.remap_region(*region.page_directory(), region); }); diff --git a/Kernel/i386.cpp b/Kernel/i386.cpp index 2a660cf55a..da95585573 100644 --- a/Kernel/i386.cpp +++ b/Kernel/i386.cpp @@ -1,16 +1,17 @@ -#include #include "i386.h" #include "Assertions.h" -#include "Process.h" -#include #include "IRQHandler.h" #include "PIC.h" +#include "Process.h" #include "Scheduler.h" +#include #include +#include //#define PAGE_FAULT_DEBUG -struct [[gnu::packed]] DescriptorTablePointer { +struct [[gnu::packed]] DescriptorTablePointer +{ word limit; void* address; }; @@ -55,71 +56,68 @@ asm( " popw %es\n" " popw %ds\n" " popa\n" - " iret\n" -); + " iret\n"); -#define EH_ENTRY(ec) \ -extern "C" void exception_ ## ec ## _handler(RegisterDumpWithExceptionCode&); \ -extern "C" void exception_ ## ec ## _entry(); \ -asm( \ - ".globl exception_" # ec "_entry\n" \ - "exception_" # ec "_entry: \n" \ - " pusha\n" \ - " pushw %ds\n" \ - " pushw %es\n" \ - " pushw %fs\n" \ - " pushw %gs\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " popw %ds\n" \ - " popw %es\n" \ - " popw %fs\n" \ - " popw %gs\n" \ - " mov %esp, %eax\n" \ - " call exception_" # ec "_handler\n" \ - " popw %gs\n" \ - " popw %gs\n" \ - " popw %fs\n" \ - " popw %es\n" \ - " popw %ds\n" \ - " popa\n" \ - " add $0x4, %esp\n" \ - " iret\n" \ -); +#define EH_ENTRY(ec) \ + extern "C" void exception_##ec##_handler(RegisterDumpWithExceptionCode&); \ + extern "C" void exception_##ec##_entry(); \ + asm( \ + ".globl exception_" #ec "_entry\n" \ + "exception_" #ec "_entry: \n" \ + " pusha\n" \ + " pushw %ds\n" \ + " pushw %es\n" \ + " pushw %fs\n" \ + " pushw %gs\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " popw %ds\n" \ + " popw %es\n" \ + " popw %fs\n" \ + " popw %gs\n" \ + " mov %esp, %eax\n" \ + " call exception_" #ec "_handler\n" \ + " popw %gs\n" \ + " popw %gs\n" \ + " popw %fs\n" \ + " popw %es\n" \ + " popw %ds\n" \ + " popa\n" \ + " add $0x4, %esp\n" \ + " iret\n"); -#define EH_ENTRY_NO_CODE(ec) \ -extern "C" void exception_ ## ec ## _handler(RegisterDump&); \ -extern "C" void exception_ ## ec ## _entry(); \ -asm( \ - ".globl exception_" # ec "_entry\n" \ - "exception_" # ec "_entry: \n" \ - " pusha\n" \ - " pushw %ds\n" \ - " pushw %es\n" \ - " pushw %fs\n" \ - " pushw %gs\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " pushw %ss\n" \ - " popw %ds\n" \ - " popw %es\n" \ - " popw %fs\n" \ - " popw %gs\n" \ - " mov %esp, %eax\n" \ - " call exception_" # ec "_handler\n" \ - " popw %gs\n" \ - " popw %gs\n" \ - " popw %fs\n" \ - " popw %es\n" \ - " popw %ds\n" \ - " popa\n" \ - " iret\n" \ -); +#define EH_ENTRY_NO_CODE(ec) \ + extern "C" void exception_##ec##_handler(RegisterDump&); \ + extern "C" void exception_##ec##_entry(); \ + asm( \ + ".globl exception_" #ec "_entry\n" \ + "exception_" #ec "_entry: \n" \ + " pusha\n" \ + " pushw %ds\n" \ + " pushw %es\n" \ + " pushw %fs\n" \ + " pushw %gs\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " pushw %ss\n" \ + " popw %ds\n" \ + " popw %es\n" \ + " popw %fs\n" \ + " popw %gs\n" \ + " mov %esp, %eax\n" \ + " call exception_" #ec "_handler\n" \ + " popw %gs\n" \ + " popw %gs\n" \ + " popw %fs\n" \ + " popw %es\n" \ + " popw %ds\n" \ + " popa\n" \ + " iret\n"); template static void dump(const DumpType& regs) @@ -158,7 +156,6 @@ static void dump(const DumpType& regs) } } - // 6: Invalid Opcode EH_ENTRY_NO_CODE(6); void exception_6_handler(RegisterDump& regs) @@ -171,8 +168,7 @@ void exception_6_handler(RegisterDump& regs) kprintf("%s Illegal instruction: %s(%u)\n", current->process().is_ring0() ? "Kernel" : "Process", current->process().name().characters(), - current->pid() - ); + current->pid()); dump(regs); dump_backtrace(); @@ -195,14 +191,15 @@ void exception_7_handler(RegisterDump& regs) if (g_last_fpu_thread == current) return; if (g_last_fpu_thread) { - asm volatile("fxsave %0":"=m"(g_last_fpu_thread->fpu_state())); + asm volatile("fxsave %0" + : "=m"(g_last_fpu_thread->fpu_state())); } else { asm volatile("fnclex"); } g_last_fpu_thread = current; if (current->has_used_fpu()) { - asm volatile("fxrstor %0"::"m"(current->fpu_state())); + asm volatile("fxrstor %0" ::"m"(current->fpu_state())); } else { asm volatile("fninit"); current->set_has_used_fpu(true); @@ -214,7 +211,6 @@ void exception_7_handler(RegisterDump& regs) #endif } - // 0: Divide error EH_ENTRY_NO_CODE(0); void exception_0_handler(RegisterDump& regs) @@ -222,8 +218,7 @@ void exception_0_handler(RegisterDump& regs) kprintf("%s Division by zero: %s(%u)\n", current->process().is_ring0() ? "Kernel" : "User", current->process().name().characters(), - current->pid() - ); + current->pid()); dump(regs); @@ -235,7 +230,6 @@ void exception_0_handler(RegisterDump& regs) current->process().crash(SIGFPE); } - // 13: General Protection Fault EH_ENTRY(13); void exception_13_handler(RegisterDumpWithExceptionCode& regs) @@ -259,10 +253,12 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs) ASSERT(current); dword faultAddress; - asm ("movl %%cr2, %%eax":"=a"(faultAddress)); + asm("movl %%cr2, %%eax" + : "=a"(faultAddress)); dword fault_page_directory; - asm ("movl %%cr3, %%eax":"=a"(fault_page_directory)); + asm("movl %%cr3, %%eax" + : "=a"(fault_page_directory)); #ifdef PAGE_FAULT_DEBUG dbgprintf("%s(%u): ring%u %s page fault in PD=%x, %s L%x\n", @@ -299,17 +295,21 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs) } } -#define EH(i, msg) \ - static void _exception ## i () \ - { \ - kprintf(msg"\n"); \ - dword cr0, cr2, cr3, cr4; \ - asm ("movl %%cr0, %%eax":"=a"(cr0)); \ - asm ("movl %%cr2, %%eax":"=a"(cr2)); \ - asm ("movl %%cr3, %%eax":"=a"(cr3)); \ - asm ("movl %%cr4, %%eax":"=a"(cr4)); \ +#define EH(i, msg) \ + static void _exception##i() \ + { \ + kprintf(msg "\n"); \ + dword cr0, cr2, cr3, cr4; \ + asm("movl %%cr0, %%eax" \ + : "=a"(cr0)); \ + asm("movl %%cr2, %%eax" \ + : "=a"(cr2)); \ + asm("movl %%cr3, %%eax" \ + : "=a"(cr3)); \ + asm("movl %%cr4, %%eax" \ + : "=a"(cr4)); \ kprintf("CR0=%x CR2=%x CR3=%x CR4=%x\n", cr0, cr2, cr3, cr4); \ - hang(); \ + hang(); \ } EH(1, "Debug exception") @@ -350,7 +350,8 @@ void flush_gdt() { s_gdtr.address = s_gdt; s_gdtr.limit = (s_gdt_length * 8) - 1; - asm("lgdt %0"::"m"(s_gdtr):"memory"); + asm("lgdt %0" ::"m"(s_gdtr) + : "memory"); } void gdt_init() @@ -379,16 +380,13 @@ void gdt_init() "mov %%ax, %%es\n" "mov %%ax, %%fs\n" "mov %%ax, %%gs\n" - "mov %%ax, %%ss\n" - :: "a"(0x10) - : "memory" - ); + "mov %%ax, %%ss\n" ::"a"(0x10) + : "memory"); // Make sure CS points to the kernel code descriptor. asm volatile( "ljmpl $0x8, $sanity\n" - "sanity:\n" - ); + "sanity:\n"); } static void unimp_trap() @@ -413,20 +411,20 @@ void unregister_irq_handler(byte irq, IRQHandler& handler) void register_interrupt_handler(byte index, void (*f)()) { s_idt[index].low = 0x00080000 | LSW((f)); - s_idt[index].high = ((dword)(f) & 0xffff0000) | 0x8e00; + s_idt[index].high = ((dword)(f)&0xffff0000) | 0x8e00; flush_idt(); } void register_user_callable_interrupt_handler(byte index, void (*f)()) { s_idt[index].low = 0x00080000 | LSW((f)); - s_idt[index].high = ((dword)(f) & 0xffff0000) | 0xef00; + s_idt[index].high = ((dword)(f)&0xffff0000) | 0xef00; flush_idt(); } void flush_idt() { - asm("lidt %0"::"m"(s_idtr)); + asm("lidt %0" ::"m"(s_idtr)); } /* If an 8259 gets cranky, it'll generate a spurious IRQ7. @@ -438,8 +436,7 @@ extern "C" void irq7_handler(); asm( ".globl irq7_handler \n" "irq7_handler: \n" - " iret\n" -); + " iret\n"); void idt_init() { @@ -478,7 +475,7 @@ void idt_init() void load_task_register(word selector) { - asm("ltr %0"::"r"(selector)); + asm("ltr %0" ::"r"(selector)); } void handle_irq() @@ -511,7 +508,8 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const kprintf("ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func); dump_backtrace(); asm volatile("hlt"); - for (;;); + for (;;) + ; } #endif @@ -524,6 +522,5 @@ void sse_init() "mov %eax, %cr0\n" "mov %cr4, %eax\n" "orl $0x600, %eax\n" - "mov %eax, %cr4\n" - ); + "mov %eax, %cr4\n"); } diff --git a/Kernel/i8253.cpp b/Kernel/i8253.cpp index 8a8171e125..a24168ad2c 100644 --- a/Kernel/i8253.cpp +++ b/Kernel/i8253.cpp @@ -1,8 +1,8 @@ #include "i8253.h" -#include "i386.h" #include "IO.h" #include "PIC.h" #include "Scheduler.h" +#include "i386.h" #define IRQ_TIMER 0 @@ -34,8 +34,7 @@ asm( " popw %es\n" " popw %ds\n" " popa\n" - " iret\n" -); + " iret\n"); static dword s_ticks_this_second; static dword s_seconds_since_boot; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 423ca7838d..d6e41972b9 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -1,34 +1,34 @@ -#include -#include "kmalloc.h" +#include "KSyms.h" +#include "PIC.h" +#include "Process.h" +#include "RTC.h" +#include "Scheduler.h" #include "i386.h" #include "i8253.h" -#include -#include "Process.h" -#include "PIC.h" -#include -#include -#include -#include "KSyms.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "RTC.h" -#include -#include "Scheduler.h" -#include -#include -#include +#include "kmalloc.h" +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include +#include +#include +#include //#define STRESS_TEST_SPAWNING @@ -49,7 +49,7 @@ VFS* vfs; for (unsigned i = 0; i < 10000; ++i) { int error; - Process::create_user_process("/bin/true", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0); + Process::create_user_process("/bin/true", (uid_t)100, (gid_t)100, (pid_t)0, error, {}, {}, tty0); dbgprintf("malloc stats: alloc:%u free:%u eternal:%u !delta:%u\n", sum_alloc, sum_free, kmalloc_sum_eternal, sum_alloc - last_sum_alloc); last_sum_alloc = sum_alloc; sleep(60); @@ -131,7 +131,7 @@ VFS* vfs; int error; - auto* system_server_process = Process::create_user_process("/bin/SystemServer", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, { }, tty0); + auto* system_server_process = Process::create_user_process("/bin/SystemServer", (uid_t)100, (gid_t)100, (pid_t)0, error, {}, {}, tty0); if (error != 0) { dbgprintf("init_stage2: error spawning SystemServer: %d\n", error); hang(); diff --git a/Kernel/kmalloc.cpp b/Kernel/kmalloc.cpp index c00e9c139c..c6543dafb3 100644 --- a/Kernel/kmalloc.cpp +++ b/Kernel/kmalloc.cpp @@ -3,18 +3,19 @@ * just to get going. Don't ever let anyone see this shit. :^) */ +#include #include -#include -#include -#include +#include #include #include -#include -#include +#include +#include +#include #define SANITIZE_KMALLOC -struct [[gnu::packed]] allocation_t { +struct [[gnu::packed]] allocation_t +{ size_t start; size_t nchunk; }; @@ -51,7 +52,7 @@ bool is_kmalloc_address(const void* ptr) void kmalloc_init() { memset(&alloc_map, 0, sizeof(alloc_map)); - memset((void *)BASE_PHYSICAL, 0, POOL_SIZE); + memset((void*)BASE_PHYSICAL, 0, POOL_SIZE); kmalloc_sum_eternal = 0; sum_alloc = 0; @@ -126,7 +127,7 @@ void* kmalloc_impl(size_t size) } // FIXME: This scan can be optimized further with LZCNT. for (size_t j = 0; j < 8; ++j) { - if (!(alloc_map[i] & (1<nchunk = chunks_needed; a->start = first_chunk; @@ -164,7 +165,7 @@ void* kmalloc_impl(size_t size) hang(); } -void kfree(void *ptr) +void kfree(void* ptr) { if (!ptr) return;