Commit graph

4799 commits

Author SHA1 Message Date
Liav A b4e230a7bb Kernel/Graphics: Assert if trying to initialize with the wrong driver 2021-07-03 16:28:49 +02:00
Liav A 053a832fac Kernel: Simplify graphics initialization somewhat
We use a switch-case statements to ensure we try to find the best
suitable driver for a specific graphics card. In case we don't find
such, we use the default statement to initialize the graphics card as a
generic VGA adapter, if the adapter is VGA compatible.

If we couldn't initialize the driver, we don't touch this adapter
anymore.

Also, GraphicsDevice should not be tied to a PCI::Address member, as it
can be theortically be used with other buses (e.g. ISA cards).
2021-07-03 16:28:49 +02:00
Hediadyoin1 d12e14fa95 Userland: Respect red-zone for signal handlers
We were building with red-zone before, but were not accounting for it on
signal handler entries. This should fix that.

Also shorten the stack alignment calculations for this.
2021-07-03 13:20:04 +02:00
Gunnar Beutner 52f9aaa823 Kernel: Use the GS segment for the per-CPU struct
Right now we're using the FS segment for our per-CPU struct. On x86_64
there's an instruction to switch between a kernel and usermode GS
segment (swapgs) which we could use.

This patch doesn't update the rest of the code to use swapgs but it
prepares for that by using the GS segment instead of the FS segment.
2021-07-02 23:33:17 +02:00
Daniel Bertalan 42d197cde7 Kernel: Fix miscellaneous warnings when building with Clang
These small changes fix the remaining warnings that come up during
kernel compilation with Clang. These specific fixes were for benign
things: unused lambda captures and braces around scalar initializers.
2021-07-03 01:56:31 +04:30
Daniel Bertalan fda9f394d1 Kernel: Fix always-true comparison warnings 2021-07-03 01:56:31 +04:30
Daniel Bertalan b9f30c6f2a Everywhere: Fix some alignment issues
When creating uninitialized storage for variables, we need to make sure
that the alignment is correct. Fixes a KUBSAN failure when running
kernels compiled with Clang.

In `Syscalls/socket.cpp`, we can simply use local variables, as
`sockaddr_un` is a POD type.

Along with moving the `alignas` specifier to the correct member,
`AK::Optional`'s internal buffer has been made non-zeroed by default.
GCC emitted bogus uninitialized memory access warnings, so we now use
`__builtin_launder` to tell the compiler that we know what we are doing.
This might disable some optimizations, but judging by how GCC failed to
notice that the memory's initialization is dependent on `m_has_value`,
I'm not sure that's a bad thing.
2021-07-03 01:56:31 +04:30
Daniel Bertalan 45a82b2a5b Kernel: Fix struct forward declared as class 2021-07-03 01:56:31 +04:30
Daniel Bertalan b97a00d4b1 Kernel: Add missing override specifiers
The `#pragma GCC diagnostic` part is needed because the class has
virtual methods with the same name but different arguments, and Clang
tries to warn us that we are not actually overriding anything with
these.

Weirdly enough, GCC does not seem to care.
2021-07-03 01:56:31 +04:30
Gunnar Beutner 5666809889 Kernel: Fix building the kernel with LTO
Fixes #8383.
2021-07-02 17:51:26 +02:00
Liav A 32a4a4ac19 Kernel/ProcFS: Lazily allocate all sub components of a PID folder 2021-07-02 13:16:12 +02:00
Liav A 6282df3066 Kernel/ACPI: Don't ask from TypedMapping to map 2 pages if unnecessary 2021-07-02 13:16:12 +02:00
Liav A 4499b0418c Kernel/TypedMapping: Round up length with offset_in_page
Fixes #6948.
2021-07-02 13:16:12 +02:00
Liav A 3344f91fc4 Kernel/ProcFS: Clean dead processes properly
Now we use WeakPtrs to break Ref-counting cycle. Also, we call the
prepare_for_deletion method to ensure deleted objects are ready for
deletion. This is necessary to ensure we don't keep dead processes,
which would become zombies.

In addition to that, add some debug prints to aid debug in the future.
2021-07-02 13:16:12 +02:00
Liav A 5073bf8e75 Kernel/USB: Move the USB components as a subfolder to the Bus directory 2021-07-02 13:16:12 +02:00
Liav A 6568bb47cb Kernel/PCI: Move the PCI components as a subfolder to the Bus directory 2021-07-02 13:16:12 +02:00
Gunnar Beutner db334b50d0 Kernel: Don't byteswap the ISR number on interrupt entry
Let's just add the padding before we jump to interrupt_common_asm_entry.
2021-07-01 23:36:17 +02:00
Brian Gianforcaro 60efe18a31 Kernel: Handle OOM when allocating Thread FPUState
Move FPUState allocation to Thread::try_create so that allocation
failure can be observed properly by the caller.
2021-07-01 22:43:48 +02:00
Hendiadyoin1 3694b8b690 Kernel: Only deallocate memory when alloc succeeds
Also make AllocationHeader acquisition from pointers more verbose
2021-07-01 17:32:34 +02:00
Hendiadyoin1 5f6c513610 Kernel: Add support for 64-bit unaligned Mem-ops
Also let the compiler enforce the size and type restrictions
2021-07-01 17:32:34 +02:00
Hendiadyoin1 6b9cf8376e Kernel: Remove not needed comment in Processor.h 2021-07-01 17:32:34 +02:00
Gunnar Beutner 16b9a2d2e1 Kernel+LibPthread: Add support for usermode threads on x86_64 2021-07-01 17:22:22 +02:00
Gunnar Beutner 93c741018e Kernel+LibPthread: Remove m_ prefix for public members 2021-07-01 17:22:22 +02:00
Hendiadyoin1 90cd11fa8c Kernel: Support starting up secondary processors on x86_64 2021-07-01 10:50:00 +02:00
Gunnar Beutner fe2716df21 Kernel: Disable __thread and TLS on x86_64 for now
They're not yet properly supported.
2021-06-30 15:13:30 +02:00
Gunnar Beutner e37576440d Kernel: Fix stack alignment on x86_64
These were already properly aligned (as far as I can tell).
2021-06-30 15:13:30 +02:00
Gunnar Beutner 50839bd1f1 Kernel: Properly initialize r8-r15 for new threads on x86_64 2021-06-30 15:13:30 +02:00
Gunnar Beutner cafccb866c Kernel: Don't start usermode threads on x86_64 for now
Starting usermode threads doesn't currently work on x86_64. With this
stubbed out we can get text mode to boot though.
2021-06-30 15:13:30 +02:00
Andreas Kling 6f0e8f823b Kernel: Don't compile JsonValue & friends into the kernel 2021-06-30 11:31:12 +02:00
Max Wipfli 7405536a1a AK+Everywhere: Use mostly StringView in LexicalPath
This changes the m_parts, m_dirname, m_basename, m_title and m_extension
member variables to StringViews onto the m_string String. It also
removes the m_is_absolute member in favour of computing if a path is
absolute in the is_absolute() getter. Due to this, the canonicalize()
method has been completely rewritten.

The parts() getter still returns a Vector<String>, although it is no
longer a const reference as m_parts is no longer a Vector<String>.
Rather, it is constructed from the StringViews in m_parts upon request.
The parts_view() getter has been added, which returns Vector<StringView>
const&. Most previous users of parts() have been changed to use
parts_view(), except where Strings are required.

Due to this change, it's is now no longer allow to create temporary
LexicalPath objects to call the dirname, basename, title, or extension
getters on them because the returned StringViews will point to possible
freed memory.
2021-06-30 11:13:54 +02:00
Max Wipfli fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00
Luke 37361821dd Kernel/PCI: Keep track of the currently mapped bus in MMIO mode
There is a check in map_bus_region to make sure we don't pointlessly
remap the bus region if the previous mapping was for the same bus.
This is tracked with `m_mapped_bus`.

However, nothing was actually updating `m_mapped_bus`, and it is
initialised to 0. This means that if we start with a device on bus 0,
the read in data will be valid. If we map say bus 1 then bus 0 again,
the map for bus 0 will now be ignored and invalid data will be read in.

Fixed by updating `m_mapped_bus` with the currently mapped bus.
2021-06-30 11:13:04 +02:00
Luke 02810f15b1 Kernel/PCI: Don't unmap determine_memory_mapped_bus_region after init
This can be accessed after init via lspci.
2021-06-30 11:12:44 +02:00
Andrew Kaster e821b349b2 Kernel: Give Devices without a custody a less fake absoulte_path
This hack allows self-test mode run-tests-and-shutdown.sh to give
TestProcFs a stat(2)-able /proc/self/fd/0. For some reason, when
stdin is a SerialDevice, /proc/self/fd/0 will be a symlink to the device
as expected, but, calling realpath or stat on /proc/self/fd/0 will error
out. realpath will give the string from Device::absolute_path() which
would be something like "device:4,64 (SerialDevice)". When VFS is trying
to resolve_path so that we can stat the file, it would bail out on this
fake-y path.

Change the fake path (that doesn't show up when you ls a device, nor
when checking the devices tab in SystemMonitor) from the major/minor
device number and class_name() to /dev/device_name(). There's probably
a very hairy yak standing behind this issue that was only discovered due
to the ProcFS rework.
2021-06-30 12:07:57 +04:30
Andreas Kling fd06b8b713 Kernel: ProcFS and SysFS component indices should be InodeIndex
This fixes the x86_64 kernel build. :^)
2021-06-29 23:07:02 +02:00
Andreas Kling bdc905ab93 Kernel: Make sure JSON blobs in core dumps are correctly terminated
I regressed this in 648480f715.
We have to make sure JsonObjectSerializer::finish() is called before
writing out the blob. This is done automatically when the serializer
is destroyed, so just wrap them in scopes.
2021-06-29 22:28:52 +02:00
Andreas Kling 0dbf786aed Kernel+AK: Don't compile JSON parser into the kernel
The kernel doesn't consume JSON, it only produces it. So there's no
need for the kernel to have a JSON parser built into it. :^)
2021-06-29 22:19:29 +02:00
Andreas Kling 9766fccb88 Kernel: Remove some unnecessary JSON related includes 2021-06-29 22:11:10 +02:00
Andreas Kling 648480f715 Kernel: Use JsonObjectSerializer in the core dump generation code 2021-06-29 22:07:36 +02:00
Andreas Kling 8d0cc3adc5 Kernel: Don't create a JsonArray when generating /proc/cpuinfo 2021-06-29 21:47:20 +02:00
Liav A 1f98d7d638 Kernel/ProcFS: Tighten modified time value across the filesystem objects
It didn't make any sense to hardcode the modified time of all created
inodes with "mepoch", so we should query the procfs "backend" to get
the modified time value.
Since ProcFS is dynamically changed all the time, the modified time
equals to the querying time.
This could be changed if desired, by making the modified_time()
method virtual and overriding it in different procfs-backed objects :)
2021-06-29 20:53:59 +02:00
Liav A d79d9e833e Kernel/ProcFS: Tighten permissions on the exposed objects
This is needed so we properly set the limits for different objects in
the filesystem.
2021-06-29 20:53:59 +02:00
Liav A 47149e625f Kernel/ProcFS: Split code into more separate files
Instead of using one file for the entire "backend" of the ProcFS data
and metadata, we could split that file into two files that represent
2 logical chunks of the ProcFS exposed objects:
1. Global and inter-process information. This includes all fixed data in
the root folder of the ProcFS, networking information and the bus
folder.
2. Per-process information. This includes all dynamic data about a
process that resides in the /proc/PID/ folder.

This change makes it more easier to read the code and to change it,
hence we do it although there's no technical benefit from it now :)
2021-06-29 20:53:59 +02:00
Liav A 7c87891c06 Kernel: Don't copy a Vector<FileDescriptionAndFlags>
Instead of copying a Vector everytime we need to enumerate a Process'
file descriptions, we can just temporarily lock so it won't change.
2021-06-29 20:53:59 +02:00
Liav A 12b6e69150 Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.

The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.

The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-29 20:53:59 +02:00
Liav A 1baa05d6b2 Kernel/SysFS: Add PCI exposed folder 2021-06-29 20:53:59 +02:00
Liav A 92c0dab5ab Kernel: Introduce the new SysFS
The intention is to add dynamic mechanism for notifying the userspace
about hotplug events. Currently, the DMI (SMBIOS) blobs and ACPI tables
are exposed in the new filesystem.
2021-06-29 20:53:59 +02:00
Liav A dc6defa7af Kernel: Add getters for the RSDP, XSDT/RSDT and other ACPI tables
These methods will be used with the new SysFS to expose these ACPI blobs
to userspace.
2021-06-29 20:53:59 +02:00
Liav A b8ec5449f2 Kernel: Remove DMI exposed blobs from ProcFS
This was a hack I wrote merely to allow dmidecode to find these blobs
somewhere.

These blobs are going to be part of upcoming SysFS :)
2021-06-29 20:53:59 +02:00
Daniel Bertalan 2a5d9a6944 Kernel: Fix adopt_ref_if_nonnull(new T).release_nonnull() pattern
This does the exact thing as `adopt_ref`, which is a recent addition to
AK.

Note that pointers returned by a bare new (without `nothrow`) are
guaranteed not to return null, so they can safely be converted into
references.
2021-06-29 22:57:52 +04:30