Commit Graph

95 Commits

Author SHA1 Message Date
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