Commit graph

221 commits

Author SHA1 Message Date
Andreas Kling 3b2dcd5929 Add a VMO pointer to VNode.
This way, if anyone tries to map an already mapped file, we share the VMO.
2018-11-08 15:39:26 +01:00
Andreas Kling 862f108cb5 Refactor the virtual memory object model a bit:
Process now has a number of Regions.
Each Region is backed by a VMObject.
A VMObject can be file-backed or anonymous. These can be shared.
2018-11-08 14:42:16 +01:00
Andreas Kling 3c8064a787 Support basic mmap'ing of a file!
All right, we can now mmap() a file and it gets magically paged in from fs
in response to an NP page fault. This is really cool :^)

I need to refactor this to support sharing of read-only file-backed pages,
but it's cool to just have something working.
2018-11-08 12:59:16 +01:00
Andreas Kling fdbd9f1e27 Start working on memory-mapped files.
First of all, change sys$mmap to take a struct SC_mmap_params since our
sycsall calling convention can't handle more than 3 arguments.

This exposed a bug in Syscall::invoke() needing to use clobber lists.
It was a bit confusing to debug. :^)
2018-11-08 11:40:58 +01:00
Andreas Kling 71a2942a0a Make it run in QEMU.
Looks like the problem was the weirdly-sized floppy image file.
I guess QEMU was inferring the floppy disk geometry from the image size.
2018-11-08 02:03:19 +01:00
Andreas Kling da3857b0c2 Add some simple write buffering to LibC's stdio.
Plumb it all the way to the VirtualConsole. Also fix /bin/cat to write()
the whole chunks we get from read() directly to stdout.
2018-11-08 01:23:47 +01:00
Andreas Kling e287f8ef3a The colonel task already had a halt loop.
Also don't reap() current in the scheduler, just wait until it's not current.
2018-11-08 00:30:35 +01:00
Andreas Kling ac1d12465f Move timer tick handling into Scheduler. 2018-11-08 00:26:04 +01:00
Andreas Kling 27fded7002 Unbreak signal delivery to userspace again.
My my, this code is quite fickle.
2018-11-08 00:08:50 +01:00
Andreas Kling 1dbc340da8 Get rid of the undertaker and have waitpid() be the reaper.
For dead orphans, the scheduler calls reap().
2018-11-07 23:59:49 +01:00
Andreas Kling f792349853 Unbreak sys$sigreturn() after colonel process changes. 2018-11-07 23:21:32 +01:00
Andreas Kling 43f40a3050 Finally unbreak the colonel process and make it the true idle process. 2018-11-07 23:14:56 +01:00
Andreas Kling 440029c9d1 Reduce number of passes in the scheduler by 2. 2018-11-07 22:24:20 +01:00
Andreas Kling 39d2fcbbee Move the scheduler code to its own class.
This is very mechanical.
2018-11-07 22:15:02 +01:00
Andreas Kling 6304c771dd Some refactor and style tweaks. 2018-11-07 21:38:18 +01:00
Andreas Kling 03a8357e84 Implement sending signals to blocked-in-kernel processes.
This is dirty but pretty cool! If we have a pending, unmasked signal for
a process that's blocked inside the kernel, we set up alternate stacks
for that process and unblock it to execute the signal handler.

A slightly different return trampoline is used here: since we need to
get back into the kernel, a dedicated syscall is used (sys$sigreturn.)

This restores the TSS contents of the process to the state it was in
while we were originally blocking in the kernel.

NOTE: There's currently only one "kernel resume TSS" so signal nesting
definitely won't work.
2018-11-07 21:19:47 +01:00
Andreas Kling c8b308910e Signals to processes in userspace now work again.
Ugh, how am I going to dispatch signals to processes in the kernel?
2018-11-07 19:03:44 +01:00
Andreas Kling dd887e158b Add a /proc/PID/regs that shows register state from the process's TSS. 2018-11-07 18:40:29 +01:00
Andreas Kling 678882e020 Rework process states to make a bit more sense.
Processes are either alive (with many substates), dead or forgiven.
A dead process is forgiven when the parent waitpid()s on it.
Dead orphans are also forgiven.

There's a lot of work to be done around this.
2018-11-07 18:34:37 +01:00
Andreas Kling 71bffa9864 Fix whiny build. 2018-11-07 16:38:45 +01:00
Andreas Kling 981a3ae4b3 Make VFS test environment build again. 2018-11-07 12:05:51 +01:00
Andreas Kling 83172e6a4b Rename FileHandle to FileDescriptor. 2018-11-07 11:37:54 +01:00
Andreas Kling e088121b3a Fix sys$sigaction() to return the old action metadata if requested. 2018-11-07 10:48:44 +01:00
Andreas Kling d7a41579e5 Miscellaneous compat work while seeing if GNU coreutils would build. 2018-11-07 10:23:16 +01:00
Andreas Kling a7f1d892a9 Add some basic setgroups(), getgroups() and initgroups().
Also teach /bin/id to print the user's supplemental groups.
2018-11-07 01:38:51 +01:00
Andreas Kling 7c3746592b Add strsignal() and improve sharing signal numbers between LibC and kernel. 2018-11-06 15:45:16 +01:00
Andreas Kling 8d1f8b2518 Add sys_nerr and sys_errlist.
Also keep the canonical errno list in LibC for now. The kernel gets it
from there. This makes building 3rd party code easier.

..also fix broken strchr().
2018-11-06 14:42:28 +01:00
Andreas Kling b2d23f83ab Add umask(). 2018-11-06 13:47:56 +01:00
Andreas Kling 77fe8e8363 Add getppid(). 2018-11-06 13:33:57 +01:00
Andreas Kling 3024167cbd Change syscall naming scheme. 2018-11-06 13:33:54 +01:00
Andreas Kling 153ea704af Add some basic signal support.
It only works for sending a signal to a process that's in userspace code.

We implement reception by synthesizing a PUSHA+PUSHF in the receiving process
(operating on values in the TSS.)
The TSS CS:EIP is then rerouted to the signal handler and a tiny return
trampoline is constructed in a dedicated region in the receiving process.

Also hacked up /bin/kill to be able to send arbitrary signals (kill -N PID)
2018-11-06 10:56:41 +01:00
Andreas Kling 52d502e11f Remove some no longer used files. 2018-11-05 19:20:10 +01:00
Andreas Kling 9f2b9c82bf More work towards getting bash to build.
Implemented some syscalls: dup(), dup2(), getdtablesize().
FileHandle is now a retainable, since that's needed for dup()'ed fd's.
I didn't really test any of this beyond a basic smoke check.
2018-11-05 19:01:59 +01:00
Andreas Kling 82f84bab11 More random compat hacking towards getting bash to build.
I'm now at the build stage where it complains about a bajillion missing
symbols. This is a good place to be!
2018-11-05 18:21:42 +01:00
Andreas Kling e4611248c4 Add geteuid() and getegid().
There's no support for set-uid or set-gid executables yet so these don't
actually do anything. It's just nice to get the boilerplate stuff in.
2018-11-05 15:05:27 +01:00
Andreas Kling 9e62eb4856 Only COW on fault if the physical page has retain_count > 1.
This makes COW pages lazily-but-transparently revert back to read/write.
2018-11-05 14:11:21 +01:00
Andreas Kling 2d045d2a64 Implement COW pages! :^)
sys$fork() now clones all writable regions with per-page COW bits.
The pages are then mapped read-only and we handle a PF by COWing the pages.

This is quite delightful. Obviously there's lots of work to do still,
and it needs better data structures, but the general concept works.
2018-11-05 13:48:07 +01:00
Andreas Kling e85c22fe58 Tidy up the page fault code a bit in preparation. 2018-11-05 10:29:19 +01:00
Andreas Kling 72cdc62155 Replace zones with individually tracked physical pages.
It's just a simple struct { ref_count, paddr }.
This will allow me to implement lazy zeroing and COW pages.
2018-11-05 10:23:00 +01:00
Andreas Kling 422b5403e5 Merge ExecSpace into ELFLoader. 2018-11-04 13:52:53 +01:00
Andreas Kling 8b4b684d6d Move assertion failures out-of-line to reduce binary bloat. 2018-11-04 13:12:58 +01:00
Andreas Kling 7fe4063323 Region::clone() should share the zone if it's read-only.
This avoids copying the .text and .rodata segments in fork().
The next step is copy-on-write support for the writable regions.
2018-11-03 23:20:49 +01:00
Andreas Kling da13c9a264 Map pages in read-only ELF sections as non-writable.
This is so cool! :^) Now you'll crash if you try to write into your
.text or .rodata segments.
2018-11-03 11:36:45 +01:00
Andreas Kling aa6d06b47e Use ELF program headers to load executables smarter.
This turned out way better than the old code. ELF loading is now quite
straightforward, and we don't need the weird concept of subregions anymore.

Next step is to respect the is_writable flag.
2018-11-03 11:29:30 +01:00
Andreas Kling dd060d0fa8 Share code between spawn() and exec() implementations.
Okay, now there's only one ELF loading client in the process launch code.
2018-11-03 10:55:02 +01:00
Andreas Kling c5eec9cbfc Factor out the "non-syscall" parts of sys$execve() into exec().
..to prepare for sharing code with createUserProcess().
2018-11-03 10:20:23 +01:00
Andreas Kling 20fb1fc377 Fix some bugs in execve() and make sh use it for process launching.
Interrupting children of sh now always works with ^C :^)
2018-11-03 02:08:06 +01:00
Andreas Kling 202bdb553c Implemented sys$execve().
It's really crufty, but it basically works!
2018-11-03 01:51:42 +01:00
Andreas Kling b59ce22fc5 Fix dumb-but-hard-to-find bug in paging.
This was the fix:

-process.m_page_directory[0] = m_kernel_page_directory[0];
-process.m_page_directory[1] = m_kernel_page_directory[1];
+process.m_page_directory->entries[0] = m_kernel_page_directory->entries[0];
+process.m_page_directory->entries[1] = m_kernel_page_directory->entries[1];

I spent a good two hours scratching my head, not being able to figure out why
user process page directories felt they had ownership of page tables in the
kernel page directory.

It was because I was copying the entire damn kernel page directory into
the process instead of only sharing the two first PDE's. Dang!
2018-11-03 00:35:57 +01:00
Andreas Kling 8accc92c3c Implement fork()!
This is quite cool! The syscall entry point plumbs the register dump
down to sys$fork(), which uses it to set up the child process's TSS
in order to resume execution right after the int 0x80 fork() call. :^)

This works pretty well, although there is some problem with the kernel
alias mappings used to clone the parent process's regions. If I disable
the MM::release_page_directory() code, there's no problem. Probably there's
a premature freeing of a physical page somehow.
2018-11-02 20:41:58 +01:00