Commit Graph

5911 Commits

Author SHA1 Message Date
Eric Seifert
8924b1f532 Kernel: Allow PROT_NONE in mmap and mprotect for stack regions
To allow for userspace guard pages (ruby uses this).
Redundant since serenity creates them automatically,
but should be allowed anyway.
2021-09-23 04:14:41 +00:00
Ben Wiederhake
12247fe9b4 Kernel: Use AK::Variant default initialization where appropriate 2021-09-21 04:22:52 +04:30
Ben Wiederhake
de15a6a657 Kernel: Clean up PCI::Device namespace formatting 2021-09-20 16:00:43 +03:00
Idan Horowitz
574a1c522d Kernel: Store device class name as member of VirtIO devices
This ensures we dont try to hold the PCI Access mutex under IRQ when
printing VirtIO debug logs (which is not allowed and results in an
assertion). This is also relatively free, as it requires no allocations
(we're just storing a pointer to the rodata section).
2021-09-19 21:51:03 +02:00
Idan Horowitz
53cf28c47c Kernel: Use StringView literals in VirtIO::determine_device_class()
Since the return type is StringView we can just create them at compile
time and avoid the run-time construction.
2021-09-19 21:51:03 +02:00
Nico Weber
697e6ccb89 Kernel: Add a Mailbox class for aarch64
As a demo, query the firmware version. `Meta/serenity.sh gdb aarch64`
can be used to observe that qemu puts 0x548E1 in x0 in response
to this mailbox message.
2021-09-19 17:45:59 +02:00
Nico Weber
d0b9c7a20b Kernel: Add a MMIO class for aarch64
It doesn't do anything yet except figure out the peripheral base
address.

Very likely belongs in Kernel, not Prekernel, eventually.
2021-09-19 17:45:59 +02:00
Nico Weber
3a24eb323f Kernel: Use new halt() for all our halting needs in aarch64 Prekernel 2021-09-19 17:45:59 +02:00
Nico Weber
0319aa315a Kernel: Add __stack_chk_fail to aarch64 Prekernel init
This is needed for some functions with local variables. We'll grow
such a function soon.
2021-09-19 17:45:59 +02:00
Eric Seifert
edbc5489a8 Kernel: Add support for O_NONBLOCK in pipe syscall
While working on a port, I saw a pipe creation fail due to missing
nonblock support in pipe syscall.
2021-09-19 12:20:16 +02:00
Sahan Fernando
2e079c6d69 Kernel/VirtIO: Remove lazy allocation of VirtIO::Device BAR regions
This fixes a Kernel Panic where the lazy allocation triggers inside an
ISR and grabs a mutex, which isn't allowed when interrupts are
disabled. This also fixes a bug where the mapping for VirtIO device
BARs is never allocated. #9876
2021-09-19 11:46:09 +03:00
Przemysław R. Kusiak
c6e23e45c5 Kernel: Let MouseDevice and KeyboardDevice write method return EINVAL
Currently, writing anything to `/dev/mouse0` or `/dev/keyboard0` causes
the Kernel to panic. The reason for this is that
`[Mouse,Keyboard]Device::write` always returns 0, which is explicitly
prohibited by `VERIFY` macro in `Process::sys$write`.  The fix seems
trivial; `write` should return EINVAL instead (as is the case with, for
example, `KCOVDevice`).
2021-09-18 22:57:42 +03:00
Liav A
23ef46f4f7 Kernel/Net: Enable usage of RTL8168E and RTL8168H in RTL8168 driver
I tested both (version 15 and 30 of the RTL8168 chipset) with PCI-
passthrough of these cards, and they seem to work just fine with the
driver.
2021-09-18 17:49:24 +03:00
Liav A
86fa5d71c0 Kernel/Memory: Add more super pages to satisfy contiguous allocations
When testing the RTL8168 driver, it seems we can't allocate super pages
anymore. Either we expand the super pages range, or find a solution to
dynamically expand the range (or let drivers utilize other ranges).
2021-09-18 17:49:24 +03:00
Liav A
d19bd59e28 Kernel/Storage: Tidy up RamdiskDevice class 2021-09-18 15:05:51 +03:00
Nico Weber
a339b73fc2 Kernel: Don't link Prekernel against kernel_heap
This was added in b5c98ede08, but it looks like a copy-paste
mistake from Kernel/CMakeLists.txt.

Unbreaks building for aarch64.
2021-09-17 17:59:22 +03:00
Liav A
44f5f72add Kernel/Devices: Use try_create_device helper for SB16 2021-09-17 01:02:48 +03:00
Liav A
fd4397a430 Kernel/Devices: Use try_create_device helper for ConsoleDevice 2021-09-17 01:02:48 +03:00
Liav A
5e8dcb9ca7 Kernel/Devices: Move ConsoleDevice into the Devices source directory 2021-09-17 01:02:48 +03:00
Liav A
aee4786d8e Kernel: Introduce the DeviceManagement singleton
This singleton simplifies many aspects that we struggled with before:
1. There's no need to make derived classes of Device expose the
constructor as public anymore. The singleton is a friend of them, so he
can call the constructor. This solves the issue with try_create_device
helper neatly, hopefully for good.
2. Getting a reference of the NullDevice is now being done from this
singleton, which means that NullDevice no longer needs to use its own
singleton, and we can apply the try_create_device helper on it too :)
3. We can now defer registration completely after the Device constructor
which means the Device constructor is merely assigning the major and
minor numbers of the Device, and the try_create_device helper ensures it
calls the after_inserting method immediately after construction. This
creates a great opportunity to make registration more OOM-safe.
2021-09-17 01:02:48 +03:00
Itamar
9aa6dd6b78 Kernel: Unblock tracer process in Process:unblock_waiters()
Since the tracer process may not be our parent process, we need to
explicitly unblock it (instead of the parent) if we are being traced.
2021-09-16 23:47:46 +02:00
Itamar
bb1ad759c5 Kernel: Allow calling sys$waitid on traced, non-child processes
Previously, attempting to call sys$waitid on non-child processes
returned ECHILD.

That prevented debugging non-child processes by attaching to them during
runtime (as opposed to forking and debugging the child, which is what
was previously supported).

We now allow calling sys$waitid on a any process that is being traced
by us, even if it's not our child.
2021-09-16 23:47:46 +02:00
Brian Gianforcaro
4fe99ff0d6 Kernel: Use move to avoid unnecessary ref/unref of network device RefPtr
Flagged by pvs-studio as a potential perf optimization.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
24207d3795 Kernel: Fetch range once for each iteration of find_regions_intersecting
pvs-studio flagged this as a potential optimization.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
e8ec1e908d Kernel: Only instantiate main_program_metadata in the scope it's needed
pvs-studio flagged this as a potential perf optimization.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
b530201111 Kernel: Make IPv4SocketTuple operator== by reference
No reason for this to copy when comparing equality.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
85d36e56d2 Kernel: Pack Flock struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
07b314e843 Kernel+LibC: Pack SC_stat_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
be15bd3c86 Kernel+LibC: Pack SC_mount_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
dcb327a83b Kernel+LibC: Pack SC_setsockopt_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
9956607283 Kernel+LibC: Pack SC_accept4_params struct tighter
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
Brian Gianforcaro
b45ca5d56e Kernel+LibC: Pack SC_inode_watcher_add_watch_params struct better
Flagged by pvs-studio, ordering the members from largest to smallest
allows us to save a few bytes in the size of the struct.
2021-09-16 17:17:13 +02:00
sin-ack
220b7dd779 Kernel: Weakly hold on to the file in LocalSocket
Because we were holding a strong ref to the OpenFileDescription in
LocalSocket and a strong ref to the LocalSocket in Inode, we were
creating a reference cycle in the event of the socket being cleaned up
after the file description did (i.e. unlinking the file before closing
the socket), because the file description never got destructed.
2021-09-16 16:50:36 +02:00
sin-ack
0ccef94a49 Kernel: Drop the receive buffer when socket enters the TimeWait state
The TimeWait state is intended to prevent another socket from taking the
address tuple in case any packets are still in transit after the final
close. Since this state never delivers packets to userspace, it doesn't
make sense to keep the receive buffer around.
2021-09-16 16:50:23 +02:00
Andreas Kling
b6efd66d56 Kernel: Use move semantics in sys$sendfd()
Avoid an unnecessary NonnullRefPtr<OpenFileDescription> copy.
2021-09-15 21:09:47 +02:00
Andrew Kaster
b9e3647e66 Meta+Toolchain: Rename CMAKE_CXXFILT to SERENITY_CXXFILT
The "CMAKE_<foo>" variable namespace is reserved, and CXXFILT is not
currently a variable known to upstream CMake.
2021-09-15 19:04:52 +04:30
Andrew Kaster
b5c98ede08 Meta: Switch to a SuperBuild that splits host and target builds
Replace the old logic where we would start with a host build, and swap
all the CMake compiler and target variables underneath it to trick
CMake into building for Serenity after we configured and built the Lagom
code generators.

The SuperBuild creates two ExternalProjects, one for Lagom and one for
Serenity. The Serenity project depends on the install stage for the
Lagom build. The SuperBuild also generates a CMakeToolchain file for the
Serenity build to use that replaces the old toolchain file that was only
used for Ports.

To ensure that code generators are rebuilt when core libraries such as
AK and LibCore are modified, developers will need to direct their manual
`ninja` invocations to the SuperBuild's binary directory instead of the
Serenity binary directory.

This commit includes warning coalescing and option style cleanup for the
affected CMakeLists in the Kernel, top level, and runtime support
libraries. A large part of the cleanup is replacing USE_CLANG_TOOLCHAIN
with the proper CMAKE_CXX_COMPILER_ID variable, which will no longer be
confused by a host clang compiler.
2021-09-15 19:04:52 +04:30
Brian Gianforcaro
fbb31b4519 Kernel: Disable lock rank enforcement by default for now
There are a few violations with signal handling that I won't be able to
fix it until later this week. So lets put lock rank enforcement under a
debug option for now so other folks don't hit these crashes until rank
enforcement is more fleshed out.
2021-09-14 18:31:16 +00:00
Ali Mohammad Pur
27e3589f61 AK+Kernel: Avoid unescaped control chars in append_escaped_for_json()
Otherwise it could produce invalid JSON.
2021-09-13 14:38:53 +04:30
Ali Mohammad Pur
e1e91f6c85 Kernel: Deduplicate signpost perf event strings 2021-09-13 14:38:53 +04:30
Ali Mohammad Pur
d600f0d5b3 Kernel: Specialize Traits<(Nonnull)OwnPtr<T>> for KString
To make it behave like a string, since KString is always stored as a
(Nonnull)OwnPtr in the kernel.
2021-09-13 14:38:53 +04:30
Nico Weber
3c6ad4c7db Kernel: Add a class to wrap aarch64 MIDR_EL1
We'll need part_num() to determine the MMIO address base. It's
0x3F000000 on rpi3 but 0xFE000000 on rpi4.
2021-09-12 17:26:41 +00:00
Nico Weber
2dc02607ed Kernel: Put boot.S first in aarch64 Prekernel source list
The better fix is to have a linker script. We'll need this to set
the entry point to 0x80000 for bare-metal builds anyways. But I'd
like to get some UART output in qemu before I add this (otherwise
I can't check if the bare-metal version does anything), so put
in this temporary kludge for now.
2021-09-12 17:26:41 +00:00
Nico Weber
18dcd7b9c9 Kernel: Define __stack_chk_guard for aarch64 Prekernel
Needed for functions that have local variables.

In time we need to share this between aarch64 and intel, but while
we figure out what exactly the aarch64 Prekernel should do, let's
duplicate this.
2021-09-12 17:26:41 +00:00
Nico Weber
22b2ca7b8e Kernel: Build Prekernel with -fno-threadsafe-statics
Else, function-local statics create calls to
__cxa_guard_acquire / __cxa_guard_release on aarch64, which we don't
(yet?) implement. Since Prekernel is single-threaded, just sidestep
that for now.
2021-09-12 17:26:41 +00:00
Brian Gianforcaro
a61857eb0a Kernel: Use AK::to_underlying in lock rank tracking
AK::to_underlying simplifies the code a bit, instead of having to
manually cast to the underlying type.
2021-09-12 18:24:15 +02:00
Brian Gianforcaro
d158f2ed89 Kernel: Zero initialize SlabAllocator member variables
PVS-Studio flagged these as uninitialized. While there is no bug here,
it is our policy to always initialize members to avoid potential bugs
in the future.
2021-09-12 16:36:52 +02:00
Liav A
8d0dbdeaac Kernel+Userland: Introduce a new way to reboot and poweroff the machine
This change removes the halt and reboot syscalls, and create a new
mechanism to change the power state of the machine.
Instead of how power state was changed until now, put a SysFS node as
writable only for the superuser, that with a defined value, can result
in either reboot or poweroff.
In the future, a power group can be assigned to this node (which will be
the GroupID responsible for power management).

This opens an opportunity to permit to shutdown/reboot without superuser
permissions, so in the future, a userspace daemon can take control of
this node to perform power management operations without superuser
permissions, if we enforce different UserID/GroupID on that node.
2021-09-12 11:52:16 +02:00
Liav A
06e95d0fd7 Kernel/SysFS: Make it possible to have custom permissions for nodes 2021-09-12 11:52:16 +02:00
Liav A
33f033066c Kernel: Unify BIOS and ACPI components in the SysFS firmware directory
Both should reside in the SysFS firmware directory which is normally
located in /sys/firmware.
Also, apply some OOM-safety patterns when creating the BIOS and ACPI
directories.
2021-09-12 11:52:16 +02:00