62 logw(
"scheduler",
"process_alloc called for invalid process %u\n",
alloc->
tag);
73 logw(
"scheduler",
"process_dealloc called for invalid process %u\n",
alloc->
tag);
77 size_t size = *((
size_t*)ptr - 1);
149 process->heap.start = data_start;
171 (*cpu)->rflags = 0x200;
186 uint64_t timestamp_ns_since_boot = 0;
188 static pid_t last_scheduled = -1;
195 if(
process->waiting_data.timestamp_ns_since_boot && !timestamp_ns_since_boot) {
199 if(
process->waiting_data.timestamp_ns_since_boot <= timestamp_ns_since_boot) {
242 size_t user_size =
sizeof(
struct SignalUserData);
299 new->hw.end = old->
hw.
end;
321 if(share_memory &&
entry) {
322 new->cpu.rip =
entry;
336 ptr_t page_v = fault_address & ~0xFFF;
398 ptr_t new_end = old_end + inc;
401 for(
ptr_t i = old_end & ~0xFFF; i < new_end; i += 0x1000) {
410 for(
ptr_t i = old_end; i > new_end; i -= 0x1000) {
451 for(
size_t i = 0; i <
num; ++i) {
461 bool some_enabled =
false;
463 for(
size_t i = 0; i < 8*
KiB; ++i) {
464 if(((
uint8_t*)bitmap)[i] != 0xFF) {
struct allocator allocator_t
uint8_t * bitmap_t
Type for a single entry in the array.
static void bitmap_clear(bitmap_t bitmap, uint64_t entry)
Unset given entry in bitmap.
static void bitmap_set(bitmap_t bitmap, uint64_t entry)
Set given entry in bitmap.
static VTermState * state
#define ALLOCATOR_REGION_DIRECT_MAPPING
#define ALLOCATOR_REGION_USER_STACK
#define ALLOCATOR_REGION_USER_HARDWARE
void * memcpy(void *dest, void const *source, size_t size)
void * memset(void *dest, int c, size_t size)
char * strncpy(char *s1, const char *s2, size_t n)
char name[256]
Zero terminated string with the name of the file.
uint16_t size
Size of the loaded file.
#define logd(component, fmt,...)
#define logw(component, fmt,...)
struct Message::UserData::SignalUserData Signal
size_t user_size
Size of the user data.
size_t size
Size of the message, including metadata.
struct Message::UserData::ServiceDiscoveryData ServiceDiscovery
pid_t sender
Sender of the message.
union Message::UserData user_data
@ MT_Invalid
Invalid message, only size is valid.
size_t user_size
Size of the user data.
uint16_t signal
Signal identifier.
enum MessageType type
Type of the message.
void * mm_alloc_pages(uint64_t count)
void mm_mark_physical_pages(ptr_t start, uint64_t count, mm_page_status_t status)
uint64_t mq_push(uint64_t mq, struct Message *message)
uint64_t mq_pop(uint64_t mq, struct Message *msg)
uint64_t mq_peek(uint64_t mq, struct Message *msg)
uint64_t mq_create(allocator_t *alloc)
void mq_destroy(uint64_t mq)
void mutex_unlock_holder(pid_t pid)
bool mutex_lock(mutex_t mutex, pid_t holder)
void panic_message(const char *message)
void set_iopb(struct vm_table *context, ptr_t new_iopb)
void interrupt_del_queue(uint8_t interrupt, uint64_t mq)
void interrupt_add_queue(uint8_t interrupt, uint64_t mq)
void sc_handle_ipc_mq_poll(uint64_t mq, bool wait, struct Message *msg, uint64_t *error)
void scheduler_process_save(cpu_state *cpu)
bool scheduler_idle_if_needed(cpu_state **cpu, struct vm_table **context)
void * process_alloc(allocator_t *alloc, size_t size)
void scheduler_process_cleanup(pid_t pid)
void scheduler_wait_for(pid_t pid, enum wait_reason reason, union wait_data data)
void sc_handle_ipc_service_register(uuid_t *uuid, uint64_t mq, uint64_t *error)
void sc_handle_scheduler_exit(uint64_t exit_code)
void start_task(struct vm_table *context, ptr_t entry, ptr_t data_start, ptr_t data_end, const char *name)
void sc_handle_scheduler_sleep(uint64_t nanoseconds)
void sc_handle_ipc_mq_destroy(uint64_t mq, uint64_t *error)
static process_t processes[MAX_PROCS]
void sc_handle_ipc_mq_create(bool global_read, bool global_write, size_t msg_limit, size_t data_limit, uint64_t *mq, uint64_t *error)
void scheduler_waitable_done(enum wait_reason reason, union wait_data data, size_t max_amount)
ptr_t iopb
Physical address of the first of two IOPB pages, 0 if no IO privilege granted.
pid_t setup_process(void)
void sc_handle_ipc_mq_send(uint64_t mq, pid_t pid, struct Message *msg, uint64_t *error)
void sc_handle_scheduler_clone(bool share_memory, ptr_t entry, pid_t *newPid)
void sc_handle_clock_read(uint64_t *nanoseconds)
void sc_handle_ipc_service_discover(uuid_t *uuid, uint64_t mq, struct Message *msg, uint64_t *error)
void init_scheduler(void)
enum wait_reason waiting_for
void sc_handle_memory_sbrk(int64_t inc, ptr_t *data_end)
void sc_handle_hardware_ioperm(uint16_t from, uint16_t num, bool turn_on, uint16_t *error)
void schedule_next(cpu_state **cpu, struct vm_table **context)
bool schedule_next_if_needed(cpu_state **cpu, struct vm_table **context)
union wait_data waiting_data
bool scheduler_handle_pf(ptr_t fault_address, uint64_t error_code)
void sc_handle_hardware_interrupt_notify(uint8_t interrupt, bool enable, uint64_t mq, uint64_t *error)
void process_dealloc(allocator_t *alloc, void *ptr)
ptr_t scheduler_map_hardware(ptr_t hw, size_t len)
Map a given memory area in the currently running userspace process at a random location.
struct vm_table * context
void sc_handle_scheduler_get_pid(bool parent, pid_t *pid)
volatile pid_t scheduler_current_process
void scheduler_kill_current(enum kill_reason reason)
uint64_t timestamp_ns_since_boot
int64_t sd_send(uuid_t *uuid, struct Message *msg)
uint64_t sd_register(uuid_t *uuid, mq_id_t svc_queue)
static bool size_t size_t uint64_t * mq
static bool size_t size_t data_limit
static uint16_t bool turn_on
static uint16_t bool uint64_t * error
void vm_context_unmap(struct vm_table *context, ptr_t virtual)
void vm_context_map(struct vm_table *pml4, ptr_t virtual, ptr_t physical, uint8_t pat)
void vm_copy_range(struct vm_table *dst, struct vm_table *src, ptr_t addr, size_t size)
ptr_t vm_map_hardware(ptr_t hw, size_t len)
Map a given memory area in the currently running userspace process at a random location.
ptr_t vm_context_get_physical_for_virtual(struct vm_table *context, ptr_t virtual)
struct vm_table * vm_context_new(void)
void * vm_alloc(size_t size)
Like malloc but allocates full pages only. 16 byte data overhead.
struct vm_table * VM_KERNEL_CONTEXT
void vm_free(void *ptr)
the matching free() like function for vm_alloc
A paging table, when this is a PML4 it may also be called context.