Commit Graph

357 Commits

Author SHA1 Message Date
Andreas Kling
356abbb7ee Kernel: Process should disassociate from its TTY when it dies.
Just because we die doesn't mean we got waited on yet, so keeping around
a dangling TTY pointer is just asking for trouble.
2019-02-04 10:21:15 +01:00
Andreas Kling
b51031bb54 Kernel: Add a /proc/all process table dump.
This will be useful for implementing some process-related utilities.
2019-02-03 18:53:18 +01:00
Andreas Kling
dddd0e7b03 Get nyancat nyanning in Serenity.
I found a cute program that renders an animated nyancat in the terminal.
This patch adds enough hackery to get it working correctly. :^)
2019-02-03 16:11:28 +01:00
Andreas Kling
5e9ba2ac84 Kernel: Rewrite ProcFS.
Now the filesystem is generated on-the-fly instead of manually adding and
removing inodes as processes spawn and die.

The code is convoluted and bloated as I wrote it while sleepless. However,
it's still vastly better than the old ProcFS, so I'm committing it.

I also added /proc/PID/fd/N symlinks for each of a process's open fd's.
2019-02-03 12:33:11 +01:00
Andreas Kling
1fffc0ae60 Kernel: stat(), fstat() and lstat() didn't return some error codes. 2019-02-03 06:27:16 +01:00
Andreas Kling
333aa1646c Kernel: Increase default userspace stack size to 64 kilobytes. 2019-02-03 03:56:08 +01:00
Andreas Kling
feed67ede2 Kernel: VFS::open/create should take base Inode& instead of InodeIdentifier. 2019-02-01 15:36:45 +01:00
Andreas Kling
6618411fba Kernel: mkdir() should use the containing directory's FS for inode creation. 2019-02-01 15:29:11 +01:00
Andreas Kling
33e7df5955 Kernel: mkdir() should fail if the pathname is empty. 2019-02-01 15:29:05 +01:00
Andreas Kling
95c3442d59 Implement event loop timers.
GObjects can now register a timer with the GEventLoop. This will eventually
cause GTimerEvents to be dispatched to the GObject.

This needed a few supporting changes in the kernel:

- The PIT now ticks 1000 times/sec.
- select() now supports an arbitrary timeout.
- gettimeofday() now returns something in the tv_usec field.

With these changes, the clock window in guitest2 finally ticks on its own.
2019-02-01 03:50:06 +01:00
Andreas Kling
ffab6897aa Big, possibly complete sweep of naming changes. 2019-01-31 17:31:23 +01:00
Andreas Kling
c4fce9b3f9 Make stat() work on device files again.
FileDescriptor will now keep a pointer to the original inode even after
opening it resolves to a character device.

Fixed up /bin/ls to display major and minor device numbers instead of size
for device files.
2019-01-31 05:05:57 +01:00
Andreas Kling
5c25f0c4db Destroy all remaining windows in a process when it dies. 2019-01-30 19:35:38 +01:00
Andreas Kling
45fba60ab5 Kernel: select() should fail with EBADF if any set contains an invalid fd. 2019-01-30 19:01:31 +01:00
Andreas Kling
b4e478aa50 Deallocate PTY's when they close.
This required a fair bit of plumbing. The CharacterDevice::close() virtual
will now be closed by ~FileDescriptor(), allowing device implementations to
do custom cleanup at that point.

One big problem remains: if the master PTY is closed before the slave PTY,
we go into crashy land.
2019-01-30 18:47:18 +01:00
Andreas Kling
c30e2c8d44 Implement basic chmod() syscall and /bin/chmod helper.
Only raw octal modes are supported right now.
This patch also changes mode_t from 32-bit to 16-bit to match the on-disk
type used by Ext2FS.

I also ran into EPERM being errno=0 which was confusing, so I inserted an
ESUCCESS in its place.
2019-01-29 04:55:08 +01:00
Andreas Kling
c95228b128 Add support for removing directories.
It's really only supported in Ext2FS since SynthFS doesn't really want you
mucking around with its files. This is pretty neat though :^)

I ran into some trouble with HashMap while working on this but opted to work
around it and leave that for a separate investigation.
2019-01-28 04:16:01 +01:00
Andreas Kling
0e73aa36c8 Kernel: Unbreak symbolication yet another time. 2019-01-27 10:17:56 +01:00
Andreas Kling
dfdca9d2a7 Kernel: Implement lazy FPU state restore. 2019-01-25 07:52:44 +01:00
Andreas Kling
267a903dd0 Terminal: Redraw entire line if any of its characters are dirty.
This means we only have to do one fill_rect() per line and the whole process
ends up being ~10% faster than before.

Also added a read_tsc() syscall to give userspace access to the TSC.
2019-01-25 02:09:29 +01:00
Andreas Kling
11b73c38d8 Kernel: Fix incorrect EFAULTs when syscall would write into COW pages. 2019-01-25 01:39:15 +01:00
Andreas Kling
2159d6bf76 Kernel: Fix bug in process termination on missing signal handler. 2019-01-24 21:22:13 +01:00
Andreas Kling
aa24547e12 Kernel: Finally stop exposing Region members to the public. 2019-01-24 18:09:46 +01:00
Andreas Kling
af06d5edc1 Kernel: Implement a limited version of POSIX poll(). 2019-01-23 08:03:31 +01:00
Andreas Kling
0ebaa35aa1 Kernel: Let the process argv arrays be null-terminated.
Seems like this is expected. I don't know why I thought it wasn't.
2019-01-23 07:29:10 +01:00
Andreas Kling
2bedabbd6c Stub out poll() syscall and LibC wrapper. 2019-01-23 07:28:25 +01:00
Andreas Kling
8bb18fdc56 Kernel: Get rid of Unix namespace.
This is no longer needed as the Kernel can stand on its own legs now
and there won't be any conflict with host system data types.
2019-01-23 06:57:00 +01:00
Andreas Kling
754037874c Move VFS sources into Kernel/. 2019-01-23 05:14:00 +01:00
Andreas Kling
bda0c935c2 Add unlink() syscall and /bin/rm.
This patch adds most of the plumbing for working file deletion in Ext2FS.
Directory entries are removed and inode link counts updated.
We don't yet update the inode or block bitmaps, I will do that separately.
2019-01-22 07:03:44 +01:00
Andreas Kling
2f2f28f212 Kernel: Refactor Region/PageDirectory ownership model.
Make PageDirectory retainable and have each Region co-own the PageDirectory
they're mapped into. When unmapped, Region has no associated PageDirectory.

This allows Region to automatically unmap itself when destroyed.
2019-01-22 05:06:22 +01:00
Andreas Kling
4d1d875ca7 Remove some unused errno.h duplicates. 2019-01-22 01:12:53 +01:00
Andreas Kling
f70136a324 Kernel: Support open() with O_CREAT.
It's now possible to create zero-length files! :^)
Also hook up the new functionality in /bin/touch.
2019-01-22 00:58:56 +01:00
Andreas Kling
d1af5c97ca Kernel: Process should drop any framebuffer regions on exec(). 2019-01-21 03:22:03 +01:00
Andreas Kling
61e50780aa Kernel: Forked processes should inherit arguments and environment. 2019-01-21 02:59:58 +01:00
Andreas Kling
e115ae5641 Kernel: Clone Process::m_gids on fork() and hook up any framebuffer region. 2019-01-21 01:49:30 +01:00
Andreas Kling
b75ee4aacb Coding style fixes in AK. 2019-01-19 22:53:05 +01:00
Andreas Kling
dff5051905 Support polling with select() by using a zero timeout.
Use this in WindowServer to avoid getting blocked in select() when
there are pending injected events.
2019-01-18 05:28:07 +01:00
Andreas Kling
a2ec09bc20 Allow the scheduler to unblock the current process.
It's a bit confusing that the "current" process is not actually running
while we're inside the scheduler. Perhaps the scheduler should redirect
"current" to its own dummy Process. I'm not sure.

Regardless, this patch improves responsiveness by allowing the scheduler
to unblock a process right after it calls select() in case it already has
a pending wakeup request.
2019-01-16 17:47:18 +01:00
Andreas Kling
4fef895eda Rework WindowServer to use select() in its main event loop.
The system can finally idle without burning CPU. :^)

There are some issues with scheduling making the mouse cursor sloppy
and unresponsive that need to be dealt with.
2019-01-16 17:20:58 +01:00
Andreas Kling
f7ca6d254d Tear out or duplicate what's unique for WindowServer from Widgets.
This turned into a huge refactoring that somehow also includes
making locks recursive/reentrant.
2019-01-16 16:03:50 +01:00
Andreas Kling
9dd29f9aa9 Add a PTY multiplexer (/dev/ptmx) device.
When you open /dev/ptmx, you get a file descriptor pointing to one of the
available MasterPTY's. If none are available, you get an EBUSY.

This makes it possible to open multiple (up to 4) Terminals. :^)

To support this, I also added a CharacterDevice::open() that gets control
when VFS is opening a CharacterDevice. This is useful when we want to return
a custom FileDescriptor like we do here.
2019-01-16 13:39:32 +01:00
Andreas Kling
b46ae2bf09 Get rid of Vnode concept.
We already have an abstraction between Process and Inode/CharacterDevice/FIFO
and it's called FileDescriptor. :^)
2019-01-16 12:57:07 +01:00
Andreas Kling
8ad2dfb6e1 Rename FileDescriptor::has_data_available_for_reading() -> can_read(). 2019-01-16 00:47:00 +01:00
Andreas Kling
bd3e77cc16 Pass the process to CharacterDevice::read/write.
This is much nicer than grabbing directly at 'current' inside a read().
2019-01-16 00:20:38 +01:00
Andreas Kling
10387beda7 Implement basic support for POSIX-style select().
Now we can block on both the PTY *and* the GUI event stream in Terminal.
2019-01-16 00:09:58 +01:00
Andreas Kling
e452303c66 Allow character devices to block write attempts until there is more space. 2019-01-15 09:17:22 +01:00
Andreas Kling
78696236d3 Add very basic KeyDown events to the GUI event stream.
The Terminal program now hosts an interactive shell. :^)
2019-01-15 06:51:00 +01:00
Andreas Kling
2f74c2f430 Add basic PTY support.
For now, there are four hard-coded PTYs: /dev/pt{m,s}[0123]
Use this in the Terminal to open a pty pair and spawn a shell.
2019-01-15 06:30:19 +01:00
Andreas Kling
b0e3f73375 Start refactoring the windowing system to use an event loop.
Userspace programs can now open /dev/gui_events and read a stream of GUI_Event
structs one at a time.

I was stuck on a stupid problem where we'd reenter Scheduler::yield() due to
having one of the has_data_available_for_reading() implementations using locks.
2019-01-14 14:42:49 +01:00
Andreas Kling
8f8c8d1ca3 Start working on a GUI kernel API. 2019-01-13 02:02:34 +01:00
Andreas Kling
becc2c7fa5 Make GraphicsBitmaps be Region-backed when running in the kernel.
This is a lot better than having them in kmalloc memory. I'm gonna need
a way to keep track of which process owns which bitmap eventually,
maybe through some sort of resource keying system. We'll see.
2019-01-13 00:29:32 +01:00
Andreas Kling
659c54e32b Switch into 1024x768x32bpp VESA LFB mode at boot.
This is going to be pretty cool once I can hook up the Widgets/ code to it.
2019-01-09 02:29:11 +01:00
Andreas Kling
4b6a8f8a08 Unbreak ksym loading and make reading /proc/PID/stack not crash. 2019-01-01 02:20:01 +01:00
Andreas Kling
683185e4aa MM: Allocate page tables from a separate set of physical pages.
The old approach only worked because of an overpermissive accident.
There's now a concept of supervisor physical pages that can be allocated.
They all sit in the low 4 MB of physical memory and are identity mapped,
shared between all processes, and only ring 0 can access them.
2019-01-01 02:09:43 +01:00
Andreas Kling
193ead94f8 Let PageDirectory have a PhysicalPage for the PDB instead of being the PDB.
This is more efficient than using the wasteful kmalloc_aligned() approach
to allocation. It also allows much tighter encapsulation of the class.
2018-12-31 14:58:03 +01:00
Andreas Kling
46ce47a984 Use the entry point address from the ELF header instead of looking up _start.
I love these kind of dumb gotcha moments. Turns out you can find the entry
address right there in the header. :^)
2018-12-29 03:28:55 +01:00
Andreas Kling
3f3535213b Fix some issues uncovered by the spawn stress test. 2018-12-26 22:02:24 +01:00
Andreas Kling
55c722096d Process::create_user_process() shouldn't leak a process if exec() fails. 2018-12-26 21:04:27 +01:00
Andreas Kling
033a42b580 The syncd loop can just be a lambda. 2018-12-24 23:10:48 +01:00
Andreas Kling
503e32552c Move kernel symbolication code out of init.cpp and into its own KSym files.
Also use a simple array of { dword, const char* } for the KSyms and put the
whole shebang in kmalloc_eternal() memory. This was a fugly source of
kmalloc perma-frag.
2018-12-24 23:01:09 +01:00
Andreas Kling
6a9fa3e41a Let sys$sigaction() fail if called with SIGKILL or SIGSTOP. 2018-12-24 22:22:35 +01:00
Andreas Kling
ec1c487dcd Yet another pass of style fixes. 2018-12-21 02:10:45 +01:00
Andreas Kling
ed7ae6c02c Add sync() syscall and a /bin/sync.
It walks all the live Inode objects and flushes pending metadata changes
wherever needed.

This could be optimized by keeping a separate list of dirty Inodes,
but let's not get ahead of ourselves.
2018-12-20 00:39:29 +01:00
Andreas Kling
d0f06e5f3f Automatically call Inode::flush_metadata() before an Inode is destroyed.
Use a little template magic to have Retainable::release() call out to
T::will_be_destroyed() if such a function exists before actually calling
the destructor. This gives us full access to virtual functions in the
pre-destruction code.
2018-12-19 22:28:09 +01:00
Andreas Kling
1f44cd9dd9 Reworked Inode to have a dirty bit and subclass-implemented flush_metadata().
This way we can defer disk writes as long as we like. There's no automatic
flushing happening just yet.
2018-12-19 21:56:45 +01:00
Andreas Kling
038d8641f9 Implement utime() along with a naive /bin/touch.
This synchronous approach to inodes is silly, obviously. I need to rework
it so that the in-memory CoreInode object is the canonical inode, and then
we just need a sync() that flushes pending changes to disk.
2018-12-19 21:14:55 +01:00
Andreas Kling
ca6847b5bb Import a simple text editor I started working on. 2018-12-04 00:27:16 +01:00
Andreas Kling
aff89d2fd7 Yet more coding style fixes. 2018-12-03 01:38:22 +01:00
Andreas Kling
e7cc08226f Implement basic support for times().
The kernel now bills processes for time spent in kernelspace and userspace
separately. The accounting is forwarded to the parent process in reap().

This makes the "time" builtin in bash work.
2018-12-03 01:14:19 +01:00
Andreas Kling
4bc87dc7b9 Share the "blocked-on file descriptor" number between read() and write().
A process can't be reading and writing at the same time, so it's fine for
them to share the variable for the blocked FD.
2018-12-03 00:42:48 +01:00
Andreas Kling
f6e27c2abe More coding style changes. 2018-12-03 00:39:25 +01:00
Andreas Kling
44036f32bc Move ELFLoader code into Kernel/. 2018-12-02 20:27:08 +01:00
Andreas Kling
f5a83c4d8a Fix bug where a signal-interrupted waitpid() wouldn't return EINTR. 2018-11-28 23:30:49 +01:00
Andreas Kling
464a16afa2 Implement signal() via sigaction() and get rid of sys$signal(). 2018-11-28 22:27:32 +01:00
Andreas Kling
d90104f9e0 Let reap() communicate the dead process's exit status to the caller.
This way the scheduler doesn't need to plumb the exit status into the waiter.
We still plumb the waitee pid though, I don't love it but it can be fixed.
2018-11-28 22:01:24 +01:00
Andreas Kling
938d1b8bfb Drop any old signal stacks on exec(). 2018-11-28 20:59:10 +01:00
Andreas Kling
629c5be10b Add basic zero faults.
mmap() will now map uncommitted pages that get allocated and zeroed upon the
first access. I also made /proc/PID/vm show number of "committed" bytes in
each region. This is so cool! :^)
2018-11-19 02:17:20 +01:00
Andreas Kling
de4604ac95 Finally hook up the mkdir code to a syscall.
Added a /bin/mkdir that makes directories. How very neat :^)
There are various limitations because of missing functionality.
2018-11-18 15:02:16 +01:00
Andreas Kling
95e0f6ad82 Fix race condition in exec().
...also hook up sys$fstat in the syscall dispatcher.
2018-11-17 00:52:29 +01:00
Andreas Kling
bb9766ee17 Tweak default hostname. 2018-11-17 00:23:39 +01:00
Andreas Kling
9d05f6b7a7 Make bash-2.05b build with minimal changes.
This is really neat. :^)
2018-11-17 00:14:07 +01:00
Andreas Kling
2cf477a151 Add fcntl() F_DUPFD which is slightly different from dup2(). 2018-11-16 22:14:40 +01:00
Andreas Kling
6cedb88153 Don't unblock a blocked process when it ignores a signal. 2018-11-16 21:14:25 +01:00
Andreas Kling
a788e85c09 Refactor TTY signal generation a bit.
We now respect the VINTR and VQUIT control characters in the termios.
2018-11-16 20:18:58 +01:00
Andreas Kling
52d1822c3c Add templated helpers for read/write validation, and one for strings, too. 2018-11-16 16:26:20 +01:00
Andreas Kling
8a286b9244 Improve syscall address validation a bit. 2018-11-16 16:10:59 +01:00
Andreas Kling
084287ca45 Reimplement tcsetattr/tcgetattr as ioctls. 2018-11-16 15:41:48 +01:00
Andreas Kling
c99f8af66d Add ioctl() and reimplement tcsetpgrp/tcsetpgrp as ioctls. 2018-11-16 13:13:50 +01:00
Andreas Kling
2529925fe9 Some more renaming:
FileSystem -> FS
SyntheticFileSystem -> SynthFS
ProcFileSystem -> ProcFS
Ext2FileSystem -> Ext2FS
Ext2Inode -> Ext2FSInode
2018-11-15 17:13:10 +01:00
Andreas Kling
457a5df7d5 Rename:
VirtualFileSystem -> VFS
VirtualFileSystem::Node -> Vnode
2018-11-15 14:43:10 +01:00
Andreas Kling
c735c56e4c More work on CoreInode. 2018-11-13 23:44:54 +01:00
Andreas Kling
97c799576a Add close-on-exec flag for file descriptors.
I was surprised to find that dup()'ed fds don't share the close-on-exec flag.
That means it has to be stored separately from the FileDescriptor object.
2018-11-13 01:36:31 +01:00
Andreas Kling
1cf20a2fe2 Some minor termios debugging output. 2018-11-12 12:27:28 +01:00
Andreas Kling
f1404aa948 Add primitive FIFO and hook it up to sys$pipe().
It's now possible to do this in bash:

cat kernel.map | fgrep List

This is very cool! :^)
2018-11-12 01:28:46 +01:00
Andreas Kling
d5d45d1088 Rage hacking to get bash to run. It finally runs. So cool! :^) 2018-11-11 15:38:07 +01:00
Andreas Kling
f394e3486a Stub out a bunch more functions to get closer to that sweet bash build. 2018-11-11 10:38:33 +01:00
Andreas Kling
3b2f172d48 A bunch of compat work (mostly stubs but some real implementations, too.)
Another pass at getting bash-1.14.7 to build. Not that many symbols remain.
2018-11-11 00:20:53 +01:00
Andreas Kling
6a0a2c9ab4 Some improvements to signals.
- Add sigprocmask() and sigpending().
- Forked children inherit signal dispositions and masks.
- Exec clears signal dispositions and masks.
2018-11-10 23:30:41 +01:00
Andreas Kling
2ac5e14c08 Merge VGA into VirtualConsole. 2018-11-10 16:26:18 +01:00
Andreas Kling
cba05ce75e Before sys$write returns, check for pending unmasked signals.
If there is one, put the process into a new BlockedSignal state which makes
the next scheduler iteration dispatch the signal.
2018-11-10 02:43:33 +01:00
Andreas Kling
3e3de67f02 Use the VGA start address for fast VirtualConsole scrolling.
Instead of memcpy'ing the entire screen every time we press enter at the
bottom, use the VGA start address register to make a "view" onto the
underlying memory that moves downward as we scroll.

Eventually we run out of memory and have to reset to the start of the
buffer. That's when we memcpy everything. It would be cool if there was
some way to get the hardware to act like a ring buffer with automatic
wrapping here but I don't know how to do that.
2018-11-09 21:18:03 +01:00
Andreas Kling
de38e63d3e Run QEMU with the possibility to attach gdb. 2018-11-09 18:35:32 +01:00
Andreas Kling
985074c790 Okay, now *actually* plug the leaks in exec().
I didn't even put the { } properly around everything that would leak.
Let's make sure this works correctly by splitting out the work into a
helper called do_exec().
2018-11-09 18:00:50 +01:00
Andreas Kling
8249c086c3 Get rid of redundant sys$spawn now that we have fork+exec. 2018-11-09 10:22:27 +01:00
Andreas Kling
47b7eeda44 Fix all current build warnings in the kernel. 2018-11-09 10:03:21 +01:00
Andreas Kling
e71cb1c56b Fix some paging related bugs exposed by the spawn stress test.
- Process::exec() needs to restore the original paging scope when called
  on a non-current process.
- Add missing InterruptDisabler guards around g_processes access.
- Only flush the TLB when modifying the active page tables.
2018-11-09 01:25:31 +01:00
Andreas Kling
7b96218389 Fix VMO leak in Process::exec().
Gotta make sure things get cleaned up before we yield-teleport in exec().
Also VMOs and regions are now viewable through /proc/mm and /proc/regions.
2018-11-08 22:25:29 +01:00
Andreas Kling
cd1e7419f0 Teach Process::exec() about the magic of file-backed VMO's.
This is really sweet! :^) The four instances of /bin/sh spawned at
startup now share their read-only text pages.

There are problems and limitations here, and plenty of room for
improvement. But it kinda works.
2018-11-08 21:20:09 +01:00
Andreas Kling
992769c9d4 Make Process::for_each...() functions inline and allocation-free.
AK::Function is very handy, but costs us an 8-byte allocation.
Let's not have kmalloc() calls in the scheduler hot path.
2018-11-08 16:09:05 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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