Commit Graph

541 Commits

Author SHA1 Message Date
Robin Burchell
750dbe986d Kernel: Avoid allocations for Select vectors by using inline capacity
Good tip by Andreas :)
2019-07-19 11:03:22 +02:00
Robin Burchell
52743f9eec Kernel: Rename ThreadBlocker classes to avoid stutter
Thread::ThreadBlockerFoo is a lot less nice to read than Thread::FooBlocker
2019-07-19 11:03:22 +02:00
Robin Burchell
782e4ee6e1 Kernel: Port wait to ThreadBlocker 2019-07-19 11:03:22 +02:00
Robin Burchell
4f9ae9b970 Kernel: Port select to ThreadBlocker 2019-07-19 11:03:22 +02:00
Robin Burchell
32fcfb79e9 Kernel: Port sleep to ThreadBlocker 2019-07-19 11:03:22 +02:00
Robin Burchell
0c8813e6d9 Kernel: Introduce ThreadBlocker as a way to make unblocking neater :)
And port all the descriptor-based blocks over to it as a proof of concept.
2019-07-19 11:03:22 +02:00
Jesse
a27c9e3e01 Kernel+Userland: Addd reboot syscall (#334)
Rolling with the theme of adding a dialog to shutdown the machine, it is
probably nice to have a way to reboot the machine without performing a full
system powerdown.

A reboot program has been added to `/bin/` as well as a corresponding
`syscall` (SC_reboot). This syscall works by attempting to pulse the 8042
keyboard controller. Note that this is NOT supported on  new machines, and
should only be a fallback until we have proper ACPI support.

The implementation causes a triple fault in QEMU, which then restarts the
system. The filesystems are locked and synchronized before this occurs,
so there shouldn't be any corruption etctera.
2019-07-19 09:58:12 +02:00
Robin Burchell
f2fdac789c Kernel: Add a new block state for accept() on a blocking socket
Rather than asserting, which really ruins everyone's day.
2019-07-18 10:56:49 +02:00
Robin Burchell
b907608e46 SharedBuffer: Split the creation and share steps
This allows us to seal a buffer *before* anyone else has access to it
(well, ok, the creating process still does, but you can't win them all).

It also means that a SharedBuffer can be shared with multiple clients:
all you need is to have access to it to share it on again.
2019-07-18 10:06:20 +02:00
Robin Burchell
a648331e26 Kernel: Fix a nasty lock bug with exec()
Exec doesn't leave through the syscall handler, so it didn't unlock the
big_lock. This means that reentering can lock it again, and then another
thread could endlessly yield waiting to acquire the lock (futilely).

This fixes AudioServer using 100% CPU.
2019-07-17 14:23:15 +02:00
Robin Burchell
6aa77d1999 SharedBuffer: Fix deadlock on destroy
We were locking the list of references, and then destroying the
reference, which made things go a little crazy.

It's more straightforward to just remove the per-reference lock: the
syscalls all have to lock the full list anyway, so let's just do that
and avoid the hassle.

While I'm at it, also move the SharedBuffer code out to its own file as it's
getting a little long and unwieldly, and Process.cpp is already huge.
2019-07-16 15:27:46 +02:00
Robin Burchell
d53e54f8bf SharedBuffer: fix nullptr dereference on seal
If the buffer hadn't been used by all participants yet, there wouldn't
be a region, which leads to bad things.
2019-07-16 15:27:46 +02:00
Robin Burchell
df3e295ba6 Kernel: SharedBuffer sharing cleanup
Rather than limiting it to two shared processes, store a Vector of
references, so we can add more if we want. Makes the code a little
more generic.

No actual change to the syscall interface yet, so nothing takes
advantage of this yet.
2019-07-16 10:03:14 +02:00
Andreas Kling
3073ea7d84 Kernel: Add support for the WSTOPPED flag to the waitpid() syscall.
This makes waitpid() return when a child process is stopped via a signal.
Use this in Shell to catch stopped children and return control to the
command line. :^)

Fixes #298.
2019-07-14 11:35:49 +02:00
Andreas Kling
ad7ec2bbc7 Kernel: Make the create_thread() syscall return the new thread ID. 2019-07-14 10:17:58 +02:00
Andreas Kling
5254a320d8 Kernel: Remove use of copy_ref() in favor of regular RefPtr copies.
This is obviously more readable. If we ever run into a situation where
ref count churn is actually causing trouble in the future, we can deal with
it then. For now, let's keep it simple. :^)
2019-07-11 15:40:04 +02:00
Andreas Kling
23a6c2086b Kernel: Move SharedMemory.{cpp,h} into FileSystem/ 2019-07-09 15:04:45 +02:00
Andreas Kling
6c87d3afa9 Kernel: Move i8253.cpp => Arch/i386/PIT.cpp 2019-07-09 15:04:45 +02:00
Andreas Kling
c110cf193d Kernel: Have the open() syscall take an explicit path length parameter.
Instead of computing the path length inside the syscall handler, let the
caller do that work. This allows us to implement to new variants of open()
and creat(), called open_with_path_length() and creat_with_path_length().
These are suitable for use with e.g StringView.
2019-07-08 20:01:49 +02:00
Andreas Kling
27f699ef0c AK: Rename the common integer typedefs to make it obvious what they are.
These types can be picked up by including <AK/Types.h>:

* u8, u16, u32, u64 (unsigned)
* i8, i16, i32, i64 (signed)
2019-07-03 21:20:13 +02:00
Andreas Kling
601b0a8c68 Kernel: Use NonnullRefPtrVector in parts of the kernel. 2019-06-27 13:35:02 +02:00
Andreas Kling
46a06c23e3 Kernel: Fix all compiler warnings. 2019-06-22 16:22:34 +02:00
Andreas Kling
c26e3ce86b Change "retain" to "ref" in various comments. 2019-06-21 18:40:24 +02:00
Andreas Kling
90b1354688 AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr. 2019-06-21 18:37:47 +02:00
Andreas Kling
77b9fa89dd AK: Rename Retainable => RefCounted.
(And various related renames that go along with it.)
2019-06-21 15:30:03 +02:00
Andreas Kling
15bea7153a Kernel: Symbolicate the crash address too, not just the call stack.
Also print it in shiny red to make it extra easy to spot. :^)
Fixes #244.
2019-06-19 18:51:17 +02:00
Andreas Kling
c1bbd40b9e Kernel: Rename "descriptor" to "description" where appropriate.
Now that FileDescription is called that, variables of that type should not
be called "descriptor". This is kinda wordy but we'll get used to it.
2019-06-13 22:03:04 +02:00
Andreas Kling
de65c960e9 Kernel: Tweak some String&& => const String&.
String&& is just not very practical. Also return const String& when the
returned string is a member variable. The call site is free to make a copy
if he wants, but otherwise we can avoid the retain count churn.
2019-06-07 20:58:12 +02:00
Andreas Kling
736092a087 Kernel: Move i386.{cpp,h} => Arch/i386/CPU.{cpp,h}
There's a ton of work that would need to be done before we could spin up on
another architecture, but let's at least try to separate things out a bit.
2019-06-07 20:02:01 +02:00
Andreas Kling
891d4c4834 Kernel: Qualify a bunch of #include statements. 2019-06-07 19:29:34 +02:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Andreas Kling
e42c3b4fd7 Kernel: Rename LinearAddress => VirtualAddress. 2019-06-07 12:56:50 +02:00
Andreas Kling
bc951ca565 Kernel: Run clang-format on everything. 2019-06-07 11:43:58 +02:00
Andreas Kling
d194ce828d Kernel: Implement the alarm() syscall. 2019-06-07 11:30:07 +02:00
Andreas Kling
08cd75ac4b Kernel: Rename FileDescriptor to FileDescription.
After reading a bunch of POSIX specs, I've learned that a file descriptor
is the number that refers to a file description, not the description itself.
So this patch renames FileDescriptor to FileDescription, and Process now has
FileDescription* file_description(int fd).
2019-06-07 09:36:51 +02:00
Andreas Kling
29a9430246 AK: Make timeval_add() and timeval_sub() take references. 2019-06-06 18:02:28 +02:00
Andreas Kling
bf905225e7 Kernel: Tidy up sys$select() to make it more readable. 2019-06-06 17:49:01 +02:00
Robin Burchell
b55b6cd7fc AK: Add implicit String -> StringView conversion
And tidy up existing view() users.
2019-06-02 12:55:51 +02:00
Andreas Kling
4320c5fd58 Kernel: Make better use of the multiboot info.
Define the multiboot info struct properly so we don't have to grab at byte
offsets in the memory access checker code. Also print kernel command line
in init().
2019-06-02 09:53:42 +02:00
Andreas Kling
93d3d1ede1 Kernel: Add fchown() syscall. 2019-06-01 20:31:36 +02:00
Andreas Kling
00f291b090 Kernel: Set the absolute path as name for executable regions. 2019-06-01 17:50:43 +02:00
Andreas Kling
3fbddcecd2 Kernel: Discard a process's ELFLoader on finalization.
We don't need after that point, and throwing it out might free up some
cached data used for backtraces.
2019-05-31 08:03:58 +02:00
Andreas Kling
d58eb3bf21 Kernel: Process finalization should release cwd and executable custodies.
Since Process destruction happens with interrupts disabled, it's not safe to
still hold custodies at that point. Drop them in finalization.
2019-05-31 07:19:54 +02:00
Andreas Kling
e33dadbdd6 Kernel: Do a bit more of do_exec() before disabling interrupts.
We definitely need to replace m_executable before clearing interrupts, since
otherwise we might call ~Custody() which would make it assert in locking.
Also avoid calling FileDescriptor::metadata() repeatedly and just cache the
result from the first call.

I also added a comment at the point where we've decided to commit to the new
executable and follow through with the swap.
2019-05-31 07:19:50 +02:00
Andreas Kling
0f3b5e1f02 Kernel: The stat() syscall should follow symlinks. 2019-05-30 23:21:01 +02:00
Andreas Kling
55821c91f8 Kernel: Rename Process::cwd_custody() to Process::current_directory().
...and executable_custody() to just executable().
2019-05-30 22:30:25 +02:00
Andreas Kling
393851418b FileSystem: Port most of the code over to using custodies.
The current working directory is now stored as a custody. Likewise for a
process executable file. This unbreaks /proc/PID/fd which has not been
working since we made the filesystem bigger.

This still needs a bunch of work, for instance when renaming or removing
a file somewhere, we have to update the relevant custody links.
2019-05-30 18:58:59 +02:00
Andreas Kling
baaede1bf9 Kernel: Make the Process allocate_region* API's understand "int prot".
Instead of having to inspect 'prot' at every call site, make the Process
API's take care of that so we can just pass it through.
2019-05-30 16:14:37 +02:00
Andreas Kling
8fe72d7b3c Kernel: Make fcntl(F_SETFL) actually update the append/blocking flags. 2019-05-30 15:37:51 +02:00
Andreas Kling
08926e59b3 Kernel: Add InodeFile, a File subclass for regular files.
Finally everything that can be held by a FileDescriptor actually inherits
from the File class.
2019-05-30 13:39:17 +02:00
Robin Burchell
9cd0f6ffac Kernel/LibC: Implement sched_* functionality to set/get process priority
Right now, we allow anything inside a user to raise or lower any other process's
priority. This feels simple enough to me. Linux disallows raising, but
that's annoying in practice.
2019-05-30 02:57:15 +02:00
Andreas Kling
0cac84d6bd Kernel: Sending a signal to yourself should block until dispatch.
By moving the sending (and receiving) thread into the BlockedSignal state,
we ensure that the thread doesn't continue executing until the signal
has been dispatched.
2019-05-26 02:35:25 +02:00
Andreas Kling
6ffcee9176 Kernel: Send more specific signals when crashing due to CPU exceptions.
- For division by zero, send SIGFPE.
- For illegal instruction, send SIGILL.
- For the rest, default to SIGSEGV.
2019-05-26 02:35:25 +02:00
Robin Burchell
c6e79bd53a Kernel: Support O_APPEND
As per the manpage, this acts as a transparent lseek() before write.
2019-05-26 01:32:05 +02:00
Robin Burchell
6917c42140 Kernel/AK: Move ELF loader to AK
This is in preparation for eventually using it in userspace.
LinearAddress.h has not been moved for the time being (as it seems to be
only used by a very small part of the code).
2019-05-23 16:57:34 +02:00
Andreas Kling
14a202f011 Kernel: getpeername() should fail with ENOTCONN for non-connected sockets. 2019-05-23 15:39:52 +02:00
Andreas Kling
7afc0fb9c8 Kernel: Forked children should inherit their RangeAllocator by copy.
Otherwise we'll start handing out addresses that are very likely already in
use by existing ranges.
2019-05-22 13:24:28 +02:00
Andreas Kling
ae470ec955 Kernel: Add getpeername() syscall, and fix getsockname() behavior.
We were copying the raw IPv4 addresses into the wrong part of sockaddr_in,
and we didn't set sa_family or sa_port.
2019-05-20 20:33:03 +02:00
Andreas Kling
bcc6ddfb6b Kernel: Let PageDirectory own the associated RangeAllocator.
Since we transition to a new PageDirectory on exec(), we need a matching
RangeAllocator to go with the new directory. Instead of juggling this in
Process and MemoryManager, simply attach the RangeAllocator to the
PageDirectory instead.

Fixes #61.
2019-05-20 04:46:29 +02:00
Andreas Kling
b3a1671f1a Kernel: Add support for recv() with MSG_DONTWAIT.
Passing this flag to recv() temporarily puts the file descriptor into
non-blocking mode.

Also implement LocalSocket::recv() as a simple forwarding to read().
2019-05-20 03:47:02 +02:00
Andreas Kling
212a263f0a Kernel+LibC: Implement getsockname() syscall. 2019-05-19 19:55:27 +02:00
Andreas Kling
189b342e6f LibC: Add mmap_with_name() that names the allocation immediately.
This allows us to skip the separate call to set_mmap_name() in code that
we control, e.g malloc() and GraphicsBitmap.
2019-05-19 15:54:56 +02:00
Robin Burchell
d8b74c8c86 Kernel: Check can_write for blocking write
This way the socket write buffer sizes are respected, and things that
exceed them get sent EAGAIN.
2019-05-19 14:13:49 +02:00
Robin Burchell
635eb20289 Kernel: Add the ability to debug poll/select independently of read/write 2019-05-19 14:13:49 +02:00
Robin Burchell
99dd60611f Kernel: Fix select with a 0 timeout
select essentially has 3 modes (which is presumably why we're finding it
so hard to get this right in a reliable way :)).

1. NULL timeout -- no timeout on blocking
2. non-NULL timeout that is not zero'd -- timeout on blocking
3. non-NULL but zero timeout -- no blocking at all (immediate poll)

For cases 1 and 2, we want to block the thread. We have a timeout set
only for case 2, though.

Case 3 should not block the thread, and does not have a timeout set.
2019-05-18 19:01:08 +02:00
Andreas Kling
237628a7a6 Kernel: Tidy up FileDescriptor members a bit. 2019-05-18 04:14:22 +02:00
Robin Burchell
123283d840 Kernel: Fix poll() with timeout 2019-05-18 04:03:28 +02:00
Andreas Kling
cdaf8cd656 Kernel: select() was transferring the readfds into the exceptfds vector.
Just a mistake I spotted while reading the code. We don't actually detect
exceptional descriptor events yet.
2019-05-18 03:09:37 +02:00
Andreas Kling
14c896ec58 Kernel: Pass ELF program header locations from multiboot to kernel.
Patch contributed by "pd"
2019-05-18 03:08:29 +02:00
Robin Burchell
ba92c07a75 Kernel: Make sure to clear FD sets when preparing for a select
NULL sets can happen, and we don't want to incorrectly return FDs which
aren't in the set too.
2019-05-18 02:57:38 +02:00
Robin Burchell
df74a9222f Kernel: Fix timeout support in select
The scheduler expects m_select_timeout to act as a deadline. That is, it
should contain the time that a task should wake at -- but we were
directly copying the time from userspace, which meant that it always
returned virtually immediately.

At the same time, fix CEventLoop to not rely on the broken select behavior
by subtracting the current time from the time of the nearest timer.
2019-05-18 02:57:38 +02:00
Andreas Kling
2d98f4e28f Kernel: Make the times() syscall return something other than 0.
Based on the description I read, this syscall doesn't seem completely
reasonable, but let's at least return a number that is likely to change
between invocations in case somebody depends on that happening.
2019-05-17 20:19:29 +02:00
Robin Burchell
0d77aa841a Kernel/Process: Use auto to avoid incompatible types, causing a signedness warning in the ASSERT 2019-05-17 16:06:26 +02:00
Andreas Kling
cde47089d2 Kernel: Remove some unnecessary massaging of region base/size pairs.
These will be appropriately rounded by the allocate_range(), so call sites
can stop worrying about it.
2019-05-17 04:47:06 +02:00
Andreas Kling
6957825444 Kernel: Factor out range allocation from Process::allocate_region*().
These functions were doing exactly the same thing for range allocation, so
share that code in an allocate_range() helper.

Region allocation will now also fail if range allocation fails, which means
that mmap() can actually fail without falling apart. Exciting times!
2019-05-17 04:39:22 +02:00
Andreas Kling
87b54a82c7 Kernel: Let Region keep a Range internally. 2019-05-17 04:32:08 +02:00
Andreas Kling
b1bb737704 Kernel: Remove Process::m_next_address.
This isn't needed now that we have RangeAllocator. :^)
2019-05-17 03:47:00 +02:00
Andreas Kling
c414e65498 Kernel: Implement a simple virtual address range allocator.
This replaces the previous virtual address allocator which was basically
just "m_next_address += size;"

With this in place, virtual addresses can get reused, which cuts down on
the number of page tables created. When we implement ASLR some day, we'll
probably have to do page table deallocation, but for now page tables are
only deallocated once the process dies.
2019-05-17 03:40:15 +02:00
Andreas Kling
4e88872c8e Kernel: Always dump_backtrace() on process crash. 2019-05-16 19:49:48 +02:00
Andreas Kling
174639b7f0 Kernel: Symbolicate userspace backtraces using ELFLoader.
Stash away the ELFLoader used to load an executable in Process so we can use
it for symbolicating userspace addresses later on. This will make debugging
userspace programs a lot nicer. :^)
2019-05-16 17:18:25 +02:00
Andreas Kling
2f4e7edee5 Kernel: Simplify dump_backtrace() API for clients.
It makes no sense that clients had to worry about whether or not KSyms
were loaded.
2019-05-16 13:41:16 +02:00
Andreas Kling
486c675850 Kernel: Allocate kernel signal stacks using the region allocator as well. 2019-05-14 12:06:09 +02:00
Andreas Kling
c8a216b107 Kernel: Allocate kernel stacks for threads using the region allocator.
This patch moves away from using kmalloc memory for thread kernel stacks.
This reduces pressure on kmalloc (16 KB per thread adds up fast) and
prevents kernel stack overflow from scribbling all over random unrelated
kernel memory.
2019-05-14 11:51:00 +02:00
Andreas Kling
99aead4857 Kernel: Add a writev() syscall for writing multiple buffers in one go.
We then use this immediately in the WindowServer/LibGUI communication in
order to send both message + optional "extra data" with a single syscall.
2019-05-10 03:19:25 +02:00
Andreas Kling
72cbcd8e98 Kernel: Dump backtrace on exit() syscall.
This makes assertion failures a lot more pleasant to investigate.
2019-05-06 21:48:48 +02:00
Andreas Kling
780d2a08c4 IPv4: Save the source address/port together with incoming packet payloads.
We need the address/port to fill in the out-params in recvfrom().
It should now be more or less possible to create a UDP server. :^)
2019-05-04 03:27:50 +02:00
Andreas Kling
8b249bd09b Kernel+Userland: Implement mknod() syscall and add a /bin/mknod program. 2019-05-03 22:59:58 +02:00
Andreas Kling
03da7046bd Kernel: Prepare Socket for becoming a File.
Make the Socket functions take a FileDescriptor& rather than a socket role
throughout the code. Also change threads to block on a FileDescriptor,
rather than either an fd index or a Socket.
2019-05-03 20:15:54 +02:00
Andreas Kling
c3b7ace3e0 Kernel: Assign Lock names in class member initializers. 2019-05-02 03:28:20 +02:00
Andreas Kling
14ac77131b Kernel: The exit_thread() syscall should unlock the big lock.
Since exit_thread() never returns, it can't rely on the syscall trap handler
to unlock the big lock before returning.
2019-04-29 15:56:25 +02:00
Andreas Kling
d07be1087a Kernel+LibC: Add exit_thread() syscall. 2019-04-29 15:17:20 +02:00
Andreas Kling
8cbb7f101f Kernel: Have File virtuals take a FileDescriptor& rather than a Process&.
This will allow us to implement different behaviors depending on the role
of the descriptor a File is being accessed through.
2019-04-29 13:58:40 +02:00
Andreas Kling
0a0d739e98 Kernel: Make FIFO inherit from File. 2019-04-29 04:55:54 +02:00
Andreas Kling
e886337a67 Kernel: Make ProcessTracer inherit from File. 2019-04-28 15:02:55 +02:00
Andreas Kling
679ac386eb Kernel: "Succeed" quietly for zero-length read() and write(). 2019-04-27 16:17:24 +02:00
Andreas Kling
490e89e240 LibC: Add execvpe() and make execvp()'ed children inherit environment. 2019-04-26 03:16:26 +02:00
Andreas Kling
d5578826af Kernel: Make it possible to look up FIFO's by ID.
This will be useful when implementing the /proc/PID/fd/N links where N is
a file descriptor referring to a FIFO.
2019-04-25 13:53:24 +02:00
Andreas Kling
c5c4e54a67 Kernel: Process destruction should destroy all child threads.
We were only destroying the main thread when a process died, leaving any
secondary threads around. They couldn't run, but because they were still
in the global thread list, strange things could happen since they had some
now-stale pointers to their old process.
2019-04-23 22:17:01 +02:00
Andreas Kling
5c68929aa1 Kernel: Add a systrace() syscall and implement /bin/strace using it.
Calling systrace(pid) gives you a file descriptor with a stream of the
syscalls made by a peer process. The process must be owned by the same
UID who calls systrace(). :^)
2019-04-22 18:44:45 +02:00
Andreas Kling
a9d09e9020 Kernel: Get rid of the "cool globals" thingy.
This was something I used while debugging with Computron. I haven't needed
it for months, so let's get rid of it. It's trivial to readd if needed.
2019-04-21 12:33:14 +02:00
Andreas Kling
5f63f8120c Kernel: Remove "restorer" field from SignalActionData.
I was originally implementing signals by looking at some man page about
sigaction() to see how it works. It seems like the restorer thingy is
system-specific and not required by POSIX, so let's get rid of it.
2019-04-20 19:32:14 +02:00
Andreas Kling
b2ebf6c798 Kernel: Shrink Thread by making kernel resume TSS heap-allocated. 2019-04-20 19:23:45 +02:00
Andreas Kling
ec365b82d5 Kernel: Make the colonel run at "Idle" priority (the lowest possible.)
This means it won't hog the CPU for more than a single timeslice. :^)
2019-04-20 15:58:45 +02:00
Andreas Kling
5eedb22834 Sprinkle use of AK::Vector in various places.
Some of these are less helpful than others. Avoiding a bunch of mallocs
in the event loop wakeup code is definitely nice.
2019-04-20 14:02:19 +02:00
Andreas Kling
1debc0a78c Kernel: Reduce kmallocing in all_processes() and all_pids(). 2019-04-16 00:37:35 +02:00
Andreas Kling
ae0dc22716 Kernel: Make validate_read_from_kernel() return early for nullptr checks.
Null pointers are always invalid, so don't bother going through all the
various checks for them.
2019-04-15 23:48:31 +02:00
Andreas Kling
13041f894f Kernel: Start using StringView in the VFS class.
The less kmalloc() we can do, the better. Calling kmalloc() disables all
interrupts while it runs, so it's directly affecting responsiveness.
2019-04-15 14:57:27 +02:00
Andreas Kling
3f6408919f AK: Improve smart pointer ergonomics a bit. 2019-04-14 02:36:06 +02:00
Andreas Kling
29d0412a06 Kernel: Remove system.h and make the uptime global a qword. 2019-04-14 01:29:14 +02:00
Andreas Kling
60a819c14a Kernel: Yet more work on bringing up POSIX SHM. 2019-04-09 02:37:38 +02:00
Andreas Kling
26a06f3fcd Kernel: More work towards POSIX SHM, also add ftruncate(). 2019-04-09 01:10:00 +02:00
Andreas Kling
99f3cc26c3 Kernel+LibC: Add stubs for POSIX shared memory API.
Specifically shm_open() and shm_unlink(). This patch just adds stubs.
2019-04-08 23:44:12 +02:00
Andreas Kling
65d6318c33 Kernel: Support non-blocking connect().
If connect() is called on a non-blocking socket, it will "fail" immediately
with -EINPROGRESS. After that, you select() on the socket and wait for it to
become writable.
2019-04-08 04:52:21 +02:00
Andreas Kling
37ae00a4dd Kernel+Userland: Add the rename() syscall along with a basic /bin/mv. 2019-04-07 23:35:26 +02:00
Andreas Kling
644c887594 Kernel: Move FIFO into FileSystem/ and Socket+LocalSocket into Net/. 2019-04-06 20:29:48 +02:00
Andreas Kling
ac6c7d3e19 Kernel: Use alloc_fd() more instead of walking fd list manually. 2019-04-06 14:54:32 +02:00
Andreas Kling
a58d7fd8bb Kernel: Get rid of Kernel/types.h, separate LinearAddress/PhysicalAddress. 2019-04-06 14:29:29 +02:00
Andreas Kling
b9738fa8ac Kernel: Move VM-related files into Kernel/VM/.
Also break MemoryManager.{cpp,h} into one file per class.
2019-04-03 15:13:07 +02:00
Andreas Kling
a095a90b51 Kernel: Remove ancient nprocess and nblocked globals.
These were not in sync with reality, and not used anywhere anyway.
2019-04-03 13:05:20 +02:00
Andreas Kling
ab43658c55 Kernel: Move devices into Kernel/Devices/. 2019-04-03 12:36:40 +02:00
Andreas Kling
072ea7eece Kernel: Move ELF-related files into Kernel/ELF/. 2019-04-03 12:30:04 +02:00
Andreas Kling
9fca94269e Kernel: Move TTY-related files into Kernel/TTY/. 2019-04-03 12:28:45 +02:00
Andreas Kling
f9864940eb Kernel: Move FS-related files into Kernel/FileSystem/ 2019-04-03 12:25:24 +02:00
Andreas Kling
d11b5407a3 Kernel: Get rid of the GPL elf.h and import exec_elf.h from OpenBSD. 2019-04-03 11:30:56 +02:00
Andreas Kling
649c81a714 Kernel: Move networking related files into Kernel/Net/. 2019-04-02 19:54:38 +02:00
Andreas Kling
d5a9f4596b Kernel: Add a blunt big process lock.
We can't have multiple threads in the same process running in the kernel
at the same time, so let's have a per-process lock that threads have to
acquire on syscall entry/exit (and yield while blocked.)
2019-04-01 20:04:29 +02:00
Andreas Kling
245c4bd7c8 Kernel: Add a bit of debug output in do_exec() to learn about thread counts. 2019-03-30 21:14:40 +01:00
Andreas Kling
44e1e7423f Kernel: Put a bunch of debug spam behind #ifdefs. 2019-03-27 15:07:12 +01:00
Andreas Kling
a2fe5f8517 Kernel: Don't disable interrupts during Process destruction. 2019-03-27 14:38:32 +01:00
Andreas Kling
1592612a60 Kernel: Don't disable interrupts during Thread destruction. 2019-03-27 14:30:13 +01:00
Andreas Kling
75207ddffd Kernel: Load ELF executable pages lazily when possible.
This currently only works for "normal" processes created by fork().
It does not work for create_user_process() processes spawned by the
kernel, as those are a bit special during construction.
2019-03-27 04:01:15 +01:00
Andreas Kling
500df578fe LibGUI+Kernel: Add a GLock class (userspace mutex.)
It's basically a userspace port of the kernel's Lock class.
Added gettid() and donate() syscalls to support the timeslice donation
feature we already enjoyed in the kernel.
2019-03-25 13:03:49 +01:00
Andreas Kling
ab11f42094 Kernel: Do timekeeping manually instead of asking the RTC all the time.
This introduces a tiny amount of timer drift which I will have to fix
somehow eventually, but it's a huge improvement in timing consistency
as we no longer suddenly jump from e.g 10:45:49.123 to 10:45:50.000.
2019-03-25 02:06:57 +01:00
Andreas Kling
239c0bd6a6 Kernel: Make block() and yield() automatically call Scheduler::yield().
This exposed some places we were accidentally doing a double yield().
2019-03-24 01:52:10 +01:00
Andreas Kling
5713c3a0cb Kernel: Fix broken destruction order for Process/Thread. 2019-03-24 01:20:35 +01:00
Andreas Kling
e561ab1b0b Kernel+LibC: Add a simple create_thread() syscall.
It takes two parameters, a function pointer for the entry function,
and a void* argument to be passed to that function on the new thread.
2019-03-23 22:59:08 +01:00
Andreas Kling
60d25f0f4a Kernel: Introduce threads, and refactor everything in support of it.
The scheduler now operates on threads, rather than on processes.
Each process has a main thread, and can have any number of additional
threads. The process exits when the main thread exits.

This patch doesn't actually spawn any additional threads, it merely
does all the plumbing needed to make it possible. :^)
2019-03-23 22:03:17 +01:00
Andreas Kling
367bb9e4eb Kernel: Remove ioctl for getting a socket peer's PID.
Now that everything is nice and mature, the WindowServer can just use the
client PID it receives in the Greeting message, and we can get rid of this
hacky ioctl. :^)
2019-03-20 17:14:48 +01:00
Andreas Kling
bc1da7f1fd Kernel: Snooze the NetworkTask until there are incoming packets to process.
This is accomplished using a new Alarm class and a BlockedSnoozing state.
Basically, you call Process::snooze_until(some_alarm) and then the scheduler
won't wake up the process until some_alarm.is_ringing() returns true.
2019-03-20 17:09:46 +01:00
Andreas Kling
e48cbf3c8c Kernel: connect() should fail with EISCONN for already-connected sockets.
Also make sure to reset the socket role if Socket::connect() fails.
2019-03-20 02:38:36 +01:00
Andreas Kling
4aa0ab4e08 Kernel: Fix race between accept() and connect().
We had a bug where an accepted socket would appear to be EOF/disconnected
on the accepting side until the connecting side had called attach_fd().

Fix this by adding a new SocketRole::Connecting state.
2019-03-20 02:33:51 +01:00
Andreas Kling
69ffaa366d Kernel: Handle unaligned ELF segments gracefully in the executable loader. 2019-03-14 14:51:43 +01:00
Andreas Kling
66d55f8e0c IPv4: More work on the TCP implementation.
I can now establish a connection to my little test server on the host.
2019-03-14 00:20:44 +01:00
Andreas Kling
032d9d7065 IPv4: More hacking on bringing up TCP support.
This was a bit more complicated than I expected, but it's moving forward.
2019-03-13 23:14:30 +01:00
Andreas Kling
19a51132f5 Kernel: recvfrom() should treat the address arguments as outparams. 2019-03-13 14:47:21 +01:00
Andreas Kling
562663df7c Add support for socket send/receive timeouts.
Only the receive timeout is hooked up yet. You can change the timeout by
calling setsockopt(..., SOL_SOCKET, SO_RCVTIMEO, ...).

Use this mechanism to make /bin/ping report timeouts.
2019-03-13 13:15:05 +01:00
Andreas Kling
ce7c302933 Kernel: Oops, gettimeofday()'s tv_usec should be micro, not milliseconds. 2019-03-13 03:25:18 +01:00
Andreas Kling
a7d5e9781a Kernel+LibC+Userland: Yet more networking bringup hacking.
All ICMP sockets now receive all ICMP packets. All this buffering is gonna
need some limits and such.
2019-03-12 17:27:07 +01:00
Andreas Kling
a017a77442 Kernel+LibC+Userland: Start working on an IPv4 socket backend.
The first userland networking program will be "ping" :^)
2019-03-12 15:51:42 +01:00
Andreas Kling
c6a2012fe9 Kernel: Collect IPv4 stuff in IPv4.h and ARP stuff in ARP.h. 2019-03-12 12:49:01 +01:00
Andreas Kling
a36eaeb18c Kernel: Remove accidentally committed debugging code. 2019-03-11 01:57:34 +01:00
Andreas Kling
1678ac69ef Kernel: More work on Ethernet support. 2019-03-10 23:40:09 +01:00
Andreas Kling
97664fad60 Kernel: A bunch of hacking towards initial Ethernet support. 2019-03-10 20:59:23 +01:00
Andreas Kling
eda0866992 Add a C++ helper class for working with shared buffers.
This is a bit more comfortable than passing the shared buffer ID manually
everywhere and keeping track of size etc.
2019-03-08 12:24:05 +01:00
Andreas Kling
e56fe71dbc Kernel: And some more KResult/KResultOr<T> porting work. 2019-03-06 22:30:13 +01:00
Andreas Kling
028afabf6b Kernel: Port more code to KResult and KResultOr<T>. 2019-03-06 22:14:31 +01:00
Andreas Kling
1cc32ebc7e Kernel: Remove "requested wakeups" feature.
I only needed this to support the WindowServer living inside the kernel.
Now that it's been migrated to userspace, this can go. :^)
2019-03-05 13:34:36 +01:00
Andreas Kling
91031346e5 Kernel: More signal handling improvements.
Finally fixed the weird flaky crashing when resizing Terminal windows.
It was because we were dispatching a signal to "current" from the scheduler.
Yet another thing I dislike about even having a "current" process while
we're in the scheduler. Not sure yet how to fix this.

Let the signal handler's kernel stack be a kmalloc() allocation for now.
Once we can do allocation of consecutive physical pages in the supervisor
memory region, we can use that for all types of kernel stacks.
2019-03-05 12:52:35 +01:00
Andreas Kling
9e1fcb74a2 Kernel: Returning from a signal handler reset the signal mask correctly.
We were setting the handled signal number as the new signal mask, oops.
2019-03-05 11:00:26 +01:00
Andreas Kling
251293f2e1 Kernel: Block a signal from being dispatched again until handler returns.
We don't handle nesting yet, but this is a step in the right direction.
2019-03-05 10:34:08 +01:00
Andreas Kling
67fc42f64e Kernel: SIGCONT should unblock a blocked process.
Otherwise we might stay in BlockedSignal state forever. Unblocking just
means that the current syscall may fail with EINTR.
2019-03-04 11:25:24 +01:00
Andreas Kling
725b57fe1f Kernel: Try to do the right thing by default for unhandled signals. 2019-03-03 12:13:41 +01:00
Andreas Kling
2c5a378ccc Kernel+Userland: Add symlink() syscall and add "-s" flag to /bin/ln.
It's now possible to create symbolic links! :^)

This exposed an issue in Ext2FS where we'd write uninitialized data past
the end of an inode's content. Fix this by zeroing out the tail end of
the last block in a file.
2019-03-02 01:52:24 +01:00
Andreas Kling
37f6844c6c Kernel: Port stat() to KResult/KResultOr<T>. 2019-03-02 00:11:27 +01:00
Andreas Kling
f75eb9af16 Kernel: Support chdir() to a directory that's executable but not readable.
Also the superuser should be allowed to resolve any possible path without
getting tripped up by EACCES.
2019-03-01 23:54:07 +01:00
Andreas Kling
274b0260f7 Kernel: Don't send SIGCHLD to parent process if he has SA_NOCLDWAIT set.
Just transfer ownership of the dead process to the colonel and let the
scheduler reap it on next iteration.
2019-03-01 15:52:05 +01:00
Andreas Kling
1b16a29044 Kernel+Userland: Implement fchmod() syscall and use it to improve /bin/cp.
/bin/cp will now copy the permission bits from source to destination. :^)
2019-03-01 10:39:19 +01:00
Andreas Kling
e427b514dc Kernel: Implement basic SIGSTOP and SIGCONT support. 2019-02-28 12:27:26 +01:00
Andreas Kling
c09ab7cc40 Kernel: Only allow sending signals to process you own. 2019-02-28 11:46:38 +01:00
Andreas Kling
258f4671ea Kernel: kill() syscall should support sending a signal to yourself. 2019-02-28 09:44:48 +01:00
Andreas Kling
60d0a48be5 Kernel: Use KResult in link(). 2019-02-27 15:31:26 +01:00
Andreas Kling
5b27f11b97 Kernel: Use KResult in unlink() and rmdir(). 2019-02-27 14:11:25 +01:00
Andreas Kling
1d2529b4a1 Add chown() syscall and a simple /bin/chown program. 2019-02-27 12:32:53 +01:00
Andreas Kling
e421c10735 More compat work towards porting vim.
It now builds and runs in the small-featureset configuration. :^)
2019-02-27 00:02:01 +01:00
Andreas Kling
a356746d04 Compat work towards porting vim. 2019-02-26 15:57:59 +01:00
Andreas Kling
e0c1541847 Compat work towards making bash-5.0 build with less patches.
Hacked implementations of sigsetjmp() and siglongjmp(). I didn't know about
these APIs until just now, but I hope I got them right.
2019-02-26 14:05:28 +01:00
Andreas Kling
cccc8d8aeb More compat work.
Move syscall to int 0x82 since using int 0x80 was kinda prone to fork bombs
when building things on Linux. :^)
2019-02-26 12:57:02 +01:00
Andreas Kling
9624b54703 More moving towards using signed types.
I'm still feeling this out, but I am starting to like the general idea.
2019-02-25 22:06:55 +01:00
Andreas Kling
beda478821 Kernel: Make syscalls that take a buffer size use ssize_t instead of size_t.
Dealing with the unsigned overflow propagation here just seems unreasonably
error prone. Let's limit ourselves to 2GB buffer sizes instead.
2019-02-25 21:21:12 +01:00
Andreas Kling
5af4e622b9 Kernel: Add KResult and KResultOr<T> classes.
The idea here is to combine a potential syscall error code with an arbitrary
type in the case of success. I feel like this will end up much less error
prone than returning some arbitrary type that kinda sorta has bool semantics
(but sometimes not really) and passing the error through an out-param.

This patch only converts a few syscalls to using it. More to come.
2019-02-25 20:50:22 +01:00
Andreas Kling
15fb917f28 Convert more RetainPtr use to Retained. 2019-02-25 16:04:08 +01:00
Andreas Kling
f98dcbf1d6 Kernel: Respect the process umask in open() and mkdir(). 2019-02-22 02:39:13 +01:00
Andreas Kling
6d3e12899b Kernel: Pass process arguments directly on the stack.
Get rid of the convoluted get_arguments and get_environment syscalls.
This patch also adds a simple /bin/env that just prints its environment.
2019-02-22 01:55:22 +01:00
Andreas Kling
e969419202 Kernel: Don't allocate and discard an extra stack for every process. 2019-02-22 00:27:06 +01:00
Andreas Kling
920e8e58ed Kernel+Userland: Implement setuid() and setgid() and add /bin/su
Also show setuid and setgid bits in "ls -l" output. :^)
2019-02-21 23:38:10 +01:00
Andreas Kling
8b64f213a1 Kernel: sigpending() and sigprocmask() should validate memory writes. 2019-02-21 21:33:52 +01:00
Andreas Kling
a624fe06b8 Kernel: Add file permission checks to utime() syscall. 2019-02-21 16:37:41 +01:00
Andreas Kling
f0a869ea50 Kernel: Process::cwd_inode() should return a reference.
There's always a current working directory inode.
2019-02-21 16:19:07 +01:00
Andreas Kling
ce3b548077 Kernel: Separate VFS stat() from open().
It was very confusing that you had to open a FileDescriptor in order to stat
a file. This patch gives VFS a separate stat() function and uses it to
implement the stat() and lstat() syscalls.
2019-02-21 16:09:12 +01:00
Andreas Kling
7d288aafb2 Kernel: Add link() syscall to create hard links.
This accidentally grew into a little bit of VFS cleanup as well.

Also add a simple /bin/ln implementation to exercise it.
2019-02-21 13:26:40 +01:00
Andreas Kling
0aaec6b19a Support resizing the Terminal app.
I set it up so that TIOCSWINSZ on a master PTY gets forwarded to the slave.
This feels intuitively right. Terminal can then use that to inform the shell
or whoever is inside the slave that the window size has changed.

TIOCSWINSZ also triggers the generation of a SIGWINCH signal. :^)
2019-02-20 23:38:20 +01:00
Andreas Kling
6158f456fa Kernel: Don't remove from SharedBuffer map while iterating it.
This was causing a finalizer crash when handling a process that co-owned
multiple shared buffers.
2019-02-20 21:31:52 +01:00
Andreas Kling
59b8183c4b WindowServer: Support resizing windows.
This is pretty limited and not entirely stable, but it does work! :^)
2019-02-20 15:34:55 +01:00
Andreas Kling
7bb00ea1e3 Kernel: socket() with SOCK_CLOEXEC was setting the wrong fd flag.
Turns out FD_CLOEXEC and O_CLOEXEC are different values. Silly mistake.
I noticed that Terminal's shell process still had the Terminal's window
server connection open, albeit in a broken state.
2019-02-17 10:41:37 +01:00
Andreas Kling
cf8dd312ab Kernel: Fix String leaks in exec().
When the kernel performs a successful exec(), whatever was on the kernel
stack for that process before goes away. For this reason, we need to make
sure we don't have any stack objects holding onto kmalloc memory.
2019-02-17 10:18:25 +01:00
Andreas Kling
df2d46d5dc Kernel: Add SocketRole::Listener and report the role nicely in /proc/PID/fds. 2019-02-17 09:40:52 +01:00
Andreas Kling
2dc0ef8813 Kernel: munmap() should round up to nearest page size, just like mmap().
The mismatch between the two was causing some trouble if you'd mmap e.g 1KB
and then try to munmap() it. The kernel would whine that it couldn't find
any such mapping (because mmap() actually rounded the 1KB to a 4KB page.)
2019-02-17 08:33:13 +01:00
Andreas Kling
809266a9fb Kernel: Remove tracking of bitmap memory.
There are no more kernel bitmaps. It's much better this way.
2019-02-17 01:16:38 +01:00
Andreas Kling
640360e958 Move WindowServer to userspace.
This is a monster patch that required changing a whole bunch of things.
There are performance and stability issues all over the place, but it works.
Pretty cool, I have to admit :^)
2019-02-17 00:13:47 +01:00
Andreas Kling
4ea28bf0a5 Kernel: Add a simple shared memory API for two processes only.
And use this to implement shared bitmaps between WindowServer and clients.
2019-02-16 12:13:43 +01:00