Commit graph

364 commits

Author SHA1 Message Date
Andreas Kling b5c5286ee1 Tidy up ELFLoader. 2018-11-04 14:11:16 +01:00
Andreas Kling 422b5403e5 Merge ExecSpace into ELFLoader. 2018-11-04 13:52:53 +01:00
Andreas Kling d90b891406 Remove bootstrapping code from ELFLoader.
This runs inside the kernel now, and I no longer need the emulated version.
2018-11-04 13:44:17 +01:00
Andreas Kling 9bd09454e3 Mark LibC's assertion faillure helper with __NORETURN. 2018-11-04 13:13:57 +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 8f51f0e6b2 ELFLoader: Add program header support.
We don't do anything useful with the data yet, but I'm gonna rewrite
the layout code to run off of the program header table instead.
This will allow us to map .text and .rodata sections in read-only memory.
2018-11-03 10:13:07 +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
Andreas Kling 10b666f69a Basic ^C interrupt implementation.
For testing, I made cat put itself into a new process group.
This should eventually be done by sh between fork() and exec().
2018-11-02 14:06:48 +01:00
Andreas Kling 621217ffeb Add tcsetpgrp()+tcgetpgrp().
One more step on the path to being able to ^C a runaway process. :^)
2018-11-02 13:14:25 +01:00
Andreas Kling d8f0dd6f3b Start working on sessions and process groups. 2018-11-02 12:56:51 +01:00
Andreas Kling 05565bad58 Make IO helpers inline and use immediate-encoded ports when possible. 2018-11-02 10:14:26 +01:00
Andreas Kling 812e7940e2 Add a simple /proc/cpuinfo that includes some info from CPUID. 2018-11-02 10:14:21 +01:00
Andreas Kling 90ddbca127 Free physical pages allocated for a process's page directory on exit.
Also use a ProcessPagingScope instead of region aliasing to implement
create-process ELF loading.
2018-11-01 23:08:10 +01:00
Andreas Kling c70afd045e Use a freelist for GDT entries.
Tweak the kmalloc space layout a bit. Get the spawn stress test up
and running again.
2018-11-01 16:23:12 +01:00
Andreas Kling 9da4864a9a Oops, fix null termination bug in getpwent(). 2018-11-01 16:22:28 +01:00
Andreas Kling 3a901ae36d Way tighter locking in process creation.
We no longer disable interrupts around the whole affair.
Since MM manages per-process data structures, this works quite smoothly now.
Only procfs had to be tweaked with an InterruptDisabler.
2018-11-01 14:41:49 +01:00
Andreas Kling 52607aa086 Allow processes to go into a BeingInspected state (used by procfs.)
This ensures that the process won't get scheduled, and so inspecting
it is safe and easy without blocking interrupts.
2018-11-01 14:21:02 +01:00
Andreas Kling dfaa2b6b02 Convert VirtualConsole to the new coding style.
I'm still playing around with finding a style that I like.
This is starting to feel pleasing to the eye. I guess this is how long
it took me to break free from the habit of my previous Qt/WK coding style.
2018-11-01 14:11:22 +01:00
Andreas Kling fd03776443 Add a /proc/PID/fds text files that lists all the fds open in a process. 2018-11-01 14:00:28 +01:00
Andreas Kling 065f0aee35 Preallocate the maximum number of FileHandle pointers (fds) in every process.
This could even use a more specific data structure since it doesn't need the
grow/shrink capabilities of a vector.
2018-11-01 13:39:28 +01:00
Andreas Kling fce81d376c Move Region and Subregion out of Process and make them free classes. 2018-11-01 13:21:02 +01:00
Andreas Kling 3e532ac7b6 Process now maps regions immediately when they are allocated.
This avoids having to do a separate MM.mapRegionsForTask() pass.

Also, more Task => Process renaming that I apparently hadn't saved yet.
2018-11-01 13:15:46 +01:00
Andreas Kling 4e60551aec Rename Task to Process. 2018-11-01 13:10:12 +01:00
Andreas Kling 8525cdd6a2 Fix crash when process spawn fails. 2018-11-01 12:55:06 +01:00
Andreas Kling c178d7a9e3 Remove some unused MM functions.
These were just Q&D hacks I used while bringing up the paging code.
2018-11-01 12:51:54 +01:00
Andreas Kling 0f70b9105f Implement address validation by querying the task's page directory.
This is way better than walking the region lists. I suppose we could
even let the hardware trigger a page fault and handle that. That'll
be the next step in the evolution here I guess.
2018-11-01 12:45:51 +01:00
Andreas Kling f76fcd1e62 Do a bit less work in every context switch. 2018-11-01 11:57:36 +01:00
Andreas Kling 5891691640 Fix /proc/PID/stack in the new per-process page directory world.
I added an RAII helper called OtherTaskPagingScope. While present,
it switches the kernel over to using another task's page directory.
This is perfect for e.g walking the stack in /proc/PID/stack.
2018-11-01 11:44:21 +01:00
Andreas Kling c45f166c63 More work on per-process page directories. It basically works now!
I spent some time stuck on a problem where processes would clobber each
other's stacks. Took me a moment to figure out that their stacks
were allocated in the sub-4MB linear address range which is shared
between all processes. Oops!
2018-11-01 11:36:25 +01:00
Andreas Kling 1da0a7c949 Give each task its own page directory.
This isn't finished but I'll commit as I go. We need to get to where context
switching only needs to change CR3 and everything's ready to go.

My basic idea is:
- The first 4 kB is off-limits. This catches null dereferences.
- Up to the 4 MB mark is identity-mapped and kernel-only.
- The rest is available to everyone!

While the first 4 MB is only available to the kernel, it's still mapped in
every process, for convenience when entering the kernel.
2018-11-01 09:01:51 +01:00
Andreas Kling cddd2f37e9 Have sh print out which signal terminated a child process. 2018-11-01 01:11:00 +01:00
Andreas Kling a685809e75 Waiters should be notified when a waitee is killed.
Ran into a horrendous bug where VirtualConsole would overrun its buffer
and scribble right into some other object if we were interrupted while
processing a character. Slapped an InterruptDisabler onto onChar for now.

This provokes an interesting question though.. if a process is killed
while its in kernel space, how the heck do we release any locks it held?
I'm sure there are many different solutions to this problem, but I'll
have to think about it.
2018-11-01 01:05:59 +01:00
Andreas Kling 9a086b2d35 Add a kmalloc_eternal() for things that will never be destroyed. 2018-10-31 23:19:15 +01:00
Andreas Kling d980ddc745 Fix busted display of tty names in /proc/summary. 2018-10-31 22:43:49 +01:00
Andreas Kling a8f36f72a8 printfing a number or string bigger than the field width should not crash. 2018-10-31 22:40:10 +01:00
Andreas Kling c7d5ce6b5a Add a /bin/tty command that prints the current tty.
Also fix ttyname() syscall to include "/dev/" in the name.
2018-10-31 21:46:05 +01:00
Andreas Kling 4605b549d6 perror() should send output to stderr. 2018-10-31 21:37:09 +01:00
Andreas Kling 8f6998c902 Add SpinLock to IDE disk access.
This forces serialization of accesses. This driver needs to be redesigned.
2018-10-31 21:33:27 +01:00
Andreas Kling dec5683e9c Snazz up the kprintf() output a bit by giving it its own color. 2018-10-31 20:14:23 +01:00
Andreas Kling 9886b27d9c Add getpwent() family of functions to LibC.
Also add a little /etc/passwd database. There's just me in there.
2018-10-31 19:54:25 +01:00
Andreas Kling 819ce91395 Enough compatibility work to make figlet build and run!
I ran out of steam writing library routines and imported two
BSD-licensed libc routines: sscanf() and getopt().

I will most likely rewrite them sooner or later. For now
I just wanted to see figlet running.
2018-10-31 17:52:59 +01:00
Andreas Kling 69c7a59e6f Fix wrong allocation size used in opendir(). 2018-10-31 17:25:24 +01:00