Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
60fef5a
[PROCESS] threading (limited to manual-scheduled threads)
Jun 26, 2026
ca8f0f3
[SYSCALL] current thread to get non-ptr types
Jun 26, 2026
e392702
[PROCFS] moved to own file
Jun 26, 2026
904d83f
[KPROC] proper stack
Jun 26, 2026
100af00
[MEM] stack manager
Jun 26, 2026
1107f84
[PROC] in_ready_queue moved to just use state
Jun 26, 2026
f372a78
[PROC] spsr to thread
Jun 26, 2026
46f918a
[FS,WIP] filesystem in userspace skeleton
Jun 27, 2026
5ad1364
[UFS] defer module init/deinit to process
Jun 27, 2026
43dad15
[PROC] main thread in process
Jun 26, 2026
17dbfb4
[DOS] desktop zoom
Jun 29, 2026
194cdb0
[PROC] proper scheduling for threads
Jun 30, 2026
96de00e
Merge branch 'threading' of git.diferrari.com:dfs/redactedos into thr…
Jun 30, 2026
1bdedea
[THREAD] thread count and ids
Jun 30, 2026
12b74c2
[PROC] kernel proc mem cleanup
Jun 30, 2026
0968f8d
[PROC] main thread with new_thread
Jun 30, 2026
627720d
[PROC] removed redundant stack info
Jun 30, 2026
b218a93
[THREADING, WIP] job system (no memory sharing between procs yet)
Jul 3, 2026
af76310
[JOB] copying buffers into worker
Jul 4, 2026
81864d7
[JOB] copy back
Jul 4, 2026
1940b05
[THREADING] stack cleanup
Jul 4, 2026
cef074e
[JOB] open file job
Jul 6, 2026
404c9fe
[THREADING] enqueue threads instead of processes
Jul 11, 2026
e6d65db
[PROC] cleaner process/thread definition
Jul 11, 2026
af944a6
[THREADING] thread-based sleep
Jul 11, 2026
bf6c751
[BUILD] makefile error cleanup
Jul 15, 2026
833abff
[FAT32] correct mem alloc for writing
Jul 15, 2026
387184c
Merge branch 'threading' of mm.local:dfs/redactedos into threading
Jul 15, 2026
1187c87
[TRES] window fallback fix
Jul 15, 2026
2bbe49d
[PROC] manual assign shared page return to main thread
Jul 15, 2026
01cbdfd
[PROC] sleep state
Jul 15, 2026
eca5d63
[PROC] proc full memset 0 on reset
Jul 15, 2026
8c2f6e8
[PROC] privileged process stack fix (wow)
Jul 15, 2026
132e5e8
[PROC] undo full wipe, linked list needs to be kept
Jul 15, 2026
1908444
[PROC] thread_state to state
Jul 15, 2026
937338b
[LAUNCHER] fail to load keeps launcher open
Jul 18, 2026
56a1875
[DESKTOP] (empty) menu bar
Jul 24, 2026
83be0be
[DOS] bar shawdows
Jul 24, 2026
58c758b
[ZOOM] float zoom
Jul 24, 2026
69abc04
[ZOOM] zoom in
Jul 26, 2026
9eca480
[DOS] desaturate window toolbar if not focused
Jul 29, 2026
488b2b6
[MENUBAR] added (cursed) central widget
Jul 29, 2026
db88dd0
[THREADING] proper sleep process
Jul 29, 2026
bf2182e
[TERMINAL] restored cpp terminal
Jul 30, 2026
8bd4fd2
[SIGNAL] defaults for non-immediates
Jul 31, 2026
3a3bef3
[SCHEDULER] properly skip resettable processes
Jul 31, 2026
fd741f9
[PFS] multi-module loading support
Jul 31, 2026
49e8a37
[THREADING] use queue for threads instead of current
Jul 31, 2026
d78cd1b
[ENV] window info
Jul 31, 2026
77e4d7e
[FS_MOD,WIP] basic menu fs test in filebrowser, crashes on subdirs
Jul 31, 2026
a55a46a
[FS] usfs read/write
Jul 31, 2026
4e25795
[JOB] zero memory when creating it
Jul 31, 2026
d907054
[DISK] vfs mount fix
Aug 2, 2026
4014d43
[FS] simplify truncate to use just descriptor
Jul 30, 2026
1abd00f
[TERMINAL] made usfs fully vanilla
Aug 2, 2026
8b73cca
[PROJ] warning fixes
Aug 2, 2026
ba19ef2
[JOB] open fix and read/write/trunc operations
Aug 2, 2026
221756e
[MENU, WIP] get menu from application, disabled due to job system not
Aug 2, 2026
187fb90
[FS] reserve mount points
Aug 2, 2026
c372d9a
[FS] isolated fs null pointer fix
Aug 2, 2026
79cfce4
[SCHEDULER] syscall return fix
Aug 2, 2026
113fde8
Merge branch 'threading' of mm.local:dfs/redactedos into threading
Aug 2, 2026
8e73f59
[SYSCALL] interrupt syscalls for jobs
Aug 2, 2026
8b9d328
[JOB] reschedule thread
Aug 2, 2026
3c16bb5
[JOB] cleanup logs and return type
Aug 2, 2026
0f223e9
[JOB] properly restore process
Aug 2, 2026
717b5d7
[JOB] proper stack management
Aug 2, 2026
6a5a4ad
[THREADING] alternate kstack cleanup todo
Aug 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ dump:
$(ARCH)objdump -S -D kernel.elf > dump
$(MAKE) -C user $@
$(MAKE) -C tools $@
$(MAKE) -C modules $@

install:
$(MAKE) clean
Expand Down
2 changes: 1 addition & 1 deletion kernel/exceptions/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void irq_el1_handler() {

if (irq == IRQ_TIMER) {
bool can_preempt = true;
if (get_current_proc() && get_current_proc()->mm.ttbr0 && (get_current_proc()->spsr & 0xF) != 0) can_preempt = false;
if (get_current_proc() && get_current_proc()->mm.ttbr0 && is_privileged(get_current_proc())) can_preempt = false;
if (RPI_BOARD != 3) write32(GICC_BASE + 0x10, irq);
syscall_depth--;
if (can_preempt) switch_proc(INTERRUPT);
Expand Down
2 changes: 1 addition & 1 deletion kernel/exceptions/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ uint64_t timer_now() {
asm volatile ("mrs %0, cntvct_el0" : "=r"(val));
return val;
}

//TODO: do we want more precision since we have it?
uint64_t timer_now_msec() {
uint64_t ticks = timer_now();
uint64_t freq = rd_cntfrq_el0();
Expand Down
2 changes: 1 addition & 1 deletion kernel/filesystem/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {
#include "types.h"
#include "files/system_module.h"

bool init_disk_device();
bool init_disk_device(system_module *mod);
void disk_verbose();

void disk_write(const void *buffer, uint32_t sector, uint32_t count);
Expand Down
16 changes: 9 additions & 7 deletions kernel/filesystem/fat32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool FAT32FS::write_section_to_cluster(u32 cluster, u32 offset, void *buf, size_

u32 sector_count = ceil(((float)offset + size)/512);

void *initial = zalloc(512 * sector_count);
void *initial = kalloc(fs_page, 512 * sector_count, ALIGN_64B, MEM_PRIV_KERNEL);

disk_read(initial, sector, sector_count);

Expand Down Expand Up @@ -505,8 +505,9 @@ size_t FAT32FS::write_file(file *descriptor, const char* buf, size_t size){

if (written)
write_to_disk(mfile->serial, mfile->file_buffer.buffer, mfile->file_buffer.buffer_size);

truncate(descriptor, mfile->file_size);

descriptor->size = mfile->file_size;
truncate(descriptor);

return written;
}
Expand Down Expand Up @@ -625,7 +626,7 @@ bool FAT32FS::stat(const char *path, fs_stat *out_stat){
return true;
}

bool FAT32FS::truncate(file *descriptor, size_t size){
bool FAT32FS::truncate(file *descriptor){
irq_flags_t irq = irq_save_disable();
module_file *mfile = (module_file*)hash_map_get(open_files, &descriptor->id, sizeof(uint64_t));
if (!mfile || !mfile->name.data) {
Expand All @@ -639,7 +640,7 @@ bool FAT32FS::truncate(file *descriptor, size_t size){

if (!result.found) return false;

result.entry.filesize = size & UINT32_MAX;
result.entry.filesize = descriptor->size & UINT32_MAX;

write_section_to_cluster(result.cluster,result.offset, &result.entry, sizeof(f32file_entry));

Expand Down Expand Up @@ -684,14 +685,15 @@ bool boot_stat(const char *path, fs_stat *out_stat){
return fs_driver->stat(path, out_stat);
}

bool boot_truncate(file *descriptor, size_t size){
return fs_driver->truncate(descriptor, size);
bool boot_truncate(file *descriptor){
return fs_driver->truncate(descriptor);
}

system_module boot_fs_module = (system_module){
.name = "boot",
.mount = "boot",
.version = VERSION_NUM(0, 1, 0, 0),
.owner = 0,
.init = boot_partition_init,
.fini = boot_partition_fini,
.open = boot_partition_open,
Expand Down
2 changes: 1 addition & 1 deletion kernel/filesystem/fat32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class FAT32FS: public FSDriver {
size_t list_contents(const char *path, void* buf, size_t size, uint64_t *offset) override;
void close_file(file* descriptor) override;
bool stat(const char *path, fs_stat *out_stat) override;
bool truncate(file *descriptor, size_t size) override;
bool truncate(file *descriptor) override;
protected:
sizedptr read_full_file(uint32_t cluster_start, uint32_t cluster_size, uint32_t cluster_count, uint64_t file_size, uint32_t root_index);
void read_FAT(uint32_t location, uint32_t size, uint8_t count);
Expand Down
101 changes: 80 additions & 21 deletions kernel/filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "process/scheduler.h"
#include "pipe.h"
#include "files/dir_list.h"
#include "process/jobs/job_manager.h"

uint64_t fd_id = 256;//First byte reserved

Expand Down Expand Up @@ -46,25 +47,31 @@ bool init_filesystem(){
return true;
}

FS_RESULT open_file_global(module_root *root, const char* path, file* descriptor, system_module **mod){
FS_RESULT open_file_global(module_root *root, const char* path, file* descriptor, system_module **out_mod){
const char *search_path = path;
if (*search_path == '/') search_path++;
if (!*search_path) return FS_RESULT_NOTFOUND;
system_module *module = get_module_from(root, &search_path);
if (!module) return FS_RESULT_NOTFOUND;
if (!module->open) return FS_RESULT_NOTFOUND;
FS_RESULT result = module->open(search_path, descriptor);
system_module *mod = get_module_from(root, &search_path);
if (!mod) return FS_RESULT_NOTFOUND;
if (!mod->open) return FS_RESULT_NOTFOUND;
FS_RESULT result = FS_RESULT_DRIVER_ERROR;
if (mod->owner != get_kernel_proc()->id){
job_make(job_open, mod, {
job_serialize_str(&app, 0, search_path);
job_serialize_fd(&app, 1, descriptor, copy_on_end);
});
return j_ret;
} else {
result = mod->open(search_path, descriptor);
}
if (result != FS_RESULT_SUCCESS) return result;
if (!open_files) return FS_RESULT_DRIVER_ERROR;
descriptor->cursor = 0;
*mod = module;
*out_mod = mod;
return FS_RESULT_SUCCESS;
}

FS_RESULT open_file(module_root *root, const char* path, file* descriptor){
system_module *mod = 0;
FS_RESULT result = open_file_global(root, path, descriptor, &mod);
if (result != FS_RESULT_SUCCESS) return result;
FS_RESULT instance_local_fd(system_module *mod, file *descriptor){
open_file_descriptors *of = (open_file_descriptors*)open_files_alloc(sizeof(open_file_descriptors));
if (!of) {
close_file_global(descriptor, mod);
Expand All @@ -76,9 +83,7 @@ FS_RESULT open_file(module_root *root, const char* path, file* descriptor){
of->mod = mod;
of->pid = get_current_proc_pid();
descriptor->id = of->file_id;
irq_flags_t irq = irq_save_disable();
int put = hash_map_put(open_files, &of->file_id, sizeof(uint64_t), of);
irq_restore(irq);

if (put != 1) {
file tmp = {
Expand All @@ -90,9 +95,19 @@ FS_RESULT open_file(module_root *root, const char* path, file* descriptor){
release(of);
return FS_RESULT_DRIVER_ERROR;
}

return FS_RESULT_SUCCESS;
}

FS_RESULT open_file(module_root *root, const char* path, file* descriptor){
system_module *mod = 0;
FS_RESULT result = open_file_global(root, path, descriptor, &mod);
if (result != FS_RESULT_SUCCESS) return result;
result = instance_local_fd(mod, descriptor);
if (result != FS_RESULT_SUCCESS) return result;
return result;
}

size_t read_file(file *descriptor, char* buf, size_t size){
if (!open_files){
kprintf("[FS] No open files");
Expand All @@ -111,7 +126,16 @@ size_t read_file(file *descriptor, char* buf, size_t size){
.cursor = start_cursor,
.data_type = descriptor->data_type
};
size_t amount_read = local.mod->read(&gfd, buf, size, start_cursor);
size_t amount_read = 0;
if (local.mod->owner != get_kernel_proc()->id){
job_make(job_read, local.mod, {
job_serialize_fd(&app, 0, &gfd, copy_on_start);
job_serialize_buf(&app, 1, true, (void*)buf, size, copy_on_end);
});
return j_ret;
} else {
amount_read = local.mod->read(&gfd, buf, size, start_cursor);
}
descriptor->cursor = gfd.cursor != start_cursor ? gfd.cursor : start_cursor + amount_read;
descriptor->size = gfd.size;
return amount_read;
Expand All @@ -136,7 +160,13 @@ void close_file(file *descriptor){

void close_file_global(file *descriptor, system_module *mod){
if (!mod || !mod->close) return;
mod->close(descriptor);
if (mod->owner != get_kernel_proc()->id){
job_make(job_close, mod, {
job_serialize_fd(&app, 0, descriptor, copy_on_start);
});
return;
} else
mod->close(descriptor);
}

size_t write_file(file *descriptor, const char* buf, size_t size){
Expand All @@ -162,7 +192,16 @@ size_t write_file(file *descriptor, const char* buf, size_t size){
.cursor = start_cursor,
.data_type = descriptor->data_type
};
size_t amount_written = local.mod->write(&gfd, buf, size, 0);
size_t amount_written = 0;
if (local.mod->owner != get_kernel_proc()->id){
job_make(job_write, local.mod, {
job_serialize_fd(&app, 0, &gfd, copy_on_start);
job_serialize_buf(&app, 1, true, (void*)buf, size, copy_on_start);
});
return j_ret;
} else {
amount_written = local.mod->write(&gfd, buf, size, 0);
}
descriptor->cursor = gfd.cursor != start_cursor ? gfd.cursor : start_cursor + amount_written;
descriptor->size = gfd.size;
irq = irq_save_disable();
Expand Down Expand Up @@ -197,7 +236,7 @@ size_t simple_write(module_root *root, const char *path, const void *buf, size_t
seek(&fd, fd.size, SEEK_ABSOLUTE);
}
size_t res = write_file(&fd, (char*)buf, size);
if (append){
if (!append){
truncate(&fd, size);
}
close_file(&fd);
Expand All @@ -217,7 +256,15 @@ size_t list_directory_contents(module_root *root, const char *path, void* buf, s
return 0;
}
if (!mod->readdir) return 0;
return mod->readdir(search_path, buf, size, offset);
if (mod->owner != get_kernel_proc()->id){
job_make(job_readdir, mod, {
job_serialize_str(&app, 0, search_path);
job_serialize_buf(&app, 1, true, buf, size, copy_on_end);
job_serialize_off(&app, 3, offset);
});
return j_ret;
} else
return mod->readdir(search_path, buf, size, offset);
}

bool get_stat(module_root *root, const char *path, fs_stat *out_stat){
Expand All @@ -233,6 +280,13 @@ bool get_stat(module_root *root, const char *path, fs_stat *out_stat){
return false;
}
if (!mod->getstat) return false;
if (mod->owner != get_kernel_proc()->id){
job_make(job_stat, mod, {
job_serialize_str(&app, 0, search_path);
job_serialize_stat(&app, 1, out_stat);
})
return j_ret;
}
return mod->getstat(search_path, out_stat);
}

Expand All @@ -251,12 +305,17 @@ bool truncate(file *descriptor, size_t size){

file gfd = (file){
.id = local.mfile_id,
.size = descriptor->size,
.size = size,
.cursor = descriptor->cursor,
.data_type = descriptor->data_type
};

if (!local.mod->truncate(&gfd, size)) return false;

if (local.mod->owner != get_kernel_proc()->id){
job_make(job_trunc, local.mod, {
job_serialize_fd(&app, 0, &gfd, copy_on_start);
});
return j_ret;
} else if (!local.mod->truncate(&gfd)) return false;

descriptor->size = gfd.size;
descriptor->cursor = gfd.cursor;
Expand Down Expand Up @@ -292,5 +351,5 @@ void close_files_for_process(uint16_t pid){
close_file(&fd);
}
}
close_pipes_for_process(pid);
close_pipes_for_process(pid);//TODO: pipes need to be cleaned. They're not being used
}
1 change: 1 addition & 0 deletions kernel/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern "C" {

FS_RESULT open_file_global(module_root *root, const char* path, file* descriptor, system_module **mod);
FS_RESULT open_file(module_root *root, const char* path, file* descriptor);
FS_RESULT instance_local_fd(system_module *mod, file *descriptor);
size_t read_file(file *descriptor, char* buf, size_t size);
size_t write_file(file *descriptor, const char* buf, size_t size);
void close_file_global(file *descriptor, system_module *mod);
Expand Down
2 changes: 1 addition & 1 deletion kernel/filesystem/fsdriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class FSDriver {
virtual size_t list_contents(const char *path, void* buf, size_t size, file_offset *offset = 0) = 0;
virtual void close_file(file* descriptor) = 0;
virtual bool stat(const char *path, fs_stat *out_stat) = 0;
virtual bool truncate(file *descriptor, size_t size) = 0;
virtual bool truncate(file *descriptor) = 0;
};
36 changes: 21 additions & 15 deletions kernel/filesystem/modules/fs_isolation.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,43 @@ chunk_array_t *fs_permissions;

u64 register_fs_id(){
if (!fs_permissions) fs_permissions = chunk_array_create(sizeof(uptr), 256);
hash_map_t *map = hash_map_create(64);
return chunk_array_push(fs_permissions, &map);
module_root *map = zalloc(sizeof(module_root));
map->map = hash_map_create(64);
return chunk_array_push(fs_permissions, map);
}

hash_map_t* get_fs_for_id(u64 id){
module_root* get_fs_for_id(u64 id){
if (!fs_permissions) return 0;
return *(hash_map_t**)chunk_array_get(fs_permissions, id);
return (module_root*)chunk_array_get(fs_permissions, id);
}

hash_map_t* kernel_modules;
module_root kernel_modules = {};

hash_map_t* kernel_fs(){
return kernel_modules;
module_root* kernel_fs(){
return &kernel_modules;
}

bool load_module(system_module *module){
if (!kernel_modules) kernel_modules = hash_map_create(64);
return load_module_to(kernel_modules, module);
if (!kernel_modules.map) kernel_modules.map = hash_map_create(64);
return load_module_to(&kernel_modules, module);
}

bool unload_module(system_module *module){
return unload_module_from(kernel_modules, module);
return unload_module_from(&kernel_modules, module);
}

system_module* get_module(const char **full_path){
return get_module_from(kernel_modules, full_path);
return get_module_from(&kernel_modules, full_path);
}

size_t list_root(void* buf, size_t size, uint64_t *offset){
fs_dir_list_helper helper = create_dir_list_helper(buf, size);
return list_root_from(kernel_modules, &helper, offset);
return list_root_from(&kernel_modules, &helper, offset);
}

string resolve_isolated_path(const char *path, u64 id, module_root *resolved, bool allow_kfs){
if (!path || !resolved || !id) return (string){};
hash_map_t *localfs = get_fs_for_id(id);
module_root *localfs = get_fs_for_id(id);
const char *localpath = path;
system_module *localmod = get_module_from(localfs, &localpath);
if (!localmod){
Expand All @@ -53,17 +54,22 @@ string resolve_isolated_path(const char *path, u64 id, module_root *resolved, bo
if (!rootmod){
return (string){};
}
memcpy(resolved,kernel_modules,sizeof(module_root));
memcpy(resolved,&kernel_modules,sizeof(module_root));
return string_from_literal(path);
}
if (localmod->alias_info.alias_path.length){
string s = string_format("%S%s", localmod->alias_info.alias_path, localpath);
const char *rootpath = s.data;
system_module *rootmod = get_module(&rootpath);
if (!rootmod) return (string){};
memcpy(resolved,kernel_modules,sizeof(module_root));
memcpy(resolved,&kernel_modules,sizeof(module_root));
return s;
}
memcpy(resolved,localfs,sizeof(module_root));
return string_from_literal(path);
}

void destroy_fs(u64 fsid){
if (!fsid) return;
//TODO: STUB
}
Loading
Loading