Commit Graph

6196 Commits

Author SHA1 Message Date
Ben Wiederhake
735da58d44 Kernel: Avoid OpenFileDescription::absolute_path 2021-10-31 12:06:28 +01:00
Ben Wiederhake
fa018d3ba1 Kernel: Fix common misuse of KString in debug messages 2021-10-30 17:35:18 +02:00
Idan Horowitz
a8bd78e634 LibC: Include sys/uio.h in sys/socket.h for struct iovec 2021-10-28 11:24:36 +02:00
Idan Horowitz
2882a90dec Kernel: Add the IFF_* SIOCGIFFLAGS flag macros 2021-10-28 11:24:36 +02:00
Idan Horowitz
adc9939a7b Kernel+LibC: Add support for the IPv4 TOS field via the IP_TOS sockopt 2021-10-28 11:24:36 +02:00
Idan Horowitz
20c7fcfedf Kernel: Fix accidental memory over-read in getsockopt(IP_TTL)
We were accidentally casting the pointer to m_ttl from an u8* to an int*
which resulted in copying of 3 extra unrelated bytes (which turned out
to be padding in this case).
2021-10-28 11:24:36 +02:00
Idan Horowitz
c45b1e1983 LibC: Add IPPROTO_ICMPV6 macro 2021-10-28 11:24:36 +02:00
Filiph Sandström
c6247fe414 Everywhere: Rename back-click to backward-click
This matches the current forward-click terminology.
2021-10-27 22:05:58 +03:00
Liav A
8554952690 Kernel + WindowServer: Re-define the interface to framebuffer devices
We create a base class called GenericFramebufferDevice, which defines
all the virtual functions that must be implemented by a
FramebufferDevice. Then, we make the VirtIO FramebufferDevice and other
FramebufferDevice implementations inherit from it.
The most important consequence of rearranging the classes is that we now
have one IOCTL method, so all drivers should be committed to not
override the IOCTL method or make their own IOCTLs of FramebufferDevice.
All graphical IOCTLs are known to all FramebufferDevices, and it's up to
the specific implementation whether to support them or discard them (so
we require extensive usage of KResult and KResultOr, together with
virtual characteristic functions).
As a result, the interface is much cleaner and understandable to read.
2021-10-27 07:57:44 +03:00
Liav A
78e724a899 Kernel/Graphics: Rename GraphicsDevice => GenericGraphicsAdapter
We already use the term adapter for instances of this class, so let's
better represent this class by changing its name to what it really is.
2021-10-27 07:57:44 +03:00
Liav A
c7eb761b7f Kernel/Graphics: Re-order parameters in VirtIO GraphicsAdapter methods
As suggested by @ccapitalK, it makes the interface more neat and clean.
The proper order is to get ScanoutID first, then ResourceID and after it
everything else that is needed to complete the operation successfully.
2021-10-27 07:57:44 +03:00
Liav A
f476b49fd8 Kernel/Graphics: Merge VirtIO GraphicsAdapter and VirtIO GPU code
A VirtIO graphics adapter is really the VirtIO GPU, so the virtualized
hardware has no distinction between both components so there's no
need to put such distinction in software.

We might need to split things in the future, but when we do so, we must
take proper care to ensure that the interface between the components
is correct and use the usual codebase patterns.
2021-10-27 07:57:44 +03:00
Liav A
a9538b5879 Kernel/Graphics: Convert type method => bool vga compatible method
We never used that type method except in initialization in
GraphicsManagement, and we used it there to query whether the device is
VGA compatible or not.
2021-10-27 07:57:44 +03:00
Liav A
fb0ed2ae46 Kernel/Graphics: Force VirtIO Framebuffer to inherit FramebufferDevice
The distinction is not justified because a VirtIO Framebuffer device
acts much more like a regular FramebufferDevice than a pure BlockDevice.
2021-10-27 07:57:44 +03:00
Liav A
4815282a5f Kernel/Graphics: Rename VirtIO FrameBufferDevice => FramebufferDevice 2021-10-27 07:57:44 +03:00
Andreas Kling
e0f0b6379a Kernel: Make WorkQueue::WorkItem slab allocated 2021-10-26 10:50:44 +02:00
Andreas Kling
44b273f3ac Kernel: Use SpinlockProtected<T> in WorkQueue 2021-10-26 10:44:10 +02:00
Andreas Kling
b443e9e1a9 Kernel: Use a larger kmalloc chunk size on 64-bit platforms
This reduces test-js runtime by over 40% on my machine.

(And once again we find another way to defer writing a better kernel
heap allocator..)
2021-10-26 10:38:35 +02:00
Andreas Kling
25250590d0 Kernel: Take VMObject lock once in Region::remap_vmobject_page()
We were taking and releasing the lock repeatedly instead of holding it
across the entire remap operation.
2021-10-26 09:03:41 +02:00
Andreas Kling
0592f80186 Kernel: Add TimeManagement::is_initialized()
This allows clients to check whether TimeManagement is available before
trying to ask it about time related things.
2021-10-26 01:00:54 +02:00
Ben Wiederhake
bf88adbcb6 Kernel: Avoid allocation when checking for vmmouse 2021-10-25 23:38:28 +02:00
Ben Wiederhake
8d13f6ddce Kernel+SystemServer: Change bootmode to system_mode
'bootmode' now only controls which set of services are started by
SystemServer, so it is more appropriate to rename it to system_mode, and
no longer validate it in the Kernel.
2021-10-25 23:38:28 +02:00
Ben Wiederhake
09432a8241 Kernel: Separate panic behavior from bootmode
Bootmode used to control panic behavior and SystemServer.
This patch factors panic behavior control into a separate flag.
2021-10-25 23:38:28 +02:00
Ben Wiederhake
542a88a7be Kernel: Separate framebuffers from bootmode
Bootmode used to control framebuffers, panic behavior, and SystemServer.
This patch factors framebuffer control into a separate flag.
Note that the combination 'bootmode=self-test fbdev=on' leads to
unexpected behavior, which can only be fixed in a later commit.
2021-10-25 23:38:28 +02:00
Daniel Bertalan
5f6030b13c Kernel+LibC: Default to 8-bit characters in TTY
Some ports (like `bc` with history enabled) sensibly set the termios
character size to 8 bits.

Previously, we left the character size value (given by the bitmask
CSIZE) as zero by default (meaning 5 bits per character), and returned
ENOTIMPL whenever someone modified it. This was dumb.
2021-10-25 21:42:26 +02:00
Jelle Raaijmakers
4131b35851 Kernel: Prevent VMWareMouseDevice from handling invalid mouse packets
Bit 3 is set here:
c5b2f55981/hw/input/ps2.c (L736)

Spurious mouse packets can be received without this bit set, for
example when double-clicking and keeping the mouse button depressed
instead of releasing it the second time (i.e. mousedown > mouseup >
mousedown). We should not process such packets.

This makes interaction with our buttons much smoother!

Fixes #5881.
2021-10-24 21:59:08 +02:00
Jelle Raaijmakers
8b3232121b Kernel: Do not detect mouse or keyboard when handling IRQ for I8042
Instead of detecting which flag was set in the status register, we can
use the instrument type passed to us. This works because the mouse and
keyboard use different IRQs.
2021-10-24 21:59:08 +02:00
Jelle Raaijmakers
26c84967fa Kernel: Enumify all magic constants for I8042 devices
This makes the code much easier to read.
2021-10-24 21:59:08 +02:00
Daniel Bertalan
db71c36657 Kernel: Properly align stack for signal handlers
The System V ABI requires that the stack is 16-byte aligned on function
call. Confusingly, however, they mean that the stack must be aligned
this way **before** the `CALL` instruction is executed. That instruction
pushes the return value onto the stack, so the callee will actually see
the stack pointer as a value `sizeof(FlatPtr)` smaller.

The signal trampoline was written with this in mind, but `setup_stack`
aligned the entire stack, *including the return address* to a 16-byte
boundary. Because of this, the trampoline subtracted too much from the
stack pointer, thus misaligning it.

This was not a problem on i686 because we didn't execute any
instructions from signal handlers that would require memory operands to
be aligned to more than 4 bytes. This is not the case, however, on
x86_64, where SSE instructions are enabled by default and they require
16-byte aligned operands. Running such instructions raised a GP fault,
immediately killing the offending program with a SIGSEGV signal.

This issue caused TestKernelAlarm to fail in LibC when ran locally, and
at one point, the zsh port was affected too.

Fixes #9291
2021-10-24 21:54:51 +02:00
Liav A
8e55c4bfaf Kernel/PCI: Remove InterruptDisabler usage
Instead, just ensure we pick the m_access_lock and then m_scan_lock when
doing a scan/re-scan of the PCI configuration space so we know nobody
can actually access the PCI configuration space during the scan.

The m_scan_lock is now a Spinlock, to ensure we cannot yield to other
process while we do the PCI configuration space scanning.
2021-10-23 19:17:44 +02:00
Liav A
72e831e9e9 Kernel/PCI: Ensure m_domains is not empty if scanning with memory access 2021-10-23 19:17:44 +02:00
Liav A
40b1e6376b Kernel/PCI: Split Access::rescan_hardware method
To ensure clarity, this method is essentially splitted to two methods to
be called according to the access type being determined beforehand.
2021-10-23 19:17:44 +02:00
Liav A
d395ac8f59 Kernel/PCI: Rename Access::scan_pci_domains method
We rename it to scan_pci_domains_from_acpi_mcfg_table to ensure clarity,
because this method relies on the ACPI MCFG table to work.
2021-10-23 19:17:44 +02:00
Liav A
ca32ee5714 Kernel/PCI: Simplify detect_optimal_access_type function
Instead of getting the kernel commandline argument as function parameter
we just take internally in the function.
2021-10-23 19:17:44 +02:00
Liav A
026687816d Kernel: Fix restrictions in is_allowed_to_mmap_to_userspace function
This small change simplifies the function a bit but also fixes a problem
with it.
Let's take an example to see this:
Let's say we have a reserved range between 0xe0000 to 0xfffff (EBDA),
then we want to map from the memory device (/dev/mem) the entire
EBDA to a program. If a program tries to map more than 131072 bytes,
the current logic will work - the start address is 0xe0000, and ofcourse
it's below the limit, hence it passes the first two restrictions.
Then, the third if statement will fail if we try to mmap more than
the said allowed bytes.
However, let's take another scenario, where we try to mmap from
0xf0000 - but we try to mmap less than 131072 - but more than 65536.
In such case, we again pass the first two if statements, but the third
one is passed two, because it doesn't take into account the offseted
address from the start of the reserved range (0xe0000). In such case,
a user can easily mmap 65535 bytes above 0x100000. This might
seem negligible. However, it's still a severe bug that can theoretically
be exploited into a info leak or tampering with important kernel
structures.
2021-10-22 13:13:00 +02:00
Andreas Kling
4ffee78146 Kernel: Make FrameBufferDevice::try_to_set_resolution() return KResult 2021-10-22 01:21:34 +02:00
Andreas Kling
21bfa02dd2 Kernel: Remove unused InodeIdentifier::to_string() 2021-10-22 01:19:04 +02:00
Andreas Kling
fe98cb2c4b Kernel: Make Ext2FS::free_inode() return KResult, and use TRY() more
While there's no clear propagation path for errors that happen in an
inode destructor, using TRY() still makes the code a lot nicer.
2021-10-21 23:23:23 +02:00
Andreas Kling
98b865fe10 Kernel: Make Ext2FS::write_ext2_inode() return KResult
This allows us to use TRY() in more places.
2021-10-21 23:23:23 +02:00
Andreas Kling
6f69d5204f Kernel: Make Inode::flush_metadata() return a KResult
Even if this goes nowhere yet, we have to start building an error
propagation path somewhere.
2021-10-21 23:23:23 +02:00
Daniel Bertalan
17b66eaa3c Kernel: Call try_set_coredump_property with StringView arguments
Storing assigning a string literal to a String object just to pass it to
a function expecting a StringView is wasteful. Let's just not do that.

For consistency's sake, this commit changes all of the other invocations
to use StringView literals, too.
2021-10-21 22:19:50 +02:00
Daniel Bertalan
bbb4eb0aa1 Kernel: Convert Formatter<Process> to use Formatter<FormatString>
This lets us avoid allocating memory on the heap most of the time, as
Formatter<FormatString> writes into a quite large stack buffer instead.
2021-10-21 22:19:50 +02:00
Daniel Bertalan
018c4e0e7e AK+Kernel: Format DistinctNumeric using the underlying type's formatter
Forcing the formatting to go through `Formatter<FormatString>` is
completely unnecessary, increases code size, performs a String
allocation and prevents us from using the formatting options available
on that type.

This commit also removes explicit formatters from
`BlockBasedFileSystem::BlockIndex` and `Kernel::InodeIndex`, as those
are already covered by the blanket implementation for all
`DistinctNumeric` types.
2021-10-21 22:19:50 +02:00
Liav A
64aaf263a2 Kernel/Net: Generate interface name near construction point
This change allows the Kernel to actually construct other interfaces
besides the E1000 type.
This solves a breakage that was introduced recently because of move
semantics.

A couple of points on this patch:
1. In current situation, we can waste time to create a KString and throw
it for nothing. This patch ensures we only create it near construction
point so we know we actually need it.
2. It's very likely to assume that non-x86 machines will expose network
device with a device tree (or with ACPI). The raspberry pi machine is a
good example of that. Therefore, each driver should explicitly ask the
correct interface name generation method, and this patch simplifies this
pattern greatly, especially in a case where the same network device can
appear as a PCI device or as device in another bus type on the same
platform target. For example, the (in)famous ne2000 device can be used
either as a PCI device or as an ISA device, depending on the model.
3. In my opinion, it seems much more readable to construct the name near
calling point of the object constructor than to just pass it with move
semantics.
2021-10-18 12:25:56 -07:00
Daniel Bertalan
10c3cf9a47 Kernel: Enable LTO for kernel_heap if ENABLE_KERNEL_LTO is set
By enabling LTO for the kernel_heap object too, we open the door for
optimization opportunities that come from (partially) inlining `::new`
or kmalloc. Every software spends a non-trivial amount of its run time
on allocating memory, so hopefully this change will make LTO builds even
faster.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
06fc64be13 Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes
with better C++20 support and improved handling of new features by
clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our
Clang binaries will only be 2-4% slower than if we dynamically linked
them, but we save hundreds of megabytes of disk space.

The `BuildClang.sh` script has been reworked to build the entire
toolchain in just three steps: one for the compiler, one for GNU
binutils, and one for the runtime libraries. This reduces the complexity
of the build script, and will allow us to modify the CI configuration to
only rebuild the libraries when our libc headers change.

Most of the compile flags have been moved out to a separate CMake cache
file, similarly to how the Android and Fuchsia toolchains are
implemented within the LLVM repo. This provides a nicer interface than
the heaps of command-line arguments.

We no longer build separate toolchains for each architecture, as the
same Clang binary can compile code for multiple targets.

The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in
this commit. Clang happily accepts an `i686-pc-serenity` target triple,
which matches what our GCC toolchain accepts.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
28c088cd91 Kernel: Support split data sections
This feature is used by Clang when performing LTO. With this change,
these split sections now go in the right place.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
a8fefd89cd Everywhere: Make some symbols __attribute__((used)) for LTO
With these changes, the userland builds correctly with Clang's ThinLTO
enabled.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
1faffc2192 Kernel: Introduce workaround to make LTO builds work with Clang
LLD fails to define the _GLOBAL_OFFSET_TABLE_ symbol if all inputs to it
are LLVM bitcode files (i.e. those used for LTO). To allow the kernel to
be built with ThinLTO, the workaround suggested in the original LLVM bug
report (<https://bugs.llvm.org/show_bug.cgi?id=39634>) is added in this
commit.
2021-10-17 17:09:58 +01:00
Tim Schumacher
20986b7066 Prekernel: Force enable PAE on Intel Pentium M CPUs 2021-10-17 16:15:36 +01:00
Tim Schumacher
e8808b259a Prekernel: Split early boot printing into two subroutines 2021-10-17 16:15:36 +01:00
SeekingBlues
3d174e3ad2 Kernel/ProcFS: Provide a way to write to ProcFS inodes
ProcFSGlobalInode now calls `write_bytes()`, `truncate()` and
`set_mtime()` on its associated component. This allows us to write 0 or
1 to a ProcFSSystemBoolean component to toggle a boolean value.
2021-10-17 14:46:59 +02:00
Tim Schumacher
52621093c7 Kernel: Print CPU check errors by writing to VRAM 2021-10-17 12:25:50 +01:00
James Mintram
e35222a76e Kernel: Move ScopedCritical + SmapDisabler CPP files into x86 common 2021-10-16 15:43:41 -07:00
James Mintram
8e4d53f216 Kernel: Add MiniStdLib to the Aarch64 kernel 2021-10-16 23:31:52 +01:00
James Mintram
3a9c7ce9d4 Kernel: Add StdLib.cpp to aarch64 build and update stubs in dummy.cpp 2021-10-15 21:48:45 +01:00
James Mintram
e8f09279d3 Kernel: Move spinlock into Arch
Spinlocks are tied to the platform they are built for, this is why they
have been moved into the Arch folder. They are still available via
"Locking/Spinlock.h"

An Aarch64 stub has been created
2021-10-15 21:48:45 +01:00
James Mintram
dfe4810c3a Kernel: Add cross platform RegisterState header and Aarch64 version
A new RegisterState header includes the platform specific RegisterState
header based on the platform being compiled.

The Aarch64 RegisterState header contains stubs for Debug
2021-10-15 21:48:45 +01:00
James Mintram
0fbeac6011 Kernel: Split SmapDisabler so header is platform independent
A new header file has been created in the Arch/ folder while the
implementation has been moved into a CPP living in the X86 folder.
2021-10-15 21:48:45 +01:00
James Mintram
f4fb637914 Kernel: Split ScopedCritical so header is platform independent
A new header file has been created in the Arch/ folder while the
implementation has been moved into a CPP living in the X86 folder.
2021-10-15 21:48:45 +01:00
Nico Weber
b135efe870 Kernel: List AK_SOURCES only once 2021-10-15 17:49:54 +01:00
Marcin Undak
d14d7ee78b Kernel: Discover initial exception level when booting Aarch64
When booting on RPI3 firmware puts CPU in EL2 mode which is
different from QEMU's default EL3.

I've added logic to discover initial mode at boot
and then act accordingly. This results in Serenity corectly
switching to EL1 on target hardware now.
2021-10-15 17:47:39 +01:00
Marcin Undak
ebf810f9a6 Kernel: Make Aarch64 register variables bit more descriptive 2021-10-15 17:47:39 +01:00
Marcin Undak
2d9fa8146c Kernel: Switch processor to EL1 immediately after boot on Aarch64 2021-10-15 17:47:39 +01:00
Marcin Undak
d6021300d5 Kernel: Move wait_cycles() function to Aarch_asm_utils.S
Just a bit of housekeeping.
2021-10-15 17:47:39 +01:00
Marcin Undak
18eb4a59d6 Kernel: Print current CPU exception level after booting on Aarch64
This is a first step to switch to exception level 1.

This is also my first patch for SerenityOS :)
2021-10-15 17:47:39 +01:00
James Mintram
a48985422c Kernel: Add UBSanitizer.cpp to the Aarch64 kernel build 2021-10-14 10:20:03 +01:00
James Mintram
ceb3328877 Kernel: Fix all linker errors for Aarch64 build 2021-10-14 01:23:08 +01:00
James Mintram
ab70268d61 Kernel: Add the AK sources to the Aarch64 kernel build 2021-10-14 01:23:08 +01:00
James Mintram
545ce5b595 Kernel: Add per platform Processor.h headers
The platform independent Processor.h file includes the shared processor
code and includes the specific platform header file.

All references to the Arch/x86/Processor.h file have been replaced with
a reference to Arch/Processor.h.
2021-10-14 01:23:08 +01:00
James Mintram
23676bee1f Kernel: Add -fsigned-char to ensure consistency across platforms 2021-10-14 01:23:08 +01:00
James Mintram
2a4969d281 Kernel: Move asserts inside platform #if clauses 2021-10-14 01:23:08 +01:00
James Mintram
580006d784 Kernel: Replace includes with a forward declaration 2021-10-14 01:23:08 +01:00
James Mintram
baa7925c0c Kernel: Remove unused includes 2021-10-14 01:23:08 +01:00
James Mintram
26d7c25076 Kernel: Add header includes closer to their use 2021-10-14 01:23:08 +01:00
James Mintram
d92967406a Kernel: Add post build step to generate kernel8.img
Add a postbuild step which creates a raw binary file called kernel8.img
from the Prekernel elf file.
2021-10-13 23:34:29 +01:00
Rodrigo Tobar
e1093c3403 Kernel: Implement pread syscall
The OpenFileDescription class already offers the necessary functionlity,
so implementing this was only a matter of following the structure for
`read` while handling the additional `offset` argument.
2021-10-13 16:10:50 +02:00
Rodrigo Tobar
8936b111a7 Kernel: Factor out common code from read/readv syscalls
Having these bits of code factored out not only prevents duplication
now, but will also allow us to implement pread without repeating
ourselves (too much).
2021-10-13 16:10:50 +02:00
James Mintram
a8e5130183 Kernel: Pass RegisterState by ref to event buffer 2021-10-12 10:49:56 -07:00
James Mintram
a4509ba633 Kernel: Accept RegisterState in append_with_ip_and_bp 2021-10-12 10:49:56 -07:00
Rodrigo Tobar
bf4e536f00 Kernel: Correctly interpret ioctl's FIONBIO user value
Values in `ioctl` are given through a pointer, but ioctl's FIONBIO
implementation was interpreting this pointer as an integer directly.
This meant that programs using `ioctl` to set a file descriptor in
blocking mode met with incorrect behavior: they passed a non-null
pointer pointing to a value of 0, but the kernel interpreted the pointer
as a non-zero integer, thus making the file non-blocking.

This commit fixes this behavior by reading the value from the userspace
pointer and using that to set the non-blocking flag on the file
descriptor.

This bug was found while trying to run the openssl tool on serenity,
which used `ioctl` to ensure newly-created sockets are in blocking mode.
2021-10-11 10:46:01 -07:00
Ben Wiederhake
fd8300e52d Kernel: Declare copy-ability of IOAddressGroup 2021-10-10 21:03:27 +01:00
Liav A
f8489da8ee Kernel/SysFS: Provide a way to "truncate" and "set" mtime on inodes
Normally, trying to truncate a SysFSInode should result in EPERM error.
However, as suggested by Ali (@alimpfard), we can allow the PowerState
node to be "truncated" so one can open that file with O_TRUNC option.
Likewise, we also need to provide a way to set modified time on SysFS
inodes. For most inodes, we should return ENOTIMPL error, but for the
power state switch, we ignore the modified time setting and just return
KSuccess.

These fixes allow to do "echo -n 1 > /sys/firmware/power_state" in Shell
after gaining root permissions, to switch the power state.
2021-10-09 12:07:56 +02:00
David Isaksson
b2e57f555b Kernel: Add ioctl request for getting a storage device's block size 2021-10-09 12:06:47 +02:00
David Isaksson
3b089032f4 Kernel: Add STORAGE_DEVICE_GET_SIZE ioctl request
This ioctl request makes it possible to get the size of a storage device
that has not yet been mounted.
2021-10-09 12:06:47 +02:00
Liav A
741c871bc1 Kernel/Storage: Unify all ATA devices
There's basically no real difference in software between a SATA harddisk
and IDE harddisk. The difference in the implementation is for the host
bus adapter protocol and registers layout.
Therefore, there's no point in putting a distinction in software to
these devices.

This change also greatly simplifies and removes stale APIs and removes
unnecessary parameters in constructor calls, which tighten things
further everywhere.
2021-10-09 01:39:55 +02:00
Nico Weber
1cdb12e920 Kernel: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Idan Horowitz
4174fe0156 Kernel: Use find_largest_not_above in VirtualRangeAllocator
Instead of iterating over the regions in the tree which is O(n), we can
just use RedBlackTree's find_largest_not_above method, which is O(logn)
2021-10-07 22:10:45 +02:00
Luke Wilde
49259777ef Kernel: Note if the page fault address is a destroyed smart pointer
While I was working on LibWeb, I got a page fault at 0xe0e0e0e4.
This indicates a destroyed RefPtr if compiled with SANITIZE_PTRS
defined. However, the page fault handler didn't print out this
indication.

This makes the page fault handler print out a note if the faulting
address looks like a recently destroyed RefPtr, OwnPtr, NonnullRefPtr,
NonnullOwnPtr, ThreadSafeRefPtr or ThreadSafeNonnullRefPtr. It will
only do this if SANITIZE_PTRS is defined, as smart pointers don't get
scrubbed without it being defined.
2021-10-07 21:30:13 +02:00
Idan Horowitz
399b5ffb64 Kernel: Add the /proc/stat ProcFS component
This exposes a small subset of the information exposed by the Linux
equivalent, and will be used to optimize applications that would like
to know the current CPU usage statistics, but don't want to read all of
the unrelated information in /proc/all
2021-10-07 21:09:38 +02:00
Idan Horowitz
900fac27c6 Kernel: Add Processor::time_spent_idle() 2021-10-07 21:09:38 +02:00
Andreas Kling
5b1f697460 AK+Kernel: Make automatically locking RefPtr & co a kernel-only thing
Some time ago, automatic locking was added to the AK smart pointers to
paper over various race conditions in the kernel. Until we've actually
solved the issues in the kernel, we're stuck with the locking.

However, we don't need to punish single-threaded userspace programs with
the high cost of locking. This patch moves the thread-safe variants of
RefPtr, NonnullRefPtr, WeakPtr and RefCounted into Kernel/Library/.
2021-10-07 19:27:30 +02:00
Tim Schumacher
228a32effc Kernel: Don't retrieve possibly nonexistent APIC table 2021-10-06 17:11:02 +02:00
Peter Elliott
669b23ac0a Kernel: Handle backspace for tab character in TTY cooked mode
Before, serenity would only backspace one character for a tab.
This is the only feature that my OS has and serenity doesn't.
2021-10-06 12:31:13 +02:00
Idan Horowitz
ce334ee1bc Kernel: Validate x86_64 address canonicality before SafeMem operations
This ensures we don't GP on x86_64 when a non-canonical address is fed
to a safe_foo() operation.
2021-10-05 02:07:43 +02:00
Idan Horowitz
cd975668d6 Kernel: Detect and store the virtual address bit width during CPU init 2021-10-05 02:07:43 +02:00
Brian Gianforcaro
9d17070047 Kernel: Fix copy paste in VirtIO::RNG::class_name()
Ben noticed this copy paste error during code review.

Co-authored-by: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
40a58f1fd4 Kernel: Remove unused partition name API
I was about to convert this to use KString, but then I realized it
wasn't actually used at all, so lets remove it until the day it is
needed.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
54a2aaaa6f Kernel: Remove now unused StorageDevice constructor 2021-10-03 13:36:10 +02:00
Brian Gianforcaro
70ad18fbcd Kernel: Remove most String usage from storage_name() API
This change is another minor step towards removing `AK::String` from
the Kernel. Instead of dynamically allocating the storage_name we can
instead allocate it via a KString in the factory for each device, and
then push the device name down into the StorageDevice base class.

We don't have a way of doing `AK::String::formatted(..)` with a KString
at the moment, so cleaning that up will be left for a later day.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
3a945051fc Kernel: Use operator ""sv in all purpose() implementations
Previously there was a mix of returning plain strings and returning
explicit string views using `operator ""sv`. This change switches them
all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
5f1c98e576 Kernel: Use operator ""sv in all class_name() implementations
Previously there was a mix of returning plain strings and returning
explicit string views using `operator ""sv`. This change switches them
all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
836c22ea13 Kernel: Remove AK::String usage from Storage/StorageManagement.cpp 2021-10-03 13:36:10 +02:00
Brian Gianforcaro
7f88d5058e Kernel: Remove AK::String usage from Storage/IDEChannel.cpp 2021-10-03 13:36:10 +02:00
Nico Weber
2c0d329bf6 Kernel: Make aarch64 UART::print_num() print u64s 2021-10-02 21:23:28 +01:00
Nico Weber
bc213ad7a2 Kernel: Add a Timer class for aarch64
For now, this can only query microseconds since boot.

Use this to print a timestamp every second. This busy-loops
until a second has passed. This might be a good first use of
interrupts soon.

qemu used to not implement this timer at some point, but
it seems to work fine even in qemu now (qemu v 5.2.0).
2021-10-02 21:23:28 +01:00
Brian Gianforcaro
92844a6af6 Kernel: Access Processor static methods statically
SonarCloud flagged this "Code Smell", where we are accessing these
static methods as if they are instance methods. While it is technically
possible, it is very confusing to read when you realize they are static
functions.
2021-10-02 18:16:15 +02:00
Brian Gianforcaro
0223faf6f4 Kernel: Access MemoryManager static functions statically
SonarCloud flagged this "Code Smell", where we are accessing these
static methods as if they are instance methods. While it is technically
possible, it is very confusing to read when you realize they are static
functions.
2021-10-02 18:16:15 +02:00
Nico Weber
6c4392bc50 Prekernel: Better datasheet link for RPi3 2021-10-02 02:01:07 +02:00
Brian Gianforcaro
b90cc1148a Kernel: Switch RTL8168NetworkAdapter::possible_device_name to StringView
There is no need to allocate a `AK::String` for the device name, when
the list of devices is entirely static.
2021-10-01 17:22:17 +00:00
Brian Gianforcaro
2770433d30 Kernel: Convert network adapter names to Kernel::KString
Another step of incremental progress of removing `AK::String` from the
kernel, to harden against OOM.
2021-10-01 17:22:17 +00:00
Liav A
4974727dbb Kernel: Move x86 IO instructions code into the x86 specific folder 2021-10-01 12:27:20 +02:00
Liav A
3e9dfd2e74 Kernel: Remove IO.h include from a bunch of places 2021-10-01 12:27:20 +02:00
Nico Weber
5a951d6258 Kernel: Fix a few typos 2021-10-01 00:51:49 +01:00
Andreas Kling
eeb4f2fa9b Kernel: Exclude userspace heap memory from coredumps by default
When a process with a large heap crashes (e.g WebContent), it gets very
cumbersome to dump out a huge amount of memory.

In the vast majority of cases, we're only interested in generating a
nice backtrace from the coredump, so let's have the kernel skip over
userspace heap regions when dumping memory for now.

This is not ideal, and almost a little bit ugly, but it does make
investigating 500 MiB WebContent crashes significantly easier for now.
2021-09-30 17:54:32 +02:00
Nico Weber
94d0562569 Kernel: Make UART::print_num(0) work on aarch64 2021-09-30 15:38:43 +01:00
Nico Weber
d0c1db5efc Kernel: Zero out .bss contents on aarch64
After building and running

     objcopy -O binary Build/aarch64/Kernel/Prekernel/Prekernel \
                       /media/sdcard/kernel8.img

things start booting on an actual RPi4 :^)

(Assuming the sdcard contains RPi firmware, an empty config.txt,
and no other kernel*.img files).
2021-09-30 15:38:43 +01:00
Rodrigo Tobar
d16131b100 Kernel: Implement getsockopt(SO_TYPE)
This is easy to implement, and is required by some applications like
python's ssl module.
2021-09-30 11:45:24 +02:00
Liav A
ef9b8ff0c7 Kernel/PCI: Remove all macros and replace them with enum classes 2021-09-29 11:24:33 +02:00
Liav A
9d9d57056e Kernel/PCI: Remove Address from enumeration callback
If we need that address, we can always get it from the DeviceIdentifier.
2021-09-29 11:24:33 +02:00
Liav A
a411a44fda Kernel/PCI: Cache interrupt line and interrupt pin of a device
This allows us to remove the PCI::get_interrupt_line API function. As a
result, this removes a bunch of not so great patterns that we used to
cache PCI interrupt line in many IRQHandler derived classes instead of
just using interrupt_number method of IRQHandler class.
2021-09-29 11:24:33 +02:00
Liav A
057f5a12c2 Kernel/PCI: Propagate usage of DeviceIdentifier everywhere
This allows us to remove a bunch of PCI API functions, and instead to
leverage the cached data from DeviceIdentifier object in many places.
2021-09-29 11:24:33 +02:00
Liav A
da327746a2 Kernel: Rename two PCI components
Rename ID => HardwareID, and PhysicalID => DeviceIdentifier.
This change merely does that to clarify what these objects really are.
2021-09-29 11:24:33 +02:00
Liav A
82bb08a15c Kernel/PCI: Cache more details about PCI devices when enumerating them
There's no good reason to fetch these values each time we need them.
2021-09-29 11:24:33 +02:00
Hendiadyoin1
683bf558e4 AK: Add missing AK/Types.h include to VirtIO/Protocol.h
How did this even work?
2021-09-28 03:13:54 +03:00
Liav A
acd44bdcad Kernel/Graphics: Modernize somewhat the code of BochsGraphicsAdapter
Reduce the amount of macros in favor to enum classes.
2021-09-27 16:15:04 +02:00
Liav A
38bddca378 Kernel/Graphics: Ensure we set BGR format of bochs-display if supported
Instead of blindly forcing BGR format on the bochs-display device, let's
ensure we do that only on QEMU bochs-display and not on VirtualBox
graphics adapter too.
2021-09-27 16:15:04 +02:00
Liav A
de1b649783 Kernel/Graphics: Force BGR format when modesetting the bochs-display
By default bochs-display uses the BGR format, but for future-proof
solution, let's force it explicitly to use that format.
2021-09-27 16:15:04 +02:00
Nico Weber
b0858b2a55 Kernel: Fix a typo in a comment 2021-09-27 10:17:52 +02:00
Nico Weber
4c876e88e0 Kernel: Adjust aarch64 linker script
- .text now starts at 0x80000, where an actual (non-qemu) RPi expects
- use magic section name ".text.first" to make sure the linker script
  puts the kernel entry point at the start of the .text section
- remove a few things from the x86 linker script that aren't needed
  for aarch64 (yet?)
2021-09-27 10:17:52 +02:00
Nico Weber
cbdf4b575d Kernel: Move prekernel linker.ld into Arch subdirectories
This moves Kernel/Prekernel/linker.ld unchanged to
Kernel/Prekernel/Arch/aarch64 and Kernel/Prekernel/Arch/x86.
The aarch64 will change in a future commit.

No behavior change.
2021-09-27 10:17:52 +02:00
Nico Weber
54aabb07f9 Kernel: Add UART class for aarch64 2021-09-26 23:14:01 +00:00
Nico Weber
44c787e88b Kernel: Add Mailbox::set_clock_rate() 2021-09-26 23:14:01 +00:00
Nico Weber
fdc86ddae5 Kernel: Add a GPIO class for aarch64
This allows configuring the alternate pin functions and pin
pull up/down states, which is needed for using the UART.
2021-09-26 11:55:51 +02:00
Jelle Raaijmakers
9a6283c524 Kernel: Define PT_READ_I and PT_READ_D
Looking at how these two constants are commonly used in other systems,
we should be able to mimic their behavior using our PT_PEEK constant.

For example, see:
https://man.netbsd.org/NetBSD-6.0.1/i386/ptrace.2
2021-09-23 18:51:21 +02:00
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
Liav A
9132596b8e Kernel: Move ACPI and BIOS code into the new Firmware directory
This will somwhat help unify them also under the same SysFS directory in
the commit.
Also, it feels much more like this change reflects the reality that both
ACPI and the BIOS are part of the firmware on x86 computers.
2021-09-12 11:52:16 +02:00
TheFightingCatfish
a81b21c1a7 Kernel+LibC: Implement fsync 2021-09-12 11:24:02 +02:00
Liav A
c181494b19 Kernel/SysFS: Move the PCI bus directory to the /sys/bus directory
The USB bus directory is already in /sys/bus directory, so I don't see a
reason why the PCI bus directory shouldn't be in that directory too.
2021-09-12 01:44:19 +02:00
Liav A
04ba31b8c5 Kernel+Userland: Remove loadable kernel moduless
These interfaces are broken for about 9 months, maybe longer than that.
At this point, this is just a dead code nobody tests or tries to use, so
let's remove it instead of keeping a stale code just for the sake of
keeping it and hoping someone will fix it.

To better justify this, I read that OpenBSD removed loadable kernel
modules in 5.7 release (2014), mainly for the same reason we do -
nobody used it so they had no good reason to maintain it.
Still, OpenBSD had LKMs being effectively working, which is not the
current state in our project for a long time.
An arguably better approach to minimize the Kernel image size is to
allow dropping drivers and features while compiling a new image.
2021-09-11 19:05:00 +02:00
Idan Horowitz
92a3318375 Kernel: Run clang-format on SerialDevice.h 2021-09-11 17:20:19 +03:00
Liav A
7dfecbee44 Kernel: Initialize and expose SerialDevice(s) properly
I forgot that we need to also initialize SerialDevice and also to ensure
it creates a sysfs node properly. Although I had a better fix for this,
it keeps the CI happy, so for now it's more than enough :)
2021-09-11 17:07:38 +03:00
Liav A
f5de4f24b2 Kernel/Devices: Defer creation of SysFS component after the constructor
Instead of doing so in the constructor, let's do immediately after the
constructor, so we can safely pass a reference of a Device, so the
SysFSDeviceComponent constructor can use that object to identify whether
it's a block device or a character device.
This allows to us to not hold a device in SysFSDeviceComponent with a
RefPtr.
Also, we also call the before_removing method in both SlavePTY::unref
and File::unref, so because Device has that method being overrided, it
can ensure the device is removed always cleanly.
2021-09-11 11:41:14 +02:00
Andreas Kling
890c647e0f Kernel: Fix off-by-one in Memory::is_user_range() check
This function was checking 1 byte after the provided range, which caused
it to reject valid userspace ranges that happened to end exactly at the
top of the user address space.

This fixes a long-standing issue with mysterious Optional errors in
Coredump::write_regions(). (It happened when trying to add a memory
region at the very top of the address space to a coredump.)
2021-09-11 02:34:55 +02:00
Linus Groh
f646d49ac1 Kernel: Add _SC_HOST_NAME_MAX 2021-09-11 00:28:39 +02:00
Liav A
d0245b5e6b Kernel/CommandLine: Verify ACPI feature level cannot have invalid string
The allowed options are "on", "limited" and "off". Anything else is now
not allowed and will result in kernel panic.
2021-09-10 22:01:23 +02:00
Liav A
026f80a95b Kernel/ACPI: Simplify parser initialization
Let's remove the DynamicParser class, as it really did nothing yet in
the Kernel. Instead, when we add support for AML parsing, we can figure
out how to do it properly without the need of a derived class that just
complicates everything for no good reason.
2021-09-10 22:01:23 +02:00
Idan Horowitz
6348b63476 Kernel: Add kernelearlyputstr and use it in dbgln in very-early boot
This variant of dbgputstr does not lock the global log lock, as it is
called before the current or any other processor was initialized,
meaning that:
A) The $gs base was not setup yet, so we cannot enter into critical
   sections, and as a result we cannot use SpinLocks
B) No other processors may try to print at the same time anyway
2021-09-10 22:58:08 +03:00
Idan Horowitz
bc7b0a8986 Kernel: Replace inline assembly for turning on IA32_EFER.NXE with MSR
This fixes a triple fault that occurs when compiling serenity with
the i686 clang toolchain. (The underlying issue is that the old inline
assembly did not specify that it clobbered the eax/ecx/edx registers
and as such the compiler assumed they were not changed and used their
values across it)

Co-authored-by: Brian Gianforcaro <bgianf@serenityos.org>
2021-09-10 22:58:08 +03:00
Ali Mohammad Pur
14c8373eb0 AK+Kernel: Reduce the number of template parameters of IntrusiveRBTree
This makes the user-facing type only take the node member pointer, and
lets the compiler figure out the other needed types from that.
2021-09-10 18:05:46 +03:00
Ali Mohammad Pur
5a0cdb15b0 AK+Everywhere: Reduce the number of template parameters of IntrusiveList
This makes the user-facing type only take the node member pointer, and
lets the compiler figure out the other needed types from that.
2021-09-10 18:05:46 +03:00