1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

Kernel: Run clang-format on everything.

This commit is contained in:
Andreas Kling 2019-06-07 11:43:58 +02:00
parent 98eeb8f22d
commit bc951ca565
63 changed files with 974 additions and 856 deletions

View file

@ -1,29 +1,29 @@
#include <Kernel/Devices/BXVGADevice.h> #include <Kernel/Devices/BXVGADevice.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/PCI.h> #include <Kernel/PCI.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
#define VBE_DISPI_IOPORT_INDEX 0x01CE #define VBE_DISPI_IOPORT_INDEX 0x01CE
#define VBE_DISPI_IOPORT_DATA 0x01CF #define VBE_DISPI_IOPORT_DATA 0x01CF
#define VBE_DISPI_INDEX_ID 0x0 #define VBE_DISPI_INDEX_ID 0x0
#define VBE_DISPI_INDEX_XRES 0x1 #define VBE_DISPI_INDEX_XRES 0x1
#define VBE_DISPI_INDEX_YRES 0x2 #define VBE_DISPI_INDEX_YRES 0x2
#define VBE_DISPI_INDEX_BPP 0x3 #define VBE_DISPI_INDEX_BPP 0x3
#define VBE_DISPI_INDEX_ENABLE 0x4 #define VBE_DISPI_INDEX_ENABLE 0x4
#define VBE_DISPI_INDEX_BANK 0x5 #define VBE_DISPI_INDEX_BANK 0x5
#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6 #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7 #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
#define VBE_DISPI_INDEX_X_OFFSET 0x8 #define VBE_DISPI_INDEX_X_OFFSET 0x8
#define VBE_DISPI_INDEX_Y_OFFSET 0x9 #define VBE_DISPI_INDEX_Y_OFFSET 0x9
#define VBE_DISPI_DISABLED 0x00 #define VBE_DISPI_DISABLED 0x00
#define VBE_DISPI_ENABLED 0x01 #define VBE_DISPI_ENABLED 0x01
#define VBE_DISPI_LFB_ENABLED 0x40 #define VBE_DISPI_LFB_ENABLED 0x40
#define BXVGA_DEV_IOCTL_SET_Y_OFFSET 1982 #define BXVGA_DEV_IOCTL_SET_Y_OFFSET 1982
#define BXVGA_DEV_IOCTL_SET_RESOLUTION 1985 #define BXVGA_DEV_IOCTL_SET_RESOLUTION 1985
struct BXVGAResolution { struct BXVGAResolution {
int width; int width;
int height; int height;
@ -75,7 +75,7 @@ dword BXVGADevice::find_framebuffer_address()
static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 }; static const PCI::ID bochs_vga_id = { 0x1234, 0x1111 };
static const PCI::ID virtualbox_vga_id = { 0x80ee, 0xbeef }; static const PCI::ID virtualbox_vga_id = { 0x80ee, 0xbeef };
dword framebuffer_address = 0; 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) { if (id == bochs_vga_id || id == virtualbox_vga_id) {
framebuffer_address = PCI::get_BAR0(address) & 0xfffffff0; framebuffer_address = PCI::get_BAR0(address) & 0xfffffff0;
kprintf("BXVGA: framebuffer @ P%x\n", framebuffer_address); kprintf("BXVGA: framebuffer @ P%x\n", framebuffer_address);
@ -95,11 +95,10 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescription&, LinearA
move(vmo), move(vmo),
0, 0,
"BXVGA Framebuffer", "BXVGA Framebuffer",
prot prot);
);
kprintf("BXVGA: %s(%u) created Region{%p} with size %u for framebuffer P%x with laddr L%x\n", kprintf("BXVGA: %s(%u) created Region{%p} with size %u for framebuffer P%x with laddr L%x\n",
process.name().characters(), process.pid(), process.name().characters(), process.pid(),
region, region->size(), framebuffer_address().as_ptr(), region->laddr().get()); region, region->size(), framebuffer_address().as_ptr(), region->laddr().get());
ASSERT(region); ASSERT(region);
return region; return region;
} }

View file

@ -25,4 +25,3 @@ ssize_t DebugLogDevice::write(FileDescription&, const byte* data, ssize_t data_s
IO::out8(0xe9, data[i]); IO::out8(0xe9, data[i]);
return data_size; return data_size;
} }

View file

@ -3,8 +3,8 @@
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
Device::Device(unsigned major, unsigned minor) Device::Device(unsigned major, unsigned minor)
: m_major(major) : m_major(major)
, m_minor(minor) , m_minor(minor)
{ {
VFS::the().register_device({}, *this); VFS::the().register_device({}, *this);
} }

View file

@ -27,4 +27,3 @@ bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in)
ASSERT(end_block <= 0xffffffff); ASSERT(end_block <= 0xffffffff);
return write_blocks(first_block, end_block - first_block, in); return write_blocks(first_block, end_block - first_block, in);
} }

View file

@ -8,7 +8,8 @@ Retained<DiskPartition> DiskPartition::create(Retained<DiskDevice>&& device, uns
} }
DiskPartition::DiskPartition(Retained<DiskDevice>&& device, unsigned block_offset) DiskPartition::DiskPartition(Retained<DiskDevice>&& device, unsigned block_offset)
: m_device(move(device)), m_block_offset(block_offset) : m_device(move(device))
, m_block_offset(block_offset)
{ {
} }

View file

@ -79,4 +79,3 @@ const char* FileBackedDiskDevice::class_name() const
{ {
return "FileBackedDiskDevice"; return "FileBackedDiskDevice";
} }

View file

@ -1,7 +1,7 @@
#include "FullDevice.h" #include "FullDevice.h"
#include <LibC/errno_numbers.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/kstdio.h> #include <AK/kstdio.h>
#include <LibC/errno_numbers.h>
FullDevice::FullDevice() FullDevice::FullDevice()
: CharacterDevice(1, 7) : CharacterDevice(1, 7)
@ -30,4 +30,3 @@ ssize_t FullDevice::write(FileDescription&, const byte*, ssize_t size)
return 0; return 0;
return -ENOSPC; return -ENOSPC;
} }

View file

@ -1,81 +1,81 @@
#include <Kernel/Devices/IDEDiskDevice.h> #include <Kernel/Devices/IDEDiskDevice.h>
#include <Kernel/FileSystem/ProcFS.h> #include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/Process.h>
#include <Kernel/StdLib.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/PIC.h> #include <Kernel/PIC.h>
#include <Kernel/Process.h>
#include <Kernel/StdLib.h>
#include <Kernel/VM/MemoryManager.h>
//#define DISK_DEBUG //#define DISK_DEBUG
#define IRQ_FIXED_DISK 14 #define IRQ_FIXED_DISK 14
#define ATA_SR_BSY 0x80 #define ATA_SR_BSY 0x80
#define ATA_SR_DRDY 0x40 #define ATA_SR_DRDY 0x40
#define ATA_SR_DF 0x20 #define ATA_SR_DF 0x20
#define ATA_SR_DSC 0x10 #define ATA_SR_DSC 0x10
#define ATA_SR_DRQ 0x08 #define ATA_SR_DRQ 0x08
#define ATA_SR_CORR 0x04 #define ATA_SR_CORR 0x04
#define ATA_SR_IDX 0x02 #define ATA_SR_IDX 0x02
#define ATA_SR_ERR 0x01 #define ATA_SR_ERR 0x01
#define ATA_ER_BBK 0x80 #define ATA_ER_BBK 0x80
#define ATA_ER_UNC 0x40 #define ATA_ER_UNC 0x40
#define ATA_ER_MC 0x20 #define ATA_ER_MC 0x20
#define ATA_ER_IDNF 0x10 #define ATA_ER_IDNF 0x10
#define ATA_ER_MCR 0x08 #define ATA_ER_MCR 0x08
#define ATA_ER_ABRT 0x04 #define ATA_ER_ABRT 0x04
#define ATA_ER_TK0NF 0x02 #define ATA_ER_TK0NF 0x02
#define ATA_ER_AMNF 0x01 #define ATA_ER_AMNF 0x01
#define ATA_CMD_READ_PIO 0x20 #define ATA_CMD_READ_PIO 0x20
#define ATA_CMD_READ_PIO_EXT 0x24 #define ATA_CMD_READ_PIO_EXT 0x24
#define ATA_CMD_READ_DMA 0xC8 #define ATA_CMD_READ_DMA 0xC8
#define ATA_CMD_READ_DMA_EXT 0x25 #define ATA_CMD_READ_DMA_EXT 0x25
#define ATA_CMD_WRITE_PIO 0x30 #define ATA_CMD_WRITE_PIO 0x30
#define ATA_CMD_WRITE_PIO_EXT 0x34 #define ATA_CMD_WRITE_PIO_EXT 0x34
#define ATA_CMD_WRITE_DMA 0xCA #define ATA_CMD_WRITE_DMA 0xCA
#define ATA_CMD_WRITE_DMA_EXT 0x35 #define ATA_CMD_WRITE_DMA_EXT 0x35
#define ATA_CMD_CACHE_FLUSH 0xE7 #define ATA_CMD_CACHE_FLUSH 0xE7
#define ATA_CMD_CACHE_FLUSH_EXT 0xEA #define ATA_CMD_CACHE_FLUSH_EXT 0xEA
#define ATA_CMD_PACKET 0xA0 #define ATA_CMD_PACKET 0xA0
#define ATA_CMD_IDENTIFY_PACKET 0xA1 #define ATA_CMD_IDENTIFY_PACKET 0xA1
#define ATA_CMD_IDENTIFY 0xEC #define ATA_CMD_IDENTIFY 0xEC
#define ATAPI_CMD_READ 0xA8 #define ATAPI_CMD_READ 0xA8
#define ATAPI_CMD_EJECT 0x1B #define ATAPI_CMD_EJECT 0x1B
#define ATA_IDENT_DEVICETYPE 0 #define ATA_IDENT_DEVICETYPE 0
#define ATA_IDENT_CYLINDERS 2 #define ATA_IDENT_CYLINDERS 2
#define ATA_IDENT_HEADS 6 #define ATA_IDENT_HEADS 6
#define ATA_IDENT_SECTORS 12 #define ATA_IDENT_SECTORS 12
#define ATA_IDENT_SERIAL 20 #define ATA_IDENT_SERIAL 20
#define ATA_IDENT_MODEL 54 #define ATA_IDENT_MODEL 54
#define ATA_IDENT_CAPABILITIES 98 #define ATA_IDENT_CAPABILITIES 98
#define ATA_IDENT_FIELDVALID 106 #define ATA_IDENT_FIELDVALID 106
#define ATA_IDENT_MAX_LBA 120 #define ATA_IDENT_MAX_LBA 120
#define ATA_IDENT_COMMANDSETS 164 #define ATA_IDENT_COMMANDSETS 164
#define ATA_IDENT_MAX_LBA_EXT 200 #define ATA_IDENT_MAX_LBA_EXT 200
#define IDE_ATA 0x00 #define IDE_ATA 0x00
#define IDE_ATAPI 0x01 #define IDE_ATAPI 0x01
#define ATA_REG_DATA 0x00 #define ATA_REG_DATA 0x00
#define ATA_REG_ERROR 0x01 #define ATA_REG_ERROR 0x01
#define ATA_REG_FEATURES 0x01 #define ATA_REG_FEATURES 0x01
#define ATA_REG_SECCOUNT0 0x02 #define ATA_REG_SECCOUNT0 0x02
#define ATA_REG_LBA0 0x03 #define ATA_REG_LBA0 0x03
#define ATA_REG_LBA1 0x04 #define ATA_REG_LBA1 0x04
#define ATA_REG_LBA2 0x05 #define ATA_REG_LBA2 0x05
#define ATA_REG_HDDEVSEL 0x06 #define ATA_REG_HDDEVSEL 0x06
#define ATA_REG_COMMAND 0x07 #define ATA_REG_COMMAND 0x07
#define ATA_REG_STATUS 0x07 #define ATA_REG_STATUS 0x07
#define ATA_REG_SECCOUNT1 0x08 #define ATA_REG_SECCOUNT1 0x08
#define ATA_REG_LBA3 0x09 #define ATA_REG_LBA3 0x09
#define ATA_REG_LBA4 0x0A #define ATA_REG_LBA4 0x0A
#define ATA_REG_LBA5 0x0B #define ATA_REG_LBA5 0x0B
#define ATA_REG_CONTROL 0x0C #define ATA_REG_CONTROL 0x0C
#define ATA_REG_ALTSTATUS 0x0C #define ATA_REG_ALTSTATUS 0x0C
#define ATA_REG_DEVADDRESS 0x0D #define ATA_REG_DEVADDRESS 0x0D
Retained<IDEDiskDevice> IDEDiskDevice::create() Retained<IDEDiskDevice> IDEDiskDevice::create()
@ -137,14 +137,14 @@ bool IDEDiskDevice::write_block(unsigned index, const byte* data)
static void print_ide_status(byte status) 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", 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_DRQ) != 0,
(status & ATA_SR_BSY) != 0, (status & ATA_SR_BSY) != 0,
(status & ATA_SR_DRDY) != 0, (status & ATA_SR_DRDY) != 0,
(status & ATA_SR_DSC) != 0, (status & ATA_SR_DSC) != 0,
(status & ATA_SR_DF) != 0, (status & ATA_SR_DF) != 0,
(status & ATA_SR_CORR) != 0, (status & ATA_SR_CORR) != 0,
(status & ATA_SR_IDX) != 0, (status & ATA_SR_IDX) != 0,
(status & ATA_SR_ERR) != 0); (status & ATA_SR_ERR) != 0);
} }
bool IDEDiskDevice::wait_for_irq() 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 piix3_ide_id = { 0x8086, 0x7010 };
static const PCI::ID piix4_ide_id = { 0x8086, 0x7111 }; 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) { if (id == piix3_ide_id || id == piix4_ide_id) {
m_pci_address = address; m_pci_address = address;
kprintf("PIIX%u IDE device found!\n", id == piix3_ide_id ? 3 : 4); kprintf("PIIX%u IDE device found!\n", id == piix3_ide_id ? 3 : 4);
@ -199,7 +199,8 @@ void IDEDiskDevice::initialize()
m_interrupted = false; 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(); enable_irq();
@ -236,8 +237,7 @@ void IDEDiskDevice::initialize()
bbuf.pointer() + 54, bbuf.pointer() + 54,
m_cylinders, m_cylinders,
m_heads, m_heads,
m_sectors_per_track m_sectors_per_track);
);
// Let's try to set up DMA transfers. // Let's try to set up DMA transfers.
if (!m_pci_address.is_null()) { 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); LOCKER(m_lock);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
dbgprintf("%s(%u): IDEDiskDevice::read_sectors_with_dma (%u x%u) -> %p\n", dbgprintf("%s(%u): IDEDiskDevice::read_sectors_with_dma (%u x%u) -> %p\n",
current->process().name().characters(), current->process().name().characters(),
current->pid(), lba, count, outbuf); current->pid(), lba, count, outbuf);
#endif #endif
disable_irq(); disable_irq();
@ -286,7 +286,8 @@ bool IDEDiskDevice::read_sectors_with_dma(dword lba, word count, byte* outbuf)
m_interrupted = false; m_interrupted = false;
enable_irq(); 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; bool is_slave = false;
@ -337,13 +338,14 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf)
LOCKER(m_lock); LOCKER(m_lock);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
dbgprintf("%s: Disk::read_sectors request (%u sector(s) @ %u)\n", dbgprintf("%s: Disk::read_sectors request (%u sector(s) @ %u)\n",
current->process().name().characters(), current->process().name().characters(),
count, count,
start_sector); start_sector);
#endif #endif
disable_irq(); 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 #ifdef DISK_DEBUG
kprintf("IDEDiskDevice: Reading %u sector(s) @ LBA %u\n", count, start_sector); 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(m_io_base + ATA_REG_HDDEVSEL, 0xe0 | ((start_sector >> 24) & 0xf)); // 0xf0 for 2nd device
IO::out8(0x3F6, 0x08); 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); IO::out8(m_io_base + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
m_interrupted = false; m_interrupted = false;
@ -381,8 +384,8 @@ bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* in
LOCKER(m_lock); LOCKER(m_lock);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
dbgprintf("%s(%u): IDEDiskDevice::write_sectors_with_dma (%u x%u) <- %p\n", dbgprintf("%s(%u): IDEDiskDevice::write_sectors_with_dma (%u x%u) <- %p\n",
current->process().name().characters(), current->process().name().characters(),
current->pid(), lba, count, inbuf); current->pid(), lba, count, inbuf);
#endif #endif
disable_irq(); disable_irq();
@ -406,7 +409,8 @@ bool IDEDiskDevice::write_sectors_with_dma(dword lba, word count, const byte* in
m_interrupted = false; m_interrupted = false;
enable_irq(); 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; bool is_slave = false;
@ -455,14 +459,15 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da
LOCKER(m_lock); LOCKER(m_lock);
#ifdef DISK_DEBUG #ifdef DISK_DEBUG
dbgprintf("%s(%u): IDEDiskDevice::write_sectors request (%u sector(s) @ %u)\n", dbgprintf("%s(%u): IDEDiskDevice::write_sectors request (%u sector(s) @ %u)\n",
current->process().name().characters(), current->process().name().characters(),
current->pid(), current->pid(),
count, count,
start_sector); start_sector);
#endif #endif
disable_irq(); 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); //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); 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); byte status = IO::in8(m_io_base + ATA_REG_STATUS);
ASSERT(status & ATA_SR_DRQ); ASSERT(status & ATA_SR_DRQ);
@ -488,7 +494,8 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da
disable_irq(); disable_irq();
IO::out8(m_io_base + ATA_REG_COMMAND, ATA_CMD_CACHE_FLUSH); 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; m_interrupted = false;
enable_irq(); enable_irq();
wait_for_irq(); wait_for_irq();

View file

@ -1,24 +1,23 @@
#include <AK/Types.h>
#include "i386.h"
#include "IO.h" #include "IO.h"
#include "PIC.h" #include "PIC.h"
#include "i386.h"
#include <AK/Assertions.h>
#include <AK/Types.h>
#include <Kernel/Devices/KeyboardDevice.h> #include <Kernel/Devices/KeyboardDevice.h>
#include <Kernel/TTY/VirtualConsole.h> #include <Kernel/TTY/VirtualConsole.h>
#include <AK/Assertions.h>
//#define KEYBOARD_DEBUG //#define KEYBOARD_DEBUG
#define IRQ_KEYBOARD 1 #define IRQ_KEYBOARD 1
#define I8042_BUFFER 0x60 #define I8042_BUFFER 0x60
#define I8042_STATUS 0x64 #define I8042_STATUS 0x64
#define I8042_ACK 0xFA #define I8042_ACK 0xFA
#define I8042_BUFFER_FULL 0x01 #define I8042_BUFFER_FULL 0x01
#define I8042_WHICH_BUFFER 0x20 #define I8042_WHICH_BUFFER 0x20
#define I8042_MOUSE_BUFFER 0x20 #define I8042_MOUSE_BUFFER 0x20
#define I8042_KEYBOARD_BUFFER 0x00 #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', 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, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\',
@ -26,8 +25,7 @@ static char map[0x80] =
0, 0, 0, ' ' 0, 0, 0, ' '
}; };
static char shift_map[0x80] = static char shift_map[0x80] = {
{
0, '\033', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0x08, '\t', 0, '\033', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0x08, '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|',
@ -35,24 +33,76 @@ static char shift_map[0x80] =
0, 0, 0, ' ' 0, 0, 0, ' '
}; };
static KeyCode unshifted_key_map[0x80] = static KeyCode unshifted_key_map[0x80] = {
{ Key_Invalid,
Key_Invalid, Key_Escape, 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_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_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_Q,
Key_Return, // 28 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_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_LeftShift, // 42
Key_Backslash, 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_RightShift, // 54
Key_Invalid, Key_Invalid,
Key_Alt, // 56 Key_Alt, // 56
Key_Space, // 57 Key_Space, // 57
Key_Invalid, // 58 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,
Key_Invalid, // 70 Key_Invalid, // 70
Key_Home, Key_Home,
@ -78,24 +128,76 @@ static KeyCode unshifted_key_map[0x80] =
Key_Logo, Key_Logo,
}; };
static KeyCode shifted_key_map[0x100] = static KeyCode shifted_key_map[0x100] = {
{ Key_Invalid,
Key_Invalid, Key_Escape, 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_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_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_Return,
Key_Control, 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_LeftShift, // 42
Key_Pipe, 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_RightShift, // 54
Key_Invalid, Key_Invalid,
Key_Alt, Key_Alt,
Key_Space, // 57 Key_Space, // 57
Key_Invalid, // 58 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,
Key_Invalid, // 70 Key_Invalid, // 70
Key_Home, Key_Home,
@ -163,7 +265,8 @@ void KeyboardDevice::handle_irq()
break; break;
} }
switch (ch) { switch (ch) {
case I8042_ACK: break; case I8042_ACK:
break;
default: default:
if (m_modifiers & Mod_Alt) { if (m_modifiers & Mod_Alt) {
switch (map[ch]) { switch (map[ch]) {

View file

@ -34,4 +34,3 @@ ssize_t NullDevice::write(FileDescription&, const byte*, ssize_t buffer_size)
{ {
return min(PAGE_SIZE, buffer_size); return min(PAGE_SIZE, buffer_size);
} }

View file

@ -1,7 +1,7 @@
#include <Kernel/Devices/PCSpeaker.h> #include <Kernel/Devices/PCSpeaker.h>
#include <Kernel/i8253.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/i386.h> #include <Kernel/i386.h>
#include <Kernel/i8253.h>
void PCSpeaker::tone_on(int frequency) void PCSpeaker::tone_on(int frequency)
{ {

View file

@ -1,16 +1,16 @@
#include "PS2MouseDevice.h" #include "PS2MouseDevice.h"
#include "IO.h" #include "IO.h"
#define IRQ_MOUSE 1 #define IRQ_MOUSE 1
#define I8042_BUFFER 0x60 #define I8042_BUFFER 0x60
#define I8042_STATUS 0x64 #define I8042_STATUS 0x64
#define I8042_ACK 0xFA #define I8042_ACK 0xFA
#define I8042_BUFFER_FULL 0x01 #define I8042_BUFFER_FULL 0x01
#define I8042_WHICH_BUFFER 0x20 #define I8042_WHICH_BUFFER 0x20
#define I8042_MOUSE_BUFFER 0x20 #define I8042_MOUSE_BUFFER 0x20
#define I8042_KEYBOARD_BUFFER 0x00 #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_SET_SAMPLE_RATE 0xF3
#define PS2MOUSE_INTELLIMOUSE_ID 0x03 #define PS2MOUSE_INTELLIMOUSE_ID 0x03
@ -54,8 +54,7 @@ void PS2MouseDevice::handle_irq()
m_data[2], m_data[2],
(m_data[0] & 1) ? "Left" : "", (m_data[0] & 1) ? "Left" : "",
(m_data[0] & 2) ? "Right" : "", (m_data[0] & 2) ? "Right" : "",
m_queue.size() m_queue.size());
);
#endif #endif
parse_data_packet(); parse_data_packet();
}; };

View file

@ -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? // FIXME: Use input for entropy? I guess that could be a neat feature?
return min(PAGE_SIZE, size); return min(PAGE_SIZE, size);
} }

View file

@ -27,4 +27,3 @@ ssize_t ZeroDevice::write(FileDescription&, const byte*, ssize_t size)
{ {
return min(PAGE_SIZE, size); return min(PAGE_SIZE, size);
} }

View file

@ -28,4 +28,3 @@ KResultOr<Region*> File::mmap(Process&, FileDescription&, LinearAddress, size_t,
{ {
return KResult(-ENODEV); return KResult(-ENODEV);
} }

View file

@ -31,9 +31,9 @@ Retained<Custody> Custody::get_or_create(Custody* parent, const String& name, In
if (RetainPtr<Custody> cached_custody = get_if_cached(parent, name)) { if (RetainPtr<Custody> cached_custody = get_if_cached(parent, name)) {
if (&cached_custody->inode() != &inode) { if (&cached_custody->inode() != &inode) {
dbgprintf("WTF! cached custody for name '%s' has inode=%s, new inode=%s\n", dbgprintf("WTF! cached custody for name '%s' has inode=%s, new inode=%s\n",
name.characters(), name.characters(),
cached_custody->inode().identifier().to_string().characters(), cached_custody->inode().identifier().to_string().characters(),
inode.identifier().to_string().characters()); inode.identifier().to_string().characters());
} }
ASSERT(&cached_custody->inode() == &inode); ASSERT(&cached_custody->inode() == &inode);
return *cached_custody; return *cached_custody;
@ -83,4 +83,3 @@ void Custody::did_rename(Badge<VFS>, const String& name)
{ {
m_name = name; m_name = name;
} }

View file

@ -1,7 +1,7 @@
#include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/TTY/SlavePTY.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/TTY/SlavePTY.h>
static DevPtsFS* s_the; static DevPtsFS* s_the;

View file

@ -1,12 +1,12 @@
#include "Ext2FileSystem.h" #include "Ext2FileSystem.h"
#include "ext2_fs.h"
#include "UnixTypes.h"
#include "RTC.h" #include "RTC.h"
#include "UnixTypes.h"
#include "ext2_fs.h"
#include <AK/Bitmap.h> #include <AK/Bitmap.h>
#include <AK/StdLibExtras.h>
#include <AK/BufferStream.h> #include <AK/BufferStream.h>
#include <LibC/errno_numbers.h> #include <AK/StdLibExtras.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <LibC/errno_numbers.h>
//#define EXT2_DEBUG //#define EXT2_DEBUG
@ -162,10 +162,10 @@ ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& block_i
auto& super_block = this->super_block(); auto& super_block = this->super_block();
if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&super_block)) if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&super_block))
return { }; return {};
if (inode > super_block.s_inodes_count) if (inode > super_block.s_inodes_count)
return { }; return {};
auto& bgd = group_descriptor(group_index_from_inode(inode)); auto& bgd = group_descriptor(group_index_from_inode(inode));
@ -314,7 +314,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode(const ext2_inode& e2inod
if (!blocks_remaining) if (!blocks_remaining)
return list; 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) if (include_block_list_blocks)
callback(array_block_index); callback(array_block_index);
auto array_block = read_block(array_block_index); auto array_block = read_block(array_block_index);
@ -331,15 +331,15 @@ Vector<Ext2FS::BlockIndex> 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); list.unchecked_append(entry);
}); });
if (!blocks_remaining) if (!blocks_remaining)
return list; return list;
process_block_array(e2inode.i_block[EXT2_DIND_BLOCK], [&] (unsigned entry) { process_block_array(e2inode.i_block[EXT2_DIND_BLOCK], [&](unsigned entry) {
process_block_array(entry, [&] (unsigned entry) { process_block_array(entry, [&](unsigned entry) {
list.unchecked_append(entry); list.unchecked_append(entry);
}); });
}); });
@ -347,9 +347,9 @@ Vector<Ext2FS::BlockIndex> Ext2FS::block_list_for_inode(const ext2_inode& e2inod
if (!blocks_remaining) if (!blocks_remaining)
return list; return list;
process_block_array(e2inode.i_block[EXT2_TIND_BLOCK], [&] (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) {
process_block_array(entry, [&] (unsigned entry) { process_block_array(entry, [&](unsigned entry) {
list.unchecked_append(entry); list.unchecked_append(entry);
}); });
}); });
@ -468,7 +468,7 @@ RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
unsigned offset; unsigned offset;
auto block = read_block_containing_inode(inode.index(), block_index, offset); auto block = read_block_containing_inode(inode.index(), block_index, offset);
if (!block) if (!block)
return { }; return {};
auto it = m_inode_cache.find(inode.index()); auto it = m_inode_cache.find(inode.index());
if (it != m_inode_cache.end()) if (it != m_inode_cache.end())
@ -709,13 +709,13 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const String& name, mod
LOCKER(m_lock); LOCKER(m_lock);
ASSERT(is_directory()); 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()); dbgprintf("Ext2FS: Adding inode %u with name '%s' to directory %u\n", child_id.index(), name.characters(), index());
//#endif //#endif
Vector<FS::DirectoryEntry> entries; Vector<FS::DirectoryEntry> entries;
bool name_already_exists = false; bool name_already_exists = false;
traverse_as_directory([&] (auto& entry) { traverse_as_directory([&](auto& entry) {
if (!strcmp(entry.name, name.characters())) { if (!strcmp(entry.name, name.characters())) {
name_already_exists = true; name_already_exists = true;
return false; return false;
@ -755,12 +755,12 @@ KResult Ext2FSInode::remove_child(const String& name)
InodeIdentifier child_id { fsid(), child_inode_index }; InodeIdentifier child_id { fsid(), child_inode_index };
//#ifdef EXT2_DEBUG //#ifdef EXT2_DEBUG
dbgprintf("Ext2FS: Removing '%s' in directory %u\n", name.characters(), index()); dbgprintf("Ext2FS: Removing '%s' in directory %u\n", name.characters(), index());
//#endif //#endif
Vector<FS::DirectoryEntry> entries; Vector<FS::DirectoryEntry> entries;
traverse_as_directory([&] (auto& entry) { traverse_as_directory([&](auto& entry) {
if (strcmp(entry.name, name.characters()) != 0) if (strcmp(entry.name, name.characters()) != 0)
entries.append(entry); entries.append(entry);
return true; return true;
@ -842,7 +842,6 @@ unsigned Ext2FS::inodes_per_group() const
unsigned Ext2FS::inode_size() const unsigned Ext2FS::inode_size() const
{ {
return EXT2_INODE_SIZE(&super_block()); return EXT2_INODE_SIZE(&super_block());
} }
unsigned Ext2FS::blocks_per_group() const unsigned Ext2FS::blocks_per_group() const
{ {
@ -868,12 +867,12 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex group_index, int c
LOCKER(m_lock); LOCKER(m_lock);
dbgprintf("Ext2FS: allocate_blocks(group: %u, count: %u)\n", group_index, count); dbgprintf("Ext2FS: allocate_blocks(group: %u, count: %u)\n", group_index, count);
if (count == 0) if (count == 0)
return { }; return {};
auto& bgd = group_descriptor(group_index); auto& bgd = group_descriptor(group_index);
if (bgd.bg_free_blocks_count < count) { 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); 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. // 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; 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); auto& bgd = group_descriptor(group_index);
return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= needed_blocks; return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= needed_blocks;
}; };
@ -1138,7 +1137,7 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
if (!inode_id) { if (!inode_id) {
kprintf("Ext2FS: create_inode: allocate_inode failed\n"); kprintf("Ext2FS: create_inode: allocate_inode failed\n");
error = -ENOSPC; error = -ENOSPC;
return { }; return {};
} }
auto needed_blocks = ceil_div(size, block_size()); auto needed_blocks = ceil_div(size, block_size());
@ -1146,14 +1145,14 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
if (blocks.size() != needed_blocks) { if (blocks.size() != needed_blocks) {
kprintf("Ext2FS: create_inode: allocate_blocks failed\n"); kprintf("Ext2FS: create_inode: allocate_blocks failed\n");
error = -ENOSPC; error = -ENOSPC;
return { }; return {};
} }
// Try adding it to the directory first, in case the name is already in use. // 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)); auto result = parent_inode->add_child({ fsid(), inode_id }, name, to_ext2_file_type(mode));
if (result.is_error()) { if (result.is_error()) {
error = result; error = result;
return { }; return {};
} }
// Looks like we're good, time to update the inode bitmap and group+global inode counters. // 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; return;
HashMap<String, unsigned> children; HashMap<String, unsigned> children;
traverse_as_directory([&children] (auto& entry) { traverse_as_directory([&children](auto& entry) {
children.set(String(entry.name, entry.name_length), entry.inode.index()); children.set(String(entry.name, entry.name_length), entry.inode.index());
return true; return true;
}); });
@ -1229,7 +1228,7 @@ InodeIdentifier Ext2FSInode::lookup(StringView name)
auto it = m_lookup_cache.find(name); auto it = m_lookup_cache.find(name);
if (it != m_lookup_cache.end()) if (it != m_lookup_cache.end())
return { fsid(), (*it).value }; return { fsid(), (*it).value };
return { }; return {};
} }
void Ext2FSInode::one_retain_left() void Ext2FSInode::one_retain_left()

View file

@ -1,10 +1,10 @@
#include <AK/HashTable.h>
#include <AK/StdLibExtras.h>
#include <Kernel/FileSystem/FIFO.h> #include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Lock.h> #include <Kernel/Lock.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <AK/StdLibExtras.h>
#include <AK/HashTable.h>
//#define FIFO_DEBUG //#define FIFO_DEBUG
@ -34,7 +34,7 @@ Retained<FileDescription> FIFO::open_direction(FIFO::Direction direction)
{ {
auto descriptor = FileDescription::create(this); auto descriptor = FileDescription::create(this);
attach(direction); attach(direction);
descriptor->set_fifo_direction({ }, direction); descriptor->set_fifo_direction({}, direction);
return descriptor; return descriptor;
} }
@ -98,7 +98,7 @@ ssize_t FIFO::read(FileDescription&, byte* buffer, ssize_t size)
if (!m_writers && m_buffer.is_empty()) if (!m_writers && m_buffer.is_empty())
return 0; return 0;
#ifdef FIFO_DEBUG #ifdef FIFO_DEBUG
dbgprintf("fifo: read(%u)\n",size); dbgprintf("fifo: read(%u)\n", size);
#endif #endif
ssize_t nread = m_buffer.read(buffer, size); ssize_t nread = m_buffer.read(buffer, size);
#ifdef FIFO_DEBUG #ifdef FIFO_DEBUG

View file

@ -179,7 +179,7 @@ ssize_t FileDescription::get_dir_entries(byte* buffer, ssize_t size)
auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate); auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate);
BufferStream stream(temp_buffer); 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 << (dword)entry.inode.index();
stream << (byte)entry.file_type; stream << (byte)entry.file_type;
stream << (dword)entry.name_length; stream << (dword)entry.name_length;
@ -255,7 +255,7 @@ InodeMetadata FileDescription::metadata() const
{ {
if (m_inode) if (m_inode)
return m_inode->metadata(); return m_inode->metadata();
return { }; return {};
} }
KResultOr<Region*> FileDescription::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot) KResultOr<Region*> FileDescription::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)

View file

@ -1,11 +1,11 @@
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibC/errno_numbers.h>
#include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h>
static dword s_lastFileSystemID; static dword s_lastFileSystemID;
static HashMap<dword, FS*>* s_fs_map; static HashMap<dword, FS*>* s_fs_map;
@ -17,7 +17,6 @@ static HashMap<dword, FS*>& all_fses()
return *s_fs_map; return *s_fs_map;
} }
FS::FS() FS::FS()
: m_fsid(++s_lastFileSystemID) : m_fsid(++s_lastFileSystemID)
{ {

View file

@ -1,7 +1,7 @@
#include <Kernel/FileSystem/Inode.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <Kernel/VM/VMObject.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/VM/VMObject.h>
HashTable<Inode*>& all_inodes() HashTable<Inode*>& all_inodes()
{ {

View file

@ -1,6 +1,6 @@
#include <Kernel/FileSystem/InodeFile.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/InodeFile.h>
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>

View file

@ -1,20 +1,21 @@
#include "ProcFS.h" #include "ProcFS.h"
#include "Console.h"
#include "KSyms.h"
#include "Process.h" #include "Process.h"
#include "Scheduler.h"
#include "StdLib.h"
#include "i386.h"
#include <AK/StringBuilder.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/VM/MemoryManager.h>
#include "StdLib.h"
#include "i386.h"
#include "KSyms.h"
#include "Console.h"
#include "Scheduler.h"
#include <Kernel/PCI.h> #include <Kernel/PCI.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/kmalloc.h> #include <Kernel/kmalloc.h>
#include <AK/StringBuilder.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
enum ProcParentDirectory { enum ProcParentDirectory
{
PDI_AbstractRoot = 0, PDI_AbstractRoot = 0,
PDI_Root, PDI_Root,
PDI_Root_sys, PDI_Root_sys,
@ -22,7 +23,8 @@ enum ProcParentDirectory {
PDI_PID_fd, PDI_PID_fd,
}; };
enum ProcFileType { enum ProcFileType
{
FI_Invalid = 0, FI_Invalid = 0,
FI_Root = 1, // directory FI_Root = 1, // directory
@ -41,7 +43,7 @@ enum ProcFileType {
FI_Root_pci, FI_Root_pci,
FI_Root_uptime, FI_Root_uptime,
FI_Root_self, // symlink FI_Root_self, // symlink
FI_Root_sys, // directory FI_Root_sys, // directory
__FI_Root_End, __FI_Root_End,
FI_PID, FI_PID,
@ -54,7 +56,7 @@ enum ProcFileType {
FI_PID_fds, FI_PID_fds,
FI_PID_exe, // symlink FI_PID_exe, // symlink
FI_PID_cwd, // symlink FI_PID_cwd, // symlink
FI_PID_fd, // directory FI_PID_fd, // directory
__FI_PID_End, __FI_PID_End,
FI_MaxStaticFileIndex, FI_MaxStaticFileIndex,
@ -183,10 +185,10 @@ ByteBuffer procfs$pid_fds(InodeIdentifier identifier)
{ {
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
if (process.number_of_open_file_descriptors() == 0) if (process.number_of_open_file_descriptors() == 0)
return { }; return {};
StringBuilder builder; StringBuilder builder;
for (int i = 0; i < process.max_open_file_descriptors(); ++i) { for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
auto* descriptor = process.file_description(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)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
int fd = to_fd(identifier); int fd = to_fd(identifier);
auto* descriptor = process.file_description(fd); auto* descriptor = process.file_description(fd);
if (!descriptor) if (!descriptor)
return { }; return {};
return descriptor->absolute_path().to_byte_buffer(); 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)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
StringBuilder builder; StringBuilder builder;
builder.appendf("BEGIN END SIZE COMMIT FLAGS NAME\n"); builder.appendf("BEGIN END SIZE COMMIT FLAGS NAME\n");
@ -238,7 +240,7 @@ ByteBuffer procfs$pid_vm(InodeIdentifier identifier)
ByteBuffer procfs$pci(InodeIdentifier) ByteBuffer procfs$pci(InodeIdentifier)
{ {
StringBuilder builder; 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); 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(); return builder.to_byte_buffer();
@ -255,7 +257,7 @@ ByteBuffer procfs$pid_vmo(InodeIdentifier identifier)
{ {
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
StringBuilder builder; StringBuilder builder;
builder.appendf("BEGIN END SIZE NAME\n"); builder.appendf("BEGIN END SIZE NAME\n");
@ -275,8 +277,7 @@ ByteBuffer procfs$pid_vmo(InodeIdentifier identifier)
builder.appendf("P%x%s(%u) ", builder.appendf("P%x%s(%u) ",
physical_page ? physical_page->paddr().get() : 0, physical_page ? physical_page->paddr().get() : 0,
region->should_cow(i) ? "!" : "", region->should_cow(i) ? "!" : "",
physical_page ? physical_page->retain_count() : 0 physical_page ? physical_page->retain_count() : 0);
);
} }
builder.appendf("\n"); builder.appendf("\n");
} }
@ -287,7 +288,7 @@ ByteBuffer procfs$pid_stack(InodeIdentifier identifier)
{ {
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
ProcessPagingScope paging_scope(process); ProcessPagingScope paging_scope(process);
struct RecognizedSymbol { struct RecognizedSymbol {
@ -295,7 +296,7 @@ ByteBuffer procfs$pid_stack(InodeIdentifier identifier)
const KSym* ksym; const KSym* ksym;
}; };
StringBuilder builder; StringBuilder builder;
process.for_each_thread([&] (Thread& thread) { process.for_each_thread([&](Thread& thread) {
builder.appendf("Thread %d:\n", thread.tid()); builder.appendf("Thread %d:\n", thread.tid());
Vector<RecognizedSymbol, 64> recognized_symbols; Vector<RecognizedSymbol, 64> recognized_symbols;
recognized_symbols.append({ thread.tss().eip, ksymbolicate(thread.tss().eip) }); 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)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
StringBuilder builder; StringBuilder builder;
process.for_each_thread([&] (Thread& thread) { process.for_each_thread([&](Thread& thread) {
builder.appendf("Thread %d:\n", thread.tid()); builder.appendf("Thread %d:\n", thread.tid());
auto& tss = thread.tss(); auto& tss = thread.tss();
builder.appendf("eax: %x\n", tss.eax); 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)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
auto* custody = process.executable(); auto* custody = process.executable();
ASSERT(custody); ASSERT(custody);
@ -363,7 +364,7 @@ ByteBuffer procfs$pid_cwd(InodeIdentifier identifier)
{ {
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
if (!handle) if (!handle)
return { }; return {};
return handle->process().current_directory().absolute_path().to_byte_buffer(); 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. // FIXME: This is obviously racy against the VFS mounts changing.
StringBuilder builder; StringBuilder builder;
VFS::the().for_each_mount([&builder] (auto& mount) { VFS::the().for_each_mount([&builder](auto& mount) {
auto& fs = mount.guest_fs(); auto& fs = mount.guest_fs();
builder.appendf("%s @ ", fs.class_name()); builder.appendf("%s @ ", fs.class_name());
if (!mount.host().is_valid()) if (!mount.host().is_valid())
@ -425,7 +426,7 @@ ByteBuffer procfs$df(InodeIdentifier)
{ {
// FIXME: This is obviously racy against the VFS mounts changing. // FIXME: This is obviously racy against the VFS mounts changing.
StringBuilder builder; StringBuilder builder;
VFS::the().for_each_mount([&builder] (auto& mount) { VFS::the().for_each_mount([&builder](auto& mount) {
auto& fs = mount.guest_fs(); auto& fs = mount.guest_fs();
builder.appendf("%s,", fs.class_name()); builder.appendf("%s,", fs.class_name());
builder.appendf("%u,", fs.total_block_count()); builder.appendf("%u,", fs.total_block_count());
@ -444,7 +445,7 @@ ByteBuffer procfs$cpuinfo(InodeIdentifier)
{ {
CPUID cpuid(0); CPUID cpuid(0);
builder.appendf("cpuid: "); builder.appendf("cpuid: ");
auto emit_dword = [&] (dword value) { auto emit_dword = [&](dword value) {
builder.appendf("%c%c%c%c", builder.appendf("%c%c%c%c",
value & 0xff, value & 0xff,
(value >> 8) & 0xff, (value >> 8) & 0xff,
@ -486,7 +487,7 @@ ByteBuffer procfs$cpuinfo(InodeIdentifier)
// and verifying that the returned eax>=0x80000004. // and verifying that the returned eax>=0x80000004.
char buffer[48]; char buffer[48];
dword* bufptr = reinterpret_cast<dword*>(buffer); dword* bufptr = reinterpret_cast<dword*>(buffer);
auto copy_brand_string_part_to_buffer = [&] (dword i) { auto copy_brand_string_part_to_buffer = [&](dword i) {
CPUID cpuid(0x80000002 + i); CPUID cpuid(0x80000002 + i);
*bufptr++ = cpuid.eax(); *bufptr++ = cpuid.eax();
*bufptr++ = cpuid.ebx(); *bufptr++ = cpuid.ebx();
@ -510,8 +511,7 @@ ByteBuffer procfs$kmalloc(InodeIdentifier)
"free: %u\n", "free: %u\n",
kmalloc_sum_eternal, kmalloc_sum_eternal,
sum_alloc, sum_alloc,
sum_free sum_free);
);
return builder.to_byte_buffer(); 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.super_physical_pages_in_existence() - MM.m_free_supervisor_physical_pages.size(),
MM.m_free_supervisor_physical_pages.size(), MM.m_free_supervisor_physical_pages.size(),
g_kmalloc_call_count, g_kmalloc_call_count,
g_kfree_call_count g_kfree_call_count);
);
return builder.to_byte_buffer(); return builder.to_byte_buffer();
} }
@ -561,7 +560,7 @@ ByteBuffer procfs$all(InodeIdentifier)
InterruptDisabler disabler; InterruptDisabler disabler;
auto processes = Process::all_processes(); auto processes = Process::all_processes();
StringBuilder builder(processes.size() * 80); 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", builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u,%u,%s,%u\n",
process->pid(), process->pid(),
process->main_thread().times_scheduled(), // FIXME(Thread): Bill all scheds to the process 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->amount_shared(),
process->main_thread().ticks(), // FIXME(Thread): Bill all ticks to the process process->main_thread().ticks(), // FIXME(Thread): Bill all ticks to the process
to_string(process->priority()), to_string(process->priority()),
process->syscall_count() process->syscall_count());
);
}; };
build_process_line(Scheduler::colonel()); build_process_line(Scheduler::colonel());
for (auto* process : processes) for (auto* process : processes)
@ -601,9 +599,10 @@ ByteBuffer procfs$inodes(InodeIdentifier)
} }
struct SysVariableData final : public ProcFSInodeCustomData { struct SysVariableData final : public ProcFSInodeCustomData {
virtual ~SysVariableData() override { } virtual ~SysVariableData() override {}
enum Type { enum Type
{
Invalid, Invalid,
Boolean, Boolean,
String, String,
@ -617,7 +616,7 @@ static ByteBuffer read_sys_bool(InodeIdentifier inode_id)
{ {
auto inode_ptr = ProcFS::the().get_inode(inode_id); auto inode_ptr = ProcFS::the().get_inode(inode_id);
if (!inode_ptr) if (!inode_ptr)
return { }; return {};
auto& inode = static_cast<ProcFSInode&>(*inode_ptr); auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
ASSERT(inode.custom_data()); ASSERT(inode.custom_data());
auto buffer = ByteBuffer::create_uninitialized(2); 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); auto inode_ptr = ProcFS::the().get_inode(inode_id);
if (!inode_ptr) if (!inode_ptr)
return { }; return {};
auto& inode = static_cast<ProcFSInode&>(*inode_ptr); auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
ASSERT(inode.custom_data()); ASSERT(inode.custom_data());
if (data.is_empty() || !(data[0] == '0' || data[0] == '1')) 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); auto inode_ptr = ProcFS::the().get_inode(inode_id);
if (!inode_ptr) if (!inode_ptr)
return { }; return {};
auto& inode = static_cast<ProcFSInode&>(*inode_ptr); auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
ASSERT(inode.custom_data()); ASSERT(inode.custom_data());
auto buffer = ByteBuffer::create_uninitialized(2); 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); auto inode_ptr = ProcFS::the().get_inode(inode_id);
if (!inode_ptr) if (!inode_ptr)
return { }; return {};
auto& inode = static_cast<ProcFSInode&>(*inode_ptr); auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
ASSERT(inode.custom_data()); ASSERT(inode.custom_data());
auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data()); auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
@ -730,7 +729,7 @@ const char* ProcFS::class_name() const
RetainPtr<Inode> ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, int&) RetainPtr<Inode> ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, int&)
{ {
kprintf("FIXME: Implement ProcFS::create_inode()?\n"); kprintf("FIXME: Implement ProcFS::create_inode()?\n");
return { }; return {};
} }
RetainPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error) RetainPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
@ -932,8 +931,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
callback({ entry.name, (int)strlen(entry.name), to_identifier(fsid(), PDI_PID, pid, (ProcFileType)entry.proc_file_type), 0 }); callback({ entry.name, (int)strlen(entry.name), to_identifier(fsid(), PDI_PID, pid, (ProcFileType)entry.proc_file_type), 0 });
} }
} }
} } break;
break;
case FI_PID_fd: { case FI_PID_fd: {
auto handle = ProcessInspectionHandle::from_pid(pid); auto handle = ProcessInspectionHandle::from_pid(pid);
@ -948,8 +946,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
int name_length = ksprintf(name, "%u", i); int name_length = ksprintf(name, "%u", i);
callback({ name, name_length, to_identifier_with_fd(fsid(), pid, i), 0 }); callback({ name, name_length, to_identifier_with_fd(fsid(), pid, i), 0 });
} }
} } break;
break;
default: default:
return true; return true;
} }
@ -988,7 +985,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
if (process_exists) if (process_exists)
return to_identifier(fsid(), PDI_Root, name_as_number, FI_PID); return to_identifier(fsid(), PDI_Root, name_as_number, FI_PID);
} }
return { }; return {};
} }
if (proc_file_type == FI_Root_sys) { if (proc_file_type == FI_Root_sys) {
@ -997,13 +994,13 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
if (!strcmp(entry.name, name.characters())) if (!strcmp(entry.name, name.characters()))
return sys_var_to_identifier(fsid(), i); return sys_var_to_identifier(fsid(), i);
} }
return { }; return {};
} }
if (proc_file_type == FI_PID) { if (proc_file_type == FI_PID) {
auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier())); auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier()));
if (!handle) if (!handle)
return { }; return {};
auto& process = handle->process(); auto& process = handle->process();
for (auto& entry : fs().m_entries) { for (auto& entry : fs().m_entries) {
if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) { 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) { if (proc_file_type == FI_PID_fd) {
@ -1028,13 +1025,12 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
InterruptDisabler disabler; InterruptDisabler disabler;
if (auto* process = Process::from_pid(to_pid(identifier()))) if (auto* process = Process::from_pid(to_pid(identifier())))
fd_exists = process->file_description(name_as_number); fd_exists = process->file_description(name_as_number);
} }
if (fd_exists) if (fd_exists)
return to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number); return to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number);
} }
} }
return { }; return {};
} }
void ProcFSInode::flush_metadata() void ProcFSInode::flush_metadata()
@ -1075,7 +1071,7 @@ size_t ProcFSInode::directory_entry_count() const
{ {
ASSERT(is_directory()); ASSERT(is_directory());
size_t count = 0; size_t count = 0;
traverse_as_directory([&count] (const FS::DirectoryEntry&) { traverse_as_directory([&count](const FS::DirectoryEntry&) {
++count; ++count;
return true; return true;
}); });
@ -1099,7 +1095,7 @@ ProcFS::ProcFS()
m_entries[FI_Root_all] = { "all", FI_Root_all, procfs$all }; 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_memstat] = { "memstat", FI_Root_memstat, procfs$memstat };
m_entries[FI_Root_summary] = { "summary", FI_Root_summary, procfs$summary }; 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_inodes] = { "inodes", FI_Root_inodes, procfs$inodes };
m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg }; m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg };
m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self }; m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self };

View file

@ -1,7 +1,7 @@
#include <Kernel/FileSystem/SyntheticFileSystem.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <LibC/errno_numbers.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/SyntheticFileSystem.h>
#include <LibC/errno_numbers.h>
//#define SYNTHFS_DEBUG //#define SYNTHFS_DEBUG
@ -140,13 +140,13 @@ InodeIdentifier SynthFS::root_inode() const
RetainPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, off_t size, dev_t, int& error) RetainPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, off_t size, dev_t, int& error)
{ {
(void) parentInode; (void)parentInode;
(void) name; (void)name;
(void) mode; (void)mode;
(void) size; (void)size;
(void) error; (void)error;
kprintf("FIXME: Implement SyntheticFileSystem::create_inode().\n"); kprintf("FIXME: Implement SyntheticFileSystem::create_inode().\n");
return { }; return {};
} }
RetainPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_t, int& error) RetainPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
@ -166,7 +166,7 @@ RetainPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const
LOCKER(m_lock); LOCKER(m_lock);
auto it = m_inodes.find(inode.index()); auto it = m_inodes.find(inode.index());
if (it == m_inodes.end()) if (it == m_inodes.end())
return { }; return {};
return (*it).value; return (*it).value;
} }
@ -243,7 +243,7 @@ InodeIdentifier SynthFSInode::lookup(StringView name)
if (child->m_name == name) if (child->m_name == name)
return child->identifier(); return child->identifier();
} }
return { }; return {};
} }
void SynthFSInode::flush_metadata() void SynthFSInode::flush_metadata()

View file

@ -1,12 +1,12 @@
#include "VirtualFileSystem.h" #include "VirtualFileSystem.h"
#include <Kernel/FileSystem/FileDescription.h>
#include "FileSystem.h" #include "FileSystem.h"
#include <AK/FileSystemPath.h> #include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <Kernel/Devices/CharacterDevice.h> #include <Kernel/Devices/CharacterDevice.h>
#include <LibC/errno_numbers.h>
#include <Kernel/Process.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Process.h>
#include <LibC/errno_numbers.h>
//#define VFS_DEBUG //#define VFS_DEBUG
@ -104,7 +104,7 @@ bool VFS::is_vfs_root(InodeIdentifier inode) const
void VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::DirectoryEntry&)> callback) void VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::DirectoryEntry&)> callback)
{ {
dir_inode.traverse_as_directory([&] (const FS::DirectoryEntry& entry) { dir_inode.traverse_as_directory([&](const FS::DirectoryEntry& entry) {
InodeIdentifier resolved_inode; InodeIdentifier resolved_inode;
if (auto mount = find_mount_for_host(entry.inode)) if (auto mount = find_mount_for_host(entry.inode))
resolved_inode = mount->guest(); resolved_inode = mount->guest();
@ -586,7 +586,7 @@ String VFS::Mount::absolute_path() const
InodeIdentifier VFS::Mount::host() const InodeIdentifier VFS::Mount::host() const
{ {
if (!m_host_custody) if (!m_host_custody)
return { }; return {};
return m_host_custody->inode().identifier(); return m_host_custody->inode().identifier();
} }
@ -702,11 +702,10 @@ KResultOr<Retained<Custody>> VFS::resolve_path(StringView path, Custody& base, R
// FIXME: We should limit the recursion here and return -ELOOP if it goes to deep. // FIXME: We should limit the recursion here and return -ELOOP if it goes to deep.
return resolve_path( return resolve_path(
StringView(symlink_contents.pointer(), StringView(symlink_contents.pointer(),
symlink_contents.size()), symlink_contents.size()),
*current_parent, *current_parent,
parent_custody, parent_custody,
options options);
);
} }
} }
return custody_chain.last(); return custody_chain.last();

View file

@ -1,6 +1,6 @@
#include "IRQHandler.h" #include "IRQHandler.h"
#include "i386.h"
#include "PIC.h" #include "PIC.h"
#include "i386.h"
IRQHandler::IRQHandler(byte irq) IRQHandler::IRQHandler(byte irq)
: m_irq_number(irq) : m_irq_number(irq)
@ -22,4 +22,3 @@ void IRQHandler::disable_irq()
{ {
PIC::disable(m_irq_number); PIC::disable(m_irq_number);
} }

View file

@ -13,6 +13,7 @@ public:
const String& cmdline() const { return m_cmdline; } const String& cmdline() const { return m_cmdline; }
String get(const String& key) const; String get(const String& key) const;
bool has(const String& key) const; bool has(const String& key) const;
private: private:
String m_cmdline; String m_cmdline;
HashMap<String, String> m_params; HashMap<String, String> m_params;

View file

@ -1,9 +1,9 @@
#include "KSyms.h" #include "KSyms.h"
#include "Process.h" #include "Process.h"
#include "Scheduler.h" #include "Scheduler.h"
#include <Kernel/FileSystem/FileDescription.h>
#include <AK/ELF/ELFLoader.h> #include <AK/ELF/ELFLoader.h>
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <Kernel/FileSystem/FileDescription.h>
static KSym* s_ksyms; static KSym* s_ksyms;
dword ksym_lowest_address; dword ksym_lowest_address;
@ -140,7 +140,8 @@ void dump_backtrace()
} }
TemporaryChange change(in_dump_backtrace, true); TemporaryChange change(in_dump_backtrace, true);
dword ebp; dword ebp;
asm volatile("movl %%ebp, %%eax":"=a"(ebp)); asm volatile("movl %%ebp, %%eax"
: "=a"(ebp));
dump_backtrace_impl(ebp, ksyms_ready); dump_backtrace_impl(ebp, ksyms_ready);
} }

View file

@ -1,90 +1,90 @@
#include <Kernel/IO.h>
#include <Kernel/Net/E1000NetworkAdapter.h> #include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/PCI.h> #include <Kernel/PCI.h>
#include <Kernel/IO.h>
#define REG_CTRL 0x0000 #define REG_CTRL 0x0000
#define REG_STATUS 0x0008 #define REG_STATUS 0x0008
#define REG_EEPROM 0x0014 #define REG_EEPROM 0x0014
#define REG_CTRL_EXT 0x0018 #define REG_CTRL_EXT 0x0018
#define REG_IMASK 0x00D0 #define REG_IMASK 0x00D0
#define REG_RCTRL 0x0100 #define REG_RCTRL 0x0100
#define REG_RXDESCLO 0x2800 #define REG_RXDESCLO 0x2800
#define REG_RXDESCHI 0x2804 #define REG_RXDESCHI 0x2804
#define REG_RXDESCLEN 0x2808 #define REG_RXDESCLEN 0x2808
#define REG_RXDESCHEAD 0x2810 #define REG_RXDESCHEAD 0x2810
#define REG_RXDESCTAIL 0x2818 #define REG_RXDESCTAIL 0x2818
#define REG_TCTRL 0x0400 #define REG_TCTRL 0x0400
#define REG_TXDESCLO 0x3800 #define REG_TXDESCLO 0x3800
#define REG_TXDESCHI 0x3804 #define REG_TXDESCHI 0x3804
#define REG_TXDESCLEN 0x3808 #define REG_TXDESCLEN 0x3808
#define REG_TXDESCHEAD 0x3810 #define REG_TXDESCHEAD 0x3810
#define REG_TXDESCTAIL 0x3818 #define REG_TXDESCTAIL 0x3818
#define REG_RDTR 0x2820 // RX Delay Timer Register #define REG_RDTR 0x2820 // RX Delay Timer Register
#define REG_RXDCTL 0x3828 // RX Descriptor Control #define REG_RXDCTL 0x3828 // RX Descriptor Control
#define REG_RADV 0x282C // RX Int. Absolute Delay Timer #define REG_RADV 0x282C // RX Int. Absolute Delay Timer
#define REG_RSRPD 0x2C00 // RX Small Packet Detect Interrupt #define REG_RSRPD 0x2C00 // RX Small Packet Detect Interrupt
#define REG_TIPG 0x0410 // Transmit Inter Packet Gap #define REG_TIPG 0x0410 // Transmit Inter Packet Gap
#define ECTRL_SLU 0x40 //set link up #define ECTRL_SLU 0x40 //set link up
#define RCTL_EN (1 << 1) // Receiver Enable #define RCTL_EN (1 << 1) // Receiver Enable
#define RCTL_SBP (1 << 2) // Store Bad Packets #define RCTL_SBP (1 << 2) // Store Bad Packets
#define RCTL_UPE (1 << 3) // Unicast Promiscuous Enabled #define RCTL_UPE (1 << 3) // Unicast Promiscuous Enabled
#define RCTL_MPE (1 << 4) // Multicast Promiscuous Enabled #define RCTL_MPE (1 << 4) // Multicast Promiscuous Enabled
#define RCTL_LPE (1 << 5) // Long Packet Reception Enable #define RCTL_LPE (1 << 5) // Long Packet Reception Enable
#define RCTL_LBM_NONE (0 << 6) // No Loopback #define RCTL_LBM_NONE (0 << 6) // No Loopback
#define RCTL_LBM_PHY (3 << 6) // PHY or external SerDesc 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_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_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 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_36 (0 << 12) // Multicast Offset - bits 47:36
#define RCTL_MO_35 (1 << 12) // Multicast Offset - bits 46:35 #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_34 (2 << 12) // Multicast Offset - bits 45:34
#define RCTL_MO_32 (3 << 12) // Multicast Offset - bits 43:32 #define RCTL_MO_32 (3 << 12) // Multicast Offset - bits 43:32
#define RCTL_BAM (1 << 15) // Broadcast Accept Mode #define RCTL_BAM (1 << 15) // Broadcast Accept Mode
#define RCTL_VFE (1 << 18) // VLAN Filter Enable #define RCTL_VFE (1 << 18) // VLAN Filter Enable
#define RCTL_CFIEN (1 << 19) // Canonical Form Indicator Enable #define RCTL_CFIEN (1 << 19) // Canonical Form Indicator Enable
#define RCTL_CFI (1 << 20) // Canonical Form Indicator Bit Value #define RCTL_CFI (1 << 20) // Canonical Form Indicator Bit Value
#define RCTL_DPF (1 << 22) // Discard Pause Frames #define RCTL_DPF (1 << 22) // Discard Pause Frames
#define RCTL_PMCF (1 << 23) // Pass MAC Control Frames #define RCTL_PMCF (1 << 23) // Pass MAC Control Frames
#define RCTL_SECRC (1 << 26) // Strip Ethernet CRC #define RCTL_SECRC (1 << 26) // Strip Ethernet CRC
// Buffer Sizes // Buffer Sizes
#define RCTL_BSIZE_256 (3 << 16) #define RCTL_BSIZE_256 (3 << 16)
#define RCTL_BSIZE_512 (2 << 16) #define RCTL_BSIZE_512 (2 << 16)
#define RCTL_BSIZE_1024 (1 << 16) #define RCTL_BSIZE_1024 (1 << 16)
#define RCTL_BSIZE_2048 (0 << 16) #define RCTL_BSIZE_2048 (0 << 16)
#define RCTL_BSIZE_4096 ((3 << 16) | (1 << 25)) #define RCTL_BSIZE_4096 ((3 << 16) | (1 << 25))
#define RCTL_BSIZE_8192 ((2 << 16) | (1 << 25)) #define RCTL_BSIZE_8192 ((2 << 16) | (1 << 25))
#define RCTL_BSIZE_16384 ((1 << 16) | (1 << 25)) #define RCTL_BSIZE_16384 ((1 << 16) | (1 << 25))
// Transmit Command // Transmit Command
#define CMD_EOP (1 << 0) // End of Packet #define CMD_EOP (1 << 0) // End of Packet
#define CMD_IFCS (1 << 1) // Insert FCS #define CMD_IFCS (1 << 1) // Insert FCS
#define CMD_IC (1 << 2) // Insert Checksum #define CMD_IC (1 << 2) // Insert Checksum
#define CMD_RS (1 << 3) // Report Status #define CMD_RS (1 << 3) // Report Status
#define CMD_RPS (1 << 4) // Report Packet Sent #define CMD_RPS (1 << 4) // Report Packet Sent
#define CMD_VLE (1 << 6) // VLAN Packet Enable #define CMD_VLE (1 << 6) // VLAN Packet Enable
#define CMD_IDE (1 << 7) // Interrupt Delay Enable #define CMD_IDE (1 << 7) // Interrupt Delay Enable
// TCTL Register // TCTL Register
#define TCTL_EN (1 << 1) // Transmit Enable #define TCTL_EN (1 << 1) // Transmit Enable
#define TCTL_PSP (1 << 3) // Pad Short Packets #define TCTL_PSP (1 << 3) // Pad Short Packets
#define TCTL_CT_SHIFT 4 // Collision Threshold #define TCTL_CT_SHIFT 4 // Collision Threshold
#define TCTL_COLD_SHIFT 12 // Collision Distance #define TCTL_COLD_SHIFT 12 // Collision Distance
#define TCTL_SWXOFF (1 << 22) // Software XOFF Transmission #define TCTL_SWXOFF (1 << 22) // Software XOFF Transmission
#define TCTL_RTLC (1 << 24) // Re-transmit on Late Collision #define TCTL_RTLC (1 << 24) // Re-transmit on Late Collision
#define TSTA_DD (1 << 0) // Descriptor Done #define TSTA_DD (1 << 0) // Descriptor Done
#define TSTA_EC (1 << 1) // Excess Collisions #define TSTA_EC (1 << 1) // Excess Collisions
#define TSTA_LC (1 << 2) // Late Collision #define TSTA_LC (1 << 2) // Late Collision
#define LSTA_TU (1 << 3) // Transmit Underrun #define LSTA_TU (1 << 3) // Transmit Underrun
OwnPtr<E1000NetworkAdapter> E1000NetworkAdapter::autodetect() OwnPtr<E1000NetworkAdapter> E1000NetworkAdapter::autodetect()
{ {
static const PCI::ID qemu_bochs_vbox_id = { 0x8086, 0x100e }; static const PCI::ID qemu_bochs_vbox_id = { 0x8086, 0x100e };
PCI::Address found_address; 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) { if (id == qemu_bochs_vbox_id) {
found_address = address; found_address = address;
return; return;
@ -231,7 +231,7 @@ void E1000NetworkAdapter::initialize_rx_descriptors()
out32(REG_RXDESCHEAD, 0); out32(REG_RXDESCHEAD, 0);
out32(REG_RXDESCTAIL, number_of_rx_descriptors - 1); 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() void E1000NetworkAdapter::initialize_tx_descriptors()

View file

@ -1,17 +1,17 @@
#include <Kernel/Net/IPv4Socket.h>
#include <Kernel/Net/TCPSocket.h>
#include <Kernel/Net/UDPSocket.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/Process.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/ICMP.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/UDP.h>
#include <Kernel/Net/ARP.h>
#include <Kernel/Net/Routing.h>
#include <LibC/errno_numbers.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Net/ARP.h>
#include <Kernel/Net/ICMP.h>
#include <Kernel/Net/IPv4.h>
#include <Kernel/Net/IPv4Socket.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Net/Routing.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/TCPSocket.h>
#include <Kernel/Net/UDP.h>
#include <Kernel/Net/UDPSocket.h>
#include <Kernel/Process.h>
#include <Kernel/UnixTypes.h>
#include <LibC/errno_numbers.h>
#define IPV4_SOCKET_DEBUG #define IPV4_SOCKET_DEBUG

View file

@ -1,8 +1,8 @@
#include <Kernel/Net/LocalSocket.h>
#include <Kernel/UnixTypes.h>
#include <Kernel/Process.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Net/LocalSocket.h>
#include <Kernel/Process.h>
#include <Kernel/UnixTypes.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
//#define DEBUG_LOCAL_SOCKET //#define DEBUG_LOCAL_SOCKET

View file

@ -1,10 +1,10 @@
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Net/EthernetFrameHeader.h>
#include <Kernel/Net/EtherType.h>
#include <Kernel/StdLib.h>
#include <Kernel/kmalloc.h>
#include <AK/HashTable.h> #include <AK/HashTable.h>
#include <Kernel/Lock.h> #include <Kernel/Lock.h>
#include <Kernel/Net/EtherType.h>
#include <Kernel/Net/EthernetFrameHeader.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/StdLib.h>
#include <Kernel/kmalloc.h>
static Lockable<HashTable<NetworkAdapter*>>& all_adapters() static Lockable<HashTable<NetworkAdapter*>>& all_adapters()
{ {
@ -81,7 +81,7 @@ ByteBuffer NetworkAdapter::dequeue_packet()
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
if (m_packet_queue.is_empty()) if (m_packet_queue.is_empty())
return { }; return {};
return m_packet_queue.take_first(); return m_packet_queue.take_first();
} }

View file

@ -1,18 +1,17 @@
#include <Kernel/Net/E1000NetworkAdapter.h> #include <Kernel/Lock.h>
#include <Kernel/Net/EthernetFrameHeader.h>
#include <Kernel/Net/ARP.h> #include <Kernel/Net/ARP.h>
#include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/Net/EtherType.h>
#include <Kernel/Net/EthernetFrameHeader.h>
#include <Kernel/Net/ICMP.h> #include <Kernel/Net/ICMP.h>
#include <Kernel/Net/UDP.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/IPv4.h> #include <Kernel/Net/IPv4.h>
#include <Kernel/Net/IPv4Socket.h> #include <Kernel/Net/IPv4Socket.h>
#include <Kernel/Net/TCPSocket.h>
#include <Kernel/Net/UDPSocket.h>
#include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/TCPSocket.h>
#include <Kernel/Net/UDP.h>
#include <Kernel/Net/UDPSocket.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Net/EtherType.h>
#include <Kernel/Lock.h>
//#define ETHERNET_DEBUG //#define ETHERNET_DEBUG
#define IPV4_DEBUG #define IPV4_DEBUG
@ -36,7 +35,7 @@ Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
class CombinedPacketQueueAlarm : public Alarm { class CombinedPacketQueueAlarm : public Alarm {
public: public:
CombinedPacketQueueAlarm() { } CombinedPacketQueueAlarm() {}
virtual bool is_ringing() const override virtual bool is_ringing() const override
{ {
@ -61,7 +60,7 @@ void NetworkTask_main()
if (adapter) if (adapter)
adapter->set_ipv4_address(IPv4Address(192, 168, 5, 2)); adapter->set_ipv4_address(IPv4Address(192, 168, 5, 2));
auto dequeue_packet = [&] () -> ByteBuffer { auto dequeue_packet = [&]() -> ByteBuffer {
auto packet = LoopbackAdapter::the().dequeue_packet(); auto packet = LoopbackAdapter::the().dequeue_packet();
if (!packet.is_null()) { if (!packet.is_null()) {
dbgprintf("Receive loopback packet (%d bytes)\n", packet.size()); dbgprintf("Receive loopback packet (%d bytes)\n", packet.size());
@ -69,7 +68,7 @@ void NetworkTask_main()
} }
if (adapter && adapter->has_queued_packets()) if (adapter && adapter->has_queued_packets())
return adapter->dequeue_packet(); return adapter->dequeue_packet();
return { }; return {};
}; };
CombinedPacketQueueAlarm queue_alarm; CombinedPacketQueueAlarm queue_alarm;
@ -91,8 +90,7 @@ void NetworkTask_main()
eth.source().to_string().characters(), eth.source().to_string().characters(),
eth.destination().to_string().characters(), eth.destination().to_string().characters(),
eth.ether_type(), eth.ether_type(),
packet.size() packet.size());
);
#endif #endif
switch (eth.ether_type()) { 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)) { if (packet.hardware_type() != 1 || packet.hardware_address_length() != sizeof(MACAddress)) {
kprintf("handle_arp: Hardware type not ethernet (%w, len=%u)\n", kprintf("handle_arp: Hardware type not ethernet (%w, len=%u)\n",
packet.hardware_type(), packet.hardware_type(),
packet.hardware_address_length() packet.hardware_address_length());
);
return; return;
} }
if (packet.protocol_type() != EtherType::IPv4 || packet.protocol_address_length() != sizeof(IPv4Address)) { if (packet.protocol_type() != EtherType::IPv4 || packet.protocol_address_length() != sizeof(IPv4Address)) {
kprintf("handle_arp: Protocol type not IPv4 (%w, len=%u)\n", kprintf("handle_arp: Protocol type not IPv4 (%w, len=%u)\n",
packet.hardware_type(), packet.hardware_type(),
packet.protocol_address_length() packet.protocol_address_length());
);
return; return;
} }
@ -135,8 +131,7 @@ void handle_arp(const EthernetFrameHeader& eth, int frame_size)
packet.sender_hardware_address().to_string().characters(), packet.sender_hardware_address().to_string().characters(),
packet.sender_protocol_address().to_string().characters(), packet.sender_protocol_address().to_string().characters(),
packet.target_hardware_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 #endif
if (packet.operation() == ARPOperation::Request) { 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())) { if (auto* adapter = NetworkAdapter::from_ipv4_address(packet.target_protocol_address())) {
// We do! // We do!
kprintf("handle_arp: Responding to ARP request for my IPv4 address (%s)\n", 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; ARPPacket response;
response.set_operation(ARPOperation::Response); response.set_operation(ARPOperation::Response);
response.set_target_hardware_address(packet.sender_hardware_address()); 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 #ifdef IPV4_DEBUG
kprintf("handle_ipv4: source=%s, target=%s\n", kprintf("handle_ipv4: source=%s, target=%s\n",
packet.source().to_string().characters(), packet.source().to_string().characters(),
packet.destination().to_string().characters() packet.destination().to_string().characters());
);
#endif #endif
switch ((IPv4Protocol)packet.protocol()) { 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.source().to_string().characters(),
ipv4_packet.destination().to_string().characters(), ipv4_packet.destination().to_string().characters(),
icmp_header.type(), icmp_header.type(),
icmp_header.code() icmp_header.code());
);
#endif #endif
{ {
@ -231,10 +224,9 @@ void handle_icmp(const EthernetFrameHeader& eth, int frame_size)
if (icmp_header.type() == ICMPType::EchoRequest) { if (icmp_header.type() == ICMPType::EchoRequest) {
auto& request = reinterpret_cast<const ICMPEchoPacket&>(icmp_header); auto& request = reinterpret_cast<const ICMPEchoPacket&>(icmp_header);
kprintf("handle_icmp: EchoRequest from %s: id=%u, seq=%u\n", kprintf("handle_icmp: EchoRequest from %s: id=%u, seq=%u\n",
ipv4_packet.source().to_string().characters(), ipv4_packet.source().to_string().characters(),
(word)request.identifier, (word)request.identifier,
(word)request.sequence_number (word)request.sequence_number);
);
size_t icmp_packet_size = ipv4_packet.payload_size(); size_t icmp_packet_size = ipv4_packet.payload_size();
auto buffer = ByteBuffer::create_zeroed(icmp_packet_size); auto buffer = ByteBuffer::create_zeroed(icmp_packet_size);
auto& response = *(ICMPEchoPacket*)buffer.pointer(); auto& response = *(ICMPEchoPacket*)buffer.pointer();
@ -267,8 +259,7 @@ void handle_udp(const EthernetFrameHeader& eth, int frame_size)
udp_packet.source_port(), udp_packet.source_port(),
ipv4_packet.destination().to_string().characters(), ipv4_packet.destination().to_string().characters(),
udp_packet.destination_port(), udp_packet.destination_port(),
udp_packet.length() udp_packet.length());
);
#endif #endif
auto socket = UDPSocket::from_port(udp_packet.destination_port()); 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_syn() ? "SYN" : "",
tcp_packet.has_ack() ? "ACK" : "", tcp_packet.has_ack() ? "ACK" : "",
tcp_packet.window_size(), tcp_packet.window_size(),
payload_size payload_size);
);
#endif #endif
auto socket = TCPSocket::from_port(tcp_packet.destination_port()); 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); 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", 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.ack_number(),
tcp_packet.sequence_number(), tcp_packet.sequence_number(),
payload_size, payload_size,
socket->ack_number(), socket->ack_number(),
socket->sequence_number() socket->sequence_number());
);
socket->send_tcp_packet(TCPFlags::ACK); socket->send_tcp_packet(TCPFlags::ACK);
if (payload_size != 0) if (payload_size != 0)

View file

@ -1,5 +1,5 @@
#include <Kernel/Net/Routing.h>
#include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/Routing.h>
NetworkAdapter* adapter_for_route_to(const IPv4Address& ipv4_address) NetworkAdapter* adapter_for_route_to(const IPv4Address& ipv4_address)
{ {

View file

@ -1,9 +1,9 @@
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Net/Socket.h>
#include <Kernel/Net/LocalSocket.h>
#include <Kernel/Net/IPv4Socket.h> #include <Kernel/Net/IPv4Socket.h>
#include <Kernel/UnixTypes.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/Net/Socket.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/UnixTypes.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
KResultOr<Retained<Socket>> Socket::create(int domain, int type, int protocol) KResultOr<Retained<Socket>> Socket::create(int domain, int type, int protocol)

View file

@ -1,9 +1,9 @@
#include <Kernel/Net/TCPSocket.h> #include <Kernel/Devices/RandomDevice.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/NetworkAdapter.h> #include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Net/Routing.h> #include <Kernel/Net/Routing.h>
#include <Kernel/Net/TCP.h>
#include <Kernel/Net/TCPSocket.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Devices/RandomDevice.h>
Lockable<HashMap<word, TCPSocket*>>& TCPSocket::sockets_by_port() Lockable<HashMap<word, TCPSocket*>>& TCPSocket::sockets_by_port()
{ {
@ -20,14 +20,13 @@ TCPSocketHandle TCPSocket::from_port(word port)
LOCKER(sockets_by_port().lock()); LOCKER(sockets_by_port().lock());
auto it = sockets_by_port().resource().find(port); auto it = sockets_by_port().resource().find(port);
if (it == sockets_by_port().resource().end()) if (it == sockets_by_port().resource().end())
return { }; return {};
socket = (*it).value; socket = (*it).value;
ASSERT(socket); ASSERT(socket);
} }
return { move(socket) }; return { move(socket) };
} }
TCPSocket::TCPSocket(int protocol) TCPSocket::TCPSocket(int protocol)
: IPv4Socket(SOCK_STREAM, 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_syn() ? "SYN" : "",
tcp_packet.has_ack() ? "ACK" : "", tcp_packet.has_ack() ? "ACK" : "",
tcp_packet.sequence_number(), tcp_packet.sequence_number(),
tcp_packet.ack_number() tcp_packet.ack_number());
);
adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, move(buffer)); adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, move(buffer));
} }
NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket& packet, word payload_size) NetworkOrdered<word> 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 source;
IPv4Address destination; IPv4Address destination;
byte zero; byte zero;

View file

@ -1,9 +1,9 @@
#include <Kernel/Net/UDPSocket.h>
#include <Kernel/Net/UDP.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Process.h>
#include <Kernel/Devices/RandomDevice.h> #include <Kernel/Devices/RandomDevice.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Net/Routing.h> #include <Kernel/Net/Routing.h>
#include <Kernel/Net/UDP.h>
#include <Kernel/Net/UDPSocket.h>
#include <Kernel/Process.h>
Lockable<HashMap<word, UDPSocket*>>& UDPSocket::sockets_by_port() Lockable<HashMap<word, UDPSocket*>>& UDPSocket::sockets_by_port()
{ {
@ -20,14 +20,13 @@ UDPSocketHandle UDPSocket::from_port(word port)
LOCKER(sockets_by_port().lock()); LOCKER(sockets_by_port().lock());
auto it = sockets_by_port().resource().find(port); auto it = sockets_by_port().resource().find(port);
if (it == sockets_by_port().resource().end()) if (it == sockets_by_port().resource().end())
return { }; return {};
socket = (*it).value; socket = (*it).value;
ASSERT(socket); ASSERT(socket);
} }
return { move(socket) }; return { move(socket) };
} }
UDPSocket::UDPSocket(int protocol) UDPSocket::UDPSocket(int protocol)
: IPv4Socket(SOCK_DGRAM, protocol) : IPv4Socket(SOCK_DGRAM, protocol)
{ {

View file

@ -1,32 +1,32 @@
#include <Kernel/PCI.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/PCI.h>
#define PCI_VENDOR_ID 0x00 // word #define PCI_VENDOR_ID 0x00 // word
#define PCI_DEVICE_ID 0x02 // word #define PCI_DEVICE_ID 0x02 // word
#define PCI_COMMAND 0x04 // word #define PCI_COMMAND 0x04 // word
#define PCI_STATUS 0x06 // word #define PCI_STATUS 0x06 // word
#define PCI_REVISION_ID 0x08 // byte #define PCI_REVISION_ID 0x08 // byte
#define PCI_PROG_IF 0x09 // byte #define PCI_PROG_IF 0x09 // byte
#define PCI_SUBCLASS 0x0a // byte #define PCI_SUBCLASS 0x0a // byte
#define PCI_CLASS 0x0b // byte #define PCI_CLASS 0x0b // byte
#define PCI_CACHE_LINE_SIZE 0x0c // byte #define PCI_CACHE_LINE_SIZE 0x0c // byte
#define PCI_LATENCY_TIMER 0x0d // byte #define PCI_LATENCY_TIMER 0x0d // byte
#define PCI_HEADER_TYPE 0x0e // byte #define PCI_HEADER_TYPE 0x0e // byte
#define PCI_BIST 0x0f // byte #define PCI_BIST 0x0f // byte
#define PCI_BAR0 0x10 // dword #define PCI_BAR0 0x10 // dword
#define PCI_BAR1 0x14 // dword #define PCI_BAR1 0x14 // dword
#define PCI_BAR2 0x18 // dword #define PCI_BAR2 0x18 // dword
#define PCI_BAR3 0x1C // dword #define PCI_BAR3 0x1C // dword
#define PCI_BAR4 0x20 // dword #define PCI_BAR4 0x20 // dword
#define PCI_BAR5 0x24 // dword #define PCI_BAR5 0x24 // dword
#define PCI_INTERRUPT_LINE 0x3C // byte #define PCI_INTERRUPT_LINE 0x3C // byte
#define PCI_SECONDARY_BUS 0x19 // byte #define PCI_SECONDARY_BUS 0x19 // byte
#define PCI_HEADER_TYPE_DEVICE 0 #define PCI_HEADER_TYPE_DEVICE 0
#define PCI_HEADER_TYPE_BRIDGE 1 #define PCI_HEADER_TYPE_BRIDGE 1
#define PCI_TYPE_BRIDGE 0x0604 #define PCI_TYPE_BRIDGE 0x0604
#define PCI_ADDRESS_PORT 0xCF8 #define PCI_ADDRESS_PORT 0xCF8
#define PCI_VALUE_PORT 0xCFC #define PCI_VALUE_PORT 0xCFC
#define PCI_NONE 0xFFFF #define PCI_NONE 0xFFFF
namespace PCI { namespace PCI {

View file

@ -1,17 +1,17 @@
#include <AK/Types.h>
#include "i386.h"
#include "IO.h"
#include "PIC.h" #include "PIC.h"
#include "Assertions.h" #include "Assertions.h"
#include "IO.h"
#include "i386.h"
#include <AK/Types.h>
// The slave 8259 is connected to the master's IRQ2 line. // The slave 8259 is connected to the master's IRQ2 line.
// This is really only to enhance clarity. // This is really only to enhance clarity.
#define SLAVE_INDEX 2 #define SLAVE_INDEX 2
#define PIC0_CTL 0x20 #define PIC0_CTL 0x20
#define PIC0_CMD 0x21 #define PIC0_CMD 0x21
#define PIC1_CTL 0xA0 #define PIC1_CTL 0xA0
#define PIC1_CMD 0xA1 #define PIC1_CMD 0xA1
#ifdef DEBUG_PIC #ifdef DEBUG_PIC
static bool initialized; static bool initialized;
@ -74,7 +74,7 @@ void initialize()
/* ICW4 (set x86 mode) */ /* ICW4 (set x86 mode) */
IO::out8(PIC0_CMD, 0x01); IO::out8(PIC0_CMD, 0x01);
IO::out8(PIC1_CMD, 0x01 ); IO::out8(PIC1_CMD, 0x01);
// Mask -- start out with all IRQs disabled. // Mask -- start out with all IRQs disabled.
IO::out8(PIC0_CMD, 0xff); IO::out8(PIC0_CMD, 0xff);

View file

@ -1,31 +1,31 @@
#include <AK/Types.h>
#include "Process.h" #include "Process.h"
#include "kmalloc.h"
#include "StdLib.h"
#include "i386.h"
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Devices/NullDevice.h>
#include <Kernel/VM/MemoryManager.h>
#include "i8253.h"
#include "RTC.h"
#include <AK/StdLibExtras.h>
#include <LibC/signal_numbers.h>
#include <LibC/errno_numbers.h>
#include "Syscall.h"
#include "Scheduler.h"
#include <Kernel/FileSystem/FIFO.h>
#include "KSyms.h" #include "KSyms.h"
#include <Kernel/Net/Socket.h> #include "RTC.h"
#include <Kernel/TTY/MasterPTY.h> #include "Scheduler.h"
#include <AK/ELF/exec_elf.h> #include "StdLib.h"
#include "Syscall.h"
#include "i386.h"
#include "i8253.h"
#include "kmalloc.h"
#include <AK/ELF/ELFLoader.h> #include <AK/ELF/ELFLoader.h>
#include <AK/ELF/exec_elf.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <Kernel/SharedMemory.h> #include <AK/Types.h>
#include <Kernel/ProcessTracer.h> #include <Kernel/Devices/NullDevice.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Multiboot.h> #include <Kernel/Multiboot.h>
#include <Kernel/Net/Socket.h>
#include <Kernel/ProcessTracer.h>
#include <Kernel/SharedMemory.h>
#include <Kernel/TTY/MasterPTY.h>
#include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h>
#include <LibC/signal_numbers.h>
//#define DEBUG_POLL_SELECT //#define DEBUG_POLL_SELECT
//#define DEBUG_IO //#define DEBUG_IO
@ -299,7 +299,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
// FIXME(Thread): Kill any threads the moment we commit to the exec(). // FIXME(Thread): Kill any threads the moment we commit to the exec().
if (thread_count() != 1) { if (thread_count() != 1) {
dbgprintf("Gonna die because I have many threads! These are the threads:\n"); 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()); dbgprintf("Thread{%p}: TID=%d, PID=%d\n", &thread, thread.tid(), thread.pid());
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
@ -307,7 +307,6 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
auto parts = path.split('/'); auto parts = path.split('/');
if (parts.is_empty()) if (parts.is_empty())
return -ENOENT; return -ENOENT;
@ -349,7 +348,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
auto old_regions = move(m_regions); auto old_regions = move(m_regions);
m_regions.append(*region); m_regions.append(*region);
loader = make<ELFLoader>(region->laddr().as_ptr()); loader = make<ELFLoader>(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(size);
ASSERT(alignment == PAGE_SIZE); ASSERT(alignment == PAGE_SIZE);
int prot = 0; int prot = 0;
@ -359,10 +358,10 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
prot |= PROT_WRITE; prot |= PROT_WRITE;
if (is_executable) if (is_executable)
prot |= PROT_EXEC; 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(); 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(size);
ASSERT(alignment == PAGE_SIZE); ASSERT(alignment == PAGE_SIZE);
int prot = 0; int prot = 0;
@ -370,7 +369,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
prot |= PROT_READ; prot |= PROT_READ;
if (is_writable) if (is_writable)
prot |= PROT_WRITE; prot |= PROT_WRITE;
(void) allocate_region(laddr, size, String(name), prot); (void)allocate_region(laddr, size, String(name), prot);
return laddr.as_ptr(); return laddr.as_ptr();
}; };
bool success = loader->load(); bool success = loader->load();
@ -406,7 +405,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
auto& daf = m_fds[i]; auto& daf = m_fds[i];
if (daf.descriptor && daf.flags & FD_CLOEXEC) { if (daf.descriptor && daf.flags & FD_CLOEXEC) {
daf.descriptor->close(); daf.descriptor->close();
daf = { }; daf = {};
} }
} }
@ -636,7 +635,7 @@ Process::~Process()
m_main_thread = nullptr; m_main_thread = nullptr;
Vector<Thread*, 16> my_threads; Vector<Thread*, 16> my_threads;
for_each_thread([&my_threads] (auto& thread) { for_each_thread([&my_threads](auto& thread) {
my_threads.append(&thread); my_threads.append(&thread);
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
@ -973,7 +972,7 @@ int Process::sys$close(int fd)
if (!descriptor) if (!descriptor)
return -EBADF; return -EBADF;
int rc = descriptor->close(); int rc = descriptor->close();
m_fds[fd] = { }; m_fds[fd] = {};
return rc; 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) int Process::sys$fcntl(int fd, int cmd, dword arg)
{ {
(void) cmd; (void)cmd;
(void) arg; (void)arg;
dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg); dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg);
auto* descriptor = file_description(fd); auto* descriptor = file_description(fd);
if (!descriptor) if (!descriptor)
@ -1183,7 +1182,7 @@ int Process::sys$killpg(int pgrp, int signum)
{ {
if (signum < 1 || signum >= 32) if (signum < 1 || signum >= 32)
return -EINVAL; return -EINVAL;
(void) pgrp; (void)pgrp;
ASSERT_NOT_REACHED(); 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); dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
// FIXME: Respect options // FIXME: Respect options
(void) options; (void)options;
if (wstatus) if (wstatus)
if (!validate_write_typed(wstatus)) if (!validate_write_typed(wstatus))
return -EFAULT; return -EFAULT;
@ -1405,7 +1404,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
if (waitee == -1) { if (waitee == -1) {
pid_t reaped_pid = 0; pid_t reaped_pid = 0;
InterruptDisabler disabler; InterruptDisabler disabler;
for_each_child([&reaped_pid, &exit_status] (Process& process) { for_each_child([&reaped_pid, &exit_status](Process& process) {
if (process.is_dead()) { if (process.is_dead()) {
reaped_pid = process.pid(); reaped_pid = process.pid();
exit_status = reap(process); 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; return current->m_waitee_pid;
} }
enum class KernelMemoryCheckResult
enum class KernelMemoryCheckResult { {
NotInsideKernelMemory, NotInsideKernelMemory,
AccessGranted, AccessGranted,
AccessDenied AccessDenied
@ -1556,7 +1555,7 @@ pid_t Process::sys$setsid()
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
bool found_process_with_same_pgid_as_my_pid = false; 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; found_process_with_same_pgid_as_my_pid = true;
return false; return false;
}); });
@ -1781,7 +1780,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
current->m_select_has_timeout = false; 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(); vector.clear_with_capacity();
if (!fds) if (!fds)
return 0; return 0;
@ -1809,7 +1808,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
current->block(Thread::State::BlockedSelect); current->block(Thread::State::BlockedSelect);
int marked_fd_count = 0; 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) if (!fds)
return; return;
FD_ZERO(fds); 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->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->writefds, current->m_select_write_fds, [](auto& descriptor) { return descriptor.can_write(); });
// FIXME: We should also mark params->exceptfds as appropriate. // FIXME: We should also mark params->exceptfds as appropriate.
return marked_fd_count; return marked_fd_count;
} }
@ -1998,7 +1997,7 @@ void Process::die()
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
for_each_thread([] (Thread& thread) { for_each_thread([](Thread& thread) {
if (thread.state() != Thread::State::Dead) if (thread.state() != Thread::State::Dead)
thread.set_state(Thread::State::Dying); thread.set_state(Thread::State::Dying);
return IterationDecision::Continue; return IterationDecision::Continue;
@ -2189,7 +2188,7 @@ ssize_t Process::sys$recvfrom(const Syscall::SC_recvfrom_params* params)
if (!validate_write(addr, *addr_length)) if (!validate_write(addr, *addr_length))
return -EFAULT; return -EFAULT;
} else if (addr) { } else if (addr) {
return -EINVAL; return -EINVAL;
} }
auto* descriptor = file_description(sockfd); auto* descriptor = file_description(sockfd);
if (!descriptor) 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); shared_buffer->m_pid1_region->set_shared(true);
*buffer = shared_buffer->m_pid1_region->laddr().as_ptr(); *buffer = shared_buffer->m_pid1_region->laddr().as_ptr();
#ifdef SHARED_BUFFER_DEBUG #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 #endif
shared_buffers().resource().set(shared_buffer_id, move(shared_buffer)); shared_buffers().resource().set(shared_buffer_id, move(shared_buffer));
return shared_buffer_id; 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) const char* to_string(Process::Priority priority)
{ {
switch (priority) { switch (priority) {
case Process::IdlePriority: return "Idle"; case Process::IdlePriority:
case Process::LowPriority: return "Low"; return "Idle";
case Process::NormalPriority: return "Normal"; case Process::LowPriority:
case Process::HighPriority: return "High"; return "Low";
case Process::NormalPriority:
return "Normal";
case Process::HighPriority:
return "High";
} }
kprintf("to_string(Process::Priority): Invalid priority: %u\n", priority); kprintf("to_string(Process::Priority): Invalid priority: %u\n", priority);
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
@ -2602,14 +2605,14 @@ void Process::send_signal(byte signal, Process* sender)
int Process::thread_count() const int Process::thread_count() const
{ {
int count = 0; int count = 0;
for_each_thread([&count] (auto&) { for_each_thread([&count](auto&) {
++count; ++count;
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
return count; 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*))) if (!validate_read((const void*)entry, sizeof(void*)))
return -EFAULT; return -EFAULT;
@ -2648,7 +2651,7 @@ int Process::sys$donate(int tid)
return -EINVAL; return -EINVAL;
InterruptDisabler disabler; InterruptDisabler disabler;
Thread* beneficiary = nullptr; Thread* beneficiary = nullptr;
for_each_thread([&] (Thread& thread) { for_each_thread([&](Thread& thread) {
if (thread.tid() == tid) { if (thread.tid() == tid) {
beneficiary = &thread; beneficiary = &thread;
return IterationDecision::Abort; return IterationDecision::Abort;

View file

@ -1,15 +1,13 @@
#include <Kernel/ProcessTracer.h>
#include <AK/kstdio.h> #include <AK/kstdio.h>
#include <Kernel/ProcessTracer.h>
ProcessTracer::ProcessTracer(pid_t pid) ProcessTracer::ProcessTracer(pid_t pid)
: m_pid(pid) : m_pid(pid)
{ {
} }
ProcessTracer::~ProcessTracer() ProcessTracer::~ProcessTracer()
{ {
} }
void ProcessTracer::did_syscall(dword function, dword arg1, dword arg2, dword arg3, dword result) void ProcessTracer::did_syscall(dword function, dword arg1, dword arg2, dword arg3, dword result)

View file

@ -7,7 +7,7 @@ namespace RTC {
static time_t s_boot_time; static time_t s_boot_time;
void initialize() void initialize()
{ {
byte cmos_mode = CMOS::read(0x0b); byte cmos_mode = CMOS::read(0x0b);
cmos_mode |= 2; // 24 hour mode cmos_mode |= 2; // 24 hour mode
cmos_mode |= 4; // No BCD mode cmos_mode |= 4; // No BCD mode
@ -116,12 +116,11 @@ time_t now()
ASSERT(year >= 2018); ASSERT(year >= 2018);
return days_in_years_since_epoch(year - 1) * 86400 return days_in_years_since_epoch(year - 1) * 86400
+ days_in_months_since_start_of_year(month - 1, year) * 86400 + days_in_months_since_start_of_year(month - 1, year) * 86400
+ (day - 1) * 86400 + (day - 1) * 86400
+ hour * 3600 + hour * 3600
+ minute * 60 + minute * 60
+ second; + second;
} }
} }

View file

@ -4,8 +4,8 @@
#include "i8253.h" #include "i8253.h"
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <Kernel/Alarm.h> #include <Kernel/Alarm.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Devices/PCSpeaker.h> #include <Kernel/Devices/PCSpeaker.h>
#include <Kernel/FileSystem/FileDescription.h>
//#define LOG_EVERY_CONTEXT_SWITCH //#define LOG_EVERY_CONTEXT_SWITCH
//#define SCHEDULER_DEBUG //#define SCHEDULER_DEBUG
@ -72,7 +72,7 @@ bool Scheduler::pick_next()
auto now_usec = now.tv_usec; auto now_usec = now.tv_usec;
// Check and unblock threads whose wait conditions have been met. // 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(); auto& process = thread.process();
if (thread.state() == Thread::BlockedSleep) { if (thread.state() == Thread::BlockedSleep) {
@ -82,7 +82,7 @@ bool Scheduler::pick_next()
} }
if (thread.state() == Thread::BlockedWait) { if (thread.state() == Thread::BlockedWait) {
process.for_each_child([&] (Process& child) { process.for_each_child([&](Process& child) {
if (!child.is_dead()) if (!child.is_dead())
return true; return true;
if (thread.waitee_pid() == -1 || thread.waitee_pid() == child.pid()) { if (thread.waitee_pid() == -1 || thread.waitee_pid() == child.pid()) {
@ -180,7 +180,7 @@ bool Scheduler::pick_next()
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
Process::for_each([&] (Process& process) { Process::for_each([&](Process& process) {
if (process.is_dead()) { if (process.is_dead()) {
if (current != &process.main_thread() && (!process.ppid() || !Process::from_pid(process.ppid()))) { if (current != &process.main_thread() && (!process.ppid() || !Process::from_pid(process.ppid()))) {
auto name = process.name(); auto name = process.name();
@ -199,7 +199,7 @@ bool Scheduler::pick_next()
// Dispatch any pending signals. // Dispatch any pending signals.
// FIXME: Do we really need this to be a separate pass over the process list? // 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()) if (!thread.has_unmasked_pending_signals())
return true; return true;
// FIXME: It would be nice if the Scheduler didn't have to worry about who is "current" // 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; InterruptDisabler disabler;
ASSERT(current); 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()) if (!pick_next())
return false; 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(); switch_now();
return true; return true;
} }
@ -312,9 +312,7 @@ void Scheduler::switch_now()
descriptor.type = 9; descriptor.type = 9;
flush_gdt(); flush_gdt();
asm("sti\n" asm("sti\n"
"ljmp *(%%eax)\n" "ljmp *(%%eax)\n" ::"a"(&current->far_ptr()));
::"a"(&current->far_ptr())
);
} }
bool Scheduler::context_switch(Thread& thread) bool Scheduler::context_switch(Thread& thread)
@ -333,9 +331,9 @@ bool Scheduler::context_switch(Thread& thread)
#ifdef LOG_EVERY_CONTEXT_SWITCH #ifdef LOG_EVERY_CONTEXT_SWITCH
dbgprintf("Scheduler: %s(%u:%u) -> %s(%u:%u) %w:%x\n", dbgprintf("Scheduler: %s(%u:%u) -> %s(%u:%u) %w:%x\n",
current->process().name().characters(), current->process().pid(), current->tid(), current->process().name().characters(), current->process().pid(), current->tid(),
thread.process().name().characters(), thread.process().pid(), thread.tid(), thread.process().name().characters(), thread.process().pid(), thread.tid(),
thread.tss().cs, thread.tss().eip); thread.tss().cs, thread.tss().eip);
#endif #endif
} }
@ -456,6 +454,5 @@ void Scheduler::timer_tick(RegisterDump& regs)
asm( asm(
"pushf\n" "pushf\n"
"orl $0x00004000, (%esp)\n" "orl $0x00004000, (%esp)\n"
"popf\n" "popf\n");
);
} }

View file

@ -1,8 +1,8 @@
#include <Kernel/SharedMemory.h> #include <AK/HashMap.h>
#include <Kernel/VM/VMObject.h>
#include <Kernel/Lock.h> #include <Kernel/Lock.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <AK/HashMap.h> #include <Kernel/SharedMemory.h>
#include <Kernel/VM/VMObject.h>
Lockable<HashMap<String, RetainPtr<SharedMemory>>>& shared_memories() Lockable<HashMap<String, RetainPtr<SharedMemory>>>& shared_memories()
{ {

View file

@ -1,4 +1,3 @@
#include <AK/Types.h>
#include "Assertions.h" #include "Assertions.h"
#include "kmalloc.h" #include "kmalloc.h"
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
@ -22,17 +21,14 @@ void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
"rep movsl\n" "rep movsl\n"
: "=S"(src), "=D"(dest) : "=S"(src), "=D"(dest)
: "S"(src), "D"(dest), "c"(size_ts) : "S"(src), "D"(dest), "c"(size_ts)
: "memory" : "memory");
);
n -= size_ts * sizeof(size_t); n -= size_ts * sizeof(size_t);
if (n == 0) if (n == 0)
return dest_ptr; return dest_ptr;
} }
asm volatile( asm volatile(
"rep movsb\n" "rep movsb\n" ::"S"(src), "D"(dest), "c"(n)
:: "S"(src), "D"(dest), "c"(n) : "memory");
: "memory"
);
return dest_ptr; return dest_ptr;
} }
@ -41,18 +37,19 @@ void* memmove(void* dest, const void* src, size_t n)
if (dest < src) if (dest < src)
return memcpy(dest, src, n); return memcpy(dest, src, n);
byte *pd = (byte*)dest; byte* pd = (byte*)dest;
const byte *ps = (const byte*)src; const byte* ps = (const byte*)src;
for (pd += n, ps += n; n--;) for (pd += n, ps += n; n--;)
*--pd = *--ps; *--pd = *--ps;
return dest; return dest;
} }
char* strcpy(char* dest, const char *src) char* strcpy(char* dest, const char* src)
{ {
auto* dest_ptr = dest; auto* dest_ptr = dest;
auto* src_ptr = src; auto* src_ptr = src;
while ((*dest_ptr++ = *src_ptr++) != '\0'); while ((*dest_ptr++ = *src_ptr++) != '\0')
;
return dest; return dest;
} }
@ -61,7 +58,7 @@ char* strncpy(char* dest, const char* src, size_t n)
size_t i; size_t i;
for (i = 0; i < n && src[i] != '\0'; ++i) for (i = 0; i < n && src[i] != '\0'; ++i)
dest[i] = src[i]; dest[i] = src[i];
for ( ; i < n; ++i) for (; i < n; ++i)
dest[i] = '\0'; dest[i] = '\0';
return dest; return dest;
} }
@ -79,24 +76,22 @@ void* memset(void* dest_ptr, int c, size_t n)
"rep stosl\n" "rep stosl\n"
: "=D"(dest) : "=D"(dest)
: "D"(dest), "c"(size_ts), "a"(expanded_c) : "D"(dest), "c"(size_ts), "a"(expanded_c)
: "memory" : "memory");
);
n -= size_ts * sizeof(size_t); n -= size_ts * sizeof(size_t);
if (n == 0) if (n == 0)
return dest_ptr; return dest_ptr;
} }
asm volatile( asm volatile(
"rep stosb\n" "rep stosb\n"
: "=D" (dest), "=c" (n) : "=D"(dest), "=c"(n)
: "0" (dest), "1" (n), "a" (c) : "0"(dest), "1"(n), "a"(c)
: "memory" : "memory");
);
return dest_ptr; return dest_ptr;
} }
char* strrchr(const char* str, int ch) char* strrchr(const char* str, int ch)
{ {
char *last = nullptr; char* last = nullptr;
char c; char c;
for (; (c = *str); ++str) { for (; (c = *str); ++str) {
if (c == ch) if (c == ch)
@ -113,7 +108,7 @@ size_t strlen(const char* str)
return len; return len;
} }
int strcmp(const char *s1, const char *s2) int strcmp(const char* s1, const char* s2)
{ {
for (; *s1 == *s2; ++s1, ++s2) { for (; *s1 == *s2; ++s1, ++s2) {
if (*s1 == 0) if (*s1 == 0)
@ -122,7 +117,7 @@ int strcmp(const char *s1, const char *s2)
return *(const byte*)s1 < *(const byte*)s2 ? -1 : 1; return *(const byte*)s1 < *(const byte*)s2 ? -1 : 1;
} }
char* strdup(const char *str) char* strdup(const char* str)
{ {
size_t len = strlen(str); size_t len = strlen(str);
char* new_str = (char*)kmalloc(len + 1); 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(); ASSERT_NOT_REACHED();
} }
} }

View file

@ -1,9 +1,9 @@
#include "i386.h" #include <Kernel/Console.h>
#include "Process.h" #include <Kernel/Process.h>
#include "Syscall.h"
#include "Console.h"
#include "Scheduler.h"
#include <Kernel/ProcessTracer.h> #include <Kernel/ProcessTracer.h>
#include <Kernel/Scheduler.h>
#include <Kernel/Syscall.h>
#include <Kernel/i386.h>
extern "C" void syscall_trap_entry(RegisterDump&); extern "C" void syscall_trap_entry(RegisterDump&);
extern "C" void syscall_trap_handler(); extern "C" void syscall_trap_handler();
@ -34,8 +34,7 @@ asm(
" popw %es\n" " popw %es\n"
" popw %ds\n" " popw %ds\n"
" popa\n" " popa\n"
" iret\n" " iret\n");
);
namespace Syscall { namespace Syscall {
@ -259,7 +258,7 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
case Syscall::SC_setsockopt: case Syscall::SC_setsockopt:
return current->process().sys$setsockopt((const SC_setsockopt_params*)arg1); return current->process().sys$setsockopt((const SC_setsockopt_params*)arg1);
case Syscall::SC_create_thread: 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: case Syscall::SC_rename:
return current->process().sys$rename((const char*)arg1, (const char*)arg2); return current->process().sys$rename((const char*)arg1, (const char*)arg2);
case Syscall::SC_shm_open: case Syscall::SC_shm_open:
@ -303,4 +302,3 @@ void syscall_trap_entry(RegisterDump& regs)
tracer->did_syscall(function, arg1, arg2, arg3, regs.eax); tracer->did_syscall(function, arg1, arg2, arg3, regs.eax);
current->process().big_lock().unlock(); current->process().big_lock().unlock();
} }

View file

@ -108,7 +108,7 @@
__ENUMERATE_SYSCALL(getpeername) \ __ENUMERATE_SYSCALL(getpeername) \
__ENUMERATE_SYSCALL(sched_setparam) \ __ENUMERATE_SYSCALL(sched_setparam) \
__ENUMERATE_SYSCALL(sched_getparam) \ __ENUMERATE_SYSCALL(sched_getparam) \
__ENUMERATE_SYSCALL(fchown) \ __ENUMERATE_SYSCALL(fchown)
namespace Syscall { namespace Syscall {

View file

@ -1,6 +1,6 @@
#include "MasterPTY.h" #include "MasterPTY.h"
#include "SlavePTY.h"
#include "PTYMultiplexer.h" #include "PTYMultiplexer.h"
#include "SlavePTY.h"
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
#include <LibC/signal_numbers.h> #include <LibC/signal_numbers.h>

View file

@ -1,5 +1,5 @@
#include <Kernel/TTY/TTY.h>
#include "Process.h" #include "Process.h"
#include <Kernel/TTY/TTY.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
#include <LibC/signal_numbers.h> #include <LibC/signal_numbers.h>
#include <LibC/sys/ioctl_numbers.h> #include <LibC/sys/ioctl_numbers.h>
@ -80,7 +80,7 @@ void TTY::generate_signal(int signal)
return; return;
dbgprintf("%s: Send signal %d to everyone in pgrp %d\n", tty_name().characters(), signal, pgid()); 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? 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()); dbgprintf("%s: Send signal %d to %d\n", tty_name().characters(), signal, process.pid());
process.send_signal(signal, nullptr); process.send_signal(signal, nullptr);
return true; return true;
@ -94,21 +94,18 @@ void TTY::set_termios(const termios& t)
tty_name().characters(), tty_name().characters(),
should_echo_input(), should_echo_input(),
should_generate_signals(), should_generate_signals(),
in_canonical_mode() in_canonical_mode());
);
dbgprintf("%s set_termios: ECHOE=%u, ECHOK=%u, ECHONL=%u\n", dbgprintf("%s set_termios: ECHOE=%u, ECHOK=%u, ECHONL=%u\n",
tty_name().characters(), tty_name().characters(),
(m_termios.c_lflag & ECHOE) != 0, (m_termios.c_lflag & ECHOE) != 0,
(m_termios.c_lflag & ECHOK) != 0, (m_termios.c_lflag & ECHOK) != 0,
(m_termios.c_lflag & ECHONL) != 0 (m_termios.c_lflag & ECHONL) != 0);
);
dbgprintf("%s set_termios: ISTRIP=%u, ICRNL=%u, INLCR=%u, IGNCR=%u\n", dbgprintf("%s set_termios: ISTRIP=%u, ICRNL=%u, INLCR=%u, IGNCR=%u\n",
tty_name().characters(), tty_name().characters(),
(m_termios.c_iflag & ISTRIP) != 0, (m_termios.c_iflag & ISTRIP) != 0,
(m_termios.c_iflag & ICRNL) != 0, (m_termios.c_iflag & ICRNL) != 0,
(m_termios.c_iflag & INLCR) != 0, (m_termios.c_iflag & INLCR) != 0,
(m_termios.c_iflag & IGNCR) != 0 (m_termios.c_iflag & IGNCR) != 0);
);
} }
int TTY::ioctl(FileDescription&, unsigned request, unsigned arg) int TTY::ioctl(FileDescription&, unsigned request, unsigned arg)

View file

@ -1,8 +1,8 @@
#include "VirtualConsole.h" #include "VirtualConsole.h"
#include "kmalloc.h"
#include "i386.h"
#include "IO.h" #include "IO.h"
#include "StdLib.h" #include "StdLib.h"
#include "i386.h"
#include "kmalloc.h"
#include <AK/AKString.h> #include <AK/AKString.h>
static byte* s_vga_buffer; static byte* s_vga_buffer;
@ -128,7 +128,8 @@ inline bool is_valid_final_character(byte ch)
return ch >= 0x40 && ch <= 0x7e; return ch >= 0x40 && ch <= 0x7e;
} }
enum class VGAColor : byte { enum class VGAColor : byte
{
Black = 0, Black = 0,
Blue, Blue,
Green, Green,
@ -147,7 +148,8 @@ enum class VGAColor : byte {
White, White,
}; };
enum class ANSIColor : byte { enum class ANSIColor : byte
{
Black = 0, Black = 0,
Red, Red,
Green, Green,
@ -169,22 +171,38 @@ enum class ANSIColor : byte {
static inline VGAColor ansi_color_to_vga(ANSIColor color) static inline VGAColor ansi_color_to_vga(ANSIColor color)
{ {
switch (color) { switch (color) {
case ANSIColor::Black: return VGAColor::Black; case ANSIColor::Black:
case ANSIColor::Red: return VGAColor::Red; return VGAColor::Black;
case ANSIColor::Brown: return VGAColor::Brown; case ANSIColor::Red:
case ANSIColor::Blue: return VGAColor::Blue; return VGAColor::Red;
case ANSIColor::Magenta: return VGAColor::Magenta; case ANSIColor::Brown:
case ANSIColor::Green: return VGAColor::Green; return VGAColor::Brown;
case ANSIColor::Cyan: return VGAColor::Cyan; case ANSIColor::Blue:
case ANSIColor::LightGray: return VGAColor::LightGray; return VGAColor::Blue;
case ANSIColor::DarkGray: return VGAColor::DarkGray; case ANSIColor::Magenta:
case ANSIColor::BrightRed: return VGAColor::BrightRed; return VGAColor::Magenta;
case ANSIColor::BrightGreen: return VGAColor::BrightGreen; case ANSIColor::Green:
case ANSIColor::Yellow: return VGAColor::Yellow; return VGAColor::Green;
case ANSIColor::BrightBlue: return VGAColor::BrightBlue; case ANSIColor::Cyan:
case ANSIColor::BrightMagenta: return VGAColor::BrightMagenta; return VGAColor::Cyan;
case ANSIColor::BrightCyan: return VGAColor::BrightCyan; case ANSIColor::LightGray:
case ANSIColor::White: return VGAColor::White; 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(); ASSERT_NOT_REACHED();
return VGAColor::LightGray; return VGAColor::LightGray;
@ -317,14 +335,29 @@ void VirtualConsole::execute_escape_sequence(byte final)
params.append(value); params.append(value);
} }
switch (final) { switch (final) {
case 'A': escape$A(params); break; case 'A':
case 'D': escape$D(params); break; escape$A(params);
case 'H': escape$H(params); break; break;
case 'J': escape$J(params); break; case 'D':
case 'm': escape$m(params); break; escape$D(params);
case 's': escape$s(params); break; break;
case 'u': escape$u(params); break; case 'H':
default: break; 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(); m_parameters.clear();

View file

@ -1,7 +1,7 @@
#include <Kernel/Thread.h>
#include <Kernel/Scheduler.h>
#include <Kernel/Process.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Process.h>
#include <Kernel/Scheduler.h>
#include <Kernel/Thread.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <LibC/signal_numbers.h> #include <LibC/signal_numbers.h>
@ -145,24 +145,42 @@ void Thread::sleep(dword ticks)
const char* to_string(Thread::State state) const char* to_string(Thread::State state)
{ {
switch (state) { switch (state) {
case Thread::Invalid: return "Invalid"; case Thread::Invalid:
case Thread::Runnable: return "Runnable"; return "Invalid";
case Thread::Running: return "Running"; case Thread::Runnable:
case Thread::Dying: return "Dying"; return "Runnable";
case Thread::Dead: return "Dead"; case Thread::Running:
case Thread::Stopped: return "Stopped"; return "Running";
case Thread::Skip1SchedulerPass: return "Skip1"; case Thread::Dying:
case Thread::Skip0SchedulerPasses: return "Skip0"; return "Dying";
case Thread::BlockedSleep: return "Sleep"; case Thread::Dead:
case Thread::BlockedWait: return "Wait"; return "Dead";
case Thread::BlockedRead: return "Read"; case Thread::Stopped:
case Thread::BlockedWrite: return "Write"; return "Stopped";
case Thread::BlockedSignal: return "Signal"; case Thread::Skip1SchedulerPass:
case Thread::BlockedSelect: return "Select"; return "Skip1";
case Thread::BlockedLurking: return "Lurking"; case Thread::Skip0SchedulerPasses:
case Thread::BlockedConnect: return "Connect"; return "Skip0";
case Thread::BlockedReceive: return "Receive"; case Thread::BlockedSleep:
case Thread::BlockedSnoozing: return "Snoozing"; 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); kprintf("to_string(Thread::State): Invalid state: %u\n", state);
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
@ -185,7 +203,7 @@ void Thread::finalize_dying_threads()
Vector<Thread*, 32> dying_threads; Vector<Thread*, 32> dying_threads;
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
for_each_in_state(Thread::State::Dying, [&] (Thread& thread) { for_each_in_state(Thread::State::Dying, [&](Thread& thread) {
dying_threads.append(&thread); dying_threads.append(&thread);
}); });
} }
@ -236,7 +254,8 @@ ShouldUnblockThread Thread::dispatch_one_pending_signal()
return dispatch_signal(signal); return dispatch_signal(signal);
} }
enum class DefaultSignalAction { enum class DefaultSignalAction
{
Terminate, Terminate,
Ignore, Ignore,
DumpCore, DumpCore,
@ -490,7 +509,7 @@ void Thread::make_userspace_stack_for_main_thread(Vector<String> arguments, Vect
push_value_on_stack(0); 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())); auto* region = m_process.allocate_region(LinearAddress(), default_userspace_stack_size, String::format("Stack (Thread %d)", tid()));
ASSERT(region); ASSERT(region);

View file

@ -1,11 +1,11 @@
#include <Kernel/VM/MemoryManager.h> #include "CMOS.h"
#include <Kernel/FileSystem/Inode.h> #include "Process.h"
#include "StdLib.h"
#include "i386.h"
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/kstdio.h> #include <AK/kstdio.h>
#include "i386.h" #include <Kernel/FileSystem/Inode.h>
#include "StdLib.h" #include <Kernel/VM/MemoryManager.h>
#include "Process.h"
#include "CMOS.h"
//#define MM_DEBUG //#define MM_DEBUG
//#define PAGE_FAULT_DEBUG //#define PAGE_FAULT_DEBUG
@ -96,12 +96,12 @@ void MemoryManager::initialize_paging()
dbgprintf("MM: Installing page directory\n"); dbgprintf("MM: Installing page directory\n");
#endif #endif
asm volatile("movl %%eax, %%cr3"::"a"(kernel_page_directory().cr3())); asm volatile("movl %%eax, %%cr3" ::"a"(kernel_page_directory().cr3()));
asm volatile( asm volatile(
"movl %%cr0, %%eax\n" "movl %%cr0, %%eax\n"
"orl $0x80000001, %%eax\n" "orl $0x80000001, %%eax\n"
"movl %%eax, %%cr0\n" "movl %%eax, %%cr0\n" ::
:::"%eax", "memory"); : "%eax", "memory");
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbgprintf("MM: Paging initialized.\n"); dbgprintf("MM: Paging initialized.\n");
@ -302,7 +302,6 @@ bool MemoryManager::copy_on_write(Region& region, unsigned page_index_in_region)
return true; return true;
} }
bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_region) bool MemoryManager::page_in_from_inode(Region& region, unsigned page_index_in_region)
{ {
ASSERT(region.page_directory()); ASSERT(region.page_directory());
@ -416,7 +415,7 @@ RetainPtr<PhysicalPage> MemoryManager::allocate_physical_page(ShouldZeroFill sho
if (1 > m_free_physical_pages.size()) { if (1 > m_free_physical_pages.size()) {
kprintf("FUCK! No physical pages available.\n"); kprintf("FUCK! No physical pages available.\n");
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
return { }; return {};
} }
#ifdef MM_DEBUG #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()); 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<PhysicalPage> MemoryManager::allocate_supervisor_physical_page()
if (1 > m_free_supervisor_physical_pages.size()) { if (1 > m_free_supervisor_physical_pages.size()) {
kprintf("FUCK! No physical pages available.\n"); kprintf("FUCK! No physical pages available.\n");
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
return { }; return {};
} }
#ifdef MM_DEBUG #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()); 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); ASSERT(current);
InterruptDisabler disabler; InterruptDisabler disabler;
current->tss().cr3 = process.page_directory().cr3(); 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() void MemoryManager::flush_entire_tlb()
{ {
asm volatile( asm volatile(
"mov %%cr3, %%eax\n" "mov %%cr3, %%eax\n"
"mov %%eax, %%cr3\n" "mov %%eax, %%cr3\n" ::
::: "%eax", "memory" : "%eax", "memory");
);
} }
void MemoryManager::flush_tlb(LinearAddress laddr) 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) void MemoryManager::map_for_kernel(LinearAddress laddr, PhysicalAddress paddr)

View file

@ -1,7 +1,7 @@
#include <Kernel/VM/PageDirectory.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PageDirectory.h>
static const dword userspace_range_base = 0x01000000; static const dword userspace_range_base = 0x01000000;
static const dword kernelspace_range_base = 0xc0000000; static const dword kernelspace_range_base = 0xc0000000;

View file

@ -1,5 +1,5 @@
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/kmalloc.h> #include <Kernel/kmalloc.h>
Retained<PhysicalPage> PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor) Retained<PhysicalPage> PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor)

View file

@ -1,6 +1,6 @@
#include <AK/QuickSort.h>
#include <Kernel/VM/RangeAllocator.h> #include <Kernel/VM/RangeAllocator.h>
#include <Kernel/kstdio.h> #include <Kernel/kstdio.h>
#include <AK/QuickSort.h>
//#define VRA_DEBUG //#define VRA_DEBUG
@ -33,7 +33,7 @@ Vector<Range, 2> Range::carve(const Range& taken)
{ {
Vector<Range, 2> parts; Vector<Range, 2> parts;
if (taken == *this) if (taken == *this)
return { }; return {};
if (taken.base() > base()) if (taken.base() > base())
parts.append({ base(), taken.base().get() - base().get() }); parts.append({ base(), taken.base().get() - base().get() });
if (taken.end() < end()) if (taken.end() < end())
@ -79,7 +79,7 @@ Range RangeAllocator::allocate_anywhere(size_t size)
return allocated_range; return allocated_range;
} }
kprintf("VRA: Failed to allocate anywhere: %u\n", size); kprintf("VRA: Failed to allocate anywhere: %u\n", size);
return { }; return {};
} }
Range RangeAllocator::allocate_specific(LinearAddress base, size_t size) 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; return allocated_range;
} }
kprintf("VRA: Failed to allocate specific range: %x(%u)\n", base.get(), size); kprintf("VRA: Failed to allocate specific range: %x(%u)\n", base.get(), size);
return { }; return {};
} }
void RangeAllocator::deallocate(Range range) void RangeAllocator::deallocate(Range range)
@ -121,7 +121,7 @@ void RangeAllocator::deallocate(Range range)
sort_and_merge: sort_and_merge:
// FIXME: We don't have to sort if we insert at the right position immediately. // 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(); return a.base() < b.base();
}); });

View file

@ -1,8 +1,8 @@
#include <Kernel/VM/Region.h>
#include <Kernel/VM/VMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/Region.h>
#include <Kernel/VM/VMObject.h>
Region::Region(const Range& range, String&& n, byte access, bool cow) Region::Region(const Range& range, String&& n, byte access, bool cow)
: m_range(range) : m_range(range)
@ -72,10 +72,10 @@ Retained<Region> Region::clone()
if (m_shared || (is_readable() && !is_writable())) { if (m_shared || (is_readable() && !is_writable())) {
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbgprintf("%s<%u> Region::clone(): sharing %s (L%x)\n", dbgprintf("%s<%u> Region::clone(): sharing %s (L%x)\n",
current->process().name().characters(), current->process().name().characters(),
current->pid(), current->pid(),
m_name.characters(), m_name.characters(),
laddr().get()); laddr().get());
#endif #endif
// Create a new region backed by the same VMObject. // 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)); 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> Region::clone()
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbgprintf("%s<%u> Region::clone(): cowing %s (L%x)\n", dbgprintf("%s<%u> Region::clone(): cowing %s (L%x)\n",
current->process().name().characters(), current->process().name().characters(),
current->pid(), current->pid(),
m_name.characters(), m_name.characters(),
laddr().get()); laddr().get());
#endif #endif
// Set up a COW region. The parent (this) region becomes COW as well! // Set up a COW region. The parent (this) region becomes COW as well!
m_cow_map.fill(true); m_cow_map.fill(true);

View file

@ -10,6 +10,7 @@ class VMObject;
class Region : public Retainable<Region> { class Region : public Retainable<Region> {
friend class MemoryManager; friend class MemoryManager;
public: public:
enum Access enum Access
{ {

View file

@ -1,7 +1,7 @@
#include <Kernel/VM/VMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/VMObject.h>
Retained<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode) Retained<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
{ {
@ -59,7 +59,6 @@ VMObject::VMObject(PhysicalAddress paddr, size_t size)
ASSERT(m_physical_pages.size() == page_count()); ASSERT(m_physical_pages.size() == page_count());
} }
VMObject::VMObject(RetainPtr<Inode>&& inode) VMObject::VMObject(RetainPtr<Inode>&& inode)
: m_inode(move(inode)) : m_inode(move(inode))
{ {
@ -113,7 +112,7 @@ void VMObject::inode_size_changed(Badge<Inode>, size_t old_size, size_t new_size
} }
// FIXME: Consolidate with inode_contents_changed() so we only do a single walk. // 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()); ASSERT(region.page_directory());
MM.remap_region(*region.page_directory(), region); MM.remap_region(*region.page_directory(), region);
}); });
@ -165,7 +164,7 @@ void VMObject::inode_contents_changed(Badge<Inode>, off_t offset, ssize_t size,
#endif #endif
// FIXME: Consolidate with inode_size_changed() so we only do a single walk. // 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()); ASSERT(region.page_directory());
MM.remap_region(*region.page_directory(), region); MM.remap_region(*region.page_directory(), region);
}); });

View file

@ -1,16 +1,17 @@
#include <AK/Types.h>
#include "i386.h" #include "i386.h"
#include "Assertions.h" #include "Assertions.h"
#include "Process.h"
#include <Kernel/VM/MemoryManager.h>
#include "IRQHandler.h" #include "IRQHandler.h"
#include "PIC.h" #include "PIC.h"
#include "Process.h"
#include "Scheduler.h" #include "Scheduler.h"
#include <AK/Types.h>
#include <Kernel/KSyms.h> #include <Kernel/KSyms.h>
#include <Kernel/VM/MemoryManager.h>
//#define PAGE_FAULT_DEBUG //#define PAGE_FAULT_DEBUG
struct [[gnu::packed]] DescriptorTablePointer { struct [[gnu::packed]] DescriptorTablePointer
{
word limit; word limit;
void* address; void* address;
}; };
@ -55,71 +56,68 @@ asm(
" popw %es\n" " popw %es\n"
" popw %ds\n" " popw %ds\n"
" popa\n" " popa\n"
" iret\n" " iret\n");
);
#define EH_ENTRY(ec) \ #define EH_ENTRY(ec) \
extern "C" void exception_ ## ec ## _handler(RegisterDumpWithExceptionCode&); \ extern "C" void exception_##ec##_handler(RegisterDumpWithExceptionCode&); \
extern "C" void exception_ ## ec ## _entry(); \ extern "C" void exception_##ec##_entry(); \
asm( \ asm( \
".globl exception_" # ec "_entry\n" \ ".globl exception_" #ec "_entry\n" \
"exception_" # ec "_entry: \n" \ "exception_" #ec "_entry: \n" \
" pusha\n" \ " pusha\n" \
" pushw %ds\n" \ " pushw %ds\n" \
" pushw %es\n" \ " pushw %es\n" \
" pushw %fs\n" \ " pushw %fs\n" \
" pushw %gs\n" \ " pushw %gs\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" popw %ds\n" \ " popw %ds\n" \
" popw %es\n" \ " popw %es\n" \
" popw %fs\n" \ " popw %fs\n" \
" popw %gs\n" \ " popw %gs\n" \
" mov %esp, %eax\n" \ " mov %esp, %eax\n" \
" call exception_" # ec "_handler\n" \ " call exception_" #ec "_handler\n" \
" popw %gs\n" \ " popw %gs\n" \
" popw %gs\n" \ " popw %gs\n" \
" popw %fs\n" \ " popw %fs\n" \
" popw %es\n" \ " popw %es\n" \
" popw %ds\n" \ " popw %ds\n" \
" popa\n" \ " popa\n" \
" add $0x4, %esp\n" \ " add $0x4, %esp\n" \
" iret\n" \ " iret\n");
);
#define EH_ENTRY_NO_CODE(ec) \ #define EH_ENTRY_NO_CODE(ec) \
extern "C" void exception_ ## ec ## _handler(RegisterDump&); \ extern "C" void exception_##ec##_handler(RegisterDump&); \
extern "C" void exception_ ## ec ## _entry(); \ extern "C" void exception_##ec##_entry(); \
asm( \ asm( \
".globl exception_" # ec "_entry\n" \ ".globl exception_" #ec "_entry\n" \
"exception_" # ec "_entry: \n" \ "exception_" #ec "_entry: \n" \
" pusha\n" \ " pusha\n" \
" pushw %ds\n" \ " pushw %ds\n" \
" pushw %es\n" \ " pushw %es\n" \
" pushw %fs\n" \ " pushw %fs\n" \
" pushw %gs\n" \ " pushw %gs\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" pushw %ss\n" \ " pushw %ss\n" \
" popw %ds\n" \ " popw %ds\n" \
" popw %es\n" \ " popw %es\n" \
" popw %fs\n" \ " popw %fs\n" \
" popw %gs\n" \ " popw %gs\n" \
" mov %esp, %eax\n" \ " mov %esp, %eax\n" \
" call exception_" # ec "_handler\n" \ " call exception_" #ec "_handler\n" \
" popw %gs\n" \ " popw %gs\n" \
" popw %gs\n" \ " popw %gs\n" \
" popw %fs\n" \ " popw %fs\n" \
" popw %es\n" \ " popw %es\n" \
" popw %ds\n" \ " popw %ds\n" \
" popa\n" \ " popa\n" \
" iret\n" \ " iret\n");
);
template<typename DumpType> template<typename DumpType>
static void dump(const DumpType& regs) static void dump(const DumpType& regs)
@ -158,7 +156,6 @@ static void dump(const DumpType& regs)
} }
} }
// 6: Invalid Opcode // 6: Invalid Opcode
EH_ENTRY_NO_CODE(6); EH_ENTRY_NO_CODE(6);
void exception_6_handler(RegisterDump& regs) void exception_6_handler(RegisterDump& regs)
@ -171,8 +168,7 @@ void exception_6_handler(RegisterDump& regs)
kprintf("%s Illegal instruction: %s(%u)\n", kprintf("%s Illegal instruction: %s(%u)\n",
current->process().is_ring0() ? "Kernel" : "Process", current->process().is_ring0() ? "Kernel" : "Process",
current->process().name().characters(), current->process().name().characters(),
current->pid() current->pid());
);
dump(regs); dump(regs);
dump_backtrace(); dump_backtrace();
@ -195,14 +191,15 @@ void exception_7_handler(RegisterDump& regs)
if (g_last_fpu_thread == current) if (g_last_fpu_thread == current)
return; return;
if (g_last_fpu_thread) { 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 { } else {
asm volatile("fnclex"); asm volatile("fnclex");
} }
g_last_fpu_thread = current; g_last_fpu_thread = current;
if (current->has_used_fpu()) { if (current->has_used_fpu()) {
asm volatile("fxrstor %0"::"m"(current->fpu_state())); asm volatile("fxrstor %0" ::"m"(current->fpu_state()));
} else { } else {
asm volatile("fninit"); asm volatile("fninit");
current->set_has_used_fpu(true); current->set_has_used_fpu(true);
@ -214,7 +211,6 @@ void exception_7_handler(RegisterDump& regs)
#endif #endif
} }
// 0: Divide error // 0: Divide error
EH_ENTRY_NO_CODE(0); EH_ENTRY_NO_CODE(0);
void exception_0_handler(RegisterDump& regs) void exception_0_handler(RegisterDump& regs)
@ -222,8 +218,7 @@ void exception_0_handler(RegisterDump& regs)
kprintf("%s Division by zero: %s(%u)\n", kprintf("%s Division by zero: %s(%u)\n",
current->process().is_ring0() ? "Kernel" : "User", current->process().is_ring0() ? "Kernel" : "User",
current->process().name().characters(), current->process().name().characters(),
current->pid() current->pid());
);
dump(regs); dump(regs);
@ -235,7 +230,6 @@ void exception_0_handler(RegisterDump& regs)
current->process().crash(SIGFPE); current->process().crash(SIGFPE);
} }
// 13: General Protection Fault // 13: General Protection Fault
EH_ENTRY(13); EH_ENTRY(13);
void exception_13_handler(RegisterDumpWithExceptionCode& regs) void exception_13_handler(RegisterDumpWithExceptionCode& regs)
@ -259,10 +253,12 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
ASSERT(current); ASSERT(current);
dword faultAddress; dword faultAddress;
asm ("movl %%cr2, %%eax":"=a"(faultAddress)); asm("movl %%cr2, %%eax"
: "=a"(faultAddress));
dword fault_page_directory; dword fault_page_directory;
asm ("movl %%cr3, %%eax":"=a"(fault_page_directory)); asm("movl %%cr3, %%eax"
: "=a"(fault_page_directory));
#ifdef PAGE_FAULT_DEBUG #ifdef PAGE_FAULT_DEBUG
dbgprintf("%s(%u): ring%u %s page fault in PD=%x, %s L%x\n", 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) \ #define EH(i, msg) \
static void _exception ## i () \ static void _exception##i() \
{ \ { \
kprintf(msg"\n"); \ kprintf(msg "\n"); \
dword cr0, cr2, cr3, cr4; \ dword cr0, cr2, cr3, cr4; \
asm ("movl %%cr0, %%eax":"=a"(cr0)); \ asm("movl %%cr0, %%eax" \
asm ("movl %%cr2, %%eax":"=a"(cr2)); \ : "=a"(cr0)); \
asm ("movl %%cr3, %%eax":"=a"(cr3)); \ asm("movl %%cr2, %%eax" \
asm ("movl %%cr4, %%eax":"=a"(cr4)); \ : "=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); \ kprintf("CR0=%x CR2=%x CR3=%x CR4=%x\n", cr0, cr2, cr3, cr4); \
hang(); \ hang(); \
} }
EH(1, "Debug exception") EH(1, "Debug exception")
@ -350,7 +350,8 @@ void flush_gdt()
{ {
s_gdtr.address = s_gdt; s_gdtr.address = s_gdt;
s_gdtr.limit = (s_gdt_length * 8) - 1; 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() void gdt_init()
@ -379,16 +380,13 @@ void gdt_init()
"mov %%ax, %%es\n" "mov %%ax, %%es\n"
"mov %%ax, %%fs\n" "mov %%ax, %%fs\n"
"mov %%ax, %%gs\n" "mov %%ax, %%gs\n"
"mov %%ax, %%ss\n" "mov %%ax, %%ss\n" ::"a"(0x10)
:: "a"(0x10) : "memory");
: "memory"
);
// Make sure CS points to the kernel code descriptor. // Make sure CS points to the kernel code descriptor.
asm volatile( asm volatile(
"ljmpl $0x8, $sanity\n" "ljmpl $0x8, $sanity\n"
"sanity:\n" "sanity:\n");
);
} }
static void unimp_trap() static void unimp_trap()
@ -413,20 +411,20 @@ void unregister_irq_handler(byte irq, IRQHandler& handler)
void register_interrupt_handler(byte index, void (*f)()) void register_interrupt_handler(byte index, void (*f)())
{ {
s_idt[index].low = 0x00080000 | LSW((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(); flush_idt();
} }
void register_user_callable_interrupt_handler(byte index, void (*f)()) void register_user_callable_interrupt_handler(byte index, void (*f)())
{ {
s_idt[index].low = 0x00080000 | LSW((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(); flush_idt();
} }
void 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. /* If an 8259 gets cranky, it'll generate a spurious IRQ7.
@ -438,8 +436,7 @@ extern "C" void irq7_handler();
asm( asm(
".globl irq7_handler \n" ".globl irq7_handler \n"
"irq7_handler: \n" "irq7_handler: \n"
" iret\n" " iret\n");
);
void idt_init() void idt_init()
{ {
@ -478,7 +475,7 @@ void idt_init()
void load_task_register(word selector) void load_task_register(word selector)
{ {
asm("ltr %0"::"r"(selector)); asm("ltr %0" ::"r"(selector));
} }
void handle_irq() 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); kprintf("ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func);
dump_backtrace(); dump_backtrace();
asm volatile("hlt"); asm volatile("hlt");
for (;;); for (;;)
;
} }
#endif #endif
@ -524,6 +522,5 @@ void sse_init()
"mov %eax, %cr0\n" "mov %eax, %cr0\n"
"mov %cr4, %eax\n" "mov %cr4, %eax\n"
"orl $0x600, %eax\n" "orl $0x600, %eax\n"
"mov %eax, %cr4\n" "mov %eax, %cr4\n");
);
} }

View file

@ -1,8 +1,8 @@
#include "i8253.h" #include "i8253.h"
#include "i386.h"
#include "IO.h" #include "IO.h"
#include "PIC.h" #include "PIC.h"
#include "Scheduler.h" #include "Scheduler.h"
#include "i386.h"
#define IRQ_TIMER 0 #define IRQ_TIMER 0
@ -34,8 +34,7 @@ asm(
" popw %es\n" " popw %es\n"
" popw %ds\n" " popw %ds\n"
" popa\n" " popa\n"
" iret\n" " iret\n");
);
static dword s_ticks_this_second; static dword s_ticks_this_second;
static dword s_seconds_since_boot; static dword s_seconds_since_boot;

View file

@ -1,34 +1,34 @@
#include <AK/Types.h> #include "KSyms.h"
#include "kmalloc.h" #include "PIC.h"
#include "Process.h"
#include "RTC.h"
#include "Scheduler.h"
#include "i386.h" #include "i386.h"
#include "i8253.h" #include "i8253.h"
#include <Kernel/Devices/KeyboardDevice.h> #include "kmalloc.h"
#include "Process.h" #include <AK/Types.h>
#include "PIC.h"
#include <Kernel/Devices/IDEDiskDevice.h>
#include <Kernel/Devices/MBRPartitionTable.h>
#include <Kernel/Devices/DiskPartition.h>
#include "KSyms.h"
#include <Kernel/Devices/NullDevice.h>
#include <Kernel/Devices/ZeroDevice.h>
#include <Kernel/Devices/FullDevice.h>
#include <Kernel/Devices/RandomDevice.h>
#include <Kernel/FileSystem/Ext2FileSystem.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/FileSystem/ProcFS.h>
#include "RTC.h"
#include <Kernel/TTY/VirtualConsole.h>
#include "Scheduler.h"
#include <Kernel/Devices/PS2MouseDevice.h>
#include <Kernel/TTY/PTYMultiplexer.h>
#include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/Devices/BXVGADevice.h> #include <Kernel/Devices/BXVGADevice.h>
#include <Kernel/Devices/DebugLogDevice.h>
#include <Kernel/Devices/DiskPartition.h>
#include <Kernel/Devices/FullDevice.h>
#include <Kernel/Devices/IDEDiskDevice.h>
#include <Kernel/Devices/KeyboardDevice.h>
#include <Kernel/Devices/MBRPartitionTable.h>
#include <Kernel/Devices/NullDevice.h>
#include <Kernel/Devices/PS2MouseDevice.h>
#include <Kernel/Devices/RandomDevice.h>
#include <Kernel/Devices/ZeroDevice.h>
#include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/FileSystem/Ext2FileSystem.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/KParams.h>
#include <Kernel/Multiboot.h>
#include <Kernel/Net/E1000NetworkAdapter.h> #include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/Net/NetworkTask.h> #include <Kernel/Net/NetworkTask.h>
#include <Kernel/Devices/DebugLogDevice.h> #include <Kernel/TTY/PTYMultiplexer.h>
#include <Kernel/Multiboot.h> #include <Kernel/TTY/VirtualConsole.h>
#include <Kernel/KParams.h> #include <Kernel/VM/MemoryManager.h>
//#define STRESS_TEST_SPAWNING //#define STRESS_TEST_SPAWNING
@ -49,7 +49,7 @@ VFS* vfs;
for (unsigned i = 0; i < 10000; ++i) { for (unsigned i = 0; i < 10000; ++i) {
int error; 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); 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; last_sum_alloc = sum_alloc;
sleep(60); sleep(60);
@ -131,7 +131,7 @@ VFS* vfs;
int error; 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) { if (error != 0) {
dbgprintf("init_stage2: error spawning SystemServer: %d\n", error); dbgprintf("init_stage2: error spawning SystemServer: %d\n", error);
hang(); hang();

View file

@ -3,18 +3,19 @@
* just to get going. Don't ever let anyone see this shit. :^) * just to get going. Don't ever let anyone see this shit. :^)
*/ */
#include <AK/Assertions.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/kmalloc.h> #include <Kernel/KSyms.h>
#include <Kernel/StdLib.h>
#include <Kernel/i386.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Scheduler.h> #include <Kernel/Scheduler.h>
#include <Kernel/KSyms.h> #include <Kernel/StdLib.h>
#include <AK/Assertions.h> #include <Kernel/i386.h>
#include <Kernel/kmalloc.h>
#define SANITIZE_KMALLOC #define SANITIZE_KMALLOC
struct [[gnu::packed]] allocation_t { struct [[gnu::packed]] allocation_t
{
size_t start; size_t start;
size_t nchunk; size_t nchunk;
}; };
@ -51,7 +52,7 @@ bool is_kmalloc_address(const void* ptr)
void kmalloc_init() void kmalloc_init()
{ {
memset(&alloc_map, 0, sizeof(alloc_map)); 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; kmalloc_sum_eternal = 0;
sum_alloc = 0; sum_alloc = 0;
@ -126,7 +127,7 @@ void* kmalloc_impl(size_t size)
} }
// FIXME: This scan can be optimized further with LZCNT. // FIXME: This scan can be optimized further with LZCNT.
for (size_t j = 0; j < 8; ++j) { for (size_t j = 0; j < 8; ++j) {
if (!(alloc_map[i] & (1<<j))) { if (!(alloc_map[i] & (1 << j))) {
if (chunks_here == 0) { if (chunks_here == 0) {
// Mark where potential allocation starts. // Mark where potential allocation starts.
first_chunk = i * 8 + j; first_chunk = i * 8 + j;
@ -135,8 +136,8 @@ void* kmalloc_impl(size_t size)
++chunks_here; ++chunks_here;
if (chunks_here == chunks_needed) { if (chunks_here == chunks_needed) {
auto* a = (allocation_t *)(BASE_PHYSICAL + (first_chunk * CHUNK_SIZE)); auto* a = (allocation_t*)(BASE_PHYSICAL + (first_chunk * CHUNK_SIZE));
byte *ptr = (byte *)a; byte* ptr = (byte*)a;
ptr += sizeof(allocation_t); ptr += sizeof(allocation_t);
a->nchunk = chunks_needed; a->nchunk = chunks_needed;
a->start = first_chunk; a->start = first_chunk;
@ -164,7 +165,7 @@ void* kmalloc_impl(size_t size)
hang(); hang();
} }
void kfree(void *ptr) void kfree(void* ptr)
{ {
if (!ptr) if (!ptr)
return; return;