Tweak clang-format to not align across empty lines

That should fix insane function declarations
This commit is contained in:
2024-04-14 16:51:16 +02:00
parent fffc513b16
commit 63af59f5ac
47 changed files with 300 additions and 300 deletions

View File

@@ -4,19 +4,19 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: AlignConsecutiveAssignments:
Enabled: true Enabled: true
AcrossEmptyLines: true AcrossEmptyLines: false
AcrossComments: false AcrossComments: false
AlignConsecutiveBitFields: AlignConsecutiveBitFields:
Enabled: true Enabled: true
AcrossEmptyLines: true AcrossEmptyLines: false
AcrossComments: true AcrossComments: false
AlignConsecutiveDeclarations: AlignConsecutiveDeclarations:
Enabled: true Enabled: true
AcrossEmptyLines: true AcrossEmptyLines: false
AcrossComments: false AcrossComments: false
AlignConsecutiveMacros: AlignConsecutiveMacros:
Enabled: true Enabled: true
AcrossEmptyLines: true AcrossEmptyLines: false
AcrossComments: false AcrossComments: false
AlignTrailingComments: AlignTrailingComments:
Kind: Always Kind: Always

View File

@@ -11,10 +11,10 @@
class SerialTty : public Tty { class SerialTty : public Tty {
// TODO: Possibly there should be 2 mutexes? // TODO: Possibly there should be 2 mutexes?
Mutex mutex; Mutex mutex;
CV readercv; CV readercv;
CV isrcv; CV isrcv;
static void isr(void *tty); static void isr(void *tty);
void this_isr(); void this_isr();
void this_pooler(); void this_pooler();

View File

@@ -13,8 +13,8 @@ namespace Arch::GDT {
static constexpr size_t INT_STACK_SIZE = 16384; static constexpr size_t INT_STACK_SIZE = 16384;
static constexpr size_t RSP_STACK_SIZE = 16384; static constexpr size_t RSP_STACK_SIZE = 16384;
static uint64_t int_stack[INT_STACK_SIZE]; static uint64_t int_stack[INT_STACK_SIZE];
static uint64_t rsp_stack[RSP_STACK_SIZE]; static uint64_t rsp_stack[RSP_STACK_SIZE];
// //
void gdt_setup() { void gdt_setup() {
@@ -33,7 +33,7 @@ namespace Arch::GDT {
gdt_tss.gran = 0; gdt_tss.gran = 0;
gdt_tss.base_high = (tss_base >> 24) & 0xFFFFFFFFFF; gdt_tss.base_high = (tss_base >> 24) & 0xFFFFFFFFFF;
tss_entry.ist1 = (((uintptr_t) int_stack + (INT_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8; tss_entry.ist1 = (((uintptr_t) int_stack + (INT_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;
assert((tss_entry.ist1 & 0xFULL) == 8); assert((tss_entry.ist1 & 0xFULL) == 8);
tss_entry.rsp0 = (((uintptr_t) rsp_stack + (RSP_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8; tss_entry.rsp0 = (((uintptr_t) rsp_stack + (RSP_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;

View File

@@ -73,7 +73,7 @@ namespace Arch::GDT {
extern volatile struct gdt_tss_entry_bits gdt_tss; extern volatile struct gdt_tss_entry_bits gdt_tss;
extern volatile struct gdt_tss_entry_bits gdt_tss_user; extern volatile struct gdt_tss_entry_bits gdt_tss_user;
extern volatile struct gdt_entry_bits gdt_end; // It is not a pointer! extern volatile struct gdt_entry_bits gdt_end; // It is not a pointer!
extern struct { extern struct {
uint16_t limit; uint16_t limit;

View File

@@ -13,7 +13,7 @@ namespace Arch::IDT {
__attribute__((aligned(0x10))) static IdtEntry idt[256]; // Create an array of IDT entries; aligned for performance __attribute__((aligned(0x10))) static IdtEntry idt[256]; // Create an array of IDT entries; aligned for performance
// //
static Idtr idtr; static Idtr idtr;
extern "C" void pic1_irq_0(); extern "C" void pic1_irq_0();
extern "C" void pic1_irq_1(); extern "C" void pic1_irq_1();
@@ -34,8 +34,8 @@ namespace Arch::IDT {
extern "C" void pic2_irq_7(); extern "C" void pic2_irq_7();
void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags) { void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags) {
IdtEntry *descriptor = &idt[vector]; IdtEntry *descriptor = &idt[vector];
descriptor->isr_low = (uint64_t) isr & 0xFFFF; descriptor->isr_low = (uint64_t) isr & 0xFFFF;
descriptor->kernel_cs = Arch::GDT::gdt_code.selector(); descriptor->kernel_cs = Arch::GDT::gdt_code.selector();

View File

@@ -5,19 +5,19 @@
#include <cstdint> #include <cstdint>
namespace Arch::IDT { namespace Arch::IDT {
static constexpr int kPIC1 = 0x20; /* IO base address for master PIC */ static constexpr int kPIC1 = 0x20; /* IO base address for master PIC */
static constexpr int kPIC2 = 0xA0; /* IO base address for slave PIC */ static constexpr int kPIC2 = 0xA0; /* IO base address for slave PIC */
static constexpr int kPIC1_COMMAND = kPIC1; static constexpr int kPIC1_COMMAND = kPIC1;
static constexpr int kPIC1_DATA = (kPIC1 + 1); static constexpr int kPIC1_DATA = (kPIC1 + 1);
static constexpr int kPIC2_COMMAND = kPIC2; static constexpr int kPIC2_COMMAND = kPIC2;
static constexpr int kPIC2_DATA = (kPIC2 + 1); static constexpr int kPIC2_DATA = (kPIC2 + 1);
static constexpr int kPIC_EOI = 0x20; /* End-of-interrupt command code */ static constexpr int kPIC_EOI = 0x20; /* End-of-interrupt command code */
static constexpr int kICW1_ICW4 = 0x01; /* Indicates that ICW4 will be present */ static constexpr int kICW1_ICW4 = 0x01; /* Indicates that ICW4 will be present */
static constexpr int kICW1_SINGLE = 0x02; /* Single (cascade) mode */ static constexpr int kICW1_SINGLE = 0x02; /* Single (cascade) mode */
static constexpr int kICW1_INTERVAL4 = 0x04; /* Call address interval 4 (8) */ static constexpr int kICW1_INTERVAL4 = 0x04; /* Call address interval 4 (8) */
static constexpr int kICW1_LEVEL = 0x08; /* Level triggered (edge) mode */ static constexpr int kICW1_LEVEL = 0x08; /* Level triggered (edge) mode */
static constexpr int kICW1_INIT = 0x10; /* Initialization - required! */ static constexpr int kICW1_INIT = 0x10; /* Initialization - required! */
static constexpr int kICW4_8086 = 0x01; /* 8086/88 (MCS-80/85) mode */ static constexpr int kICW4_8086 = 0x01; /* 8086/88 (MCS-80/85) mode */
static constexpr int kICW4_AUTO = 0x02; /* Auto (normal) EOI */ static constexpr int kICW4_AUTO = 0x02; /* Auto (normal) EOI */
@@ -25,18 +25,18 @@ namespace Arch::IDT {
static constexpr int kICW4_BUF_MASTER = 0x0C; /* Buffered mode/master */ static constexpr int kICW4_BUF_MASTER = 0x0C; /* Buffered mode/master */
static constexpr int kICW4_SFNM = 0x10; /* Special fully nested (not) */ static constexpr int kICW4_SFNM = 0x10; /* Special fully nested (not) */
static constexpr int kPIC_READ_IRR = 0x0a; /* OCW3 irq ready next CMD read */ static constexpr int kPIC_READ_IRR = 0x0a; /* OCW3 irq ready next CMD read */
static constexpr int kPIC_READ_ISR = 0x0b; /* OCW3 irq service next CMD read */ static constexpr int kPIC_READ_ISR = 0x0b; /* OCW3 irq service next CMD read */
static constexpr int kPIC1_OFFSET = 0x20; static constexpr int kPIC1_OFFSET = 0x20;
static constexpr int kPIC2_OFFSET = 0x28; static constexpr int kPIC2_OFFSET = 0x28;
void PIC_sendEOI(unsigned char irq); void PIC_sendEOI(unsigned char irq);
void PIC_init(); void PIC_init();
void IRQ_set_mask(unsigned char IRQline); void IRQ_set_mask(unsigned char IRQline);
void IRQ_clear_mask(unsigned char IRQline); void IRQ_clear_mask(unsigned char IRQline);
uint16_t pic_get_irr(void); uint16_t pic_get_irr(void);
uint16_t pic_get_isr(void); uint16_t pic_get_isr(void);
struct IdtEntry { struct IdtEntry {
uint16_t isr_low; // The lower 16 bits of the ISR's address uint16_t isr_low; // The lower 16 bits of the ISR's address
@@ -57,15 +57,15 @@ namespace Arch::IDT {
extern "C" void exception_handler_err(uint64_t code); extern "C" void exception_handler_err(uint64_t code);
extern "C" void exception_handler_no_err(void); extern "C" void exception_handler_no_err(void);
void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags); void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags);
void idt_init(); void idt_init();
extern "C" void (*isr_stub_table[])(); extern "C" void (*isr_stub_table[])();
} // namespace Arch::IDT } // namespace Arch::IDT
using int_handler_t = void (*)(void *); using int_handler_t = void (*)(void *);
void attach_interrupt(unsigned num, int_handler_t handler, void *arg); void attach_interrupt(unsigned num, int_handler_t handler, void *arg);
#endif #endif

View File

@@ -69,7 +69,7 @@ void ktask() {
static Mutex testmutex; static Mutex testmutex;
void mtest1() { void mtest1() {
{ {
LockGuard l(testmutex); LockGuard l(testmutex);
GlobalTtyManager.all_tty_putstr("Locked1\n"); GlobalTtyManager.all_tty_putstr("Locked1\n");
@@ -160,7 +160,7 @@ void ktask_main() {
memcpy(read_data.begin(), mod.address, mod.size); memcpy(read_data.begin(), mod.address, mod.size);
ElfParser elfParser(std::move(read_data)); ElfParser elfParser(std::move(read_data));
Task *utask = new Task(Task::TaskMode::TASKMODE_USER, (void (*)()) elfParser.get_entrypoint(), saved_modules_names[i]); Task *utask = new Task(Task::TaskMode::TASKMODE_USER, (void (*)()) elfParser.get_entrypoint(), saved_modules_names[i]);
if (elfParser.copy_to(utask)) if (elfParser.copy_to(utask))
utask->start(); utask->start();
else else
@@ -180,7 +180,7 @@ void dummy_task() {
extern void (*ctors_begin[])(); extern void (*ctors_begin[])();
extern void (*ctors_end[])(); extern void (*ctors_end[])();
void kmain() { void kmain() {
for (void (**ctor)() = ctors_begin; ctor < ctors_end; ctor++) for (void (**ctor)() = ctors_begin; ctor < ctors_end; ctor++)
(*ctor)(); (*ctor)();

View File

@@ -11,15 +11,15 @@
#include "mutex.hpp" #include "mutex.hpp"
#include "string.h" #include "string.h"
struct HeapEntry *KERN_HeapBegin; struct HeapEntry *KERN_HeapBegin;
uintptr_t KERN_HeapEnd; // Past the end uintptr_t KERN_HeapEnd; // Past the end
static bool initialized = false; static bool initialized = false;
std::atomic<uint64_t> allocated = 0; std::atomic<uint64_t> allocated = 0;
std::atomic<uint64_t> used = 0; std::atomic<uint64_t> used = 0;
uint64_t get_heap_allocated() { uint64_t get_heap_allocated() {
return allocated; return allocated;
} }
uint64_t get_heap_used() { uint64_t get_heap_used() {
@@ -28,7 +28,7 @@ uint64_t get_heap_used() {
static Mutex kmem_lock; static Mutex kmem_lock;
void init_kern_heap() { void init_kern_heap() {
KERN_HeapBegin = static_cast<HeapEntry *>(get4k()); KERN_HeapBegin = static_cast<HeapEntry *>(get4k());
allocated.fetch_add(PAGE_SIZE); allocated.fetch_add(PAGE_SIZE);
KERN_HeapBegin->magic = KERN_HeapMagicFree; KERN_HeapBegin->magic = KERN_HeapMagicFree;
@@ -160,13 +160,13 @@ void *kmalloc(size_t n) {
assert2(entry->magic == KERN_HeapMagicFree, "Expected last tried entry to be free"); assert2(entry->magic == KERN_HeapMagicFree, "Expected last tried entry to be free");
assert2(entry->next == NULL, "Expected last tried entry to be the last"); assert2(entry->next == NULL, "Expected last tried entry to be the last");
size_t data_needed = n + (2 * sizeof(struct HeapEntry)); size_t data_needed = n + (2 * sizeof(struct HeapEntry));
size_t pages_needed = ((data_needed & 0xFFF) == 0) size_t pages_needed = ((data_needed & 0xFFF) == 0)
? data_needed >> 12 ? data_needed >> 12
: ((data_needed & (~0xFFF)) + 0x1000) >> 12; : ((data_needed & (~0xFFF)) + 0x1000) >> 12;
struct HeapEntry *new_entry = (struct HeapEntry *) KERN_HeapEnd; struct HeapEntry *new_entry = (struct HeapEntry *) KERN_HeapEnd;
extend_heap(pages_needed); extend_heap(pages_needed);
new_entry->next = NULL; new_entry->next = NULL;
new_entry->prev = entry; new_entry->prev = entry;
@@ -280,7 +280,7 @@ static struct HeapEntry *try_shrink_heap(struct HeapEntry *entry) {
void kfree(void *addr) { void kfree(void *addr) {
assert(initialized); assert(initialized);
LockGuard l(kmem_lock); LockGuard l(kmem_lock);
struct HeapEntry *freed = (struct HeapEntry *) (addr - (sizeof(struct HeapEntry))); struct HeapEntry *freed = (struct HeapEntry *) (addr - (sizeof(struct HeapEntry)));
used.fetch_sub(freed->len); used.fetch_sub(freed->len);

View File

@@ -25,12 +25,12 @@ struct HeapEntry {
extern struct HeapEntry *KERN_HeapBegin; extern struct HeapEntry *KERN_HeapBegin;
extern uintptr_t KERN_HeapEnd; // Past the end extern uintptr_t KERN_HeapEnd; // Past the end
void *kmalloc(size_t n); void *kmalloc(size_t n);
void kfree(void *addr); void kfree(void *addr);
void *krealloc(void *addr, size_t newsize); void *krealloc(void *addr, size_t newsize);
uint64_t get_heap_allocated(); uint64_t get_heap_allocated();
uint64_t get_heap_used(); uint64_t get_heap_used();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -204,14 +204,14 @@ struct limine_framebuffer_request {
#define LIMINE_TERMINAL_CB_MODE 70 #define LIMINE_TERMINAL_CB_MODE 70
#define LIMINE_TERMINAL_CB_LINUX 80 #define LIMINE_TERMINAL_CB_LINUX 80
#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t) (-1)) #define LIMINE_TERMINAL_CTX_SIZE ((uint64_t) (-1))
#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t) (-2)) #define LIMINE_TERMINAL_CTX_SAVE ((uint64_t) (-2))
#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t) (-3)) #define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t) (-3))
#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t) (-4)) #define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t) (-4))
/* Response revision 1 */ /* Response revision 1 */
#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t) (-10)) #define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t) (-10))
#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t) (-11)) #define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t) (-11))
#define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0) #define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0)
#define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1) #define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1)
@@ -226,8 +226,8 @@ LIMINE_DEPRECATED_IGNORE_START
struct LIMINE_DEPRECATED limine_terminal; struct LIMINE_DEPRECATED limine_terminal;
typedef void (*limine_terminal_write)(struct limine_terminal *, const char *, uint64_t); typedef void (*limine_terminal_write)(struct limine_terminal *, const char *, uint64_t);
typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t); typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t);
struct LIMINE_DEPRECATED limine_terminal { struct LIMINE_DEPRECATED limine_terminal {
uint64_t columns; uint64_t columns;

View File

@@ -9,8 +9,8 @@
#include "paging.hpp" #include "paging.hpp"
void limine_fb_save_response(struct AddressSpace *boot_address_space); void limine_fb_save_response(struct AddressSpace *boot_address_space);
void limine_fb_remap(struct AddressSpace *space); void limine_fb_remap(struct AddressSpace *space);
extern int framebuffer_count; extern int framebuffer_count;
extern struct limine_framebuffer framebuffers[10]; extern struct limine_framebuffer framebuffers[10];

View File

@@ -16,7 +16,7 @@ unsigned int limine_mm_count;
struct limine_memmap_entry limine_mm_entries[LIMINE_MM_MAX]; struct limine_memmap_entry limine_mm_entries[LIMINE_MM_MAX];
unsigned int limine_mm_overflow; unsigned int limine_mm_overflow;
void limine_mm_save_response() { void limine_mm_save_response() {
limine_mm_count = memmap_request.response->entry_count; limine_mm_count = memmap_request.response->entry_count;
if (limine_mm_count > LIMINE_MM_MAX) { if (limine_mm_count > LIMINE_MM_MAX) {
limine_mm_count = LIMINE_MM_MAX; limine_mm_count = LIMINE_MM_MAX;

View File

@@ -13,6 +13,6 @@ extern unsigned int limine_mm_count;
extern struct limine_memmap_entry limine_mm_entries[LIMINE_MM_MAX]; extern struct limine_memmap_entry limine_mm_entries[LIMINE_MM_MAX];
extern unsigned int limine_mm_overflow; extern unsigned int limine_mm_overflow;
void limine_mm_save_response(); void limine_mm_save_response();
#endif //FICUS_LIMINE_MM_H #endif //FICUS_LIMINE_MM_H

View File

@@ -17,7 +17,7 @@ limine_file saved_modules[max_saved_modules];
char saved_modules_names[max_saved_modules][max_saved_module_name] __attribute__((aligned(4096))); char saved_modules_names[max_saved_modules][max_saved_module_name] __attribute__((aligned(4096)));
unsigned saved_modules_size = 0; unsigned saved_modules_size = 0;
void limine_modules_remap() { void limine_modules_remap() {
for (int i = 0; i < module_request.response->module_count; i++) { for (int i = 0; i < module_request.response->module_count; i++) {
assert2(i < max_saved_modules, "Too many modules"); assert2(i < max_saved_modules, "Too many modules");

View File

@@ -9,13 +9,13 @@
extern volatile struct limine_module_request module_request; extern volatile struct limine_module_request module_request;
static constexpr unsigned max_saved_modules = 4; static constexpr unsigned max_saved_modules = 4;
static constexpr unsigned max_saved_module_name = 256; static constexpr unsigned max_saved_module_name = 256;
void limine_modules_remap(); void limine_modules_remap();
extern unsigned saved_modules_size; extern unsigned saved_modules_size;
extern limine_file saved_modules[max_saved_modules]; extern limine_file saved_modules[max_saved_modules];
extern char saved_modules_names[max_saved_modules][max_saved_module_name] __attribute__((aligned(4096))); extern char saved_modules_names[max_saved_modules][max_saved_module_name] __attribute__((aligned(4096)));
#endif //FICUS_LIMINE_MODULES_HPP #endif //FICUS_LIMINE_MODULES_HPP

View File

@@ -18,13 +18,13 @@
// Expected to be nulled by the bootloader // Expected to be nulled by the bootloader
static struct FourPages used_bitmap[BITMAP_SIZE]; static struct FourPages used_bitmap[BITMAP_SIZE];
static Mutex memman_lock; static Mutex memman_lock;
static uint64_t maxPid = 0; // Past the end static uint64_t maxPid = 0; // Past the end
static uint64_t minPid = 0; static uint64_t minPid = 0;
static uint64_t totalMem = 0; // Past the end static uint64_t totalMem = 0; // Past the end
static uint64_t roundup4k(uint64_t addr) { static uint64_t roundup4k(uint64_t addr) {
if ((addr & 0xFFF) == 0) return addr; if ((addr & 0xFFF) == 0) return addr;
else { else {
return (addr + 0x1000) & (~(0xFFFULL)); return (addr + 0x1000) & (~(0xFFFULL));

View File

@@ -21,7 +21,7 @@ struct FourPages {
} __attribute__((packed)); } __attribute__((packed));
static_assert(sizeof(FourPages) == 1); static_assert(sizeof(FourPages) == 1);
void parse_limine_memmap(struct limine_memmap_entry *entries, unsigned int num, uint64_t what_is_considered_free); void parse_limine_memmap(struct limine_memmap_entry *entries, unsigned int num, uint64_t what_is_considered_free);
void *get4k(); void *get4k();
void free4k(void *page); void free4k(void *page);

View File

@@ -55,10 +55,10 @@ void *AddressSpace::virt2real(void *virt) {
assert2((uint64_t) PML4 >= HHDM_BEGIN, "CR3 here must be in HHDM!"); assert2((uint64_t) PML4 >= HHDM_BEGIN, "CR3 here must be in HHDM!");
assert2((uint64_t) PML4 < kernel_virt_base, "CR3 here must be in HHDM!"); assert2((uint64_t) PML4 < kernel_virt_base, "CR3 here must be in HHDM!");
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF; uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF; uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF; uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF; uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
uint64_t *pml4e = PML4 + pml4i; uint64_t *pml4e = PML4 + pml4i;
if (!((*pml4e) & PAGE_PRESENT)) return 0; if (!((*pml4e) & PAGE_PRESENT)) return 0;
@@ -89,10 +89,10 @@ int AddressSpace::map(void *virt, void *real, uint32_t flags) {
assert2((uint64_t) PML4 >= HHDM_BEGIN, "CR3 here must be in HHDM!"); assert2((uint64_t) PML4 >= HHDM_BEGIN, "CR3 here must be in HHDM!");
assert2((uint64_t) PML4 < kernel_virt_base, "CR3 here must be in HHDM!"); assert2((uint64_t) PML4 < kernel_virt_base, "CR3 here must be in HHDM!");
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF; uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF; uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF; uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF; uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
uint64_t *pml4e = PML4 + pml4i; uint64_t *pml4e = PML4 + pml4i;
@@ -144,10 +144,10 @@ int AddressSpace::unmap(void *virt) {
assert2((uint64_t) PML4 >= HHDM_BEGIN, "CR3 here must be in HHDM!"); assert2((uint64_t) PML4 >= HHDM_BEGIN, "CR3 here must be in HHDM!");
assert2((uint64_t) PML4 < kernel_virt_base, "CR3 here must be in HHDM!"); assert2((uint64_t) PML4 < kernel_virt_base, "CR3 here must be in HHDM!");
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF; uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF; uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF; uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF; uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
uint64_t *pml4e = PML4 + pml4i; uint64_t *pml4e = PML4 + pml4i;
@@ -193,10 +193,10 @@ void limine_kern_save_response() {
static uint64_t early_pages[EARLY_PAGES_SIZE][512] __attribute__((aligned(PAGE_SIZE))); static uint64_t early_pages[EARLY_PAGES_SIZE][512] __attribute__((aligned(PAGE_SIZE)));
static uint64_t early_pages_used = 0; static uint64_t early_pages_used = 0;
uintptr_t kernel_phys_base; uintptr_t kernel_phys_base;
uintptr_t kernel_virt_base; uintptr_t kernel_virt_base;
uint64_t *get_early_frame() { uint64_t *get_early_frame() {
assert2(early_pages_used < EARLY_PAGES_SIZE, "Couldn't get a page for HHDM!"); assert2(early_pages_used < EARLY_PAGES_SIZE, "Couldn't get a page for HHDM!");
uint64_t *newp = early_pages[early_pages_used++]; uint64_t *newp = early_pages[early_pages_used++];
for (int i = 0; i < 512; i++) for (int i = 0; i < 512; i++)
@@ -221,16 +221,16 @@ void map_hhdm(uint64_t *pml4) {
// Assuming everything related to paging is HHDM // Assuming everything related to paging is HHDM
assert2((uint64_t) pml4 < 0x8000000000000000ULL, "CR3 here must be physical!"); assert2((uint64_t) pml4 < 0x8000000000000000ULL, "CR3 here must be physical!");
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF; uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF; uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF; uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
uint64_t *pml4e = pml4 + pml4i; uint64_t *pml4e = pml4 + pml4i;
if (!(*pml4e & PAGE_PRESENT)) { if (!(*pml4e & PAGE_PRESENT)) {
uint64_t *newp = get_early_frame(); uint64_t *newp = get_early_frame();
*pml4e = PAGE_PRESENT | PAGE_RW | PAGE_USER; *pml4e = PAGE_PRESENT | PAGE_RW | PAGE_USER;
*pml4e |= (uint64_t) KERN_V2P(newp) & (uint64_t) 0x000FFFFFFFFFF000ULL; *pml4e |= (uint64_t) KERN_V2P(newp) & (uint64_t) 0x000FFFFFFFFFF000ULL;
} }
@@ -240,7 +240,7 @@ void map_hhdm(uint64_t *pml4) {
if (!(*pdpee & PAGE_PRESENT)) { if (!(*pdpee & PAGE_PRESENT)) {
uint64_t *newp = get_early_frame(); uint64_t *newp = get_early_frame();
*pdpee = PAGE_PRESENT | PAGE_RW | PAGE_USER; *pdpee = PAGE_PRESENT | PAGE_RW | PAGE_USER;
*pdpee |= (uint64_t) KERN_V2P(newp) & (uint64_t) 0x000FFFFFFFFFF000ULL; *pdpee |= (uint64_t) KERN_V2P(newp) & (uint64_t) 0x000FFFFFFFFFF000ULL;
} }

View File

@@ -13,18 +13,18 @@
#include <Vector.hpp> #include <Vector.hpp>
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
#define PAGE_ROUND_DOWN(x) (((uintptr_t) (x)) & (~(PAGE_SIZE - 1))) #define PAGE_ROUND_DOWN(x) (((uintptr_t) (x)) & (~(PAGE_SIZE - 1)))
#define PAGE_ROUND_UP(x) ((((uintptr_t) (x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1))) #define PAGE_ROUND_UP(x) ((((uintptr_t) (x)) + PAGE_SIZE - 1) & (~(PAGE_SIZE - 1)))
#define KERN_V2P(a) ((((uintptr_t) (a) - (uintptr_t) kernel_virt_base) + (uintptr_t) kernel_phys_base)) #define KERN_V2P(a) ((((uintptr_t) (a) - (uintptr_t) kernel_virt_base) + (uintptr_t) kernel_phys_base))
#define KERN_P2V(a) ((((uintptr_t) (a) -kernel_phys_base) | kernel_virt_base)) #define KERN_P2V(a) ((((uintptr_t) (a) - kernel_phys_base) | kernel_virt_base))
#define HHDM_BEGIN 0xfffff80000000000ULL #define HHDM_BEGIN 0xfffff80000000000ULL
#define HHDM_SIZE 32ULL // In GB #define HHDM_SIZE 32ULL // In GB
#define HHDM_V2P(a) ((((uintptr_t) (a)) & ~HHDM_BEGIN)) #define HHDM_V2P(a) ((((uintptr_t) (a)) & ~HHDM_BEGIN))
#define HHDM_P2V(a) ((((uintptr_t) (a)) | HHDM_BEGIN)) #define HHDM_P2V(a) ((((uintptr_t) (a)) | HHDM_BEGIN))
class FDT; class FDT;
@@ -34,9 +34,9 @@ public:
AddressSpace(uint64_t *PML4); AddressSpace(uint64_t *PML4);
~AddressSpace(); ~AddressSpace();
void *virt2real(void *virt); void *virt2real(void *virt);
int map(void *virt, void *real, uint32_t flags); int map(void *virt, void *real, uint32_t flags);
int unmap(void *virt); int unmap(void *virt);
uint64_t *get_cr3() { uint64_t *get_cr3() {
return PML4; return PML4;
@@ -52,29 +52,29 @@ private:
uint64_t *get_free_frame(); uint64_t *get_free_frame();
// Pointer to PML4 in HHDM // Pointer to PML4 in HHDM
uint64_t *PML4; uint64_t *PML4;
UniquePtr<FDT> _fdt; UniquePtr<FDT> _fdt;
Mutex _fdtLock; Mutex _fdtLock;
UniquePtr<Vector<uint64_t *>> _taken_pages; UniquePtr<Vector<uint64_t *>> _taken_pages;
Mutex _lock; Mutex _lock;
}; };
extern AddressSpace *KERN_AddressSpace; extern AddressSpace *KERN_AddressSpace;
extern uintptr_t kernel_phys_base; extern uintptr_t kernel_phys_base;
extern uintptr_t kernel_virt_base; extern uintptr_t kernel_virt_base;
extern size_t kernel_file_size; extern size_t kernel_file_size;
void limine_kern_save_response(); void limine_kern_save_response();
#define PAGE_PS (1 << 7) #define PAGE_PS (1 << 7)
#define PAGE_RW (1 << 1) #define PAGE_RW (1 << 1)
#define PAGE_USER (1 << 2) #define PAGE_USER (1 << 2)
#define PAGE_PRESENT (0x01ULL) #define PAGE_PRESENT (0x01ULL)
void map_hhdm(uint64_t *pml4); void map_hhdm(uint64_t *pml4);
extern "C" void _tlb_flush(); extern "C" void _tlb_flush();

View File

@@ -9,7 +9,7 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
int init_serial(); int init_serial();
int serial_received(); int serial_received();
char read_serial(); char read_serial();

View File

@@ -115,12 +115,12 @@ uint64_t syscall_print_tasks() {
static SkipListMap<pid_t, std::pair<String, uint64_t>> last_times = Scheduler::getTaskTimePerPid(); static SkipListMap<pid_t, std::pair<String, uint64_t>> last_times = Scheduler::getTaskTimePerPid();
static std::atomic<uint64_t> last_print_time = micros; static std::atomic<uint64_t> last_print_time = micros;
uint64_t prev_print_time = last_print_time; uint64_t prev_print_time = last_print_time;
last_print_time = micros; last_print_time = micros;
SkipListMap<pid_t, std::pair<String, uint64_t>> prev_times = std::move(last_times); SkipListMap<pid_t, std::pair<String, uint64_t>> prev_times = std::move(last_times);
last_times = Scheduler::getTaskTimePerPid(); last_times = Scheduler::getTaskTimePerPid();
uint64_t slice = last_print_time - prev_print_time; uint64_t slice = last_print_time - prev_print_time;
if (slice == 0) return 0; if (slice == 0) return 0;
for (const auto &t: prev_times) { for (const auto &t: prev_times) {
@@ -187,7 +187,7 @@ uint64_t syscall_execve(const char *pathname, char *const argv[], char *const en
ElfParser elfParser(read_data); ElfParser elfParser(read_data);
uint64_t flags_bak = ((task_pointer *) (TASK_POINTER))->ret_flags; uint64_t flags_bak = ((task_pointer *) (TASK_POINTER))->ret_flags;
Scheduler::cur_task()->user_reset(); Scheduler::cur_task()->user_reset();
if (!elfParser.copy_to(Scheduler::cur_task())) if (!elfParser.copy_to(Scheduler::cur_task()))
@@ -208,7 +208,7 @@ uint64_t syscall_execve(const char *pathname, char *const argv[], char *const en
} }
char *syscall_sbrk(int brk) { char *syscall_sbrk(int brk) {
auto vma = Scheduler::cur_task()->_vma.get(); auto vma = Scheduler::cur_task()->_vma.get();
char *ret = reinterpret_cast<char *>(-1); char *ret = reinterpret_cast<char *>(-1);

View File

@@ -7,12 +7,12 @@
#include <cstdint> #include <cstdint>
void setup_syscalls(); void setup_syscalls();
extern "C" void _syscall_entrypoint(); extern "C" void _syscall_entrypoint();
extern "C" void _execve_entrypoint(); extern "C" void _execve_entrypoint();
extern "C" void _syscall_ret(); extern "C" void _syscall_ret();
extern "C" uint64_t syscall_impl(uint64_t id_rdi, uint64_t a1_rsi, uint64_t a2_rdx, uint64_t a3_rcx); extern "C" uint64_t syscall_impl(uint64_t id_rdi, uint64_t a1_rsi, uint64_t a2_rdx, uint64_t a3_rcx);

View File

@@ -43,10 +43,10 @@ std::atomic<uint64_t> max_pid = 0;
Mutex AllTasks_lock; Mutex AllTasks_lock;
SkipListMap<uint64_t, UniquePtr<Task>> AllTasks; SkipListMap<uint64_t, UniquePtr<Task>> AllTasks;
static List<Task *>::Node *RunningTask; static List<Task *>::Node *RunningTask;
static Spinlock NextTasks_lock; static Spinlock NextTasks_lock;
static List<Task *> NextTasks; static List<Task *> NextTasks;
// Task freer // Task freer
Mutex TasksToFree_lock; Mutex TasksToFree_lock;
@@ -58,10 +58,10 @@ Mutex WaitingTasks_mlock;
CV WaitingTasks_cv; CV WaitingTasks_cv;
SkipListMap<uint64_t, Vector<List<Task *>::Node *>> WaitingTasks; SkipListMap<uint64_t, Vector<List<Task *>::Node *>> WaitingTasks;
static std::atomic<bool> initialized = false; static std::atomic<bool> initialized = false;
void Scheduler::dispose_self() { void Scheduler::dispose_self() {
{ {
LockGuard l(TasksToFree_lock); LockGuard l(TasksToFree_lock);
// TasksToFree is expected to do nothing with TS_RUNNING tasks // TasksToFree is expected to do nothing with TS_RUNNING tasks
@@ -189,10 +189,10 @@ static void trampoline(void *rdi, void (*rsi_entrypoint)()) {
void Task::user_setup() { void Task::user_setup() {
assert(_mode == TaskMode::TASKMODE_USER); assert(_mode == TaskMode::TASKMODE_USER);
_frame.cs = Arch::GDT::gdt_code_user.selector() | 0x3; _frame.cs = Arch::GDT::gdt_code_user.selector() | 0x3;
_frame.ss = Arch::GDT::gdt_data_user.selector() | 0x3; _frame.ss = Arch::GDT::gdt_data_user.selector() | 0x3;
_ownAddressSpace = UniquePtr(new AddressSpace()); _ownAddressSpace = UniquePtr(new AddressSpace());
_vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get())); _vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get()));
task_pointer *taskptr = static_cast<task_pointer *>( task_pointer *taskptr = static_cast<task_pointer *>(
_vma->mmap_mem(reinterpret_cast<void *>(TASK_POINTER), _vma->mmap_mem(reinterpret_cast<void *>(TASK_POINTER),
@@ -201,7 +201,7 @@ void Task::user_setup() {
task_pointer *taskptr_real = reinterpret_cast<task_pointer *>(HHDM_P2V(_ownAddressSpace->virt2real(taskptr))); task_pointer *taskptr_real = reinterpret_cast<task_pointer *>(HHDM_P2V(_ownAddressSpace->virt2real(taskptr)));
_entry_ksp_val = ((((uintptr_t) _kstack->_ptr) + (TASK_SS - 9) - 1) & (~0xFULL)); // Ensure 16byte alignment _entry_ksp_val = ((((uintptr_t) _kstack->_ptr) + (TASK_SS - 9) - 1) & (~0xFULL)); // Ensure 16byte alignment
// It should be aligned before call, therefore it actually should be aligned here // It should be aligned before call, therefore it actually should be aligned here
assert((_entry_ksp_val & 0xFULL) == 0); assert((_entry_ksp_val & 0xFULL) == 0);
@@ -209,7 +209,7 @@ void Task::user_setup() {
taskptr_real->entry_ksp_val = _entry_ksp_val; taskptr_real->entry_ksp_val = _entry_ksp_val;
taskptr_real->ret_sp = 0x0; taskptr_real->ret_sp = 0x0;
void *ustack = _vma->mmap_mem(NULL, TASK_SS, 0, PAGE_RW | PAGE_USER); void *ustack = _vma->mmap_mem(NULL, TASK_SS, 0, PAGE_RW | PAGE_USER);
_vma->map_kern(); _vma->map_kern();
// Ensure 16byte alignment // Ensure 16byte alignment
@@ -222,7 +222,7 @@ void Task::user_reset() {
// FIXME: // FIXME:
// delete _ownAddressSpace.release(); // delete _ownAddressSpace.release();
_vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get())); _vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get()));
task_pointer *taskptr = static_cast<task_pointer *>( task_pointer *taskptr = static_cast<task_pointer *>(
_vma->mmap_mem(reinterpret_cast<void *>(TASK_POINTER), _vma->mmap_mem(reinterpret_cast<void *>(TASK_POINTER),
@@ -231,14 +231,14 @@ void Task::user_reset() {
task_pointer *taskptr_real = reinterpret_cast<task_pointer *>(HHDM_P2V(_ownAddressSpace->virt2real(taskptr))); task_pointer *taskptr_real = reinterpret_cast<task_pointer *>(HHDM_P2V(_ownAddressSpace->virt2real(taskptr)));
_entry_ksp_val = ((((uintptr_t) _kstack->_ptr) + (TASK_SS - 9) - 1) & (~0xFULL)); // Ensure 16byte alignment _entry_ksp_val = ((((uintptr_t) _kstack->_ptr) + (TASK_SS - 9) - 1) & (~0xFULL)); // Ensure 16byte alignment
// It should be aligned before call, therefore it actually should be aligned here // It should be aligned before call, therefore it actually should be aligned here
assert((_entry_ksp_val & 0xFULL) == 0); assert((_entry_ksp_val & 0xFULL) == 0);
taskptr_real->taskptr = this; taskptr_real->taskptr = this;
taskptr_real->entry_ksp_val = _entry_ksp_val; taskptr_real->entry_ksp_val = _entry_ksp_val;
void *ustack = _vma->mmap_mem(NULL, TASK_SS, 0, PAGE_RW | PAGE_USER); void *ustack = _vma->mmap_mem(NULL, TASK_SS, 0, PAGE_RW | PAGE_USER);
_vma->map_kern(); _vma->map_kern();
// Ensure 16byte alignment // Ensure 16byte alignment
@@ -376,7 +376,7 @@ static void task_waker() {
auto node = WaitingTasks.begin(); auto node = WaitingTasks.begin();
auto tasks = node->second; auto tasks = node->second;
bool ok = true; bool ok = true;
for (const auto &task: tasks) { for (const auto &task: tasks) {
if (task->val->state() == Task::TaskState::TS_RUNNING) { if (task->val->state() == Task::TaskState::TS_RUNNING) {
ok = false; ok = false;
@@ -415,17 +415,17 @@ Task *Task::clone() {
task_pointer *taskptr_real = reinterpret_cast<task_pointer *>(HHDM_P2V(ret->_addressSpace->virt2real((void *) TASK_POINTER))); task_pointer *taskptr_real = reinterpret_cast<task_pointer *>(HHDM_P2V(ret->_addressSpace->virt2real((void *) TASK_POINTER)));
_entry_ksp_val = ((((uintptr_t) _kstack->_ptr) + (TASK_SS - 9) - 1) & (~0xFULL)); // Ensure 16byte alignment _entry_ksp_val = ((((uintptr_t) _kstack->_ptr) + (TASK_SS - 9) - 1) & (~0xFULL)); // Ensure 16byte alignment
// It should be aligned before call, therefore it actually should be aligned here // It should be aligned before call, therefore it actually should be aligned here
assert((_entry_ksp_val & 0xFULL) == 0); assert((_entry_ksp_val & 0xFULL) == 0);
taskptr_real->taskptr = ret; taskptr_real->taskptr = ret;
taskptr_real->entry_ksp_val = ret->_entry_ksp_val; taskptr_real->entry_ksp_val = ret->_entry_ksp_val;
ret->_frame.ss = Arch::GDT::gdt_data.selector(); ret->_frame.ss = Arch::GDT::gdt_data.selector();
ret->_frame.cs = Arch::GDT::gdt_code.selector(); ret->_frame.cs = Arch::GDT::gdt_code.selector();
ret->_frame.sp = ret->_entry_ksp_val; ret->_frame.sp = ret->_entry_ksp_val;
ret->_parent = Scheduler::cur_task()->_pid; ret->_parent = Scheduler::cur_task()->_pid;
return ret; return ret;
} }
@@ -458,9 +458,9 @@ extern "C" void Scheduler::switch_task(Arch::TaskFrame *cur_frame) {
{ {
SpinlockLockNoIntAssert ntl(NextTasks_lock); SpinlockLockNoIntAssert ntl(NextTasks_lock);
static uint64_t lastSwitchMicros = 0; static uint64_t lastSwitchMicros = 0;
uint64_t prevSwitchMicros = lastSwitchMicros; uint64_t prevSwitchMicros = lastSwitchMicros;
lastSwitchMicros = micros; lastSwitchMicros = micros;
if (RunningTask) { if (RunningTask) {
RunningTask->val->_frame = *cur_frame; RunningTask->val->_frame = *cur_frame;

View File

@@ -39,27 +39,27 @@ public:
/// or -1, wait for anything, then it's set by the zombified process to its PID /// or -1, wait for anything, then it's set by the zombified process to its PID
pid_t _woken_pid = -1; pid_t _woken_pid = -1;
/// Place to put list node when waiting for pid/being zombified /// Place to put list node when waiting for pid/being zombified
List<Task *>::Node *_waitpid_node; List<Task *>::Node *_waitpid_node;
Task(TaskMode mode, void (*entrypoint)(), const char *name); Task(TaskMode mode, void (*entrypoint)(), const char *name);
Task(const Task &) = delete; Task(const Task &) = delete;
Task(Task &&) = delete; Task(Task &&) = delete;
Task &operator=(const Task &) = delete; Task &operator=(const Task &) = delete;
Task &operator=(Task &&) = delete; Task &operator=(Task &&) = delete;
void start(); void start();
[[nodiscard]] const String &name() const { return _name; } [[nodiscard]] const String &name() const { return _name; }
[[nodiscard]] pid_t pid() const { return _pid; } [[nodiscard]] pid_t pid() const { return _pid; }
[[nodiscard]] uint64_t used_time() const { return _used_time; } [[nodiscard]] uint64_t used_time() const { return _used_time; }
[[nodiscard]] TaskState state() const { return _state; } [[nodiscard]] TaskState state() const { return _state; }
~ Task(); ~Task();
Task *clone(); Task *clone();
void user_setup(); void user_setup();
void user_reset(); void user_reset();
//private: //private:
struct KernStack { struct KernStack {
@@ -79,15 +79,15 @@ public:
// as VMA frees what it had allocated there too // as VMA frees what it had allocated there too
UniquePtr<AddressSpace> _ownAddressSpace; UniquePtr<AddressSpace> _ownAddressSpace;
AddressSpace *_addressSpace; AddressSpace *_addressSpace;
UniquePtr<VMA> _vma; UniquePtr<VMA> _vma;
UniquePtr<KernStack> _kstack{new KernStack()}; UniquePtr<KernStack> _kstack{new KernStack()};
UniquePtr<FxSave> _fxsave{new FxSave()}; UniquePtr<FxSave> _fxsave{new FxSave()};
String _name; String _name;
TaskMode _mode; TaskMode _mode;
uint64_t _sleep_until; uint64_t _sleep_until;
TaskState _state; TaskState _state;
pid_t _parent = -1; pid_t _parent = -1;
}; };
@@ -104,32 +104,32 @@ namespace Scheduler {
Task *cur_task(); Task *cur_task();
List<Task *>::Node *extract_running_task_node(); List<Task *>::Node *extract_running_task_node();
void init_tasks(); void init_tasks();
void sleep_self(uint64_t diff); void sleep_self(uint64_t diff);
void remove_self(); void remove_self();
void dispose_self(); void dispose_self();
void zombify_self(); void zombify_self();
void dispose_zombie(Task *zombie); void dispose_zombie(Task *zombie);
void self_block(); void self_block();
void self_block(Spinlock &to_unlock); void self_block(Spinlock &to_unlock);
void self_block(Mutex &to_unlock); void self_block(Mutex &to_unlock);
void unblock(Task *what); void unblock(Task *what);
void unblock(List<Task *>::Node *what); void unblock(List<Task *>::Node *what);
void unblock_nolock(List<Task *>::Node *what); void unblock_nolock(List<Task *>::Node *what);
void waitpid_block(); void waitpid_block();
pid_t waitpid(pid_t pid, int *status, int options); pid_t waitpid(pid_t pid, int *status, int options);
extern "C" void switch_task(Arch::TaskFrame *cur_frame); extern "C" void switch_task(Arch::TaskFrame *cur_frame);
// TODO: that's quite inefficient! // TODO: that's quite inefficient!
SkipListMap<pid_t, std::pair<String, uint64_t>> getTaskTimePerPid(); SkipListMap<pid_t, std::pair<String, uint64_t>> getTaskTimePerPid();
void yield_self(); void yield_self();
} // namespace Scheduler } // namespace Scheduler
// Expects the caller to save interrupt state // Expects the caller to save interrupt state

View File

@@ -10,7 +10,7 @@
volatile std::atomic<uint64_t> ticks; volatile std::atomic<uint64_t> ticks;
volatile std::atomic<uint64_t> micros; volatile std::atomic<uint64_t> micros;
unsigned read_pit_count(void) { unsigned read_pit_count(void) {
unsigned count = 0; unsigned count = 0;
// Disable interrupts // Disable interrupts

View File

@@ -11,7 +11,7 @@
extern volatile std::atomic<uint64_t> ticks; extern volatile std::atomic<uint64_t> ticks;
extern volatile std::atomic<uint64_t> micros; extern volatile std::atomic<uint64_t> micros;
void init_timer(); void init_timer();
void timer_tick(); void timer_tick();
#endif //FICUS_TIMER_H #endif //FICUS_TIMER_H

View File

@@ -8,11 +8,11 @@
#include "Vector.hpp" #include "Vector.hpp"
#include "mutex.hpp" #include "mutex.hpp"
TtyManager GlobalTtyManager; TtyManager GlobalTtyManager;
Vector<TtyManager> ttys; Vector<TtyManager> ttys;
void TtyManager::add_tty(Tty *tty) { void TtyManager::add_tty(Tty *tty) {
LockGuard l(lock); LockGuard l(lock);
ttys.emplace_back(tty); ttys.emplace_back(tty);
} }

View File

@@ -14,10 +14,10 @@ class TtyManager {
Vector<Tty *> ttys; Vector<Tty *> ttys;
public: public:
void add_tty(Tty *tty); void add_tty(Tty *tty);
void all_tty_putchar(char c); void all_tty_putchar(char c);
void all_tty_putstr(const char *str); void all_tty_putstr(const char *str);
unsigned get_num_ttys(); unsigned get_num_ttys();
Tty *get_tty(unsigned n); Tty *get_tty(unsigned n);

View File

@@ -32,12 +32,12 @@ public:
void *mmap_mem(void *v_addr, size_t length, int prot, int flags); void *mmap_mem(void *v_addr, size_t length, int prot, int flags);
int munmap(void *addr, size_t length); int munmap(void *addr, size_t length);
static constexpr size_t kBrkSize = 16ULL*1024ULL*1024ULL; static constexpr size_t kBrkSize = 16ULL * 1024ULL * 1024ULL;
std::optional<char*> brk_start; std::optional<char *> brk_start;
std::optional<char*> brk_end_fake; std::optional<char *> brk_end_fake;
std::optional<char*> brk_end_real; std::optional<char *> brk_end_real;
void clone_from(const VMA& vma); void clone_from(const VMA &vma);
private: private:
AddressSpace *space = nullptr; AddressSpace *space = nullptr;
@@ -53,14 +53,14 @@ private:
uintptr_t begin; uintptr_t begin;
uint64_t length; uint64_t length;
EntryType type = EntryType::FREE; EntryType type = EntryType::FREE;
int flags; int flags;
}; };
ListEntry *get_entry(uintptr_t v_addr, size_t length); ListEntry *get_entry(uintptr_t v_addr, size_t length);
// //
SkipListMap<uintptr_t, ListEntry> regions; SkipListMap<uintptr_t, ListEntry> regions;
Mutex regions_lock; Mutex regions_lock;
}; };

View File

@@ -15,7 +15,7 @@
#define STACK_CHK_GUARD 0x2e61e13e4d5ae23c #define STACK_CHK_GUARD 0x2e61e13e4d5ae23c
#endif #endif
__attribute__((used)) uintptr_t __stack_chk_guard = STACK_CHK_GUARD; __attribute__((used)) uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
extern "C" __attribute__((noreturn, used)) void __stack_chk_fail(void) { extern "C" __attribute__((noreturn, used)) void __stack_chk_fail(void) {
assert2(false, "Stack protection triggered!"); assert2(false, "Stack protection triggered!");
@@ -32,11 +32,11 @@ namespace __cxxabiv1 {
/* The ABI requires a 64-bit type. */ /* The ABI requires a 64-bit type. */
__extension__ typedef int __guard __attribute__((mode(__DI__))); __extension__ typedef int __guard __attribute__((mode(__DI__)));
extern "C" int __cxa_guard_acquire(__guard *); extern "C" int __cxa_guard_acquire(__guard *);
extern "C" void __cxa_guard_release(__guard *); extern "C" void __cxa_guard_release(__guard *);
extern "C" void __cxa_guard_abort(__guard *); extern "C" void __cxa_guard_abort(__guard *);
extern "C" int __cxa_guard_acquire(__guard *g) { extern "C" int __cxa_guard_acquire(__guard *g) {
return !*(char *) (g); return !*(char *) (g);
} }
@@ -102,7 +102,7 @@ struct type_mismatch_info {
uint8_t type_check_kind; uint8_t type_check_kind;
}; };
#define SAN_STOP true #define SAN_STOP true
#define is_aligned(value, alignment) !(value & (alignment - 1)) #define is_aligned(value, alignment) !(value & (alignment - 1))
__attribute__((used)) void __ubsan_handle_type_mismatch_v1(struct type_mismatch_info *type_mismatch, __attribute__((used)) void __ubsan_handle_type_mismatch_v1(struct type_mismatch_info *type_mismatch,

View File

@@ -107,10 +107,10 @@ bool ElfParser::copy_to(Task *task) {
flags |= PAGE_RW; flags |= PAGE_RW;
} }
auto rounded_vaddr = hdr.p_vaddr & 0x000FFFFFFFFFF000ULL; auto rounded_vaddr = hdr.p_vaddr & 0x000FFFFFFFFFF000ULL;
auto real_memsz = hdr.p_memsz + (hdr.p_vaddr - rounded_vaddr); auto real_memsz = hdr.p_memsz + (hdr.p_vaddr - rounded_vaddr);
uintptr_t real_ptr = reinterpret_cast<uintptr_t>(task->_vma->mmap_mem(reinterpret_cast<void *>(rounded_vaddr), real_memsz, 0, flags | PAGE_USER)); uintptr_t real_ptr = reinterpret_cast<uintptr_t>(task->_vma->mmap_mem(reinterpret_cast<void *>(rounded_vaddr), real_memsz, 0, flags | PAGE_USER));
if (real_ptr != rounded_vaddr) return false; if (real_ptr != rounded_vaddr) return false;
auto *file_ptr = _data.begin(); auto *file_ptr = _data.begin();

View File

@@ -14,8 +14,8 @@ class Task;
// Just copying everytihng for now // Just copying everytihng for now
class ElfParser { class ElfParser {
public: public:
ElfParser(Vector<char> data); ElfParser(Vector<char> data);
bool copy_to(Task *task); bool copy_to(Task *task);
uintptr_t get_entrypoint() { return _entrypoint; } uintptr_t get_entrypoint() { return _entrypoint; }
@@ -53,7 +53,7 @@ private:
Elf64_Xword p_memsz; /* Size of segment in memory */ Elf64_Xword p_memsz; /* Size of segment in memory */
Elf64_Xword p_align; /* Alignment of segment */ Elf64_Xword p_align; /* Alignment of segment */
bool valid = false; bool valid = false;
using serializable = std::true_type; using serializable = std::true_type;
Elf64_Phdr(Vector<char>::const_iterator &in, const Vector<char>::const_iterator &end); Elf64_Phdr(Vector<char>::const_iterator &in, const Vector<char>::const_iterator &end);
}; };

View File

@@ -31,11 +31,11 @@ public:
private: private:
std::atomic<bool> locked = false; std::atomic<bool> locked = false;
List<Task *> waiters; List<Task *> waiters;
Spinlock waiters_lock; Spinlock waiters_lock;
Task *_owner = nullptr; Task *_owner = nullptr;
uint8_t spin_success = 127; uint8_t spin_success = 127;
}; };

View File

@@ -8,9 +8,9 @@
// The following functions define a portable implementation of rand and srand. // The following functions define a portable implementation of rand and srand.
static std::atomic<unsigned long int> next = 1; // NB: "unsigned long int" is assumed to be 32 bits wide static std::atomic<unsigned long int> next = 1; // NB: "unsigned long int" is assumed to be 32 bits wide
extern "C" int rand(void) // RAND_MAX assumed to be 32767 extern "C" int rand(void) // RAND_MAX assumed to be 32767
{ {
next = next * 1103515245 + 12345; next = next * 1103515245 + 12345;
return (unsigned int) (next / 65536ULL) % 32768; return (unsigned int) (next / 65536ULL) % 32768;

View File

@@ -21,13 +21,13 @@ public:
}; };
private: private:
Node *head = nullptr; Node *head = nullptr;
Node *tail = nullptr; Node *tail = nullptr;
uint64_t size = 0; uint64_t size = 0;
public: public:
List() = default; List() = default;
~List() { ~List() {
while (!empty()) { while (!empty()) {
pop_back(); pop_back();

View File

@@ -19,15 +19,15 @@ public:
explicit UniquePtr(T *data) : ptr(data) {} explicit UniquePtr(T *data) : ptr(data) {}
~ UniquePtr() { ~UniquePtr() {
if (ptr == nullptr) return; if (ptr == nullptr) return;
delete ptr; delete ptr;
} }
UniquePtr(UniquePtr const &other) = delete; UniquePtr(UniquePtr const &other) = delete;
UniquePtr &operator=(UniquePtr const &other) = delete; UniquePtr &operator=(UniquePtr const &other) = delete;
UniquePtr(UniquePtr &&other) { UniquePtr(UniquePtr &&other) {
delete ptr; delete ptr;
ptr = other.ptr; ptr = other.ptr;
other.ptr = nullptr; other.ptr = nullptr;
@@ -133,12 +133,12 @@ class SharedPtr {
friend SharedPtrTester; friend SharedPtrTester;
public: public:
SharedPtr() = default; SharedPtr() = default;
explicit SharedPtr(T *data) : _ptr(data), _base(new SharedPtr_Base{SharedPtr_Base::UsesBlock{1, 1}}) {} explicit SharedPtr(T *data) : _ptr(data), _base(new SharedPtr_Base{SharedPtr_Base::UsesBlock{1, 1}}) {}
SharedPtr(std::nullptr_t a_nullptr) : _ptr(nullptr), _base(nullptr) {} SharedPtr(std::nullptr_t a_nullptr) : _ptr(nullptr), _base(nullptr) {}
~ SharedPtr() { ~SharedPtr() {
unref(); unref();
} }
@@ -188,7 +188,7 @@ private:
explicit SharedPtr(T *ptr, SharedPtr_Base *base) : _ptr(ptr), _base(base) {} explicit SharedPtr(T *ptr, SharedPtr_Base *base) : _ptr(ptr), _base(base) {}
void unref() { void unref() {
if (!_base) return; if (!_base) return;
if (_base->strong_release()) if (_base->strong_release())
delete _ptr; delete _ptr;
@@ -204,10 +204,10 @@ private:
template<typename T> template<typename T>
class WeakPtr { class WeakPtr {
public: public:
WeakPtr() = default; WeakPtr() = default;
WeakPtr(const SharedPtr<T> &shared) : _base(shared._base), _ptr(shared._ptr) { _base->weak_lock(); } WeakPtr(const SharedPtr<T> &shared) : _base(shared._base), _ptr(shared._ptr) { _base->weak_lock(); }
WeakPtr(std::nullptr_t a_nullptr) : _ptr(nullptr), _base(nullptr) {} WeakPtr(std::nullptr_t a_nullptr) : _ptr(nullptr), _base(nullptr) {}
~WeakPtr() { ~WeakPtr() {
unref(); unref();
@@ -283,29 +283,29 @@ private:
friend COWTester; friend COWTester;
SharedPtr<T> ptr; SharedPtr<T> ptr;
void copy() { void copy() {
if (ptr.get() && ptr.useCount() > 1) { if (ptr.get() && ptr.useCount() > 1) {
ptr = SharedPtr<T>(new T(*ptr)); ptr = SharedPtr<T>(new T(*ptr));
} }
} }
public: public:
COWPointer() = default; COWPointer() = default;
explicit COWPointer(T *data) : ptr(data) {} explicit COWPointer(T *data) : ptr(data) {}
explicit COWPointer(SharedPtr<T> data) : ptr(std::move(data)) {} explicit COWPointer(SharedPtr<T> data) : ptr(std::move(data)) {}
COWPointer(COWPointer &&other) = default; COWPointer(COWPointer &&other) = default;
COWPointer(COWPointer const &data) = default; COWPointer(COWPointer const &data) = default;
COWPointer &operator=(COWPointer other) { COWPointer &operator=(COWPointer other) {
std::swap(ptr, other.ptr); std::swap(ptr, other.ptr);
return *this; return *this;
} }
~ COWPointer() = default; ~COWPointer() = default;
T *get() const { T *get() const {
return ptr.get(); return ptr.get();
@@ -316,7 +316,7 @@ public:
return ptr.get(); return ptr.get();
} }
int useCount() { return ptr.useCount(); }; int useCount() { return ptr.useCount(); };
const T &operator*() const { const T &operator*() const {
return *ptr; return *ptr;

View File

@@ -48,7 +48,7 @@ protected:
Node *nodes[size]; Node *nodes[size];
int top = -1; int top = -1;
Node *get() { Node *get() {
Node *node; Node *node;
if (top == -1) if (top == -1)
node = static_cast<Node *>(kmalloc(sizeof(Node))); node = static_cast<Node *>(kmalloc(sizeof(Node)));
@@ -63,7 +63,7 @@ protected:
} }
public: public:
NodeAllocator() noexcept = default; NodeAllocator() noexcept = default;
~NodeAllocator() noexcept { ~NodeAllocator() noexcept {
for (int i = top; i >= 0; i--) { for (int i = top; i >= 0; i--) {
@@ -114,7 +114,7 @@ protected:
mutable Node *toUpdate[maxL + 1]; mutable Node *toUpdate[maxL + 1];
size_t curL = 0; size_t curL = 0;
SkipListBase() noexcept { SkipListBase() noexcept {
root = (Node *) nodeAllocator.get_end(); root = (Node *) nodeAllocator.get_end();
endnode = (Node *) nodeAllocator.get_end(); endnode = (Node *) nodeAllocator.get_end();
endnode->before = root; endnode->before = root;
@@ -220,11 +220,11 @@ protected:
using pointer = value_type *; using pointer = value_type *;
using reference = value_type &; using reference = value_type &;
explicit SkipListBaseIteratorBase(Node *n) : n(std::move(n)){}; explicit SkipListBaseIteratorBase(Node *n) : n(std::move(n)){};
reference operator*() const { return n->get(); } reference operator*() const { return n->get(); }
pointer operator->() const { return &n->get(); } pointer operator->() const { return &n->get(); }
SkipListBaseIteratorBase &operator--() { SkipListBaseIteratorBase &operator--() {
if (n->before) if (n->before)
@@ -469,8 +469,8 @@ public:
return true; return true;
} }
iterator begin() { return iterator(root->next[0]); } iterator begin() { return iterator(root->next[0]); }
iterator end() { return iterator(endnode); } iterator end() { return iterator(endnode); }
const_iterator begin() const { return const_iterator(root->next[0]); } const_iterator begin() const { return const_iterator(root->next[0]); }
const_iterator end() const { return const_iterator(endnode); } const_iterator end() const { return const_iterator(endnode); }

View File

@@ -29,8 +29,8 @@ public:
} }
String(String &&str) noexcept { String(String &&str) noexcept {
_data = str._data; _data = str._data;
_cur_len = str._cur_len; _cur_len = str._cur_len;
str._cur_len = 0; str._cur_len = 0;
str._data = nullptr; str._data = nullptr;

View File

@@ -29,9 +29,9 @@ public:
_cur_size = l.size(); _cur_size = l.size();
_capacity = _cur_size > 0 ? _cur_size : 2; _capacity = _cur_size > 0 ? _cur_size : 2;
_data = static_cast<T *>(kmalloc(_capacity * sizeof(T))); _data = static_cast<T *>(kmalloc(_capacity * sizeof(T)));
size_t i = 0; size_t i = 0;
for (auto const &el: l) { for (auto const &el: l) {
new (_data + (i++)) T(el); new (_data + (i++)) T(el);
} }
@@ -41,7 +41,7 @@ public:
_cur_size = vec._cur_size; _cur_size = vec._cur_size;
_capacity = _cur_size > 0 ? _cur_size : 2; _capacity = _cur_size > 0 ? _cur_size : 2;
_data = static_cast<T *>(kmalloc(_capacity * sizeof(T))); _data = static_cast<T *>(kmalloc(_capacity * sizeof(T)));
for (size_t i = 0; i < _cur_size; i++) for (size_t i = 0; i < _cur_size; i++)
new (_data + i) T(vec._data[i]); new (_data + i) T(vec._data[i]);

View File

@@ -17,16 +17,16 @@ public:
FDT(); FDT();
using FD = int64_t; using FD = int64_t;
FD open(const Path &p, int opts); FD open(const Path &p, int opts);
void close(FD fd); void close(FD fd);
File *get(FD fd) const; File *get(FD fd) const;
static FDT *current(); static FDT *current();
private: private:
SkipListMap<FD, UniquePtr<File>> _files; SkipListMap<FD, UniquePtr<File>> _files;
int64_t _cur_fd = 10; int64_t _cur_fd = 10;
mutable Mutex _mtx; mutable Mutex _mtx;
}; };
class FDHandle { class FDHandle {
@@ -36,7 +36,7 @@ public:
FDHandle(const File &f) = delete; FDHandle(const File &f) = delete;
FDHandle &operator=(const File &o) = delete; FDHandle &operator=(const File &o) = delete;
FDT::FD get() { return _fd; } FDT::FD get() { return _fd; }
private: private:
FDT::FD _fd; FDT::FD _fd;

View File

@@ -17,23 +17,23 @@ class File {
public: public:
File(SharedPtr<Node> n, int opts); File(SharedPtr<Node> n, int opts);
~File(); ~File();
File(const File &f) = delete; File(const File &f) = delete;
File &operator=(const File &o) = delete; File &operator=(const File &o) = delete;
SharedPtr<Node> node() const; SharedPtr<Node> node() const;
SharedPtr<NodeDir> dir() const; SharedPtr<NodeDir> dir() const;
SharedPtr<NodeFile> file() const; SharedPtr<NodeFile> file() const;
uint64_t seek(uint64_t pos); uint64_t seek(uint64_t pos);
uint64_t pos() { return _pos; } uint64_t pos() { return _pos; }
uint64_t read(char *buf, uint64_t size); uint64_t read(char *buf, uint64_t size);
uint64_t write(const char *buf, uint64_t size); uint64_t write(const char *buf, uint64_t size);
uint64_t size(); uint64_t size();
private: private:
SharedPtr<Node> _n; SharedPtr<Node> _n;
uint64_t _pos = 0; uint64_t _pos = 0;
int _opts; int _opts;
}; };
#endif //FICUS_FILE_HPP #endif //FICUS_FILE_HPP

View File

@@ -8,7 +8,7 @@
#include <algorithm> #include <algorithm>
Vector<SharedPtr<Node>> MemFs::MemFsNodeDir::children() { Vector<SharedPtr<Node>> MemFs::MemFsNodeDir::children() {
LockGuard l(_lock); LockGuard l(_lock);
Vector<SharedPtr<Node>> out; Vector<SharedPtr<Node>> out;
for (auto c: _children) { for (auto c: _children) {

View File

@@ -14,9 +14,9 @@
class MemFs : public Filesystem { class MemFs : public Filesystem {
struct MemFsNodeDir : public NodeDir { struct MemFsNodeDir : public NodeDir {
public: public:
Vector<SharedPtr<Node>> children() override; Vector<SharedPtr<Node>> children() override;
SharedPtr<NodeDir> mkdir(const String &name) override; SharedPtr<NodeDir> mkdir(const String &name) override;
SharedPtr<NodeFile> mkfile(const String &name) override; SharedPtr<NodeFile> mkfile(const String &name) override;
static SharedPtr<MemFsNodeDir> create(const String &name) { static SharedPtr<MemFsNodeDir> create(const String &name) {
auto shared = SharedPtr(new MemFsNodeDir(name)); auto shared = SharedPtr(new MemFsNodeDir(name));
@@ -31,10 +31,10 @@ class MemFs : public Filesystem {
struct MemFsNodeFile : public NodeFile { struct MemFsNodeFile : public NodeFile {
public: public:
int64_t read(char *buf, size_t start, size_t num) override; int64_t read(char *buf, size_t start, size_t num) override;
int64_t write(const char *buf, size_t start, size_t num) override; int64_t write(const char *buf, size_t start, size_t num) override;
size_t size() override; size_t size() override;
bool is_tty() override { return false; } bool is_tty() override { return false; }
static SharedPtr<MemFsNodeFile> create(const String &name) { static SharedPtr<MemFsNodeFile> create(const String &name) {
auto shared = SharedPtr(new MemFsNodeFile(name)); auto shared = SharedPtr(new MemFsNodeFile(name));

View File

@@ -9,10 +9,10 @@
#include "Node.hpp" #include "Node.hpp"
class TtyPipe : public NodeFile { class TtyPipe : public NodeFile {
public: public:
int64_t read(char *buf, size_t start, size_t num) override; int64_t read(char *buf, size_t start, size_t num) override;
int64_t write(const char *buf, size_t start, size_t num) override; int64_t write(const char *buf, size_t start, size_t num) override;
size_t size() override; size_t size() override;
bool is_tty() override { return true; } bool is_tty() override { return true; }
static SharedPtr<TtyPipe> create() { static SharedPtr<TtyPipe> create() {
auto shared = SharedPtr(new TtyPipe()); auto shared = SharedPtr(new TtyPipe());

View File

@@ -10,14 +10,14 @@
#include "Path.hpp" #include "Path.hpp"
namespace VFSApi { namespace VFSApi {
bool mkdir(const Path &path); bool mkdir(const Path &path);
bool touch(const Path &path); bool touch(const Path &path);
FDT::FD open(const Path &path); FDT::FD open(const Path &path);
File *get(FDT::FD fd); File *get(FDT::FD fd);
void close(FDT::FD fd); void close(FDT::FD fd);
}; // namespace VFSApi }; // namespace VFSApi
#endif //FICUS_VFSAPI_HPP #endif //FICUS_VFSAPI_HPP

View File

@@ -18,7 +18,7 @@ public:
namespace VFSGlobals { namespace VFSGlobals {
extern RootNode root; extern RootNode root;
extern MountTable mounts; extern MountTable mounts;
}; // namespace VFSGlobals }; // namespace VFSGlobals
#endif //FICUS_VFSGLOBALS_HPP #endif //FICUS_VFSGLOBALS_HPP

View File

@@ -26,12 +26,12 @@ using IntType = long long;
class CRange { class CRange {
public: public:
IntType l = 0; IntType l = 0;
IntType r = 0; IntType r = 0;
CRange() = default; CRange() = default;
CRange(IntType l, IntType r) : l(l), r(r) { CRange(IntType l, IntType r) : l(l), r(r) {
if (l > r) if (l > r)
throw std::logic_error("CRange bad initialisation"); throw std::logic_error("CRange bad initialisation");
} }
@@ -239,9 +239,9 @@ public:
this->it++; this->it++;
} }
reference operator*() const { return (it->second.first); } reference operator*() const { return (it->second.first); }
pointer operator->() const { return &(it->second.first); } pointer operator->() const { return &(it->second.first); }
CRangeListIterator &operator++() { CRangeListIterator &operator++() {
++it; ++it;