Commit graph

3674 commits

Author SHA1 Message Date
Tom e21cc4cff6 Kernel: Remove MAP_PURGEABLE from mmap
This brings mmap more in line with other operating systems. Prior to
this, it was impossible to request memory that was definitely committed,
instead MAP_PURGEABLE would provide a region that was not actually
purgeable, but also not fully committed, which meant that using such memory
still could cause crashes when the underlying pages could no longer be
allocated.

This fixes some random crashes in low-memory situations where non-volatile
memory is mapped (e.g. malloc, tls, Gfx::Bitmap, etc) but when a page in
these regions is first accessed, there is insufficient physical memory
available to commit a new page.
2021-01-01 23:43:44 +01:00
Tom c3451899bc Kernel: Add MAP_NORESERVE support to mmap
Rather than lazily committing regions by default, we now commit
the entire region unless MAP_NORESERVE is specified.

This solves random crashes in low-memory situations where e.g. the
malloc heap allocated memory, but using pages that haven't been
used before triggers a crash when no more physical memory is available.

Use this flag to create large regions without actually committing
the backing memory. madvise() can be used to commit arbitrary areas
of such regions after creating them.
2021-01-01 23:43:44 +01:00
Tom bc5d6992a4 Kernel: Memory purging improvements
This adds the ability for a Region to define volatile/nonvolatile
areas within mapped memory using madvise(). This also means that
memory purging takes into account all views of the PurgeableVMObject
and only purges memory that is not needed by all of them. When calling
madvise() to change an area to nonvolatile memory, return whether
memory from that area was purged. At that time also try to remap
all memory that is requested to be nonvolatile, and if insufficient
pages are available notify the caller of that fact.
2021-01-01 23:43:44 +01:00
Liav A 9dc8bea3e7 Kernel: Allow to boot from a partition with partition UUID
Instead of specifying the boot argument to be root=/dev/hdXY, now
one can write root=PARTUUID= with the right UUID, and if the partition
is found, the kernel will boot from it.

This feature is mainly used with GUID partitions, and is considered to
be the most reliable way for the kernel to identify partitions.
2021-01-01 22:59:48 +01:00
Andreas Kling 7c3b6b10e4 Kernel: Remove the limited use of AK::TypeTraits we had in the kernel
This was only used for VMObject and we can do without it there. This is
preparation for migrating to dynamic_cast-based helpers in userspace.
2021-01-01 15:32:44 +01:00
Andrew Kaster 350d4d3543 Meta: Enable RTTI for Userspace programs
RTTI is still disabled for the Kernel, and for the Dynamic Loader. This
allows for much less awkward navigation of class heirarchies in LibCore,
LibGUI, LibWeb, and LibJS (eventually). Measured RootFS size increase
was < 1%, and libgui.so binary size was ~3.3%. The small binary size
increase here seems worth it :^)
2021-01-01 14:45:09 +01:00
Brian Gianforcaro ab6ee9f7b2 CMake: Remove some trailing whitespace from a few CMakeLists.txt files 2021-01-01 14:37:04 +01:00
Andrew Kaster a3a9016701 DynamicLoader: Tell the linker to not add a PT_INTERP header
Use the GNU LD option --no-dynamic-linker. This allows uncommenting some
code in the Kernel that gets upset if your ELF interpreter has its own
interpreter.
2021-01-01 02:12:28 +01:00
Linus Groh bbe787a0af Everywhere: Re-format with clang-format-11
Compared to version 10 this fixes a bunch of formatting issues, mostly
around structs/classes with attributes like [[gnu::packed]], and
incorrect insertion of spaces in parameter types ("T &"/"T &&").
I also removed a bunch of // clang-format off/on and FIXME comments that
are no longer relevant - on the other hand it tried to destroy a couple of
neatly formatted comments, so I had to add some as well.
2020-12-31 21:51:00 +01:00
Tom 72440d90fe Kernel: Fix BlockCondition::unblock return value
BlockCondition::unblock should return true if it unblocked at
least one thread, not if iterating the blockers had been stopped.
This is a regression introduced by 49a76164c.

Fixes #4670
2020-12-31 10:52:58 +01:00
Tom 82c4812730 Kernel: Remove flawed SharedInodeVMObject assertion
This assertion cannot be safely/reliably made in the
~SharedInodeVMObject destructor. The problem is that
Inode::is_shared_vmobject holds a weak reference to the instance
that is being destroyed (ref count 0). Checking the pointer using
WeakPtr::unsafe_ptr will produce nullptr depending on timing in
this case, and WeakPtr::safe_ref will reliably produce a nullptr
as soon as the reference count drops to 0. The only case where
this assertion could succeed is when WeakPtr::unsafe_ptr returned
the pointer because it won the race against revoking it. And
because WeakPtr::safe_ref will always return a nullptr, we cannot
reliably assert this from the ~SharedInodeVMObject destructor.

Fixes #4621
2020-12-31 10:52:45 +01:00
Andreas Kling 1fdd39ff14 Kernel: Sprinkle some lockers in Inode
It did look pretty suspicious the way we were accessing members in some
of these functions without taking the lock first.
2020-12-31 02:10:31 +01:00
Luke 0f66589007 Everywhere: Fix more typos 2020-12-31 01:47:41 +01:00
Tom 22250780ff Kernel: Fix heap expansions deadlock
If a heap expansion is triggered by allocating from e.g. the
RangeAllocator, which may be holding a spin lock, we cannot
immediately allocate another block of backup memory, which could
require the same locks to be acquired. So, defer allocating the
backup memory

Fixes #4675
2020-12-31 01:15:37 +01:00
asynts 7e62ffbc6e AK+Format: Remove TypeErasedFormatParams& from format function. 2020-12-30 20:33:53 +01:00
Luke 865f5ed4f6 Kernel: Prevent sign bit extension when creating a PDPTE
When doing the cast to u64 on the page directory physical address,
the sign bit was being extended. This only beomes an issue when
crossing the 2 GiB boundary. At >= 2 GiB, the physical address
has the sign bit set. For example, 0x80000000.

This set all the reserved bits in the PDPTE, causing a GPF
when loading the PDPT pointer into CR3. The reserved bits are
presumably there to stop you writing out a physical address that
the CPU physically cannot handle, as the size of the reserved bits
is determined by the physical address width of the CPU.

This fixes this by casting to FlatPtr instead. I believe the sign
extension only happens when casting to a bigger type. I'm also using
FlatPtr because it's a pointer we're writing into the PDPTE.
sizeof(FlatPtr) will always be the same size as sizeof(void*).

This also now asserts that the physical address in the PDPTE is
within the max physical address the CPU supports. This is better
than getting a GPF, because CPU::handle_crash tries to do the same
operation that caused the GPF in the first place. That would cause
an infinite loop of GPFs until the stack was exhausted, causing a
triple fault.

As far as I know and tested, I believe we can now use the full 32-bit
physical range without crashing.

Fixes #4584. See that issue for the full debugging story.
2020-12-30 20:33:15 +01:00
Linus Groh d84b96bddc Kernel: Embed a Metadata notes entry in coredumps 2020-12-30 16:28:27 +01:00
Linus Groh 91332515a6 Kernel: Add sys$set_coredump_metadata() syscall
This can be used by applications to store information (key/value pairs)
likely useful for debugging, which will then be embedded in the coredump.
2020-12-30 16:28:27 +01:00
Linus Groh 6fe6e0a36a Kernel: Embed a ProcessInfo notes entry in coredumps 2020-12-30 15:00:17 +01:00
Tom 49a76164c8 Kernel: Consolidate the various BlockCondition::unblock variants
The unblock_all variant used to ASSERT if a blocker didn't unblock,
but it wasn't clear from the name that it would do that. Because
the BlockCondition already asserts that no blockers are left at
destruction time, it would still catch blockers that haven't been
unblocked for whatever reason.

Fixes #4496
2020-12-30 13:23:17 +01:00
asynts 50d24e4f98 AK: Make binary_search signature more generic. 2020-12-30 02:13:30 +01:00
Tom c2332780ee Kernel: Fix HPET::update_time to set ticks within the valid range
ticks_this_second must be less than the ticks per second (frequency).
2020-12-30 02:11:06 +01:00
meme 23b23cee5a Build: Support non-i686 toolchains
* Add SERENITY_ARCH option to CMake for selecting the target toolchain
* Port all build scripts but continue to use i686
* Update GitHub Actions cache to include BuildIt.sh
2020-12-29 17:42:04 +01:00
Andreas Kling af28a8ad11 Kernel: Hold InodeVMObject reference while inspecting it in sys$mmap() 2020-12-29 15:43:35 +01:00
Andreas Kling b8db585a83 Kernel: Remove unnecessary non-const Inode::shared_vmobject() 2020-12-29 15:43:35 +01:00
Andreas Kling 30dbe9c78a Kernel+LibC: Add a very limited sys$mremap() implementation
This syscall can currently only remap a shared file-backed mapping into
a private file-backed mapping.
2020-12-29 02:20:43 +01:00
Luke b980782343 Kernel/VM: Make local_offset in PhysicalRegion::find_one_free_page unsigned
An extension to #4613, as I didn't notice that it also happens here.
2020-12-29 02:20:26 +01:00
Luke eb38fe4a82 Kernel/VM: Make local_offset in PhysicalRegion::free_page_at unsigned
Anything above or equal to the 2 GB mark has the left most bit set
(0x8000...), which was falsely interpreted as negative due to
local_offset being signed.

This makes it unsigned by using FlatPtr. To check for underflow as
was intended, lets use Checked instead.

Fixes #4585
2020-12-29 01:41:16 +01:00
Andreas Kling 43d9fe15f9 Revert "Kernel: Convert read_block method to get a reference instead of pointer"
This reverts commit 092a13211a.

Fixes #4611.
2020-12-29 00:06:52 +01:00
Liav A 72b1998f0d Kernel: Introduce a new partitioning subsystem
The partitioning code was very outdated, and required a full refactor.
The new subsystem removes duplicated code and uses more AK containers.

The most important change is that all implementations of the
PartitionTable class conform to one interface, which made it possible
to remove unnecessary code in the EBRPartitionTable class.

Finding partitions is now done in the StorageManagement singleton,
instead of doing so in init.cpp.

Also, now we don't try to find partitions on demand - the kernel will
try to detect if a StorageDevice is partitioned, and if so, will check
what is the partition table, which could be MBR, GUID or EBR.
Then, it will create DiskPartitionMetadata object for each partition
that is available in the partition table. This object will be used
by the partition enumeration code to create a DiskPartition with the
correct minor number.
2020-12-27 23:07:44 +01:00
Liav A 43d833d94f Kernel: Add DiskPartitionMetadata Class
This class will be used to describe a partition of a StorageDevice,
without creating a DiskPartition object.
2020-12-27 23:07:44 +01:00
Liav A 3a19e18d1e Kernel: Move Partition code files to the Storage folder
This folder is more appropriate for these files.
2020-12-27 23:07:44 +01:00
Liav A 247517cd4a Kernel: Introduce the DevFS
The DevFS along with DevPtsFS give a complete solution for populating
device nodes in /dev. The main purpose of DevFS is to eliminate the
need of device nodes generation when building the system.

Later on, DevFS will assist with exposing disk partition nodes.
2020-12-27 23:07:44 +01:00
Liav A 18e77aa285 Kernel: Add a method to determine the desired permissions of a Device
This method will be used later in DevFS, to set the appropriate
permissions for each device node.
2020-12-27 23:07:44 +01:00
Liav A 092a13211a Kernel: Convert read_block method to get a reference instead of pointer
BlockBasedFileSystem::read_block method should get a reference of
a UserOrKernelBuffer.

If we need to force caching a block, we will call other method to do so.
2020-12-27 23:07:44 +01:00
Nathan Lanza d1891f67ac
AK: Use direct-list-initialization for Vector::empend() (#4564)
clang trunk with -std=c++20 doesn't seem to properly look for an
aggregate initializer here when the type being constructed is a simple
aggregate (e.g. `struct Thing { int a; int b; };`). This template fails
to compile in a usage added 12/16/2020 in `AK/Trie.h`.

Both forms of initialization are supposed to call the
aggregate-initializers but direct-list-initialization delegating to
aggregate initializers is a new addition in c++20 that might not be
implemented yet.
2020-12-27 23:06:37 +01:00
Brendan Coles fae2304c67 Kernel: CoreDump::write_program_headers: set NOTE p_memsz to p_filesz 2020-12-27 22:45:25 +01:00
Andreas Kling ddaedbca87 Kernel: Allow sys$rename() to rename symlinks
Previously, this syscall would try to rename the target of the link,
not the link itself.
2020-12-27 15:38:07 +01:00
Brian Gianforcaro 815d39886f Kernel: Tag more methods and types as [[nodiscard]]
Tag methods at where not obvserving the return value is an obvious error
with [[nodiscard]] to catch potential future bugs.
2020-12-27 11:09:30 +01:00
Tom f1534ff36e Kernel: Take into account the time keeper's frequency (if no HPET)
The PIT is now also running at a rate of ~250 ticks/second, so rather
than assuming there are 1000 ticks/second we need to query the timer
being used for the actual frequency.

Fixes #4508
2020-12-27 01:17:50 +01:00
Andreas Kling 0e2b7f9c9a Kernel: Remove the per-process icon_id and sys$set_process_icon()
This was a goofy kernel API where you could assign an icon_id (int) to
a process which referred to a global shbuf with a 16x16 icon bitmap
inside it.

Instead of this, programs that want to display a process icon now
retrieve it from the process executable instead.
2020-12-27 01:16:56 +01:00
Andreas Kling 21ccbc2167 Kernel: Expose process executable paths in /proc/all 2020-12-27 01:16:56 +01:00
Andreas Kling 87492e723b Kernel: Lock target process when generating core dump
Dumping core can happen at the end of a profiling run, and in that case
we have to protect the target process and take the lock while iterating
over its region map.

Fixes #4509.
2020-12-27 01:16:56 +01:00
Tom 74fa894994 Kernel: Remove subheap from list before removing memory
When the ExpandableHeap calls the remove_memory function, the
subheap is assumed to be removed and freed entirely. remove_memory
may drop the underlying memory at any time, but it also may cause
further allocation requests. Not removing it from the list before
calling remove_memory could cause a memory allocation in that
subheap while remove_memory is executing. which then causes issues
once the underlying memory is actually freed.
2020-12-26 19:55:01 +01:00
AnotherTest 7b5aa06702 Kernel: Allow 'elevating' unveil permissions if implicitly inherited from '/'
This can happen when an unveil follows another with a path that is a
sub-path of the other one:
```c++
unveil("/home/anon/.config/whoa.ini", "rw");
unveil("/home/anon", "r"); // this would fail, as "/home/anon" inherits
                           // the permissions of "/", which is None.
```
2020-12-26 16:10:04 +01:00
AnotherTest a9184fcb76 Kernel: Implement unveil() as a prefix-tree
Fixes #4530.
2020-12-26 11:54:54 +01:00
Lenny Maiorani b2316701a8 Everywhere: void arguments to C functions
Problem:
- C functions with no arguments require a single `void` in the argument list.

Solution:
- Put the `void` in the argument list of functions in C header files.
2020-12-26 10:10:27 +01:00
Sahan Fernando 6b01d1cf14 LibC: Enable compiler warnings for printf format strings 2020-12-26 10:05:50 +01:00
Andreas Kling 1cfdaf96c4 Kernel: Reset the process dumpable flag on successful non-setid exec
Once we've committed to a new memory layout and non-setid credentials,
we can reset the dumpable flag.
2020-12-26 01:31:24 +01:00
Andreas Kling 82f86e35d6 Kernel+LibC: Introduce a "dumpable" flag for processes
This new flag controls two things:
- Whether the kernel will generate core dumps for the process
- Whether the EUID:EGID should own the process's files in /proc

Processes are automatically made non-dumpable when their EUID or EGID is
changed, either via syscalls that specifically modify those ID's, or via
sys$execve(), when a set-uid or set-gid program is executed.

A process can change its own dumpable flag at any time by calling the
new sys$prctl(PR_SET_DUMPABLE) syscall.

Fixes #4504.
2020-12-25 19:35:55 +01:00
Andreas Kling 3c9bd911b8 Kernel: Make /proc/PID directories owned by the EUID:EGID
This is instead of the UID:GID, since that was allowing some very bad
information leaks like spawning "su" as an unprivileged user and having
full /proc access to it.

Work towards #4504.
2020-12-25 19:35:55 +01:00
Andreas Kling 057c1d4798 Kernel: Fix build with E1000_DEBUG 2020-12-25 19:35:55 +01:00
Andreas Kling ed5c26d698 AK: Remove custom %w format string specifier
This was a non-standard specifier alias for %04x. This patch replaces
all uses of it with new-style formatting functions instead.
2020-12-25 17:05:05 +01:00
Andreas Kling cb2c8f71f4 AK: Remove custom %b format string specifier
This was a non-standard specifier alias for %02x. This patch replaces
all uses of it with new-style formatting functions instead.
2020-12-25 17:04:28 +01:00
Andreas Kling 89d3b09638 Kernel: Allocate new main thread stack before committing to exec
If the allocation fails (e.g ENOMEM) we want to simply return an error
from sys$execve() and continue executing the current executable.

This patch also moves make_userspace_stack_for_main_thread() out of the
Thread class since it had nothing in particular to do with Thread.
2020-12-25 16:22:01 +01:00
Andreas Kling 2f1712cc29 Kernel: Move ELF auxiliary vector building out of Process class
Process had a couple of members whose only purpose was holding on to
some temporary data while building the auxiliary vector. Remove those
members and move the vector building to a free function in execve.cpp
2020-12-25 15:23:35 +01:00
Andreas Kling 40e9edd798 LibELF: Move AuxiliaryValue into the ELF namespace 2020-12-25 14:48:30 +01:00
Andreas Kling 6c9a6bea1e Kernel+LibELF: Abort ELF executable load sooner when something fails
Make it possible to bail out of ELF::Image::for_each_program_header()
and then do exactly that if something goes wrong during executable
loading in the kernel.

Also make the errors we return slightly more nuanced than just ENOEXEC.
2020-12-25 14:42:42 +01:00
Andreas Kling 791b32e3c6 Kernel: Remove an unnecessary cast in sys$execve() 2020-12-25 14:16:35 +01:00
Andreas Kling 9c640e67ac Kernel: Don't fetch full inode metadata in sys$execve()
We only need the size, so let's not fetch all the metadata.
2020-12-25 14:15:33 +01:00
Andreas Kling c3eddbcb49 Kernel: Add back missing ELF::Image validity check
If the image is not a valid ELF we should just fail ASAP.
2020-12-25 14:13:44 +01:00
Andreas Kling 4986f268a5 Kernel: Convert dbg() => dbgln() in sys$execve() 2020-12-25 12:51:35 +01:00
Andreas Kling 73e151edd0 Kernel: Add formatter for VirtualAddress 2020-12-25 12:51:11 +01:00
Andreas Kling 09129782de Kernel: Simplify ELF loading logic in sys$execve() somewhat
Get rid of the lambda functions and put the logic inline in the program
header traversal loop instead. This makes the code quite a bit shorter
and hopefully makes it easier to see what's going on.
2020-12-25 02:33:57 +01:00
Andreas Kling 1e4c010643 LibELF: Remove ELF::Loader and move everyone to ELF::Image
This commit gets rid of ELF::Loader entirely since its very ambiguous
purpose was actually to load executables for the kernel, and that is
now handled by the kernel itself.

This patch includes some drive-by cleanup in LibDebug and CrashDaemon
enabled by the fact that we no longer need to keep the ref-counted
ELF::Loader around.
2020-12-25 02:14:56 +01:00
Andreas Kling 7551a66f73 Kernel+LibELF: Move sys$execve()'s loading logic from LibELF to Kernel
It was really weird that ELF loading was performed by the ELF::Loader
class instead of just being done by the kernel itself. This patch moves
all the layout logic from ELF::Loader over to sys$execve().

The kernel no longer cares about ELF::Loader and instead only uses an
ELF::Image as an interpreting wrapper around executables.
2020-12-25 01:22:55 +01:00
Andreas Kling d7ad082afa Kernel+LibELF: Stop doing ELF symbolication in the kernel
Now that the CrashDaemon symbolicates crashes in userspace, let's take
this one step further and stop trying to symbolicate userspace programs
in the kernel at all.
2020-12-25 01:03:46 +01:00
Itamar 0cb636078a Kernel+LibELF: Allow Non ET_DYN executables to have an interpreter 2020-12-24 21:34:51 +01:00
Itamar d64d0451e5 Kernel: Fix mmap with specific address for file backed mappings 2020-12-24 21:34:51 +01:00
Brendan Coles b156c5a8eb ProcFS: pid_vm: Replace duplicated purgeable key with kernel+cacheable
ProcFS /proc/<pid>/vm map info no longer contains two `purgeable` keys.

The second `purgeable` key has been removed and replaced with keys for
`kernel` and `cacheable`.
2020-12-24 10:26:39 +01:00
Andreas Kling 51713901b1 Kernel: Tweak parameter name in Inode::read_entire()
This is a descriptION, not a descriptOR. :^)
2020-12-23 20:36:14 +01:00
Andreas Kling 1e21d49e86 Kernel: Fix wrong-looking overflow check in sys$execve()
This was harmless since sizeof(length) and sizeof(strings) are both 4
on x86 but let's check the right things regardless.
2020-12-23 20:34:22 +01:00
Andreas Kling c6a0694f50 Kernel: Don't assert when reading from a listening-mode local socket
Instead just fail with EINVAL as a listening socket is never suitable
for reading from.

Fixes #4511.
2020-12-23 20:25:29 +01:00
Andreas Kling 23febb9d8e Kernel: Ptrace::handle_syscall() should return errors as KResult 2020-12-23 14:55:24 +01:00
Andreas Kling eaa63fdda5 Kernel: Don't assert on PT_PEEK with kernelspace address
We were casting the address to Userspace<T> without validating it first
which is no good and will trap an assertion soon after.

Let's catch this sooner with an ASSERT in the Userspace<T> constructor
and update the PT_PEEK and PT_POKE handlers to avoid it.

Fixes #4505.
2020-12-23 14:50:20 +01:00
Andreas Kling c25cf5fb56 Kernel: Panic if we're about to switch to a user thread with IOPL!=0
This is a crude protection against IOPL elevation attacks. If for
any reason we find ourselves about to switch to a user mode thread
with IOPL != 0, we'll now simply panic the kernel.

If this happens, it basically means that something tricked the kernel
into incorrectly modifying the IOPL of a thread, so it's no longer
safe to trust the kernel anyway.
2020-12-23 14:30:10 +01:00
Andreas Kling c77dda6827 Kernel: Make KBuffer::try_create_with_bytes() actually copy the bytes
KBuffers created with this API were actually just zero-filled instead
of being populated with the provided bytes.

Fixes #4493.
2020-12-23 00:40:11 +01:00
Andreas Kling 6bfbc5f5f5 Kernel: Don't allow modifying IOPL via sys$ptrace() or sys$sigreturn()
It was possible to overwrite the entire EFLAGS register since we didn't
do any masking in the ptrace and sigreturn syscalls.

This made it trivial to gain IO privileges by raising IOPL to 3 and
then you could talk to hardware to do all kinds of nasty things.

Thanks to @allesctf for finding these issues! :^)

Their exploit/write-up: https://github.com/allesctf/writeups/blob/master/2020/hxpctf/wisdom2/writeup.md
2020-12-22 19:38:25 +01:00
Andreas Kling b452dd13b6 Kernel: Allow sys$chmod() to modify the set-gid bit
We were incorrectly masking off the set-gid bit.

Fixes #4060.
2020-12-22 17:48:42 +01:00
Luke 72ce4abb99 Kernel/Net: Support all E1000 devices in the spec sheet
Since they're all covered by the same spec sheet, we can expect
the same code to cover most of the devices.

It can't currently differentiate between them, which would be nice to
add for determining what registers we can access.
2020-12-22 14:44:11 +01:00
Andreas Kling 2dfe5751f3 Kernel: Abort core dump generation if any substep fails
And make an effort to propagate errors out from the inner parts.
This fixes an issue where the kernel would infinitely loop in coredump
generation if the TmpFS filled up.
2020-12-22 10:09:41 +01:00
Luke 69d7a34bc2 Kernel/PCI: Add a bunch of debug output to accessors
This was useful for debugging this issue.
2020-12-22 09:24:48 +01:00
Luke 9ab9e548f4 Kernel/PCI: Create device configuration space mapping before creating a physical ID
When enumerating the hardware using MMIO mode, it would attempt to
create a physical ID first. To create a physical ID, it needs to
retrieve the capabilities of the device.

When enumerating the first device, there would be no device
configuration space mappings. Access::get_capabilities_pointer
calls PCI::read16, which in turn goes to MMIOAccess::read16_field.

MMIOAccess::read16_field attempts to get a device configuration space
and fully expects to get one. However, since this is the first device,
there are none and it crashes with an m_has_value assertion failure.

This fixes this by creating the device configuration space mapping
before creating the physical ID.

Testing with VMware Player 16.1.0.
2020-12-22 09:24:48 +01:00
Luke 0316f0627e Kernel/Net: E1000 interrupt rate register is 32-bit, not 16-bit
I looked at the spec sheet and noticed that it's 32-bit, not 16-bit.
This fixes E1000 causing an MMIO fault on VirtualBox.

Spec: https://www.intel.com/content/dam/doc/manual/pci-pci-x-family-gbe-controllers-software-dev-manual.pdf
Section 13.4.18
2020-12-22 09:03:46 +01:00
Tom 5f51d85184 Kernel: Improve time keeping and dramatically reduce interrupt load
This implements a number of changes related to time:
* If a HPET is present, it is now used only as a system timer, unless
  the Local APIC timer is used (in which case the HPET timer will not
  trigger any interrupts at all).
* If a HPET is present, the current time can now be as accurate as the
  chip can be, independently from the system timer. We now query the
  HPET main counter for the current time in CPU #0's system timer
  interrupt, and use that as a base line. If a high precision time is
  queried, that base line is used in combination with quering the HPET
  timer directly, which should give a much more accurate time stamp at
  the expense of more overhead. For faster time stamps, the more coarse
  value based on the last interrupt will be returned. This also means
  that any missed interrupts should not cause the time to drift.
* The default system interrupt rate is reduced to about 250 per second.
* Fix calculation of Thread CPU usage by using the amount of ticks they
  used rather than the number of times a context switch happened.
* Implement CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE and use it
  for most cases where precise timestamps are not needed.
2020-12-21 18:26:12 +01:00
Liav A 469f20d4ee Kernel: Introduce the StorageManagement class
The StorageManagement class has 2 roles:
1. During boot, it should find all storage controllers in the machine,
and then determine what is the boot device.
2. Later on boot, it is a registrar of all storage controllers and
storage devices. Thus, it could be used to show information about these
devices when implemented.

This change allows the user to specify a boot driver other than /dev/hda
and if it's connected in the machine - it will boot.
2020-12-21 00:19:21 +01:00
Liav A 78ae4b0530 Kernel: Change the indexing of storage devices in IDEController class
Previously, the indexing scheme was that 0 is Primary-Master, 1 is
Primary-Slave, 2 is Secondary-Master, 3 is Secondary-Slave.

Instead of merely matching between numbers to the channel & position,
the IDEController code will try to find all available drives connected to
the two channels, then it will create a Vector with nonnull RefPtr to
them. Then we take use the given index with this Vector.
2020-12-21 00:19:21 +01:00
Liav A 6a691306b5 Kernel: Add a method to gather the devices count of a Storage controller
Also, change device() method to be const.
2020-12-21 00:19:21 +01:00
Liav A e3b3805abf Kernel: Add a method to check the type of a StorageController
Also, the device method in the StorageController class is public now.
2020-12-21 00:19:21 +01:00
Liav A 28599af387 Kernel: Allow to initialize an IDE device on the secondary channel
We now use major number 3, and the minor number is set to 0 or 2 if
initialized on the primary channel, otherwise 1 or 3 on the secondary
channel.
2020-12-21 00:19:21 +01:00
Liav A 0a2b00a1bf Kernel: Introduce the new Storage subsystem
This new subsystem is somewhat replacing the IDE disk code we had with a
new flexible design.

StorageDevice is a generic class that represent a generic storage
device. It is meant that specific storage hardware will override the
interface. StorageController is a generic class that represent
a storage controller that can be found in a machine.

The IDEController class governs two IDEChannels. An IDEChannel is
responsible to manage the master & slave devices of the channel,
therefore an IDEChannel is an IRQHandler.
2020-12-21 00:19:21 +01:00
Liav A 39c1783387 Kernel: Allow to install a real IRQ handler on a spurious one
IRQ 7 and 15 on the PIC architecture are used for spurious interrupts.
IRQ 7 could also be used for LPT connection, and IRQ 15 can be used for
the secondary IDE channel. Therefore, we need to allow to install a
real IRQ handler and check if a real IRQ was asserted. If so, we handle
them in the usual way.

A note on this fix - unregistering or registering a new IRQ handler
after we already registered one in the spurious interrupt handler is
not supported yet.
2020-12-21 00:19:21 +01:00
Liav A cf0a12c68f Kernel: Add various methods to handle interrupts in the PCI subsystem
For now, we only are able to enable or disable pin based interrupts.
Later, when implemented, we could utilize MSI & MSI-X interrupts.
2020-12-21 00:19:21 +01:00
Liav A 97b36febd5 Kernel: Add a method to retrieve the Physical ID for a PCI address 2020-12-21 00:19:21 +01:00
Liav A 85b4256d10 PCI: Add list of capabilities for each device during first enumeration 2020-12-21 00:19:21 +01:00
Liav A 9d10eb473d Kernel: Add the DeviceController class in the PCI subsystem
Such device is not an IRQHandler by itself, but actually a controller of
many IRQ or MSI devices. The purpose of this class is to manage multiple
sources of interrupts.

For example, a generic ISA IDE controller controls 2 IRQ sources - 14
and 15. So, when we initialize the IDE controller, it will initialize
two IDE channels (also known as PATAChannels) to utilize IRQ 14 and 15,
respectively. NVMe with MSI-X support can theoretically handle up to
2048 interrupts.
2020-12-21 00:19:21 +01:00
Liav A afba614d68 Kernel: Don't skip if found free page to allocate from a super region
This was a bad pattern that wasn't detected because we only had one
super physical region that was initialized by MemoryManager.
2020-12-21 00:15:58 +01:00
Lenny Maiorani 765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Andreas Kling 34e9df3c5e Kernel: Randomize memory location of the dynamic loader :^)
This should make it a little bit harder for those who would mess with
our loader.
2020-12-20 18:49:24 +01:00
Andreas Kling 02ef3f6343 Kernel: Ptrace should not assert on poke in non-mapped tracee memory 2020-12-20 18:49:24 +01:00
Andreas Kling 9bf02c32c0 Kernel: Activate SUID/SGID credentials earlier in sys$execve()
Switch on the new credentials before loading the new executable into
memory. This ensures that attempts to ptrace() the program from an
unprivileged process will fail.

This covers one bug that was exploited in the 2020 HXP CTF:
https://hxp.io/blog/79/hxp-CTF-2020-wisdom2/

Thanks to yyyyyyy for finding the bug! :^)
2020-12-20 18:49:18 +01:00
Andreas Kling 5505159a94 Kernel: Silence debug spam about select() being interrupted 2020-12-20 16:06:52 +01:00
Andreas Kling e5eda151b4 Kernel: Silence debug spam when running dynamically linked programs 2020-12-20 16:06:39 +01:00
Andreas Kling d893498e57 Kernel: Use fallible KBuffer API in PerformanceEventBuffer 2020-12-19 10:23:12 +01:00
Andreas Kling 3d02597316 Kernel: Avoid a heap allocation for every outgoing TCP packet 2020-12-18 19:22:26 +01:00
Andreas Kling befabe31c9 Kernel/Net: Avoid a heap allocation for every outgoing UDP packet
We can use a stack buffer to build the UDP packet instead.
2020-12-18 19:22:26 +01:00
Andreas Kling 8cc81c2953 Kernel/Net: Make IPv4Socket::protocol_receive() take a ReadonlyBytes
The overrides of this function don't need to know how the original
packet was stored, so let's just give them a ReadonlyBytes view of
the raw packet data.
2020-12-18 19:22:26 +01:00
Andreas Kling 8e79bde2b7 Kernel: Move KBufferBuilder to the fallible KBuffer API
KBufferBuilder::build() now returns an OwnPtr<KBuffer> and can fail.
Clients of the API have been updated to handle that situation.
2020-12-18 19:22:26 +01:00
Andreas Kling d936d86332 Kernel: Add KBuffer::try_create_with_bytes()
Here's another fallible KBuffer construction API that creates a KBuffer
and populates it with a range of bytes.
2020-12-18 19:22:26 +01:00
Andreas Kling bcd2844439 TmpFS: Use fallible KBuffer API
If allocation fails, some TmpFS operations can now fail with ENOMEM.
2020-12-18 19:22:26 +01:00
Andreas Kling 47da86d136 Ext2FS: Fail the mount if BGD table cache allocation fails
Instead of asserting if we can't allocate enough memory for a BGD table
cache, just fail the mount instead.
2020-12-18 19:22:26 +01:00
Andreas Kling 8cde8ba511 Kernel: Add KBuffer::try_create_with_size()
We need to stop assuming that KBuffer allocation always succeeds.
This patch adds the following API:

- static OwnPtr<KBuffer> KBuffer::create_with_size(size_t);

All KBuffer clients should move towards using this (and handling any
failures with grace.)
2020-12-18 19:22:26 +01:00
Andreas Kling 4232874270 Kernel: Don't dump core when OOM-killing a process
Trying to generate a core dump under low memory conditions is not the
best idea.

Fixes #4428.
2020-12-18 11:22:21 +01:00
Liav A 5a146187cf Kernel: Workaround QEMU bug and initialize i8042 controller
ACPI 2 declared the third revision of FADT, that should have
IAPC_BOOT_ARCH flags in it, also to indicate if i8042 is present.
Q35 machine reports that it has FADT with revision 3, but the code
in QEMU simply ignores these flags and put zero on them no matter
the revision of FADT.
2020-12-18 10:02:14 +01:00
Liav A f36feb42bd Kernel: Return a correct name string of async write request 2020-12-17 19:36:56 +01:00
Tom c4176b0da1 Kernel: Fix Lock race causing infinite spinning between two threads
We need to account for how many shared lock instances the current
thread owns, so that we can properly release such references when
yielding execution.

We also need to release the process lock when donating.
2020-12-16 23:38:17 +01:00
Andreas Kling 4befc2c282 Kernel: Avoid null dereference in sys$profiling_disable()
If we can't create a profiling coredump object, we shouldn't try to
call write() on it.
2020-12-15 11:25:51 +01:00
Andreas Kling be0816507a Kernel: Remove harmless OOB ELF header access in core dump generation 2020-12-15 11:24:46 +01:00
Andreas Kling 28c042e46f Kernel: Make CoreDump::m_num_program_headers const
This makes it an error to assign to it after construction.
2020-12-15 11:24:46 +01:00
Andreas Kling ff8bf4db8d Kernel: Don't take LexicalPath as argument
LexicalPath is a big and heavy class that's really meant as a helper
for extracting parts of a path, not for storage or passing around.
Instead, pass paths around as strings and use LexicalPath locally
as needed.
2020-12-15 11:17:01 +01:00
Itamar 1efbbf3ac3 Kernel: Don't generate a backtrace when a process exists with non-zero
..status
2020-12-14 23:05:53 +01:00
Itamar 5392f42731 Kernel: Generate coredumps for profiled processes
These coredumps will be used by the Profile Viewer to symbolicate the
profiling samples.
2020-12-14 23:05:53 +01:00
Itamar 39890af833 Kernel: Pass full path of output coredump file to CoreDump 2020-12-14 23:05:53 +01:00
Itamar 349c6780ce LibELF: Refactor coredump notes section structures 2020-12-14 23:05:53 +01:00
Itamar 345abc3132 Kernel: Move InodeWatcher::Event into Kernel/API/InodeWatcherEvent
This allows userspace code to parse these events.
2020-12-14 23:05:53 +01:00
Itamar b4842d33bb Kernel: Generate a coredump file when a process crashes
When a process crashes, we generate a coredump file and write it in
/tmp/coredumps/.

The coredump file is an ELF file of type ET_CORE.
It contains a segment for every userspace memory region of the process,
and an additional PT_NOTE segment that contains the registers state for
each thread, and a additional data about memory regions
(e.g their name).
2020-12-14 23:05:53 +01:00
Itamar efe4da57df Loader: Stabilize loader & Use shared libraries everywhere :^)
The dynamic loader is now stable enough to be used everywhere in the
system - so this commit does just that.
No More .a Files, Long Live .so's!
2020-12-14 23:05:53 +01:00
Itamar 9ca1a0731f Kernel: Support TLS allocation from userspace
This adds an allocate_tls syscall through which a userspace process
can request the allocation of a TLS region with a given size.

This will be used by the dynamic loader to allocate TLS for the main
executable & its libraries.
2020-12-14 23:05:53 +01:00
Itamar 5b87904ab5 Kernel: Add ability to load interpreter instead of main program
When the main executable needs an interpreter, we load the requested
interpreter program, and pass to it an open file decsriptor to the main
executable via the auxiliary vector.

Note that we do not allocate a TLS region for the interpreter.
2020-12-14 23:05:53 +01:00
Andreas Kling 48589db3aa Kernel/Net: Socket connected state change should reevaluate blocks
This fixes an issue where TCP sockets could get into the Established
state too quickly and fail to unblock a subsequent sys$select() call.

This makes websites load *significantly* faster. :^)
2020-12-13 19:15:42 +01:00
Tom 1042762deb Kernel: Fix block recursion
Since the process lock is using the Lock class, re-locking the process
lock may cause another call to Thread::block. This caused some problems
with multiple blockers attempting to be used at the same time. To solve
this problem, remember if the process lock was held, and if it was then
relock after we're done with the blockers, just before returning.
2020-12-12 21:28:12 +01:00
Tom c455fc2030 Kernel: Change wait blocking to Process-only blocking
This prevents zombies created by multi-threaded applications and brings
our model back to closer to what other OSs do.

This also means that SIGSTOP needs to halt all threads, and SIGCONT needs
to resume those threads.
2020-12-12 21:28:12 +01:00
Tom 47ede74326 Kernel: Execute timer handlers outside of irq handler
This allows us to do things in timer handlers that involve e.g. scheduling,
such as using the Lock class or unblocking threads.
2020-12-12 21:28:12 +01:00
Tom 4bbee00650 Kernel: disown should unblock any potential waiters
This is necessary because if a process changes the state to Stopped
or resumes from that state, a wait entry is created in the parent
process. So, if a child process does this before disown is called,
we need to clear those entries to avoid leaking references/zombies
that won't be cleaned up until the former parent exits.

This also should solve an even more unlikely corner case where another
thread is waiting on a pid that is being disowned by another thread.
2020-12-12 21:28:12 +01:00
Tom da5cc34ebb Kernel: Fix some issues related to fixes and block conditions
Fix some problems with join blocks where the joining thread block
condition was added twice, which lead to a crash when trying to
unblock that condition a second time.

Deferred block condition evaluation by File objects were also not
properly keeping the File object alive, which lead to some random
crashes and corruption problems.

Other problems were caused by the fact that the Queued state didn't
handle signals/interruptions consistently. To solve these issues we
remove this state entirely, along with Thread::wait_on and change
the WaitQueue into a BlockCondition instead.

Also, deliver signals even if there isn't going to be a context switch
to another thread.

Fixes #4336 and #4330
2020-12-12 21:28:12 +01:00
Andreas Kling 97d789c75b Kernel: Fix null dereference when execve'ing ELF without PT_TLS header
Fixes #4387.
2020-12-11 22:59:46 +01:00
Tom 03fcd02dfd Kernel: Fix leaking Timer instances
When a Timer is queued we add a reference, so whenever we remove
a timer or fire it we should drop that reference.

Fixes #4382
2020-12-11 19:33:15 +01:00
Tom 766db673c1 Kernel: Flush TLBs concurrently
Instead of flushing the TLB on the current processor first and then
notifying the other processors to do the same, notify the others
first, and while waiting on the others flush our own.
2020-12-02 23:49:52 +01:00
Tom 5e08ae4e14 Kernel: Fix counting interrupts
Move counting interrupts out of the handle_interrupt method so that
it is done in all cases without the interrupt handler having to
implement it explicitly.

Also make the counter an atomic value as e.g. the LocalAPIC interrupts
may be triggered on multiple processors simultaneously.

Fixes #4297
2020-12-02 23:19:59 +01:00
Tom 12cf6f8650 Kernel: Add CLOCK_REALTIME support to the TimerQueue
This allows us to use blocking timeouts with either monotonic or
real time for all blockers. Which means that clock_nanosleep()
now also supports CLOCK_REALTIME.

Also, switch alarm() to use CLOCK_REALTIME as per specification.
2020-12-02 13:02:04 +01:00
Tom 4c1e27ec65 Kernel: Use TimerQueue for SIGALRM 2020-12-02 13:02:04 +01:00
Tom 601a688b6f Kernel: TimerQueue::cancel_timer needs to wait if timer is executing
We need to be able to guarantee that a timer won't be executing after
TimerQueue::cancel_timer returns. In the case of multiple processors
this means that we may need to wait while the timer handler finishes
execution on another core.

This also fixes a problem in Thread::block and Thread::wait_on where
theoretically the timer could execute after the function returned
and the Thread disappeared.
2020-12-02 13:02:04 +01:00
Tom 1f86d88dc4 Kernel: Don't assert if we can't deliver a signal due to thread state
Fixes an assertion found in #3990
2020-12-01 16:09:15 +01:00
Ben Wiederhake 2b3113cd2a Meta: Fix ACPI_DEBUG, and always build on CI 2020-12-01 11:06:53 +01:00
Andrew Kaster 3f808b0dda LibELF+Kernel: Validate program headers in Image::parse
This should catch more malformed ELF files earlier than simply
checking the ELF header alone. Also change the API of
validate_program_headers to take the interpreter_path by pointer. This
makes it less awkward to call when we don't care about the interpreter,
and just want the validation.
2020-12-01 09:58:21 +01:00
Tom 78f1b5e359 Kernel: Fix some problems with Thread::wait_on and Lock
This changes the Thread::wait_on function to not enable interrupts
upon leaving, which caused some problems with page fault handlers
and in other situations. It may now be called from critical
sections, with interrupts enabled or disabled, and returns to the
same state.

This also requires some fixes to Lock. To aid debugging, a new
define LOCK_DEBUG is added that enables checking for Lock leaks
upon finalization of a Thread.
2020-12-01 09:48:34 +01:00
Tom 9e32d79e02 Kernel: Fix leaking a reference on thread creation
New Thread objects should be adopted into a RefPtr upon creation.
If creating a thread failed (e.g. out of memory), releasing the RefPtr
will destruct the partially created object, but in the successful case
the thread will add an additional reference that it keeps until it
finishes execution. Adopting will drop it to 1 when returning from
create_thread, or 0 if the thread could not be fully constructed.
2020-12-01 09:26:37 +01:00
Tom 3bda458735 Kernel: Lock should keep a reference to whoever holds the lock
Fixes a crash reported in #3990
2020-11-30 13:17:02 +01:00
Tom 046d6855f5 Kernel: Move block condition evaluation out of the Scheduler
This makes the Scheduler a lot leaner by not having to evaluate
block conditions every time it is invoked. Instead evaluate them as
the states change, and unblock threads at that point.

This also implements some more waitid/waitpid/wait features and
behavior. For example, WUNTRACED and WNOWAIT are now supported. And
wait will now not return EINTR when SIGCHLD is delivered at the
same time.
2020-11-30 13:17:02 +01:00
Tom 6a620562cc Kernel: Allow passing a thread argument for new kernel threads
This adds the ability to pass a pointer to kernel thread/process.
Also add the ability to use a closure as thread function, which
allows passing information to a kernel thread more easily.
2020-11-30 13:17:02 +01:00
Tom 6cb640eeba Kernel: Move some time related code from Scheduler into TimeManagement
Use the TimerQueue to expire blocking operations, which is one less thing
the Scheduler needs to check on every iteration.

Also, add a BlockTimeout class that will automatically handle relative or
absolute timeouts as well as overriding timeouts (e.g. socket timeouts)
more consistently.

Also, rework the TimerQueue class to be able to fire events from
any processor, which requires Timer to be RefCounted. Also allow
creating id-less timers for use by blocking operations.
2020-11-30 13:17:02 +01:00
Luke 72abf3491b LibCrypto: Require intent parameter in CTR constructor
This was preventing clang from building.
2020-11-29 20:22:56 +01:00
Tom 2b78b17926 Kernel: Enable VMWareBackdoor immediately at boot
Rather than waiting until we get the first mouse packet, enable the
absolute mode immediately. This avoids having to click first to be
able to move the mouse.
2020-11-26 10:00:01 +01:00
Andreas Kling 76308c2e1f Kernel: Reduce ByteBuffer thrashing in inode block list generation
Instead of creating and destroying a new ByteBuffer for every block we
process during block list generation, just use stack memory instead.
2020-11-24 21:29:08 +01:00
Tom 68abd1cb29 Kernel: Fix SharedBuffer reference counting on fork
We need to not only add a record for a reference, but we need
to copy the reference count on fork as well, because the code
in the fork assumes that it has the same amount of references,
still.

Also, once all references are dropped when a process is disowned,
delete the shared buffer.

Fixes #4076
2020-11-24 21:26:39 +01:00
Andreas Kling 5f2f31861c Kernel: Use a doubly-linked list for the BlockBasedFS cache
This makes misses in the BlockBasedFS's LRU block cache faster by
storing the cache entries in one of two doubly-linked list.

Dirty and clean cache entries are kept in two separate lists, and
move between them when their state changes. This can probably be
improved upon further.
2020-11-24 16:42:01 +01:00
Andreas Kling 3e3a72f2a2 Ext2FS: Oops, fix forgotten assignment in Ext2FSInode::resize()
If the inode's block list cache is empty, we forgot to assign the
result of computing the block list. The fact that this worked anyway
makes me wonder when we actually don't have a cache..

Thanks to szyszkienty for spotting this! :^)
2020-11-24 16:16:09 +01:00
Andreas Kling a6a3c20071 Kernel: Add a fast lookup table to the BlockBasedFS disk cache
Instead of doing a linear scan of the entire cache when doing a lookup,
we now have a nice O(1) HashMap in front of the cache.

The cache miss case can still be improved, this patch really only helps
the cache hit case.

This dramatically improves cached filesystem I/O. :^)
2020-11-24 13:40:54 +01:00
Andreas Kling 20205708b9 Ext2FS: Use cached inode block list in resize() if available
If we have already cached the block list of an Ext2FSInode, we can save
a lot of time by not regenerating it.
2020-11-24 13:40:45 +01:00
Andreas Kling 541579bc04 Kernel: Remove unnecessary SmapDisablers in FileDescription
Since we're using UserOrKernelBuffers, SMAP will be automatically
disabled when we actually access the buffer later on. There's no need
to disable it wholesale across the entire read/write operations.
2020-11-24 11:26:40 +01:00
Sergey Bugaev 098070b767 Kernel: Add unveil('b')
This is a new "browse" permission that lets you open (and subsequently list
contents of) directories underneath the path, but not regular files or any other
types of files.
2020-11-23 18:37:40 +01:00
Tom 97b3035c14 Kernel: Don't resume thread into Running state directly on SIGCONT
We should never resume a thread by directly setting it to Running state.
Instead, if a thread was in Running state when stopped, record the state
as Runnable.

Fixes #4150
2020-11-23 18:33:19 +01:00
Andreas Kling dfce9051fa ProcFS: Take the "all inodes" lock when generating /proc/inodes
Otherwise the kernel asserts.
2020-11-23 16:19:30 +01:00
Andreas Kling 086522537e Kernel: Don't leak ref on executable inode in sys$execve()
We were leaking a ref on the executed inode in successful calls to
sys$execve(). This meant that once a binary had ever been executed,
it was impossible to remove it from the file system.

The execve system call is particularly finicky since the function
does not return normally on success, so extra care must be taken to
ensure nothing is kept alive by stack variables.

There is a big NOTE comment about this, and yet the bug still got in.
It would be nice to enforce this, but I'm unsure how.
2020-11-23 16:08:42 +01:00
Andreas Kling bb9c705fc2 Ext2FS: Move some EXT2_DEBUG logging behind EXT2_VERY_DEBUG
This makes the build actually somewhat usable with EXT2_DEBUG. :^)
2020-11-23 16:08:42 +01:00
Andreas Kling 1951dfa46a Kernel: Convert dbg() to dbgln() in Syscall.cpp 2020-11-23 16:08:42 +01:00
Andreas Kling df758a5a51 Ext2FS: Clear out the direct block list when an inode is resized to 0
e2fsck was complaining about blocks being allocated in an inode's list
of direct blocks while at the same time being free in the block bitmap.

It was easy to reproduce by creating a file with non-zero length and
then truncating it. This fixes the issue by clearing out the direct
block list when resizing a file to 0.
2020-11-23 14:08:50 +01:00
Tom a89648e159 Kernel: Inherit shared buffers when forking
We need to create a reference for the new PID for each shared buffer
that the process had a reference to. If the process subsequently
get replaced through exec, those references will be dropped again.
But if exec for some reason fails then other code, such as global
destructors could still expect having access to them.

Fixes #4076
2020-11-23 09:39:32 +01:00
Andreas Kling 94ff04b536 Kernel: Make CLOCK_MONOTONIC respect the system tick frequency
The time returned by sys$clock_gettime() was not aligned with the delay
calculations in sys$clock_nanosleep(). This patch fixes that by taking
the system's ticks_per_second value into account in both functions.

This patch also removes the need for Thread::sleep_until() and uses
Thread::sleep() for both absolute and relative sleeps.

This was causing the nesalizer emulator port to sleep for a negative
amount of time at the end of each frame, making it run way too fast.
2020-11-22 17:20:58 +01:00
Lenny Maiorani bdf3baa8ac MACAddress: AK::Array as member variable instead of C-array
Problem:
- C-style arrays do not automatically provide bounds checking and are
  less type safe overall.
- `__builtin_memcmp` is not a constant expression in the current gcc.

Solution:
- Change private m_data to be AK::Array.
- Eliminate constructor from C-style array.
- Change users of the C-style array constructor to use the default
  constructor.
- Change `operator==()` to be a hand-written comparison loop and let
  the optimizer figure out to use `memcmp`.
2020-11-20 21:18:14 +01:00
Tom 53cffb5ad9 Kernel: Fix mouse lag when VMWareBackdoor absolute mode is enabled
We won't be receiving full PS/2 mouse packets when the VMWareBackdoor
absolute mouse mode is enabled. So, read just one byte every time
and retrieve the latest mouse packet from VMWareBackdoor immediately.

Fixes #4086
2020-11-14 22:09:48 +01:00
Tom 13383f3267 Revert "Kernel: Keep reading from i8042 until the buffer is empty"
This reverts commit 467f6c74a4.
2020-11-14 22:09:48 +01:00
Andreas Kling 467f6c74a4 Kernel: Keep reading from i8042 until the buffer is empty
Otherwise we might not drain the mouse buffer until the next IRQ.
2020-11-14 17:20:17 +01:00
Andreas Kling abe9cec612 TmpFS: Set the root inode's timestamp to the current time
cc @bcoles :^)
2020-11-14 10:44:47 +01:00
Tom e445ff670d Kernel: Implement an asynchronous device request stack
This allows issuing asynchronous requests for devices and waiting
on the completion of the request. The requests can cascade into
multiple sub-requests.

Since IRQs may complete at any time, if the current process is no
longer the same that started the process, we need to swich the
paging context before accessing user buffers.

Change the PATA driver to use this model.
2020-11-12 18:04:30 +01:00
Tom 91db31880f Kernel: Add I8042Controller to detect and manage PS/2 devices
Rework the PS/2 keyboard and mouse drivers to use a common 8042
controller driver. Also, reset and reconfigure the 8042 controller
as they are not guaranteed to be in the state that we expect.
2020-11-12 18:04:16 +01:00
Tom e1c27c16d8 Kernel: Assume 8042 controller is present if ACPI FADT revision <= 1
This field wasn't specified until revision 2 and should be assumed to
be set on older versions.
2020-11-12 18:04:16 +01:00
Tom 6b97118e89 Kernel: Fix race during thread destruction if it is preempted
This fixes a lot of crashes in Bochs, which is more likely to
preempt thread destruction.
2020-11-12 10:18:16 +01:00
Tom dc9ddf8104 Kernel: Fix deadlock when unicasting/broadcasting SMP message
When two processors send each others a SMP message at the same time
they need to process messages while waiting for delivery of the
message they just sent, or they will deadlock.
2020-11-11 12:27:25 +01:00
Tom 3ee7c21fae Kernel: Implement capturing stack trace on a different CPU
When trying to get a stack trace of a thread on another CPU we send
a SMP message to that processor to capture the stack trace for us.
2020-11-11 12:27:25 +01:00
Tom 5b38132e3c Kernel: Protect the PageDirectory from concurrent access 2020-11-11 12:27:25 +01:00
Tom 2b25a89ab5 Kernel: Add locks around RangeAllocator
We need to keep multiple processors from changing it at the same time.
2020-11-11 12:27:25 +01:00
Tom 66f46d03e4 Kernel: Minor Lock optimization 2020-11-11 12:27:25 +01:00
Tom b4c9e85056 Kernel: Minor SpinLock improvements 2020-11-11 12:27:25 +01:00
Tom e26e0445b5 Kernel: Make m_halt_requested an atomic variable
We need to make sure the change to this variable is visible to all
processors instantly.
2020-11-11 12:27:25 +01:00
Tom a14884dd33 Kernel: Lock needs to call Processor::wait_check while looping
We need to process SMP messages while looping.
2020-11-11 12:27:25 +01:00
Tom 75f61fe3d9 AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they
can safely be used in the Kernel. This includes obtaining a strong
reference from a weak reference, which now requires an explicit
call to WeakPtr::strong_ref(). Another major change is that
Weakable::make_weak_ref() may require the explicit target type.
Previously we used reinterpret_cast in WeakPtr, assuming that it
can be properly converted. But WeakPtr does not necessarily have
the knowledge to be able to do this. Instead, we now ask the class
itself to deliver a WeakPtr to the type that we want.

Also, WeakLink is no longer specific to a target type. The reason
for this is that we want to be able to safely convert e.g. WeakPtr<T>
to WeakPtr<U>, and before this we just reinterpret_cast the internal
WeakLink<T> to WeakLink<U>, which is a bold assumption that it would
actually produce the correct code. Instead, WeakLink now operates
on just a raw pointer and we only make those constructors/operators
available if we can verify that it can be safely cast.

In order to guarantee thread safety, we now use the least significant
bit in the pointer for locking purposes. This also means that only
properly aligned pointers can be used.
2020-11-10 19:11:52 +01:00
Nico Weber 323e727a4c Kernel+LibC: Add adjtime(2)
Most systems (Linux, OpenBSD) adjust 0.5 ms per second, or 0.5 us per
1 ms tick. That is, the clock is sped up or slowed down by at most
0.05%.  This means adjusting the clock by 1 s takes 2000 s, and the
clock an be adjusted by at most 1.8 s per hour.

FreeBSD adjusts 5 ms per second if the remaining time adjustment is
>= 1 s (0.5%) , else it adjusts by 0.5 ms as well. This allows adjusting
by (almost) 18 s per hour.

Since Serenity OS can lose more than 22 s per hour (#3429), this
picks an adjustment rate up to 1% for now. This allows us to
adjust up to 36s per hour, which should be sufficient to adjust
the clock fast enough to keep up with how much time the clock
currently loses. Once we have a fancier NTP implementation that can
adjust tick rate in addition to offset, we can think about reducing
this.

adjtime is a bit old-school and most current POSIX-y OSs instead
implement adjtimex/ntp_adjtime, but a) we have to start somewhere
b) ntp_adjtime() is a fairly gnarly API. OpenBSD's adjfreq looks
like it might provide similar functionality with a nicer API. But
before worrying about all this, it's probably a good idea to get
to a place where the kernel APIs are (barely) good enough so that
we can write an ntp service, and once we have that we should write
a way to automatically evaluate how well it keeps the time adjusted,
and only then should we add improvements ot the adjustment mechanism.
2020-11-10 19:03:08 +01:00
Jesse Buhagiar 940380c986 Kernel: Prevent unveil returning ENOENT with cpath permissions
This addresses the issue first enountered in #3644. If a path is
first unveiled with "c" permissions, we should NOT return ENOENT
if the node does not exist on the disk, as the program will most
likely be creating it at a later time.
2020-11-10 09:53:18 +01:00
Nico Weber c9c3667ea7 Kernel: Update TimeManagement::m_epoch_time directly in increment_time_since_boot 2020-11-07 18:28:35 +01:00
Andreas Kling 1da828b8bf Ext2FS: Zero out inode metadata when deleting them
This isn't strictly necessary but it seems like a reasonable thing
to be doing. Note that we still populate the dtime field with the
time of deletion.
2020-11-07 17:48:22 +01:00
Andreas Kling bab24ce34c Ext2FS: Deallocate block list meta blocks when freeing an inode
When computing the list of blocks to deallocate when freeing an inode,
we would stop collecting blocks after reaching the inode's block count.
Since we're getting rid of the inode, we need to also include the meta
blocks used by the on-disk block list itself.
2020-11-07 16:45:03 +01:00
Tom d5bb5d109b Kernel: Fix HPET timer not firing in Bochs
* Change the register structures to use the volatile keyword explicitly
  on the register values. This avoids accidentally omitting it as any
  access will be guaranteed volatile.
* Don't assume we can read/write 64 bit value to the main counter and
  the comparator. Not all HPET implementations may support this. So,
  just use 32 bit words to access the registers. This ultimately works
  around a bug in Bochs 2.6.11 that loses 32 bits of a 64 bit write to
  a timer's comparator register (it internally writes one half and
  clears the Tn_VAL_SET_CNF bit, and then because it's cleared it
  fails to write the second half).
* Properly calculate the tick duration in calculate_ticks_in_nanoseconds
* As per specification, changing the frequency of one periodic timer
  requires a restart of all periodic timers as it requires the main
  counter to be reset.
2020-11-06 15:51:56 +01:00
Andreas Kling 501cef2bd7 Revert "Kernel: Implement an asynchronous device request stack"
This reverts commit 2fd5ce1eb0.

This broke booting without SMP. (PR was #3921)
2020-11-04 21:25:26 +01:00
Tom 2fd5ce1eb0 Kernel: Implement an asynchronous device request stack
This allows issuing asynchronous requests for devices and waiting
on the completion of the request. The requests can cascade into
multiple sub-requests.

Since IRQs may complete at any time, if the current process is no
longer the same that started the process, we need to swich the
paging context before accessing user buffers.

Change the PATA driver to use this model.
2020-11-04 21:21:37 +01:00
Tom 96081010dc Kernel: Remove dead code from BlockDevice 2020-11-04 21:21:37 +01:00
Tom 28b109688b Kernel: Defer kmalloc heap contraction
Because allocating/freeing regions may require locks that need to
wait on other processors for completion, this needs to be delayed
until it's safer. Otherwise it is possible to deadlock because we're
holding the global heap lock.
2020-11-04 21:21:37 +01:00
Tom b9a97ff81f Kernel: Add mechanism to queue deferred function calls
Function calls that are deferred will be executed before a thread
enters a pre-emptable state (meaning it is not in a critical section
and it is not in an irq handler). If it is not already in such a
state, it will be called immediately.

This is meant to be used from e.g. IRQ handlers where we might want
to block a thread until an interrupt happens.
2020-11-04 21:21:37 +01:00
Andreas Kling 5e164052f6 AK+Kernel: Escape JSON keys & values
Grab the escaping logic from JSON string value serialization and use
it for serializing all keys and values.

Fixes #3917.
2020-11-02 12:56:36 +01:00
Andreas Kling a28f29c82c Kernel+LibC: Don't allow a directory to become a subdirectory of itself
If you try to do this (e.g "mv directory directory"), sys$rename() will
now fail with EDIRINTOSELF.

Dr. POSIX says we should return EINVAL for this, but a custom error
code allows us to print a much more helpful error message when this
problem occurs. :^)
2020-11-01 19:21:19 +01:00
Tom 13aa3d2d62 Kernel: Flush TLB when quick-mapping PD/PT that was mapped on other CPU
If a PD/PT was quick-mapped by another CPU we still need to flush the
TLB on the current CPU.

Fixes #3885
2020-11-01 18:48:36 +01:00
Tom 656ffe36f2 Kernel: kmalloc_eternal should align pointers 2020-11-01 18:47:01 +01:00
Tom 7a4fb5deef Kernel: Don't remap IOAPIC registers every time we try to read/write
Remapping these registers every time we try to read from or write to
them causes a lot of SMP broadcasts and a lot of other overhead.
This improves boot time noticeably.
2020-11-01 10:30:20 +01:00
Liav A 4007ba5137 Kernel: Reduce code duplication in the PCI IO access read helpers
We just call the early helpers as they do the same thing like the IO
access helpers.
2020-11-01 10:19:17 +01:00
Liav A 6131048a5f Kernel: Map PCI devices only once during boot
Instead of mapping a 4KB region to access device configuration space
each time we call one of the PCI helpers, just map them once during
the boot process.
Then, if we request to access one of those devices, we can ask the
PCI subsystem to give us the virtual address where the device's
configuration space is mapped.
2020-11-01 10:19:17 +01:00
Andreas Kling e06d8d94da IPv4: Include IP headers when receiving from a raw socket
We were stripping the L3 headers from packets received on raw sockets.
This didn't match what other systems do, so let's adjust our behavior.

Thanks to @SpencerCDixon for noticing this! :^)
2020-10-31 13:56:21 +01:00
Tom 180cc85d79 Kernel: Report more accurate ticks per second for APIC timer 2020-10-29 22:26:08 +01:00
Tom d076b00248 Kernel: Fix APIC timer frequency
The APIC current count register decrements on each clock tick.
Fixes the APIC timer firing much less frequently than it should be.
2020-10-29 22:10:20 +01:00
Tom 328e481ee9 Kernel: Halt all processors on assertion failure 2020-10-26 08:57:25 +01:00
Tom 3ffdaabe10 Kernel: Only consider scheduler Running threads if they're the current
There will be as many threads in Running state as there are CPUs.
Only consider a thread in that state if it is the current thread
already.
2020-10-26 08:57:25 +01:00
Tom 1e2e3eed62 Kernel: Fix a few deadlocks with Thread::m_lock and g_scheduler_lock
g_scheduler_lock cannot safely be acquired after Thread::m_lock
because another processor may already hold g_scheduler_lock and wait
for the same Thread::m_lock.
2020-10-26 08:57:25 +01:00
Tom 8c764319ad Kernel: Various APIC timer fixes 2020-10-26 08:57:25 +01:00
Tom b8ad4932a9 Kernel: Fix race condition waiting for IPI while other CPU requested halt
It's possible that we broadcast an IPI message right at the same time
another processor requests a halt. Rather than spinning forever waiting
for that message to be handled, check if we should halt while waiting.
2020-10-26 08:57:25 +01:00
Tom fe615e601a Kernel: Set up and calibrate APIC timer, and enable timer on all CPUs
This enables the APIC timer on all CPUs, which means Scheduler::timer_tick
is now called on all CPUs independently. We still don't do anything on
the APs as it instantly crashes due to a number of other problems.
2020-10-25 21:18:35 +01:00
AnotherTest dd60fe4d37 Kernel: Optionally take some arguments to pass to the init program
This makes it possible to start _everything_ under UserspaceEmulator, by
setting `init_args` to `--report-to-debug,/bin/SystemServer` and `init`
to `/bin/UserspaceEmulator`.
With the UE patches before this, we get to spawn WindowServer, and crash
because of FLD_RM32 (nothing tested past that) in graphical mode.
But we get a working shell in text mode :^) (and DHCPClient fails when
setting whatever settings it has received)
2020-10-25 10:13:03 +01:00
Andreas Kling a316ca0e0d TmpFS: Don't allow file names longer than NAME_MAX
Fixes #3636.
2020-10-22 18:59:00 +02:00
Andreas Kling a6aee0c097 IPv4: Take the socket lock more (fixes TCP connection to localhost)
This fixes an issue where making a TCP connection to localhost didn't
work correctly since the loopback interface is currently synchronous.
(Sending something to localhost would enqueue a packet on the same
interface and then immediately wake the network task to process that
packet.)

This was preventing the TCP handshake from working correctly with
localhost since we'd send out the SYN packet before moving to the
SynSent state. The lock is now held long enough for this operation
to be atomic.
2020-10-21 20:51:02 +02:00
Andreas Kling ce6ef54337 ICMP: Check that incoming ICMP echo requests are large enough
Otherwise, just ignore them.
2020-10-20 18:10:10 +02:00
Lenny Maiorani d1fe6a0b53
Everywhere: Redundant inline specifier on constexpr functions (#3807)
Problem:
- `constexpr` functions are decorated with the `inline` specifier
  keyword. This is redundant because `constexpr` functions are
  implicitly `inline`.
- [dcl.constexpr], §7.1.5/2 in the C++11 standard): "constexpr
  functions and constexpr constructors are implicitly inline (7.1.2)".

Solution:
- Remove the redundant `inline` keyword.
2020-10-20 18:08:13 +02:00
Andreas Kling af20b9424f Kernel: Unbreak /proc/interrupts when running with APIC
We can't assert here since these are exposed through /proc JSON.
2020-10-18 14:40:16 +02:00
Andreas Kling c7a13b7a74 Kernel: Tweak strange PAGE_ROUND_UP(1) in APIC code 2020-10-18 14:18:38 +02:00
Tom 6fbced6f4f Kernel: Ensure PhysicalRegion free page hint is within valid range
Fixes #3770
2020-10-16 17:39:42 +02:00
Itamar 26b430bee7 Kernel: Fix sys$join_thread
Previously, when we unblocked because the joinee has died, we didn't
copy its exit value back to the user.
2020-10-16 11:42:20 +02:00
Andreas Kling 1d96ecf148 Everywhere: Add missing <AK/TemporaryChange.h> includes
Don't rely on HashTable.h pulling this in.
2020-10-15 23:49:53 +02:00
Andreas Kling 65cdac1a5b Kernel+LibC: Use uintptr_t as the main type in the syscall interface 2020-10-12 19:53:25 +02:00
Andreas Kling 75d5f436bc Toolchain: Upgrade to GCC 10.2.0 2020-10-12 19:53:25 +02:00
asynts 71fd54f76b MemoryManager: Off-by-one error when collecting memory pages.
Notice that we ensured that the size is a multiple of the page size and
that there is at least one page there, otherwise, this change would be
invalid.

We create an empty region and then expand it:

    // First iteration.
    m_user_physical_regions.append(PhysicalRegion::create(addr, addr));

    // Following iterations.
    region->expand(region->lower(), addr);

So if the memory region only has one page, we would end up with an empty
region. Thus we need to do one more iteration.
2020-10-12 19:39:00 +02:00
Andreas Kling ac8fe3d062 Kernel: Remove FIXME about unsurfaced error and log something
If something goes wrong when trying to write out a perfcore file during
process finalization, there's nowhere to report an error to, other than
the debug log. So write it to the debug log.
2020-10-10 23:47:53 +02:00
Lenny Maiorani 44d4423229 TCP: Remove unnecessarily defined constructor and destructor
Problem: Defining the destructor violates the "rule of 0" and prevents
the copy/move constructor/assignment operators from being provided by
the compiler.

Solution: Change the constructor and destructor to be the default
compiler-provided definition.
2020-10-08 10:01:10 +02:00
Nico Weber 8a01be4849 Kernel: Add some CPU feature flags related to TSC
In case we want to rely more on TSC in time keeping in the future, idk

This adds:

- RDTSCP, for when the RDTSCP instruction is available

- CONSTANT_TSC, for when the TSC has a constant frequency, invariant
  under things like the CPU boosting its frequency.

- NONSTOP_TSC, for when the TSC doesn't pause when the CPU enters
  sleep states.

AMD cpus and newer intel cpus set the INVSTC bit (bit 8 in edx of
extended cpuid 0x8000000008), which implies both CONSTANT_TSC and
NONSTOP_TSC. Some older intel processors have CONSTANT_TSC but not
NONSTOP_TSC; this is set based on cpu model checks.

There isn't a ton of documentation on this, so this follows Linux
terminology and http://blog.tinola.com/?e=54

CONSTANT_TSC:
39b3a79105

NONSTOP_TSC:
40fb17152c

qemu disables invtsc (bit 8 in edx of extended cpuid 0x8000000008)
by default even if the host cpu supports it. It can be enabled by
running with `SERENITY_QEMU_CPU=host,migratable=off` set.
2020-10-08 10:00:39 +02:00
asynts 2be7736010 Kernel: Add KBufferBuilder::appendff.
Why does this class exist anyways? What is wrong with using
StringBuilder?
2020-10-08 09:59:55 +02:00
Lenny Maiorani 9eef5fc446 SinglyLinkedList: Remove unused includes
Several files include `AK/SinglyLinkedList.h` without using
it. Removing it to simplify.
2020-10-08 09:54:41 +02:00
Andreas Kling eeffd5be07 Ext2FS: Fix block allocation ignoring the very last block group
The block group indices are 1-based for some reason. Because of that,
we were forgetting to check in the very last block group when doing
block allocation. This caused block allocation to fail even when the
superblock indicated that we had free blocks.

Fixes #3674.
2020-10-07 13:42:17 +02:00
Linus Groh bcfc6f0c57 Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
Tom 87f20f704c Kernel: Add checks for is_trivially_copyable to copy_to/from_user
If we're copying structures, we only ever want to copy trivially
copyable structures.
2020-10-02 15:38:07 +02:00
Andreas Kling b058852c62 Kernel: Fix overly eager fd closing in sys$execve()
When obeying FD_CLOEXEC, we don't need to explicitly call close() on
all the FileDescriptions. We can just clear them out from the process
fd table. ~FileDescription() will call close() anyway.

This fixes an issue where TelnetServer would shut down accepted sockets
when exec'ing a shell for them. Since the parent process still has the
socket open, we should not force-close it. Just let go.
2020-09-28 22:40:44 +02:00
Andreas Kling 0930e2323b Kernel: Remove unnecessary capture in sys$execve() 2020-09-28 22:24:27 +02:00
Luke d79194d87f Kernel: Return early in create_inode if name is too long 2020-09-28 21:52:31 +02:00
Benoît Lormeau f0f6b09acb AK: Remove the ctype adapters and use the actual ctype functions instead
This finally takes care of the kind-of excessive boilerplate code that were the
ctype adapters. On the other hand, I had to link `LibC/ctype.cpp` to the Kernel
(for `AK/JsonParser.cpp` and `AK/Format.cpp`). The previous commit actually makes
sense now: the `string.h` includes in `ctype.{h,cpp}` would require to link more LibC
stuff to the Kernel when it only needs the `_ctype_` array of `ctype.cpp`, and there
wasn't any string stuff used in ctype.
Instead of all this I could have put static derivatives of `is_any_of()` in the
concerned AK files, however that would have meant more boilerplate and workarounds;
so I went for the Kernel approach.
2020-09-27 21:15:25 +02:00
Tom 838d9fa251 Kernel: Make Thread refcounted
Similar to Process, we need to make Thread refcounted. This will solve
problems that will appear once we schedule threads on more than one
processor. This allows us to hold onto threads without necessarily
holding the scheduler lock for the entire duration.
2020-09-27 19:46:04 +02:00
Luke 721788943d Kernel: Implement _SC_OPEN_MAX 2020-09-27 01:02:11 +02:00
Luke ec136db592 Kernel: Return ENOPROTOOPT instead of asserting on unimplemented levels in getsockopt 2020-09-27 01:02:11 +02:00
Tom 69a9c78783 Kernel: Allow killing queued threads
We need to dequeue and wake threads that are waiting if the process
terminates.

Fixes #3603 without the HackStudio fixes in #3606.
2020-09-26 20:03:16 +02:00
Tom 1727b2d7cd Kernel: Fix thread joining issues
The thread joining logic hadn't been updated to account for the subtle
differences introduced by software context switching. This fixes several
race conditions related to thread destruction and joining, as well as
finalization which did not properly account for detached state and the
fact that threads can be joined after termination as long as they're not
detached.

Fixes #3596
2020-09-26 13:03:13 +02:00
Ben Wiederhake 64cc3f51d0 Meta+Kernel: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Andreas Kling b99eaad693 Kernel: Remove a whole bunch of unnecessary includes in Process.cpp 2020-09-24 10:49:43 +02:00
asynts e5497a326a AK: Add StringBuilder::appendff using the new format.
StringBuilder::appendf was already used, thus this name. If we some day
replace all usages of printf, we could rename this method.
2020-09-22 15:06:40 +02:00
asynts 4fcdc19b14 AK: Remove strtoull dependency from format.
This function is not avaliable in the kernel.

In the future it would be nice to have some sort of <charconv> header
that does this for all integer types and then call it in strtoull and et
cetera.

The difference would be that this function say 'from_chars' would return
an Optional and not just interpret anything invalid as zero.
2020-09-22 15:06:40 +02:00
Liav A d9863e0b6c Kernel: Remove unnecessary class member in UHCIController
The m_address member is not needed, since PCI::Device already has one.
2020-09-19 18:39:09 +02:00
Liav A 82b0171812 Kernel: Fix assertion statement in GenericInterruptHandler
We need to assert if interrupts are not disabled when changing the
interrupt number of an interrupt handler.
Before this fix, any change like this would lead to a crash,
because we are using InterruptDisabler in IRQHandler::change_irq_number.
2020-09-19 16:44:40 +02:00