Commit Graph

227 Commits

Author SHA1 Message Date
Andreas Kling
af81645a2a Kernel+LibC: Add a dbgputstr() syscall for sending strings to debug output.
This is very handy for the DebugLogStream implementation, among others. :^)
2019-07-21 21:43:37 +02:00
Andreas Kling
3fce2fb205 Kernel+LibC: Add a dbgputch() syscall and use it for userspace dbgprintf().
The "stddbg" stream was a cute idea but we never ended up using it in
practice, so let's simplify this and implement userspace dbgprintf() on top
of a simple dbgputch() syscall instead.

This makes debugging LibC startup a little bit easier. :^)
2019-07-21 19:45:31 +02:00
Andreas Kling
d2b521f0ab Kernel+LibC: Add a dump_backtrace() syscall.
This is very simple but already very useful. Now you're able to call to
dump_backtrace() from anywhere userspace to get a nice symbolicated
backtrace in the debugger output. :^)
2019-07-21 09:59:17 +02:00
Andreas Kling
f8beb0f665 Kernel: Share the "return to ring 0/3 from signal" trampolines globally.
Generate a special page containing the "return from signal" trampoline code
on startup and then route signalled threads to it. This avoids a page
allocation in every process that ever receives a signal.
2019-07-19 17:01:16 +02:00
Andreas Kling
5b2447a27b Kernel: Track user accessibility per Region.
Region now has is_user_accessible(), which informs the memory manager how
to map these pages. Previously, we were just passing a "bool user_allowed"
to various functions and I'm not at all sure that any of that was correct.

All the Region constructors are now hidden, and you must go through one of
these helpers to construct a region:

- Region::create_user_accessible(...)
- Region::create_kernel_only(...)

That ensures that we don't accidentally create a Region without specifying
user accessibility. :^)
2019-07-19 16:11:52 +02:00
Robin Burchell
3727a06c78 Process: Now that Thread::for_each are composable, we can reuse them rather than rewriting them
This avoids exposing the runnable lists to Process.
2019-07-19 13:19:02 +02:00
Jesse
a5d80f7e3b Kernel: Only allow superuser to halt() the system (#342)
Following the discussion in #334, shutdown must also have root-only
run permissions.
2019-07-19 13:08:26 +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
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
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
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
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
cda5a6eca3 Kernel: Add LogStream operator<< for Process.
It simply prints "process-name(pid)", nothing fancy, but kinda useful.
2019-07-08 18:58:19 +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
90b1354688 AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr. 2019-06-21 18:37:47 +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
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
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
bf905225e7 Kernel: Tidy up sys$select() to make it more readable. 2019-06-06 17:49:01 +02:00
Andreas Kling
93d3d1ede1 Kernel: Add fchown() syscall. 2019-06-01 20:31:36 +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
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
Robin Burchell
0dc9af5f7e Add clang-format file
Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
2019-05-28 17:31:20 +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
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
212a263f0a Kernel+LibC: Implement getsockname() syscall. 2019-05-19 19:55:27 +02:00
Andreas Kling
8c7d5abdc4 Kernel: Refactor thread scheduling a bit, breaking it into multiple lists.
There are now two thread lists, one for runnable threads and one for non-
runnable threads. Thread::set_state() is responsible for moving threads
between the lists.

Each thread also has a back-pointer to the list it's currently in.
2019-05-18 20:28:04 +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
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
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
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
8b249bd09b Kernel+Userland: Implement mknod() syscall and add a /bin/mknod program. 2019-05-03 22:59:58 +02:00
Andreas Kling
c3b7ace3e0 Kernel: Assign Lock names in class member initializers. 2019-05-02 03:28:20 +02:00
Andreas Kling
d07be1087a Kernel+LibC: Add exit_thread() syscall. 2019-04-29 15:17:20 +02:00
Andreas Kling
0a0d739e98 Kernel: Make FIFO inherit from File. 2019-04-29 04:55:54 +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
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
c02c6fef28 Kernel+ProcessManager: Show per-process syscall counts.
Added a simple syscall counter to the /proc/all contents. :^)
2019-04-17 23:16:14 +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