6e5d2b5335
Thread: Make g_next_id atomic
2022-12-17 10:50:49 +01:00
a32590ff8a
Call expect_value more
2022-12-16 19:44:33 +01:00
cedcfa9c63
Improve cleanup on MemoryManager failure + add methods that use KernelVM
continuous-integration/drone/push Build is passing
2022-12-16 19:36:38 +01:00
b6173e2b67
LinkedList: Return Option instead of ENONE if no value
2022-12-08 16:09:04 +01:00
779fda307a
More scope guards!!
continuous-integration/drone/push Build is passing
2022-12-08 15:01:04 +01:00
1d5d1daa57
Add scope guards
2022-12-08 14:56:11 +01:00
d93d95f23c
Add sleeping mechanism
2022-12-07 16:11:59 +00:00
757cee4693
Add accessors for when you're sure a linked list is not empty
2022-12-07 16:11:59 +00:00
70497c37fb
Check for runnable threads
2022-12-07 16:11:59 +00:00
57517252d8
Add a state to Thread
2022-12-07 16:11:59 +00:00
13f5d09cfd
Add a Scheduler!!
2022-12-07 16:11:59 +00:00
12aa014a3d
Add a Thread class which can be part of a DoublyLinkedList
2022-12-07 16:11:59 +00:00
cf758fdfdc
Initial commit :)
2022-11-13 10:09:09 +01:00
42efc21110
Start implementing read and write support in tmpfs
...
write seems to work fine, read just hangs there, waiting.
2022-11-12 20:11:26 +01:00
000ffd1fae
Scheduler: Handle weird cases when the task we're iterating on is null
2022-11-12 18:12:42 +01:00
58fb422161
Kernel: Return a Result in MemoryManager and strdup_from_user
2022-11-12 11:56:40 +01:00
662afad426
Kernel: Add a Result class
2022-11-12 11:30:28 +01:00
1ea216dfd1
Kernel: Rename assert.h to ensure.h
...
The macro is named "ensure", the header file should reflect that.
2022-11-09 15:28:35 +01:00
ea94b331fb
Scheduler: Use copy_to_user in a few system calls
2022-11-09 15:20:53 +01:00
033c41cbd7
Kernel: Rework the uid/gid system to make it compliant
2022-11-09 09:54:07 +01:00
44815b08c7
Kernel: Use copy_from_user() and copy_to_user() in read/write
...
This is huge. Finally, we can do proper reads/writes with invalid addresses, or big buffers.
2022-11-06 15:19:23 +01:00
9ab3ab7c40
Kernel: Show init's exit status before restarting
2022-11-05 11:56:16 +01:00
0fd31698b2
Kernel: Accept not opened file descriptors in dup2()
...
This involves renaming the descriptor_from_fd function to the more appropriately named
open_descriptor_from_fd (since we check if the descriptor was opened and error out otherwise),
and creating a new function that does not verify that the file descriptor was opened.
2022-11-03 16:52:21 +01:00
c604c074a1
Kernel: Rename ASSERT() to ensure()
...
Doesn't get stripped on release builds, so it shouldn't be named assert.
2022-11-02 19:38:15 +01:00
e5cf32c7b3
Kernel: Introduce page ownership
...
Some pages, such as framebuffer pages, are not physical memory frames reserved for the current process.
Some, such as the framebuffer, may be shared between all processes.
Yet, on exit() or on exec(), a process frees all frames mapped into its address spaces.
And on fork(), it copies all data between frames. So how could we map framebuffers.
Simple: we use one of the bits in page table entries which are available to the OS, and mark whether that page is owned by the current process.
If it is owned, it will be:
- Freed on address space destruction
- Its data will be copied to a new page owned by the child process on fork()
If it is not owned, it will be:
- Left alone on address space destruction
- On fork(), the child's virtual page will be mapped to the same physical frame as the parent
This still needs a bit more work, such as keeping a reference of how many processes use a page to free it when all processes using it exit/exec.
This should be done for MAP_SHARED mappings, for example, since they are not permanent forever,
unlike the framebuffer for example.
2022-11-02 19:32:28 +01:00
5eae93bbb0
Bugfix: do not crash if we are blocking for no reason
2022-10-30 20:51:32 +01:00
29c59abf7d
Kernel: Rename blocking_wait_info's wait_pid to pid
2022-10-30 19:28:43 +01:00
9c3792718c
Kernel: Remove waitpid() debug messages and add more checks
2022-10-30 19:24:56 +01:00
c68d040484
Scheduler: Make sure we are in the kernel's address space when resuming a blocked process
2022-10-30 19:10:46 +01:00
b8296eb92d
su: Also set group ID
2022-10-28 17:55:56 +02:00
09a615bd99
Kernel, libc: Expose processes' UID and GID in pstat()
2022-10-28 17:31:34 +02:00
0115cce750
Kernel/VFS: Add file owners and file modes, and check those in system calls
2022-10-28 17:10:28 +02:00
16dc227a05
Kernel: Add UID and GID fields to Task
2022-10-28 17:06:13 +02:00
fcf53ef6a5
Kernel: Make waitpid() block by default unless WNOHANG is specified
2022-10-27 17:05:42 +02:00
06e6429567
Kernel: Reorganize a bit of scheduler code
2022-10-27 08:07:34 +02:00
af46b8d9ac
Kernel: Cleanup file descriptor validation
2022-10-25 18:35:17 +02:00
bcdcfc4b45
Kernel: Add a pstat() system call
...
Not part of C or POSIX, but since there is no procfs right now, I thought it would be nice to have an interface to query process information.
It works like this: you pass the process ID and a pointer to a struct pstat (can be null).
If the process ID is -1, the kernel picks the process with the highest PID.
Then, if the pointer to a pstat struct is not null, the kernel fills it in with the process's information, and returns the process's PID.
2022-10-22 14:26:29 +02:00
6816a5b11f
Scheduler: do not reboot on PID 1 exit if we are in a test
2022-10-22 11:56:08 +02:00
da61e3648f
Kernel: Implement blocking reads
...
This is a huge step forward!! bc actually runs now, without echo or backspace, but it runs!!
2022-10-21 21:26:19 +02:00
27448611b3
UserMemory: do not map refs into kernel memory
...
This is bad design. But it fails if mapped, since something overwrites KernelHeap.
2022-10-20 18:50:07 +02:00
cd9ecc1746
Kernel: Return EFAULT when the kernel believes the wstatus pointer is invalid
2022-10-20 08:20:56 +02:00
1938a059a2
Kernel: Free the last spawned thread's PID on exit
2022-10-19 20:51:54 +02:00
51665a04b7
Kernel: Restart if init exits
2022-10-19 20:33:41 +02:00
7e9744419e
sh: Improve it
2022-10-19 20:16:21 +02:00
b035795eb3
Kernel: Move errno.h and (k)assert.h out of the main include directory
...
This is mostly so IDEs don't pick them up instead of the userspace headers :)
2022-10-19 17:41:23 +02:00
f3af3e252b
Kernel: refresh task_misbehave()
...
That function was severely outdated.
2022-10-19 17:26:36 +02:00
656667812a
Kernel: reparent child processes to PID 1 when their parent exits
2022-10-19 17:16:01 +02:00
a29f7f8df2
Kernel: waitpid: support -1 as PID (wait for any child)
2022-10-19 17:15:30 +02:00
671f2a2de3
Kernel, libc: Implement waitpid()
...
FIXME: exec() is now doing weird page table stuff. But at least it works, no panics :)
2022-10-18 21:30:52 +02:00
59506b8852
Kernel: Show current_task's name in the log
2022-10-18 18:41:17 +02:00
a9d3bdba6f
Kernel: Keep track of a task's PPID
2022-10-18 17:18:37 +02:00
4f41b9ed37
Scheduler: Implement a find_by_pid function
2022-10-17 20:40:38 +02:00
ea8a42b8c0
Kernel: Add a name field to the Task structure
2022-10-17 19:12:47 +02:00
64f5078494
Kernel, libc: Implement fork()
...
This time for real.
Also, add a new per-user-task virtual address allocator (UserHeap), so that mmap'ed pages are in user range and can be copied.
2022-10-17 18:43:35 +02:00
966fdc76d7
Move userspace task to userspace memory
2022-10-17 17:30:05 +02:00
250db2c90f
Scheduler: add an append_task() function
2022-10-17 17:14:22 +02:00
c2fa4f380d
Kernel: Use the new Task member functions
2022-10-17 17:07:25 +02:00
891651f2d6
Task: Move functions operating on Task to member functions
...
Also, add an alloc_fd_greater_than_or_equal() function, for use in fcntl(F_DUPFD)
2022-10-17 17:00:07 +02:00
9b39d618de
Kernel, libc: Implement spawn()
...
This function is a Luna alternative to fork() and exec().
Why? Simply because I can't figure out for the life of me how to implement a working fork().
So meanwhile, we have spawn() as a replacement. exec() still exists, though.
2022-10-16 18:48:35 +02:00
62d631f1b4
Kernel: Rename assert.h to kassert.h so IDEs pickup the kernel header instead of the userspace one
2022-10-15 12:56:48 +02:00
3eb1bff2e9
Task: add an alloc_fd() function
2022-10-15 10:45:12 +02:00
c8a92af4d2
Whoops! bugfix
2022-10-14 18:21:09 +02:00
1c3377fc98
Prepare for cloning address spaces, not there yet
2022-10-14 18:17:57 +02:00
e43777bd31
Apparently, it just works now.
2022-10-14 18:00:33 +02:00
81f56083c5
Almost there!
2022-10-14 17:38:29 +02:00
5abd8814e3
Kernel: Continue moving utilities to a separate subdirectory
2022-10-14 17:33:06 +02:00
e21b608af4
Utilities: Start moving utilities into specific headers in a utils/ subdirectory
2022-10-14 17:31:47 +02:00
9b3c7816a3
Scheduler: pop the interrupt state when returning early from load_user_task()
2022-10-14 16:54:52 +02:00
0c7c249935
exec is still doing some weird stuff, totally corrupting the page tables
2022-10-13 22:20:24 +02:00
24272c57ef
Almost there!
2022-10-13 21:55:51 +02:00
ee712432bd
Some more multiple address space stuff
...
This page-faults. This is because the memory where the ELF should be is all zeroes, which the CPU tries to interpret.
2022-10-13 21:14:39 +02:00
1a54342454
Sanity check
2022-10-12 18:38:18 +02:00
3ac9fed23a
ELFLoader: Add check_elf_image() and check_elf_image_from_filesystem()
...
These two functions validate an image, without actually loading it. Very useful for exec!
2022-10-12 18:37:00 +02:00
f8b3567042
Kernel: Add an exec() syscall
...
Very bare-bones for now. Doesn't support arguments or environment (we don't have that stuff right now), and the executable is not a valid ELF, it terminates the task.
But it's a start!
2022-10-12 17:42:01 +02:00
25a460e3c6
Scheduler: clear user tasks' registers
2022-10-12 17:12:06 +02:00
136c0b3ae9
Scheduler: add a reset_task function
...
This can be used later to implement execve()
2022-10-12 17:08:45 +02:00
4e3ef9593d
Scheduler: Move ELF image freeing to ELFLoader
2022-10-12 17:08:17 +02:00
a6f0a7056f
Scheduler: Set the user_task field in a Task at creation time
...
We were previously looking at its segment registers to see if they were user-like, but this method is bad.
What is the task was executing a system call?
So now, we store that value at creation time.
2022-10-12 17:07:39 +02:00
d3cb642e5f
Scheduler: add FIXME
2022-10-12 14:30:57 +02:00
0ee9bd7290
Scheduler: free a task's ELF image.
...
Now that we have support for larger pages, this works!!
2022-10-12 14:30:46 +02:00
cf160d1260
Scheduler: Use misc/utils.h instead of doing everything manually.
...
That way the code is cleaner + we have one single point of failure.
2022-10-12 13:18:35 +02:00
0131193379
ELFLoader, Scheduler: Transition to use VFS
...
We should start to drop the old InitRD API, which only allows for files to be loaded from the initrd, and which forces pathnames to be relative (bin/init)
With VFS, we can load any kind of file from any kind of filesystem, and using paths that make sense (/bin/init)
2022-10-11 19:33:48 +02:00
f83a6ace51
Kernel, libc: Add support for providing a status code to exit()
...
The exit() libc function already accepted an integer, but didn't pass it on to the kernel since we had no mechanism for it to do that.
Now, the kernel stores a task's exit status to display it later (and in the future, return it to userspace via wait()/waitpid())
2022-10-08 17:56:40 +02:00
309058888c
Bugfix: remove duplicate error check when loading a userspace ELF program
...
Also, remember to delete the allocated task, since we do not want memory leaks :)
2022-10-08 13:12:19 +00:00
abcf1b6118
Define PAGE_SIZE as 4096 and use it everywhere instead of using 4096 as a magic number
2022-10-08 14:52:28 +02:00
dc389da74e
Implement an ELFImage struct
...
This struct allows us to keep track of what memory is used by the loaded executable. For some reason, freeing this memory when the task exits triggers a kernel page fault, so I'm not doing that right now.
2022-10-07 17:54:05 +02:00
594d79143e
Kernel: enable -Wconversion
2022-10-06 17:13:34 +02:00
38470724dc
Scheduler: adjust SSE saving conditions
2022-10-02 19:13:21 +02:00
1ecd24f5d6
Kernel: Add SSE support (enable SSE on boot and save context (user tasks only) on task switch)
2022-10-02 18:53:54 +02:00
03db57bbf9
Sanity checks
2022-10-01 12:32:09 +02:00
66bee86a8b
Scheduler: add a load_user_task function that directly loads a file from the initrd
2022-10-01 12:28:32 +02:00
9012ccc49e
Remove _userspace and move the idle task to assembly
2022-10-01 12:16:30 +02:00
f25014a8ed
refine syscalls
2022-09-29 19:17:43 +02:00
f1a7138568
User mode (with a few syscalls)
...
IT ACTUALLY WORKS NOW.
Why wasn't it working? Oh, because I was not setting already present page tables's permissions to user mode. Just a little bug. THAT I SPENT DAYS TRYING TO FIND
Anyways, it works now. Such a relief...
2022-09-25 20:35:05 +02:00
57bb1164e9
change 4 pages of stack per stack to a #define
2022-09-25 18:13:20 +02:00
d3527b8824
Use new and delete in Scheduler
2022-09-25 18:12:12 +02:00
19dff40ee2
Scheduler: track total CPU time of tasks
2022-09-25 17:49:51 +02:00
aee4e55fdd
add a proper kernel panic
2022-09-25 16:56:00 +02:00
059bf86ddf
Scheduler: use kmalloc and kfree
2022-09-24 23:18:33 +02:00
3891d0c52e
Rename KernelMemoryManager to MemoryManager
...
Kind of a more catchy name, isn't it?
2022-09-24 21:45:13 +02:00
c3e5251687
Some more userland and font failing
2022-09-23 16:41:43 +02:00
11dd165a8e
Scheduler: add proper support for user tasks (still faults though)
2022-09-22 08:14:04 +02:00
ec01dc2927
Scheduler: Change fixed Task array for (highly inefficient) memory allocation, add userspace task support (which as memory is mapped kernel-only instantly crashes), and support for exiting a task (marking it as exited and reaping it later)
2022-09-21 21:06:00 +02:00
4401b31440
Remove ds from context, no need for it in x86_64, use ss instead
2022-09-21 21:03:24 +02:00
49ddb47ad4
Reorganize structure
2022-09-21 17:56:53 +02:00
1dce3a0cf7
Give 1 tick of CPU time to the idle task
2022-09-20 20:48:49 +02:00
ddbe9b8b8b
Few small adjustments to the scheduler
2022-09-20 20:02:08 +02:00
1c12cf016e
Add a Scheduler.
...
Finally.
Just Round Robin with sleeping, but it's still awesome. I think this can finish v0.3, with a few adjustments.
2022-09-20 19:58:04 +02:00
245d5e514d
Optimizations in Spinlock.asm
2022-09-19 16:36:34 +02:00
99e681aeb4
Forgot to add volatile
...
Did I check to see if it compiled before making the previous commit? Yes, of course, why are you asking? ...
2022-09-18 20:16:46 +02:00
d4a982306f
Add spinlocks
2022-09-18 20:15:19 +02:00