Andreas Kling
54986228bf
Kernel: Oops, add missing #include to fix ENABLE_ALL_THE_DEBUG_MACROS
2021-02-11 22:15:55 +01:00
Andreas Kling
0dbb22e9e0
Kernel: Remove a handful of unused things in VM/ directory
...
Also add some missing initializers.
2021-02-11 22:02:39 +01:00
Andreas Kling
ba42d741cb
Kernel: Add explicit __serenity__ define to workaround CLion problem
...
CLion doesn't understand that we switch compilers mid-build (which I
can understand since it's a bit unusual.) Defining __serenity__ makes
the majority of IDE features work correctly in the kernel context.
2021-02-11 21:23:31 +01:00
Jean-Baptiste Boric
f8c352a022
Kernel: Fix undefined signed overflow in KernelRng's RTC fallback
2021-02-11 20:58:39 +01:00
Jean-Baptiste Boric
eedb6480df
Kernel: Don't assert if RTC believes we're in the past
2021-02-11 20:58:39 +01:00
Hendiadyoin1
4d5496b2b2
KUBSAN: Add nearly all missing -fsanitize handlers ( #5254 )
2021-02-11 20:58:01 +01:00
Andreas Kling
085f80aeac
Kernel: Remove unused root directory computation in Process creation
...
sys$fork() already takes care of children inheriting the parent's root
directory, so there was no need to do the same thing when creating a
new user process.
2021-02-09 19:18:13 +01:00
Andreas Kling
1f277f0bd9
Kernel: Convert all *Builder::appendf() => appendff()
2021-02-09 19:18:13 +01:00
Andreas Kling
e8f040139b
Kernel: Remove unused Thread::is_runnable_state()
2021-02-08 23:07:33 +01:00
Andreas Kling
4ff0f971f7
Kernel: Prevent execve/ptrace race
...
Add a per-process ptrace lock and use it to prevent ptrace access to a
process after it decides to commit to a new executable in sys$execve().
Fixes #5230 .
2021-02-08 23:05:41 +01:00
Andreas Kling
4b7b92c201
Kernel: Remove two unused fields from sys$execve's LoadResult
2021-02-08 22:31:03 +01:00
Andreas Kling
4cd2c475a8
Kernel: Make the space lock a RecursiveSpinLock
2021-02-08 22:28:48 +01:00
Andreas Kling
0d7af498d7
Kernel: Move ShouldAllocateTls enum from Process to execve.cpp
2021-02-08 22:24:37 +01:00
Andreas Kling
9ca42c4c0e
Kernel: Always hold space lock while calculating memory statistics
...
And put the locker at the top of the functions for clarity.
2021-02-08 22:23:29 +01:00
Andreas Kling
8bda30edd2
Kernel: Move memory statistics helpers from Process to Space
2021-02-08 22:23:29 +01:00
Andreas Kling
b1c9f93fa3
Kernel: Skip generic region lookup in sys$futex and sys$get_stack_bounds
...
Just ask the process space directly instead of using the generic region
lookup that also checks for kernel regions.
2021-02-08 22:23:29 +01:00
Andreas Kling
f39c2b653e
Kernel: Reorganize ptrace implementation a bit
...
The generic parts of ptrace now live in Kernel/Syscalls/ptrace.cpp
and the i386 specific parts are moved to Arch/i386/CPU.cpp
2021-02-08 19:34:41 +01:00
Andreas Kling
45231051e6
Kernel: Set the dumpable flag before switching spaces in sys$execve()
2021-02-08 19:15:42 +01:00
Andreas Kling
d746639171
Kernel: Remove outdated code to dump memory layout after exec load
2021-02-08 19:07:29 +01:00
Andreas Kling
f1b5def8fd
Kernel: Factor address space management out of the Process class
...
This patch adds Space, a class representing a process's address space.
- Each Process has a Space.
- The Space owns the PageDirectory and all Regions in the Process.
This allows us to reorganize sys$execve() so that it constructs and
populates a new Space fully before committing to it.
Previously, we would construct the new address space while still
running in the old one, and encountering an error meant we had to do
tedious and error-prone rollback.
Those problems are now gone, replaced by what's hopefully a set of much
smaller problems and missing cleanups. :^)
2021-02-08 18:27:28 +01:00
Andreas Kling
b2cba3036e
Kernel: Remove unused MemoryManager::validate_range()
...
This is no longer used since we've switched to using the MMU to
generate EFAULT errors.
2021-02-08 18:27:28 +01:00
Andreas Kling
cf5ab665e0
Kernel: Remove unused Process::for_each_thread_in_coredump()
2021-02-08 18:27:28 +01:00
AnotherTest
09a43969ba
Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
...
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
AnotherTest
1f8a633cc7
Kernel: Make Arch/i386/CPU.cpp safe to run through clang-format
...
This file was far too messy, and touching it was a major pain.
Also enable clang-format linting on it.
2021-02-08 18:08:55 +01:00
AnotherTest
53ce923e10
Everywhere: Fix obvious dbgln() bugs
...
This will allow compiletime dbgln() checks to pass
2021-02-08 18:08:55 +01:00
Ben Wiederhake
0a2304ba05
Everywhere: Fix weird includes
2021-02-08 18:03:57 +01:00
Tom
1d843c46eb
Kernel: KResultOr can use the same storage as the object for the error
...
Since it can only hold either an object or an error code, we can share
the same storage to hold either.
2021-02-08 18:00:38 +01:00
Tom
27a395d964
Kernel: Fix KResultOr copy-move from itself case
...
If move-assigning from itself we shouldn't do anything.
2021-02-07 23:02:57 +01:00
Tom
b22740c08e
Kernel: Use KResultOr::release_value in Process::create_kernel_thread
...
This should avoid an unneccessary reference bump.
2021-02-07 22:25:15 +01:00
Tom
f74e31c74d
Kernel: Change KResultOr::take_value to use move semantics
...
This may be more light weight than copying the object.
2021-02-07 22:25:15 +01:00
Andreas Kling
ad42d873e5
Kernel: Remove ancient unused Scheduler::beep() declaration
2021-02-07 20:45:09 +01:00
Andreas Kling
0d8262cbab
Kernel: Remove a handful of unused things from Thread
2021-02-07 20:26:53 +01:00
Andreas Kling
2ec8b4e177
Kernel: Don't allocate kernel stack twice per thread :^)
2021-02-07 20:13:51 +01:00
Andreas Kling
b466ede1ea
Kernel: Make sure we can allocate kernel stack before creating thread
...
Wrap thread creation in a Thread::try_create() helper that first
allocates a kernel stack region. If that allocation fails, we propagate
an ENOMEM error to the caller.
This avoids the situation where a thread is half-constructed, without a
valid kernel stack, and avoids having to do messy cleanup in that case.
2021-02-07 19:27:00 +01:00
Andreas Kling
5c45b0d32d
Kernel: Combine Thread::backtrace() and backtrace_impl() into one
2021-02-07 19:27:00 +01:00
Andreas Kling
fd3eca3acc
Kernel: Add initializer for Thread::m_tss
2021-02-07 19:27:00 +01:00
Andreas Kling
5c1c82cd33
Kernel: Remove unused function Process::backtrace()
2021-02-07 19:27:00 +01:00
Andreas Kling
b1813e5dae
Kernel: Remove some unused declarations from Process
2021-02-07 19:27:00 +01:00
Brian Gianforcaro
c95d48c8d6
Kernel: KUBSAN implementation of returns-nonnull-attribute
...
This didn't find anything in the current source.
2021-02-07 10:22:03 +01:00
William Bowling
b97d23a71f
Kernel: Use the resolved parent path when testing create veil ( #5231 )
2021-02-06 19:11:44 +01:00
Andreas Kling
04ff46bff4
Kernel: And some more KUBSAN checks :^)
...
Here comes a few more:
* enum
* object-size
* vptr
2021-02-06 17:39:49 +01:00
Andreas Kling
fad0332898
Kernel: Implement some more KUBSAN checks :^)
...
This patch enables the following -fsanitize sub-options:
* bounds
* bounds-strict
* integer-divide-by-zero
* return
* shift
* shift-base
* shift-exponent
2021-02-06 17:39:49 +01:00
Andreas Kling
930e3ce00d
Kernel: Don't left-shift 1 (signed) 31 times
...
Found by KUBSAN :^)
2021-02-05 21:28:06 +01:00
Andreas Kling
4c0707e56c
Kernel: Don't create a zero-length VLA in Ext2FS block list walk
...
Found by KUBSAN :^)
2021-02-05 21:23:11 +01:00
Andreas Kling
d164f89ada
Kenrel: Implement two more KUBSAN checks
...
This patch adds the following UndefinedBehaviorSanitizer sub-options:
* signed-integer-overflow
* vla-bound
2021-02-05 21:23:11 +01:00
Andreas Kling
f4eb1f261f
Kernel: Add missing initializer for SharedIRQHandler::m_enabled
...
Found by KUBSAN :^)
2021-02-05 21:23:11 +01:00
Andreas Kling
d44be96893
Kernel: KUBSAN! (Kernel Undefined Behavior SANitizer) :^)
...
We now build the kernel with partial UBSAN support.
The following -fsanitize sub-options are enabled:
* nonnull-attribute
* bool
If the kernel detects UB at runtime, it will now print a debug message
with a stack trace. This is very cool! I'm leaving it on by default for
now, but we'll probably have to re-evaluate this as more options are
enabled and slowdown increases.
2021-02-05 21:23:11 +01:00
Andreas Kling
e87eac9273
Userland: Add LibSystem and funnel all syscalls through it
...
This achieves two things:
- Programs can now intentionally perform arbitrary syscalls by calling
syscall(). This allows us to work on things like syscall fuzzing.
- It restricts the ability of userspace to make syscalls to a single
4KB page of code. In order to call the kernel directly, an attacker
must now locate this page and call through it.
2021-02-05 12:23:39 +01:00
Jean-Baptiste Boric
edd2362f39
Kernel: Add NE2000 network card driver
...
Remember, friends don't let friends use NE2000 network cards :^)
2021-02-05 09:35:02 +01:00
Liav A
865aade42b
Kernel: Clear pending interrupts before enabling IRQs of IDE Channel
...
Calling detect_disks() can generate interrupts, so we must clear it to
allow proper function when booting with kernel argument smp=on.
2021-02-05 09:10:37 +01:00