mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-28 16:17:51 +01:00
Tweak clang-format to not align across empty lines
That should fix insane function declarations
This commit is contained in:
@@ -4,19 +4,19 @@ AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
class SerialTty : public Tty {
|
||||
// TODO: Possibly there should be 2 mutexes?
|
||||
Mutex mutex;
|
||||
CV readercv;
|
||||
CV isrcv;
|
||||
static void isr(void *tty);
|
||||
Mutex mutex;
|
||||
CV readercv;
|
||||
CV isrcv;
|
||||
static void isr(void *tty);
|
||||
|
||||
void this_isr();
|
||||
void this_pooler();
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Arch::GDT {
|
||||
static constexpr size_t INT_STACK_SIZE = 16384;
|
||||
static constexpr size_t RSP_STACK_SIZE = 16384;
|
||||
|
||||
static uint64_t int_stack[INT_STACK_SIZE];
|
||||
static uint64_t rsp_stack[RSP_STACK_SIZE];
|
||||
static uint64_t int_stack[INT_STACK_SIZE];
|
||||
static uint64_t rsp_stack[RSP_STACK_SIZE];
|
||||
|
||||
//
|
||||
void gdt_setup() {
|
||||
@@ -33,7 +33,7 @@ namespace Arch::GDT {
|
||||
gdt_tss.gran = 0;
|
||||
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);
|
||||
|
||||
tss_entry.rsp0 = (((uintptr_t) rsp_stack + (RSP_STACK_SIZE - 9) - 1) & (~0xFULL)) + 8;
|
||||
|
||||
@@ -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_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 {
|
||||
uint16_t limit;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Arch::IDT {
|
||||
__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_1();
|
||||
@@ -34,8 +34,8 @@ namespace Arch::IDT {
|
||||
extern "C" void pic2_irq_7();
|
||||
|
||||
|
||||
void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags) {
|
||||
IdtEntry *descriptor = &idt[vector];
|
||||
void idt_set_descriptor(uint8_t vector, void (*isr)(), uint8_t flags) {
|
||||
IdtEntry *descriptor = &idt[vector];
|
||||
|
||||
descriptor->isr_low = (uint64_t) isr & 0xFFFF;
|
||||
descriptor->kernel_cs = Arch::GDT::gdt_code.selector();
|
||||
|
||||
@@ -5,19 +5,19 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace Arch::IDT {
|
||||
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 kPIC1_COMMAND = kPIC1;
|
||||
static constexpr int kPIC1_DATA = (kPIC1 + 1);
|
||||
static constexpr int kPIC2_COMMAND = kPIC2;
|
||||
static constexpr int kPIC2_DATA = (kPIC2 + 1);
|
||||
static constexpr int kPIC_EOI = 0x20; /* End-of-interrupt command code */
|
||||
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 kPIC1_COMMAND = kPIC1;
|
||||
static constexpr int kPIC1_DATA = (kPIC1 + 1);
|
||||
static constexpr int kPIC2_COMMAND = kPIC2;
|
||||
static constexpr int kPIC2_DATA = (kPIC2 + 1);
|
||||
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_SINGLE = 0x02; /* Single (cascade) mode */
|
||||
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_INIT = 0x10; /* Initialization - required! */
|
||||
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_INTERVAL4 = 0x04; /* Call address interval 4 (8) */
|
||||
static constexpr int kICW1_LEVEL = 0x08; /* Level triggered (edge) mode */
|
||||
static constexpr int kICW1_INIT = 0x10; /* Initialization - required! */
|
||||
|
||||
static constexpr int kICW4_8086 = 0x01; /* 8086/88 (MCS-80/85) mode */
|
||||
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_SFNM = 0x10; /* Special fully nested (not) */
|
||||
|
||||
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_IRR = 0x0a; /* OCW3 irq ready 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 kPIC2_OFFSET = 0x28;
|
||||
static constexpr int kPIC1_OFFSET = 0x20;
|
||||
static constexpr int kPIC2_OFFSET = 0x28;
|
||||
|
||||
void PIC_sendEOI(unsigned char irq);
|
||||
void PIC_init();
|
||||
void IRQ_set_mask(unsigned char IRQline);
|
||||
void IRQ_clear_mask(unsigned char IRQline);
|
||||
uint16_t pic_get_irr(void);
|
||||
uint16_t pic_get_isr(void);
|
||||
void PIC_sendEOI(unsigned char irq);
|
||||
void PIC_init();
|
||||
void IRQ_set_mask(unsigned char IRQline);
|
||||
void IRQ_clear_mask(unsigned char IRQline);
|
||||
uint16_t pic_get_irr(void);
|
||||
uint16_t pic_get_isr(void);
|
||||
|
||||
struct IdtEntry {
|
||||
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_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[])();
|
||||
} // namespace Arch::IDT
|
||||
|
||||
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
|
||||
@@ -69,7 +69,7 @@ void ktask() {
|
||||
|
||||
static Mutex testmutex;
|
||||
|
||||
void mtest1() {
|
||||
void mtest1() {
|
||||
{
|
||||
LockGuard l(testmutex);
|
||||
GlobalTtyManager.all_tty_putstr("Locked1\n");
|
||||
@@ -160,7 +160,7 @@ void ktask_main() {
|
||||
memcpy(read_data.begin(), mod.address, mod.size);
|
||||
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))
|
||||
utask->start();
|
||||
else
|
||||
@@ -180,7 +180,7 @@ void dummy_task() {
|
||||
extern void (*ctors_begin[])();
|
||||
extern void (*ctors_end[])();
|
||||
|
||||
void kmain() {
|
||||
void kmain() {
|
||||
for (void (**ctor)() = ctors_begin; ctor < ctors_end; ctor++)
|
||||
(*ctor)();
|
||||
|
||||
|
||||
@@ -11,15 +11,15 @@
|
||||
#include "mutex.hpp"
|
||||
#include "string.h"
|
||||
|
||||
struct HeapEntry *KERN_HeapBegin;
|
||||
uintptr_t KERN_HeapEnd; // Past the end
|
||||
struct HeapEntry *KERN_HeapBegin;
|
||||
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> used = 0;
|
||||
std::atomic<uint64_t> allocated = 0;
|
||||
std::atomic<uint64_t> used = 0;
|
||||
|
||||
uint64_t get_heap_allocated() {
|
||||
uint64_t get_heap_allocated() {
|
||||
return allocated;
|
||||
}
|
||||
uint64_t get_heap_used() {
|
||||
@@ -28,7 +28,7 @@ uint64_t get_heap_used() {
|
||||
|
||||
static Mutex kmem_lock;
|
||||
|
||||
void init_kern_heap() {
|
||||
void init_kern_heap() {
|
||||
KERN_HeapBegin = static_cast<HeapEntry *>(get4k());
|
||||
allocated.fetch_add(PAGE_SIZE);
|
||||
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->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)
|
||||
? data_needed >> 12
|
||||
: ((data_needed & (~0xFFF)) + 0x1000) >> 12;
|
||||
size_t pages_needed = ((data_needed & 0xFFF) == 0)
|
||||
? data_needed >> 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);
|
||||
new_entry->next = NULL;
|
||||
new_entry->prev = entry;
|
||||
@@ -280,7 +280,7 @@ static struct HeapEntry *try_shrink_heap(struct HeapEntry *entry) {
|
||||
|
||||
void kfree(void *addr) {
|
||||
assert(initialized);
|
||||
LockGuard l(kmem_lock);
|
||||
LockGuard l(kmem_lock);
|
||||
|
||||
struct HeapEntry *freed = (struct HeapEntry *) (addr - (sizeof(struct HeapEntry)));
|
||||
used.fetch_sub(freed->len);
|
||||
|
||||
@@ -25,12 +25,12 @@ struct HeapEntry {
|
||||
extern struct HeapEntry *KERN_HeapBegin;
|
||||
extern uintptr_t KERN_HeapEnd; // Past the end
|
||||
|
||||
void *kmalloc(size_t n);
|
||||
void kfree(void *addr);
|
||||
void *krealloc(void *addr, size_t newsize);
|
||||
void *kmalloc(size_t n);
|
||||
void kfree(void *addr);
|
||||
void *krealloc(void *addr, size_t newsize);
|
||||
|
||||
uint64_t get_heap_allocated();
|
||||
uint64_t get_heap_used();
|
||||
uint64_t get_heap_allocated();
|
||||
uint64_t get_heap_used();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -204,14 +204,14 @@ struct limine_framebuffer_request {
|
||||
#define LIMINE_TERMINAL_CB_MODE 70
|
||||
#define LIMINE_TERMINAL_CB_LINUX 80
|
||||
|
||||
#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t) (-1))
|
||||
#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t) (-2))
|
||||
#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t) (-3))
|
||||
#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t) (-4))
|
||||
#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t) (-1))
|
||||
#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t) (-2))
|
||||
#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t) (-3))
|
||||
#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t) (-4))
|
||||
|
||||
/* Response revision 1 */
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t) (-10))
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t) (-11))
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t) (-10))
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t) (-11))
|
||||
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1)
|
||||
@@ -226,8 +226,8 @@ LIMINE_DEPRECATED_IGNORE_START
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal;
|
||||
|
||||
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_write)(struct limine_terminal *, const char *, uint64_t);
|
||||
typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal {
|
||||
uint64_t columns;
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
#include "paging.hpp"
|
||||
|
||||
void limine_fb_save_response(struct AddressSpace *boot_address_space);
|
||||
void limine_fb_remap(struct AddressSpace *space);
|
||||
void limine_fb_save_response(struct AddressSpace *boot_address_space);
|
||||
void limine_fb_remap(struct AddressSpace *space);
|
||||
|
||||
extern int framebuffer_count;
|
||||
extern struct limine_framebuffer framebuffers[10];
|
||||
|
||||
@@ -16,7 +16,7 @@ unsigned int limine_mm_count;
|
||||
struct limine_memmap_entry limine_mm_entries[LIMINE_MM_MAX];
|
||||
unsigned int limine_mm_overflow;
|
||||
|
||||
void limine_mm_save_response() {
|
||||
void limine_mm_save_response() {
|
||||
limine_mm_count = memmap_request.response->entry_count;
|
||||
if (limine_mm_count > LIMINE_MM_MAX) {
|
||||
limine_mm_count = LIMINE_MM_MAX;
|
||||
|
||||
@@ -13,6 +13,6 @@ extern unsigned int limine_mm_count;
|
||||
extern struct limine_memmap_entry limine_mm_entries[LIMINE_MM_MAX];
|
||||
extern unsigned int limine_mm_overflow;
|
||||
|
||||
void limine_mm_save_response();
|
||||
void limine_mm_save_response();
|
||||
|
||||
#endif //FICUS_LIMINE_MM_H
|
||||
|
||||
@@ -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)));
|
||||
unsigned saved_modules_size = 0;
|
||||
|
||||
void limine_modules_remap() {
|
||||
void limine_modules_remap() {
|
||||
for (int i = 0; i < module_request.response->module_count; i++) {
|
||||
assert2(i < max_saved_modules, "Too many modules");
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
|
||||
extern volatile struct limine_module_request module_request;
|
||||
|
||||
static constexpr unsigned max_saved_modules = 4;
|
||||
static constexpr unsigned max_saved_module_name = 256;
|
||||
static constexpr unsigned max_saved_modules = 4;
|
||||
static constexpr unsigned max_saved_module_name = 256;
|
||||
|
||||
void limine_modules_remap();
|
||||
|
||||
extern unsigned saved_modules_size;
|
||||
extern limine_file saved_modules[max_saved_modules];
|
||||
extern char saved_modules_names[max_saved_modules][max_saved_module_name] __attribute__((aligned(4096)));
|
||||
extern unsigned saved_modules_size;
|
||||
extern limine_file saved_modules[max_saved_modules];
|
||||
extern char saved_modules_names[max_saved_modules][max_saved_module_name] __attribute__((aligned(4096)));
|
||||
|
||||
#endif //FICUS_LIMINE_MODULES_HPP
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
// Expected to be nulled by the bootloader
|
||||
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 minPid = 0;
|
||||
static uint64_t totalMem = 0; // Past the end
|
||||
static uint64_t maxPid = 0; // Past the end
|
||||
static uint64_t minPid = 0;
|
||||
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;
|
||||
else {
|
||||
return (addr + 0x1000) & (~(0xFFFULL));
|
||||
|
||||
@@ -21,7 +21,7 @@ struct FourPages {
|
||||
} __attribute__((packed));
|
||||
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 free4k(void *page);
|
||||
|
||||
@@ -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 < kernel_virt_base, "CR3 here must be in HHDM!");
|
||||
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
|
||||
|
||||
uint64_t *pml4e = PML4 + pml4i;
|
||||
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 < kernel_virt_base, "CR3 here must be in HHDM!");
|
||||
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
|
||||
|
||||
|
||||
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 < kernel_virt_base, "CR3 here must be in HHDM!");
|
||||
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t ptsi = (uint64_t) virt >> 12 & 0x01FF;
|
||||
|
||||
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_used = 0;
|
||||
|
||||
uintptr_t kernel_phys_base;
|
||||
uintptr_t kernel_virt_base;
|
||||
uintptr_t kernel_phys_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!");
|
||||
uint64_t *newp = early_pages[early_pages_used++];
|
||||
for (int i = 0; i < 512; i++)
|
||||
@@ -221,16 +221,16 @@ void map_hhdm(uint64_t *pml4) {
|
||||
// Assuming everything related to paging is HHDM
|
||||
assert2((uint64_t) pml4 < 0x8000000000000000ULL, "CR3 here must be physical!");
|
||||
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
uint64_t pml4i = (uint64_t) virt >> 39 & 0x01FF;
|
||||
uint64_t pdpei = (uint64_t) virt >> 30 & 0x01FF;
|
||||
uint64_t pdei = (uint64_t) virt >> 21 & 0x01FF;
|
||||
|
||||
uint64_t *pml4e = pml4 + pml4i;
|
||||
|
||||
if (!(*pml4e & PAGE_PRESENT)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ void map_hhdm(uint64_t *pml4) {
|
||||
if (!(*pdpee & PAGE_PRESENT)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,18 +13,18 @@
|
||||
|
||||
#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_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_P2V(a) ((((uintptr_t) (a) -kernel_phys_base) | kernel_virt_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 HHDM_BEGIN 0xfffff80000000000ULL
|
||||
#define HHDM_SIZE 32ULL // In GB
|
||||
#define HHDM_V2P(a) ((((uintptr_t) (a)) & ~HHDM_BEGIN))
|
||||
#define HHDM_P2V(a) ((((uintptr_t) (a)) | HHDM_BEGIN))
|
||||
#define HHDM_BEGIN 0xfffff80000000000ULL
|
||||
#define HHDM_SIZE 32ULL // In GB
|
||||
#define HHDM_V2P(a) ((((uintptr_t) (a)) & ~HHDM_BEGIN))
|
||||
#define HHDM_P2V(a) ((((uintptr_t) (a)) | HHDM_BEGIN))
|
||||
|
||||
class FDT;
|
||||
|
||||
@@ -34,9 +34,9 @@ public:
|
||||
AddressSpace(uint64_t *PML4);
|
||||
~AddressSpace();
|
||||
|
||||
void *virt2real(void *virt);
|
||||
int map(void *virt, void *real, uint32_t flags);
|
||||
int unmap(void *virt);
|
||||
void *virt2real(void *virt);
|
||||
int map(void *virt, void *real, uint32_t flags);
|
||||
int unmap(void *virt);
|
||||
|
||||
uint64_t *get_cr3() {
|
||||
return PML4;
|
||||
@@ -52,29 +52,29 @@ private:
|
||||
uint64_t *get_free_frame();
|
||||
|
||||
// Pointer to PML4 in HHDM
|
||||
uint64_t *PML4;
|
||||
uint64_t *PML4;
|
||||
|
||||
UniquePtr<FDT> _fdt;
|
||||
Mutex _fdtLock;
|
||||
UniquePtr<FDT> _fdt;
|
||||
Mutex _fdtLock;
|
||||
|
||||
UniquePtr<Vector<uint64_t *>> _taken_pages;
|
||||
UniquePtr<Vector<uint64_t *>> _taken_pages;
|
||||
|
||||
Mutex _lock;
|
||||
Mutex _lock;
|
||||
};
|
||||
|
||||
extern AddressSpace *KERN_AddressSpace;
|
||||
|
||||
extern uintptr_t kernel_phys_base;
|
||||
extern uintptr_t kernel_virt_base;
|
||||
extern size_t kernel_file_size;
|
||||
void limine_kern_save_response();
|
||||
extern uintptr_t kernel_phys_base;
|
||||
extern uintptr_t kernel_virt_base;
|
||||
extern size_t kernel_file_size;
|
||||
void limine_kern_save_response();
|
||||
|
||||
#define PAGE_PS (1 << 7)
|
||||
#define PAGE_RW (1 << 1)
|
||||
#define PAGE_USER (1 << 2)
|
||||
#define PAGE_PRESENT (0x01ULL)
|
||||
|
||||
void map_hhdm(uint64_t *pml4);
|
||||
void map_hhdm(uint64_t *pml4);
|
||||
|
||||
extern "C" void _tlb_flush();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int init_serial();
|
||||
int init_serial();
|
||||
|
||||
int serial_received();
|
||||
char read_serial();
|
||||
|
||||
@@ -115,12 +115,12 @@ uint64_t syscall_print_tasks() {
|
||||
static SkipListMap<pid_t, std::pair<String, uint64_t>> last_times = Scheduler::getTaskTimePerPid();
|
||||
static std::atomic<uint64_t> last_print_time = micros;
|
||||
|
||||
uint64_t prev_print_time = last_print_time;
|
||||
last_print_time = micros;
|
||||
SkipListMap<pid_t, std::pair<String, uint64_t>> prev_times = std::move(last_times);
|
||||
last_times = Scheduler::getTaskTimePerPid();
|
||||
uint64_t prev_print_time = last_print_time;
|
||||
last_print_time = micros;
|
||||
SkipListMap<pid_t, std::pair<String, uint64_t>> prev_times = std::move(last_times);
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
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) {
|
||||
auto vma = Scheduler::cur_task()->_vma.get();
|
||||
auto vma = Scheduler::cur_task()->_vma.get();
|
||||
|
||||
char *ret = reinterpret_cast<char *>(-1);
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
void setup_syscalls();
|
||||
void setup_syscalls();
|
||||
|
||||
extern "C" void _syscall_entrypoint();
|
||||
extern "C" void _execve_entrypoint();
|
||||
extern "C" void _syscall_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);
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ std::atomic<uint64_t> max_pid = 0;
|
||||
Mutex AllTasks_lock;
|
||||
SkipListMap<uint64_t, UniquePtr<Task>> AllTasks;
|
||||
|
||||
static List<Task *>::Node *RunningTask;
|
||||
static List<Task *>::Node *RunningTask;
|
||||
|
||||
static Spinlock NextTasks_lock;
|
||||
static List<Task *> NextTasks;
|
||||
static Spinlock NextTasks_lock;
|
||||
static List<Task *> NextTasks;
|
||||
|
||||
// Task freer
|
||||
Mutex TasksToFree_lock;
|
||||
@@ -58,10 +58,10 @@ Mutex WaitingTasks_mlock;
|
||||
CV WaitingTasks_cv;
|
||||
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);
|
||||
// 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() {
|
||||
assert(_mode == TaskMode::TASKMODE_USER);
|
||||
_frame.cs = Arch::GDT::gdt_code_user.selector() | 0x3;
|
||||
_frame.ss = Arch::GDT::gdt_data_user.selector() | 0x3;
|
||||
_ownAddressSpace = UniquePtr(new AddressSpace());
|
||||
_vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get()));
|
||||
_frame.cs = Arch::GDT::gdt_code_user.selector() | 0x3;
|
||||
_frame.ss = Arch::GDT::gdt_data_user.selector() | 0x3;
|
||||
_ownAddressSpace = UniquePtr(new AddressSpace());
|
||||
_vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get()));
|
||||
|
||||
task_pointer *taskptr = static_cast<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)));
|
||||
|
||||
_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
|
||||
assert((_entry_ksp_val & 0xFULL) == 0);
|
||||
|
||||
@@ -209,7 +209,7 @@ void Task::user_setup() {
|
||||
taskptr_real->entry_ksp_val = _entry_ksp_val;
|
||||
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();
|
||||
|
||||
// Ensure 16byte alignment
|
||||
@@ -222,7 +222,7 @@ void Task::user_reset() {
|
||||
// FIXME:
|
||||
// delete _ownAddressSpace.release();
|
||||
|
||||
_vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get()));
|
||||
_vma = UniquePtr<VMA>(new VMA(_ownAddressSpace.get()));
|
||||
|
||||
task_pointer *taskptr = static_cast<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)));
|
||||
|
||||
_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
|
||||
assert((_entry_ksp_val & 0xFULL) == 0);
|
||||
|
||||
taskptr_real->taskptr = this;
|
||||
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();
|
||||
|
||||
// Ensure 16byte alignment
|
||||
@@ -376,7 +376,7 @@ static void task_waker() {
|
||||
auto node = WaitingTasks.begin();
|
||||
auto tasks = node->second;
|
||||
|
||||
bool ok = true;
|
||||
bool ok = true;
|
||||
for (const auto &task: tasks) {
|
||||
if (task->val->state() == Task::TaskState::TS_RUNNING) {
|
||||
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)));
|
||||
|
||||
_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
|
||||
assert((_entry_ksp_val & 0xFULL) == 0);
|
||||
|
||||
taskptr_real->taskptr = ret;
|
||||
taskptr_real->entry_ksp_val = ret->_entry_ksp_val;
|
||||
|
||||
ret->_frame.ss = Arch::GDT::gdt_data.selector();
|
||||
ret->_frame.cs = Arch::GDT::gdt_code.selector();
|
||||
ret->_frame.sp = ret->_entry_ksp_val;
|
||||
ret->_parent = Scheduler::cur_task()->_pid;
|
||||
ret->_frame.ss = Arch::GDT::gdt_data.selector();
|
||||
ret->_frame.cs = Arch::GDT::gdt_code.selector();
|
||||
ret->_frame.sp = ret->_entry_ksp_val;
|
||||
ret->_parent = Scheduler::cur_task()->_pid;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -458,9 +458,9 @@ extern "C" void Scheduler::switch_task(Arch::TaskFrame *cur_frame) {
|
||||
{
|
||||
SpinlockLockNoIntAssert ntl(NextTasks_lock);
|
||||
|
||||
static uint64_t lastSwitchMicros = 0;
|
||||
uint64_t prevSwitchMicros = lastSwitchMicros;
|
||||
lastSwitchMicros = micros;
|
||||
static uint64_t lastSwitchMicros = 0;
|
||||
uint64_t prevSwitchMicros = lastSwitchMicros;
|
||||
lastSwitchMicros = micros;
|
||||
|
||||
if (RunningTask) {
|
||||
RunningTask->val->_frame = *cur_frame;
|
||||
|
||||
@@ -39,27 +39,27 @@ public:
|
||||
/// or -1, wait for anything, then it's set by the zombified process to its PID
|
||||
pid_t _woken_pid = -1;
|
||||
/// 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(Task &&) = delete;
|
||||
Task &operator=(const Task &) = delete;
|
||||
Task &operator=(Task &&) = delete;
|
||||
Task(const Task &) = delete;
|
||||
Task(Task &&) = delete;
|
||||
Task &operator=(const Task &) = delete;
|
||||
Task &operator=(Task &&) = delete;
|
||||
|
||||
void start();
|
||||
void start();
|
||||
|
||||
[[nodiscard]] const String &name() const { return _name; }
|
||||
[[nodiscard]] pid_t pid() const { return _pid; }
|
||||
[[nodiscard]] uint64_t used_time() const { return _used_time; }
|
||||
[[nodiscard]] TaskState state() const { return _state; }
|
||||
|
||||
~ Task();
|
||||
~Task();
|
||||
|
||||
Task *clone();
|
||||
void user_setup();
|
||||
void user_reset();
|
||||
Task *clone();
|
||||
void user_setup();
|
||||
void user_reset();
|
||||
|
||||
//private:
|
||||
struct KernStack {
|
||||
@@ -79,15 +79,15 @@ public:
|
||||
// as VMA frees what it had allocated there too
|
||||
UniquePtr<AddressSpace> _ownAddressSpace;
|
||||
|
||||
AddressSpace *_addressSpace;
|
||||
UniquePtr<VMA> _vma;
|
||||
UniquePtr<KernStack> _kstack{new KernStack()};
|
||||
UniquePtr<FxSave> _fxsave{new FxSave()};
|
||||
String _name;
|
||||
TaskMode _mode;
|
||||
uint64_t _sleep_until;
|
||||
TaskState _state;
|
||||
pid_t _parent = -1;
|
||||
AddressSpace *_addressSpace;
|
||||
UniquePtr<VMA> _vma;
|
||||
UniquePtr<KernStack> _kstack{new KernStack()};
|
||||
UniquePtr<FxSave> _fxsave{new FxSave()};
|
||||
String _name;
|
||||
TaskMode _mode;
|
||||
uint64_t _sleep_until;
|
||||
TaskState _state;
|
||||
pid_t _parent = -1;
|
||||
};
|
||||
|
||||
|
||||
@@ -104,32 +104,32 @@ namespace Scheduler {
|
||||
Task *cur_task();
|
||||
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 dispose_self();
|
||||
void zombify_self();
|
||||
void dispose_zombie(Task *zombie);
|
||||
void remove_self();
|
||||
void dispose_self();
|
||||
void zombify_self();
|
||||
void dispose_zombie(Task *zombie);
|
||||
|
||||
void self_block();
|
||||
void self_block(Spinlock &to_unlock);
|
||||
void self_block(Mutex &to_unlock);
|
||||
void self_block();
|
||||
void self_block(Spinlock &to_unlock);
|
||||
void self_block(Mutex &to_unlock);
|
||||
|
||||
void unblock(Task *what);
|
||||
void unblock(List<Task *>::Node *what);
|
||||
void unblock_nolock(List<Task *>::Node *what);
|
||||
void unblock(Task *what);
|
||||
void unblock(List<Task *>::Node *what);
|
||||
void unblock_nolock(List<Task *>::Node *what);
|
||||
|
||||
void waitpid_block();
|
||||
pid_t waitpid(pid_t pid, int *status, int options);
|
||||
void waitpid_block();
|
||||
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!
|
||||
SkipListMap<pid_t, std::pair<String, uint64_t>> getTaskTimePerPid();
|
||||
|
||||
void yield_self();
|
||||
void yield_self();
|
||||
} // namespace Scheduler
|
||||
|
||||
// Expects the caller to save interrupt state
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
volatile std::atomic<uint64_t> ticks;
|
||||
volatile std::atomic<uint64_t> micros;
|
||||
|
||||
unsigned read_pit_count(void) {
|
||||
unsigned read_pit_count(void) {
|
||||
unsigned count = 0;
|
||||
|
||||
// Disable interrupts
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern volatile std::atomic<uint64_t> ticks;
|
||||
extern volatile std::atomic<uint64_t> micros;
|
||||
|
||||
void init_timer();
|
||||
void timer_tick();
|
||||
void init_timer();
|
||||
void timer_tick();
|
||||
|
||||
#endif //FICUS_TIMER_H
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include "Vector.hpp"
|
||||
#include "mutex.hpp"
|
||||
|
||||
TtyManager GlobalTtyManager;
|
||||
TtyManager GlobalTtyManager;
|
||||
|
||||
Vector<TtyManager> ttys;
|
||||
|
||||
void TtyManager::add_tty(Tty *tty) {
|
||||
void TtyManager::add_tty(Tty *tty) {
|
||||
LockGuard l(lock);
|
||||
ttys.emplace_back(tty);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ class TtyManager {
|
||||
Vector<Tty *> ttys;
|
||||
|
||||
public:
|
||||
void add_tty(Tty *tty);
|
||||
void add_tty(Tty *tty);
|
||||
|
||||
void all_tty_putchar(char c);
|
||||
void all_tty_putstr(const char *str);
|
||||
void all_tty_putchar(char c);
|
||||
void all_tty_putstr(const char *str);
|
||||
|
||||
unsigned get_num_ttys();
|
||||
Tty *get_tty(unsigned n);
|
||||
|
||||
@@ -32,12 +32,12 @@ public:
|
||||
void *mmap_mem(void *v_addr, size_t length, int prot, int flags);
|
||||
int munmap(void *addr, size_t length);
|
||||
|
||||
static constexpr size_t kBrkSize = 16ULL*1024ULL*1024ULL;
|
||||
std::optional<char*> brk_start;
|
||||
std::optional<char*> brk_end_fake;
|
||||
std::optional<char*> brk_end_real;
|
||||
static constexpr size_t kBrkSize = 16ULL * 1024ULL * 1024ULL;
|
||||
std::optional<char *> brk_start;
|
||||
std::optional<char *> brk_end_fake;
|
||||
std::optional<char *> brk_end_real;
|
||||
|
||||
void clone_from(const VMA& vma);
|
||||
void clone_from(const VMA &vma);
|
||||
|
||||
private:
|
||||
AddressSpace *space = nullptr;
|
||||
@@ -53,14 +53,14 @@ private:
|
||||
uintptr_t begin;
|
||||
uint64_t length;
|
||||
EntryType type = EntryType::FREE;
|
||||
int flags;
|
||||
int flags;
|
||||
};
|
||||
|
||||
ListEntry *get_entry(uintptr_t v_addr, size_t length);
|
||||
|
||||
//
|
||||
SkipListMap<uintptr_t, ListEntry> regions;
|
||||
Mutex regions_lock;
|
||||
Mutex regions_lock;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define STACK_CHK_GUARD 0x2e61e13e4d5ae23c
|
||||
#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) {
|
||||
assert2(false, "Stack protection triggered!");
|
||||
@@ -32,11 +32,11 @@ namespace __cxxabiv1 {
|
||||
/* The ABI requires a 64-bit type. */
|
||||
__extension__ typedef int __guard __attribute__((mode(__DI__)));
|
||||
|
||||
extern "C" int __cxa_guard_acquire(__guard *);
|
||||
extern "C" void __cxa_guard_release(__guard *);
|
||||
extern "C" void __cxa_guard_abort(__guard *);
|
||||
extern "C" int __cxa_guard_acquire(__guard *);
|
||||
extern "C" void __cxa_guard_release(__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);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ struct type_mismatch_info {
|
||||
uint8_t type_check_kind;
|
||||
};
|
||||
|
||||
#define SAN_STOP true
|
||||
#define SAN_STOP true
|
||||
|
||||
#define is_aligned(value, alignment) !(value & (alignment - 1))
|
||||
__attribute__((used)) void __ubsan_handle_type_mismatch_v1(struct type_mismatch_info *type_mismatch,
|
||||
|
||||
@@ -107,10 +107,10 @@ bool ElfParser::copy_to(Task *task) {
|
||||
flags |= PAGE_RW;
|
||||
}
|
||||
|
||||
auto rounded_vaddr = hdr.p_vaddr & 0x000FFFFFFFFFF000ULL;
|
||||
auto real_memsz = hdr.p_memsz + (hdr.p_vaddr - rounded_vaddr);
|
||||
auto rounded_vaddr = hdr.p_vaddr & 0x000FFFFFFFFFF000ULL;
|
||||
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;
|
||||
|
||||
auto *file_ptr = _data.begin();
|
||||
|
||||
@@ -14,8 +14,8 @@ class Task;
|
||||
// Just copying everytihng for now
|
||||
class ElfParser {
|
||||
public:
|
||||
ElfParser(Vector<char> data);
|
||||
bool copy_to(Task *task);
|
||||
ElfParser(Vector<char> data);
|
||||
bool copy_to(Task *task);
|
||||
|
||||
uintptr_t get_entrypoint() { return _entrypoint; }
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
Elf64_Xword p_memsz; /* Size of segment in memory */
|
||||
Elf64_Xword p_align; /* Alignment of segment */
|
||||
|
||||
bool valid = false;
|
||||
bool valid = false;
|
||||
using serializable = std::true_type;
|
||||
Elf64_Phdr(Vector<char>::const_iterator &in, const Vector<char>::const_iterator &end);
|
||||
};
|
||||
|
||||
@@ -31,11 +31,11 @@ public:
|
||||
private:
|
||||
std::atomic<bool> locked = false;
|
||||
|
||||
List<Task *> waiters;
|
||||
Spinlock waiters_lock;
|
||||
List<Task *> waiters;
|
||||
Spinlock waiters_lock;
|
||||
|
||||
Task *_owner = nullptr;
|
||||
uint8_t spin_success = 127;
|
||||
Task *_owner = nullptr;
|
||||
uint8_t spin_success = 127;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
// 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;
|
||||
return (unsigned int) (next / 65536ULL) % 32768;
|
||||
|
||||
@@ -21,13 +21,13 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
Node *head = nullptr;
|
||||
Node *tail = nullptr;
|
||||
Node *head = nullptr;
|
||||
Node *tail = nullptr;
|
||||
|
||||
uint64_t size = 0;
|
||||
|
||||
public:
|
||||
List() = default;
|
||||
List() = default;
|
||||
~List() {
|
||||
while (!empty()) {
|
||||
pop_back();
|
||||
|
||||
@@ -19,15 +19,15 @@ public:
|
||||
|
||||
explicit UniquePtr(T *data) : ptr(data) {}
|
||||
|
||||
~ UniquePtr() {
|
||||
~UniquePtr() {
|
||||
if (ptr == nullptr) return;
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
UniquePtr(UniquePtr const &other) = delete;
|
||||
UniquePtr(UniquePtr const &other) = delete;
|
||||
UniquePtr &operator=(UniquePtr const &other) = delete;
|
||||
|
||||
UniquePtr(UniquePtr &&other) {
|
||||
UniquePtr(UniquePtr &&other) {
|
||||
delete ptr;
|
||||
ptr = other.ptr;
|
||||
other.ptr = nullptr;
|
||||
@@ -133,12 +133,12 @@ class SharedPtr {
|
||||
friend SharedPtrTester;
|
||||
|
||||
public:
|
||||
SharedPtr() = default;
|
||||
SharedPtr() = default;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ private:
|
||||
|
||||
explicit SharedPtr(T *ptr, SharedPtr_Base *base) : _ptr(ptr), _base(base) {}
|
||||
|
||||
void unref() {
|
||||
void unref() {
|
||||
if (!_base) return;
|
||||
if (_base->strong_release())
|
||||
delete _ptr;
|
||||
@@ -204,10 +204,10 @@ private:
|
||||
template<typename T>
|
||||
class WeakPtr {
|
||||
public:
|
||||
WeakPtr() = default;
|
||||
WeakPtr() = default;
|
||||
|
||||
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(const SharedPtr<T> &shared) : _base(shared._base), _ptr(shared._ptr) { _base->weak_lock(); }
|
||||
WeakPtr(std::nullptr_t a_nullptr) : _ptr(nullptr), _base(nullptr) {}
|
||||
|
||||
~WeakPtr() {
|
||||
unref();
|
||||
@@ -283,29 +283,29 @@ private:
|
||||
friend COWTester;
|
||||
SharedPtr<T> ptr;
|
||||
|
||||
void copy() {
|
||||
void copy() {
|
||||
if (ptr.get() && ptr.useCount() > 1) {
|
||||
ptr = SharedPtr<T>(new T(*ptr));
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
std::swap(ptr, other.ptr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~ COWPointer() = default;
|
||||
~COWPointer() = default;
|
||||
|
||||
T *get() const {
|
||||
return ptr.get();
|
||||
@@ -316,7 +316,7 @@ public:
|
||||
return ptr.get();
|
||||
}
|
||||
|
||||
int useCount() { return ptr.useCount(); };
|
||||
int useCount() { return ptr.useCount(); };
|
||||
|
||||
const T &operator*() const {
|
||||
return *ptr;
|
||||
|
||||
@@ -48,7 +48,7 @@ protected:
|
||||
Node *nodes[size];
|
||||
int top = -1;
|
||||
|
||||
Node *get() {
|
||||
Node *get() {
|
||||
Node *node;
|
||||
if (top == -1)
|
||||
node = static_cast<Node *>(kmalloc(sizeof(Node)));
|
||||
@@ -63,7 +63,7 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
NodeAllocator() noexcept = default;
|
||||
NodeAllocator() noexcept = default;
|
||||
|
||||
~NodeAllocator() noexcept {
|
||||
for (int i = top; i >= 0; i--) {
|
||||
@@ -114,7 +114,7 @@ protected:
|
||||
mutable Node *toUpdate[maxL + 1];
|
||||
size_t curL = 0;
|
||||
|
||||
SkipListBase() noexcept {
|
||||
SkipListBase() noexcept {
|
||||
root = (Node *) nodeAllocator.get_end();
|
||||
endnode = (Node *) nodeAllocator.get_end();
|
||||
endnode->before = root;
|
||||
@@ -220,11 +220,11 @@ protected:
|
||||
using pointer = 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--() {
|
||||
if (n->before)
|
||||
@@ -469,8 +469,8 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
iterator begin() { return iterator(root->next[0]); }
|
||||
iterator end() { return iterator(endnode); }
|
||||
iterator begin() { return iterator(root->next[0]); }
|
||||
iterator end() { return iterator(endnode); }
|
||||
|
||||
const_iterator begin() const { return const_iterator(root->next[0]); }
|
||||
const_iterator end() const { return const_iterator(endnode); }
|
||||
|
||||
@@ -29,8 +29,8 @@ public:
|
||||
}
|
||||
|
||||
String(String &&str) noexcept {
|
||||
_data = str._data;
|
||||
_cur_len = str._cur_len;
|
||||
_data = str._data;
|
||||
_cur_len = str._cur_len;
|
||||
|
||||
str._cur_len = 0;
|
||||
str._data = nullptr;
|
||||
|
||||
@@ -29,9 +29,9 @@ public:
|
||||
_cur_size = l.size();
|
||||
_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) {
|
||||
new (_data + (i++)) T(el);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
_cur_size = vec._cur_size;
|
||||
_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++)
|
||||
new (_data + i) T(vec._data[i]);
|
||||
|
||||
@@ -17,16 +17,16 @@ public:
|
||||
FDT();
|
||||
|
||||
using FD = int64_t;
|
||||
FD open(const Path &p, int opts);
|
||||
void close(FD fd);
|
||||
File *get(FD fd) const;
|
||||
FD open(const Path &p, int opts);
|
||||
void close(FD fd);
|
||||
File *get(FD fd) const;
|
||||
|
||||
static FDT *current();
|
||||
|
||||
private:
|
||||
SkipListMap<FD, UniquePtr<File>> _files;
|
||||
int64_t _cur_fd = 10;
|
||||
mutable Mutex _mtx;
|
||||
int64_t _cur_fd = 10;
|
||||
mutable Mutex _mtx;
|
||||
};
|
||||
|
||||
class FDHandle {
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
FDHandle(const File &f) = delete;
|
||||
FDHandle &operator=(const File &o) = delete;
|
||||
|
||||
FDT::FD get() { return _fd; }
|
||||
FDT::FD get() { return _fd; }
|
||||
|
||||
private:
|
||||
FDT::FD _fd;
|
||||
|
||||
@@ -17,23 +17,23 @@ class File {
|
||||
public:
|
||||
File(SharedPtr<Node> n, int opts);
|
||||
~File();
|
||||
File(const File &f) = delete;
|
||||
File &operator=(const File &o) = delete;
|
||||
File(const File &f) = delete;
|
||||
File &operator=(const File &o) = delete;
|
||||
|
||||
SharedPtr<Node> node() const;
|
||||
SharedPtr<NodeDir> dir() const;
|
||||
SharedPtr<NodeFile> file() const;
|
||||
|
||||
uint64_t seek(uint64_t pos);
|
||||
uint64_t pos() { return _pos; }
|
||||
uint64_t read(char *buf, uint64_t size);
|
||||
uint64_t write(const char *buf, uint64_t size);
|
||||
uint64_t size();
|
||||
uint64_t seek(uint64_t pos);
|
||||
uint64_t pos() { return _pos; }
|
||||
uint64_t read(char *buf, uint64_t size);
|
||||
uint64_t write(const char *buf, uint64_t size);
|
||||
uint64_t size();
|
||||
|
||||
private:
|
||||
SharedPtr<Node> _n;
|
||||
uint64_t _pos = 0;
|
||||
int _opts;
|
||||
int _opts;
|
||||
};
|
||||
|
||||
#endif //FICUS_FILE_HPP
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
Vector<SharedPtr<Node>> MemFs::MemFsNodeDir::children() {
|
||||
LockGuard l(_lock);
|
||||
LockGuard l(_lock);
|
||||
|
||||
Vector<SharedPtr<Node>> out;
|
||||
for (auto c: _children) {
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
class MemFs : public Filesystem {
|
||||
struct MemFsNodeDir : public NodeDir {
|
||||
public:
|
||||
Vector<SharedPtr<Node>> children() override;
|
||||
SharedPtr<NodeDir> mkdir(const String &name) override;
|
||||
SharedPtr<NodeFile> mkfile(const String &name) override;
|
||||
Vector<SharedPtr<Node>> children() override;
|
||||
SharedPtr<NodeDir> mkdir(const String &name) override;
|
||||
SharedPtr<NodeFile> mkfile(const String &name) override;
|
||||
|
||||
static SharedPtr<MemFsNodeDir> create(const String &name) {
|
||||
auto shared = SharedPtr(new MemFsNodeDir(name));
|
||||
@@ -31,10 +31,10 @@ class MemFs : public Filesystem {
|
||||
|
||||
struct MemFsNodeFile : public NodeFile {
|
||||
public:
|
||||
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;
|
||||
size_t size() override;
|
||||
bool is_tty() override { return false; }
|
||||
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;
|
||||
size_t size() override;
|
||||
bool is_tty() override { return false; }
|
||||
|
||||
static SharedPtr<MemFsNodeFile> create(const String &name) {
|
||||
auto shared = SharedPtr(new MemFsNodeFile(name));
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
#include "Node.hpp"
|
||||
class TtyPipe : public NodeFile {
|
||||
public:
|
||||
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;
|
||||
size_t size() override;
|
||||
bool is_tty() override { return true; }
|
||||
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;
|
||||
size_t size() override;
|
||||
bool is_tty() override { return true; }
|
||||
|
||||
static SharedPtr<TtyPipe> create() {
|
||||
auto shared = SharedPtr(new TtyPipe());
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include "Path.hpp"
|
||||
|
||||
namespace VFSApi {
|
||||
bool mkdir(const Path &path);
|
||||
bool touch(const Path &path);
|
||||
bool mkdir(const Path &path);
|
||||
bool touch(const Path &path);
|
||||
|
||||
FDT::FD open(const Path &path);
|
||||
File *get(FDT::FD fd);
|
||||
void close(FDT::FD fd);
|
||||
|
||||
}; // namespace VFSApi
|
||||
}; // namespace VFSApi
|
||||
|
||||
|
||||
#endif //FICUS_VFSAPI_HPP
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
namespace VFSGlobals {
|
||||
extern RootNode root;
|
||||
extern MountTable mounts;
|
||||
}; // namespace VFSGlobals
|
||||
}; // namespace VFSGlobals
|
||||
|
||||
|
||||
#endif //FICUS_VFSGLOBALS_HPP
|
||||
|
||||
@@ -26,12 +26,12 @@ using IntType = long long;
|
||||
|
||||
class CRange {
|
||||
public:
|
||||
IntType l = 0;
|
||||
IntType r = 0;
|
||||
IntType l = 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)
|
||||
throw std::logic_error("CRange bad initialisation");
|
||||
}
|
||||
@@ -239,9 +239,9 @@ public:
|
||||
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++() {
|
||||
++it;
|
||||
|
||||
Reference in New Issue
Block a user