Commit graph

8956 commits

Author SHA1 Message Date
Sönke Holz
801a0c35cd Kernel/USBMS: Add some optional verbose debug output
The static_assert is needed so we can safely print the SCSI opcode
(bCBWCBLength also always has to be > 1).
2024-09-25 14:41:23 -04:00
Sönke Holz
f1d7b87cba Kernel/USBMS: Handle data transport errors 2024-09-25 14:41:23 -04:00
Sönke Holz
24e74086b5 Kernel/USBMS: Handle CBW transport errors 2024-09-25 14:41:23 -04:00
Sönke Holz
54709af2f5 Kernel/USBMS: Perform a Reset Recovery when CSW transport fails twice
This requires storing a const reference to the interface, as the
Bulk-Only Mass Storage Reset request takes the interface number as an
argument.
2024-09-25 14:41:23 -04:00
Sönke Holz
55b80252d9 Kernel/USBMS: Handle CSW transport errors 2024-09-25 14:41:23 -04:00
Sönke Holz
2099647cc0 Kernel/USBMS: Make send_scsi_command a member function 2024-09-25 14:41:23 -04:00
Sönke Holz
f5cd7ec711 Kernel/USBMS: Unify the two send_scsi_command implementations
These two versions can be unified with a bit of template
metaprogramming.
2024-09-25 14:41:23 -04:00
Sönke Holz
7173a02728 Kernel/USBMS: Move device initialization to BulkSCSIInterface 2024-09-25 14:41:23 -04:00
Sönke Holz
c5f4469b32 Kernel/USBMS: Move StorageDevice functions into a separate class
This will allow us to make send_scsi_command a member function. This is
necessary because we need to execute some SCSI commands
(with send_scsi_command) to get all arguments necessary for the
StorageDevice constructor.

This change should will likely also be necessary to support USB mass
storage devices with multiple LUNs.
2024-09-25 14:41:23 -04:00
Sönke Holz
e2919f92ff Kernel/USBMS: Accept SCSI version 0
Some devices seem to have this field set to 0.
0 means "The device does not claim conformance to any standard."
2024-09-25 14:41:23 -04:00
Sönke Holz
42c355f4cb Kernel/USB: Return ESHUTDOWN on stall errors 2024-09-25 14:41:23 -04:00
Sönke Holz
878d149ec9 Kernel/USB: Add a function to clear the endpoint halt condition
This is done by issuing a ClearFeature(ENDPOINT_HALT) request.
On xHCI, some extra steps are needed.
2024-09-25 14:41:23 -04:00
Sönke Holz
cb2c0c630b Kernel/USB: Make USB::Pipe hold a non-const reference to the USB::Device
This will be necessary in the next commit.
2024-09-25 14:41:23 -04:00
Sönke Holz
632afcf822 Kernel/USB: Don't treat xHCI Short Packet Completion Codes as errors
The Short Packet Completion Code just means that the xHC received fewer
bytes than expected.
We shouldn't treat them as errors, since our transfer functions already
return the actual transfer size.
2024-09-25 14:41:23 -04:00
Sönke Holz
e8ebdf804e Kernel/USB: Clear the direction bit of the HID interrupt endpoint number
InterruptInPipe::create() expects an endpoint number, not the entire
address.
2024-09-25 14:41:23 -04:00
Sönke Holz
7e3dc5b721 Kernel/USB: Rename endpoint_address to endpoint_number where appropriate
"Endpoint Address" refers to "[t]he combination of an endpoint number
and an endpoint direction on a USB device."
(USB 2.0 Specification, Chapter 2)

The USB::Pipe m_endpoint_address member doesn't have the direction part,
so rename it and all variables/functions associated with it
appropriately.
2024-09-25 14:41:23 -04:00
Hendiadyoin1
b5c6e656f8 Kernel/USB: Only create SysFS node after device is fully initialized
Otherwise all devices would report as address 0 to the SysFS, which
is nonsense.
2024-09-22 19:16:19 -04:00
Hendiadyoin1
67a13ad786 Kernel: Be a bit more judicious about how we copy USB structures
A lot of USB structures contain back pointers to their parents,
so we need to be careful about how we copy them around, and update
the back pointers as necessary.
2024-09-22 19:16:19 -04:00
kleines Filmröllchen
a3077203fe AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
2024-09-14 13:30:27 +02:00
logkos
3abaf9f3f8 Kernel/Net: Remove obsolete diagnostic trick 2024-09-12 15:57:11 -04:00
Sönke Holz
327e498463 Kernel/aarch64: Remove some unused RPi mailbox query functions
These have been unused since f74f80e13b.
2024-09-11 12:47:12 -04:00
Sönke Holz
815361aec2 Kernel/aarch64: Remove BootPPMParser.{cpp,h}
The BootPPMParser has been unused since 0acd87954b.
2024-09-11 12:47:12 -04:00
Sönke Holz
19c391ed6f Kernel/riscv64: Actually implement safe SafeMem functions
This causes the riscv64 kernel to no longer panic on failed (userspace)
memory accesses.
2024-09-11 12:45:56 -04:00
kleines Filmröllchen
d6b37e40df Kernel/Net: Naive IPv6 autoconfiguration
This commit introduces very naive IPv6 autoconfiguration by just
setting fe80::{mac address} as the adapters link local address every
time the link state comes up. Note: this is currently not compliant
with RFC4862 which mandates Duplicate Address Detection, which is
missing from this implementation.

Co-authored-by: famfo <famfo@famfo.xyz>
2024-09-08 18:27:55 -04:00
famfo
c57b1c319b Kernel/SysFS: Expose IPv6 information for adapters
This commit adds the ipv6_address and ipv6_netmask parameters to the
adapters SysFS JSON if present on the interface.
2024-09-08 18:27:55 -04:00
kleines Filmröllchen
ac44ec5ebc Kernel+ifconfig: Allow setting an IPv6 address on an interface
Since we take a socket address with an address
type, this allows us to support setting an IPv6
address using an IPv4 socket without a
particularly hacky API. This deviates from Linux's
behavior (see
https://www.man7.org/linux/man-pages/man7/netdevice.7.html
) where AF_INET6 uses a completely different
control structure, but this doesn't seem
necessary.

This requires changing the sockaddr size to fit
sockaddr_in6, as the network ioctl's are the only
place where sockaddr is used with a fixed size
(and not with variable size data like in POSIX
APIs, which would support sockaddr_in6 without
changes).

ifconfig takes a new parameter for setting the
IPv6 address of an interface. The IPv4 address
short option '-i' is removed, as it only yields
confusion (which IP version is the default? and
usually such options are called -4 or -6, if they
exist) and isn't necessary thanks to the brief
long option name.

This commit's main purpose for now is to allow
participating in IPv6 NDP and pings without
requiring SLAC.

Co-authored-by: Dominique Liberda <ja@sdomi.pl>
2024-09-08 18:27:55 -04:00
sdomi
81eae154b7 Kernel/Net: Add basic IPv6 address support to NetworkAdapter 2024-09-08 18:27:55 -04:00
landonbr
37424ade04 Kernel/riscv64: Fix typo in naming of Devicetree 2024-09-08 14:19:57 -04:00
Sönke Holz
1d83f73ec5 Kernel/PCI: Stop using a dangling pointer in dmesgln_pci
VariadicFormatParams only stores pointers to the parameters, so
the device.device_name() parameter will dangle.

This fixes broken dmesgln_pci output on riscv64 GCC.
2024-09-07 12:52:52 -04:00
Sönke Holz
b628ab0ae3 Kernel/riscv64: Add comment about the bss to the linker script 2024-09-06 16:02:08 -04:00
Sönke Holz
ed3fa378c5 Kernel/riscv64: Add FLAGS to the PHDRS linker script command
Otherwise validate_program_headers will complain about the kernel text
segment being executable and writable.
2024-09-06 16:02:08 -04:00
Liav A.
0482f4e117 Kernel: Remove passing of register state to IRQ handlers
Linux did the same thing 18 years ago and their reasons for the change
are similar to ours - https://github.com/torvalds/linux/commit/7d12e78

Most interrupt handlers (i.e. IRQ handlers) never used the register
state reference anywhere so there's simply no need of passing it around.
I didn't measure the performance boost but surely this change can't make
things worse anyway.
2024-09-01 21:00:18 +02:00
Liav A.
fdf3e0aca1 Kernel: Don't assume sizes of needed buffers early in the execve syscall
Instead, start by trying to read a buffer with size of Elf_Ehdr, and
check it for the shebang sign. If it's indeed an executable with shebang
then read again from the file, now with PAGE_SIZE size, which should
suffice for finding the interpreter path.

However, if the executable is an ELF, we quickly validate it and then
pass the preliminary buffer to the find_elf_interpreter_for_executable
method.

That method calculates the last byte offset which is needed to read all
of the program headers, so we don't just assume 4096 bytes is sufficient
anymore. The same pattern is applied when loading the interpreter ELF
main header and its program headers.
2024-09-01 20:52:55 +02:00
brody-qq
44a2157e2e Kernel/Ext2FS: Reduce allocations in compute_block_list_impl()
In Ext2FSInode::compute_block_list_impl(), each call to
process_block_array() creates a new ByteBuffer, which leads to a
kmalloc() call. The ByteBuffer is then discarded when
process_block_array() exits, leading to a kfree() call.

This leads to repeated kmalloc() and kfree() calls as ByteBuffers are
created and destroyed each time process_block_array() is called.

This commit makes it so that only 1 ByteBuffer is created for each level
of inode indirect block (so only 3 ByteBuffers are created at most).
These ByteBuffers are re-used on each call to process_block_array().

This reduces the number of kmalloc() and kfree() calls during
compute_block_list_impl(), especially for larger files.
2024-08-30 22:22:13 +02:00
Sönke Holz
75ccee81be Kernel: Use the correct ip in the dispatch_signal debug output
The signal handler RegisterState is in 'regs', not 'm_regs'.
2024-08-21 08:17:17 -04:00
Sönke Holz
7b0553eb13 Kernel/x86: Add missing rcx + r11 clobber to Syscall::invoke with 4 args
The 4-arg version was missing those.
2024-08-21 08:17:17 -04:00
Sönke Holz
d9c098f103 Kernel/x86: Use iretq instead of sysretq for sys$sigreturn
Using sysretq clobbers rcx and r11 as this instruction loads the rip and
rflags from those registers. This is fine for normal syscalls.

Signal dispatching works like this:
The kernel makes userspace jump to the signal trampoline when a signal
is dispatched. That trampoline then executes the sigreturn syscall after
calling the signal handler to continue executing the code before the
signal was dispatched.

Since e71c320154 the sigreturn syscall is done via the syscall
instruction (and int 0x82 support was removed in the next commit),
which causes the kernel to currently use sysretq to return to userspace.
But signals can happen at any time, not just during syscalls, so the
sigreturn syscall shouldn't clobber the contents of those registers when
returning to userspace.
2024-08-21 08:17:17 -04:00
Hendiadyoin1
f5d2671718 Kernel/USBMS: Query and use the Block Limits VPD page
This allows us to properly limit our block requests to the device's
capabilities, and choose more optimal block counts for I/O operations.
In theory, as Qemu  only advertises a block limit above our current
internal block size limit of u16::max and does not advertise any optimal
transfer lengths.
2024-08-20 22:06:51 -04:00
Hendiadyoin1
0d2e8ec96f Kernel/USBMS: Inquire and wait for the storage device to become ready
This is apparently what bootloaders do before using a USB storage device
so we should likely do so as well, especially when no BIOS is present,
like on riscv.

Co-Authored-By: Sönke Holz <sholz8530@gmail.com>
2024-08-20 22:06:51 -04:00
Hendiadyoin1
e3567969d4 Kernel/USBMS: Add and use a send_scsi_command helper
This makes sending commands less repetitive
2024-08-20 22:06:51 -04:00
Hendiadyoin1
0866adde12 Kernel/USB: Be a bit more const-correct with USB transfers 2024-08-20 22:06:51 -04:00
Sönke Holz
13e789a261 Kernel/riscv64: Verify the FDT magic before copying it 2024-08-20 21:52:12 -04:00
Hendiadyoin1
f74f80e13b Kernel/aarch64: Use the FDT to get the device/boot info
This removes the old hacky multiboot memory map and instead uses the
FDT to get the actual memory map.
2024-08-20 21:52:12 -04:00
Hendiadyoin1
55a22ad393 Kernel/aarch64: Save the device tree 2024-08-20 21:52:12 -04:00
Hendiadyoin1
e0a177061e Kernel/Firmware+riscv64: Move devicetree handling to Firmware directory
This also adds a `verify_fdt` method which will be used in later commits
2024-08-20 21:52:12 -04:00
Sönke Holz
1ffb7afba7 Kernel/aarch64: Make the kernel bootable from any physical load address
Instead calculate the load offset at runtime.

The mapping of the initial stack is now done explicitly. It was
previously included in the 2 MiB-aligned kernel range.

We need to use kernel8.img now, as we no longer hard-code the physical
addresses of all sections in the linker script. QEMU would otherwise
try to load us at KERNEL_MAPPING_BASE.
2024-08-20 21:52:12 -04:00
Sönke Holz
ba27989da1 Kernel/aarch64: Use MM's virtual_to_low_physical for Mailbox::send_queue
This is slightly better than assuming that cutting off the high 32 bits
results in the physical address. This worked for now because the kernel
(and stack) is mapped at KERNEL_MAPPING_BASE + PHYSICAL_LOAD_ADDR and
KERNEL_MAPPING_BASE & 0xffff'ffff == 0.

The next commit will move the kernel to KERNEL_MAPPINGS_BASE + 0, so
we need to get the physical address in a slightly less hacky way.
2024-08-20 21:52:12 -04:00
Sönke Holz
194d9df34f Kernel/Memory: Handle devicetree memory nodes with more than one region 2024-08-20 21:52:12 -04:00
Sönke Holz
ab44530304 Kernel/Memory: Remove x86 LAPIC address hack
MM is now able to handle MMIO after our "highest_phyisical_address".
2024-08-20 21:52:12 -04:00
Sönke Holz
810f2e7f29 Kernel/aarch64: Include .bss* sections in the linker script 2024-08-20 21:52:12 -04:00
Sönke Holz
e7b8eed005 Kernel: Share Processor::capture_stack_trace() between architectures
This makes Processor::capture_stack_trace() work on all our
architectures. For this function to work on AArch64 and RISC-V, the
frame pointer has to be saved during context switches.

AArch64 and RISC-V don't support SMP yet, so the code for getting a
backtrace for processes running on other cores is guarded behind a
'#if ARCH(X86_64)'.
2024-08-16 16:01:19 -04:00
Sönke Holz
fa39086922 Kernel: Add ThreadRegisters::frame_pointer() accessors 2024-08-16 16:01:19 -04:00
Sönke Holz
c1dc55ec7c Kernel: Remove Processor::is_kernel_mode
This function was only used to verify that we are running in kernel
mode. But it is pretty much impossible that we will ever end up in
kernel code and actually are able to execute it in user mode. A lot of
stuff must go completely wrong to end up in such a situation.

Getting the current privilege level is also impossible on RISC-V by
design.
2024-08-16 15:58:27 -04:00
Sönke Holz
c3c5378c82 Kernel/USB: Always check for the Intel xHCI port routing quirk
The quirk previously only worked when USBLEGSUP was present and the BIOS
owned the host controller.
2024-08-12 10:54:00 -04:00
brody-qq
a0b021cbcf Kernel/Memory: Fix crash on writes to shared file mmaps
Writes to SharedInodeVMObjects could cause a Protection Violation if a
page was marked as dirty by a different process.

This happened due to a combination of 2 things:
* handle_dirty_on_write_fault() was skipped if a page was already marked
  as dirty
* when a page was marked as dirty, only the Region that caused the page
  fault was remapped

This commit:
* fixes the crash by making handle_fault() stop checking if a page was
  marked dirty before running handle_dirty_on_write_fault()
* modifies handle_dirty_on_write_fault() so that it always marks the
  page as dirty and remaps the page (this avoids a 2nd bug that was
  never hit due to the 1st bug)
2024-08-10 16:19:12 +02:00
Liav A.
79d9abd3cc Kernel: Create coredump by using the crashed process VFS root context
Resolve a regression caused by 01e1af732b.

This unbreaks coredump generation, because we need to use the VFS root
context of the crashed process and not of the FinalizerTask, as it will
hold an empty VFS root context that is assigned to kernel processes.
2024-08-10 10:14:37 -04:00
Sönke Holz
6a195b6616 Kernel/USB: Add support for xHCI bulk transfers
Bulk transfers also use Normal TRBs, so move the reusable normal TRB
setup code from submit_async_interrupt_transfer into a new function
prepare_normal_transfer.

submit_bulk_transfer and submit_async_interrupt_transfer use this
function and then either block on the completion or submit it
asynchronously and wrap it into a PeriodicPendingTransfer.
2024-08-07 18:30:06 -04:00
Sönke Holz
d82148aae1 Kernel/USB: Don't truncate the max packet size in the MassStorage driver 2024-08-07 18:30:06 -04:00
Liav A.
cb10f70394 Kernel: Change internal handling of filesystem-specific options
Instead of using a raw `KBuffer` and letting each implementation to
populating the specific flags on its own, we change things so we only
let each FileSystem implementation to validate the flag and its value
but then store it in a HashMap which its key is the flag name and
the value is a special new class called `FileSystemSpecificOption`
which wraps around `AK::Variant<...>`.

This approach has multiple advantages over the previous:
- It allows runtime inspection of what the user has set on a `MountFile`
  description for a specific filesystem.
- It ensures accidental overriding of filesystem specific option that
  was already set is not possible
- It removes ugly casting of a `KBuffer` contents to a strongly-typed
  values. Instead, a strongly-typed `AK::Variant` is used which ensures
  we always get a value without doing any casting.

Please note that we have removed support for ASCII string-oriented flags
as there were no actual use cases, and supporting such type would make
`FileSystemSpecificOption` more complicated unnecessarily for now.
2024-08-03 20:35:06 +02:00
Sönke Holz
ad64243bb9 Kernel/x86: Properly restore rflags in the syscall handler
The sysret instruction restores the rflags value from the r11 register.
Before, we expected that the value in RegisterState::r11 is still the
rflags value saved by syscall and therefore didn't copy
RegisterState::rflags to r11 before the sysret.

But signal handlers and ptrace can change the value in
RegisterState::r11 while we are handling a syscall, so we shouldn't
assume that it still contains the saved rflags.
While handling a syscall the contents of RegisterState::rflags may also
have been updated by e.g. ptrace in which case we should restore the
updated rflags, not the original state on syscall entry.
2024-08-01 22:08:08 +02:00
Sönke Holz
640530dbed Kernel/PCI: Handle 64-bit MSI-X BARs
PCI::get_BAR just returns the raw BAR value and doesn't handle 64-bit
BARs.
2024-08-01 12:05:56 -07:00
Sönke Holz
26555baf53 Kernel/USB: Make USBHubDescriptor::hub_characteristics union packed
AArch64 Clang otherwise complains that this anonymous union is more
aligned than the struct.
2024-07-30 09:07:32 -04:00
Logkos
ad73adef5d Kernel/Net: Rename IPv4-specific files and structs 2024-07-29 09:49:56 -04:00
Sönke Holz
137cb0029b Kernel/USB: Use a Stream to parse USB descriptors
This fixes incorrect assumptions about the layout of descriptors and
gets rid of all the pointer arithmetic.
The USB spec doesn't define a strict order for all descriptors to appear
in.
It just says that endpoint descriptors follow its interface descriptor.
We also have to skip all unknown descriptors (which also can appear
anywhere), not just HID descriptors.
2024-07-27 13:28:15 -04:00
Sönke Holz
594664d9b5 Kernel/USB: Add AssertSizes to USB descriptor definitions 2024-07-27 13:28:15 -04:00
Sönke Holz
8799524b00 Kernel/USB: Don't copy the USBConfiguration during device initialization 2024-07-27 09:40:09 -04:00
Sönke Holz
d8cfe3b4a8 Kernel/USB: Pass the configuration value in the GET_DESCRIPTOR request
The low byte of wValue is the configuration value for
GetDescriptor(Configuration) requests.
2024-07-27 09:40:09 -04:00
Sönke Holz
a5b33734f8 Kernel/USB: Explicitly request the boot protocol in the USB mouse driver
By default the report protocol is used.
2024-07-27 09:40:09 -04:00
Sönke Holz
4f573ebdc3 Kernel/USB: Add spec references to HID/Codes.h 2024-07-27 09:40:09 -04:00
Sönke Holz
345117e404 Kernel/USB: Handle USB mice with more than one interface
This simply looks for the first interface with the appropriate class,
subclass and protocol which we can initialize now.
2024-07-27 09:40:09 -04:00
Sönke Holz
ed73aa3364 Kernel/USB: Don't prepend "0x" to the logged VID/PID in the mouse driver
This just looks silly and USB VID/PIDs are typically formatted without
the prefix.
2024-07-27 09:40:09 -04:00
Sönke Holz
64f827dbc8 Kernel/USB: Correct the xHCI version check
0x102 would be 1.0.2, not 1.2.0.
2024-07-27 09:40:09 -04:00
brody-qq
f3f681ae45 Kernel/Ext2FS: Replace hardcoded offset with a constexpr
The superblock of an ext2 filesystem is always found on the storage
device at offset 1024. This 1024 number was hardcoded in the Ext2FS
code.

This commit:
* adds a constexpr to replace the hardcoded 1024 values
* removes a comment about one of the the hardcoded 1024 values which is
  now umnecessary
2024-07-27 07:50:07 -04:00
brody-qq
416875f952 Kernel/FileSystem: Change const placement to match style guide
This moves 3 const keywords in OpenFileDescription::tty() to make them
consistent with the 'const placement' rule in the style guide.
2024-07-27 07:50:07 -04:00
Sönke Holz
c04f240398 Kernel: Set the configuration during USB Hub initialization
All USB Devices (including hubs) need to have a configuration set before
you can use them. We already do this in other USB drivers, but forgot to
do it for USB hubs as well.
2024-07-26 14:25:49 -04:00
Idan Horowitz
3dec9aa54e Kernel: Add a minimal xHCI driver implementation
This adds a minimal (that is, just enough to make USB mouse/keyboard
work) implementation of an xHCI driver, to let us use serenity on
modern baremetal machines.
2024-07-26 14:25:49 -04:00
Idan Horowitz
ccd614212f Kernel: Correct pointer math in USBConfiguration::enumerate_interfaces
Both the calculation for the interface descriptor address and the
endpoint descriptors addresses (for second interface and above) were
incorrect, and would read the wrong data (and go out-of-bounds as well)
2024-07-26 14:25:49 -04:00
Idan Horowitz
c35446b232 Kernel: Give USB::Pipe a reference to its owning USB::Device
Previously USB::Pipe would just try to poorly maintain copies of some
of the relevant properties of USB::Device. (address & speed)
Now it just holds a reference to it's owning device and can query them
when needed.
2024-07-26 14:25:49 -04:00
Idan Horowitz
c5956663f7 Kernel: Move USB device initialization to controllers
The current USB::Device::enumerate_device() implementation is UHCI
specific, and is not relevant for xHCI controllers.

Move it to a USBController virtual method to allow different
implementations for the other controller types.
2024-07-26 14:25:49 -04:00
Idan Horowitz
1e2919b5c1 Kernel: Add create_kernel_thread overload that accepts a lambda
Also fixes the entry function argument initialization to be
architecture-independent.
2024-07-26 14:25:49 -04:00
Sönke Holz
0f18fb6c03 Kernel/x86: Stop the APIC timer before configuring it
This avoids spurious interrupts during APIC timer calibration, as the
timer might otherwise immediately generate an interrupt when enabling
interrupts if the initial count was at a low enough value.
2024-07-24 08:08:47 -04:00
Sönke Holz
87f194b3f5 Kernel: Don't truncate the pc value in the scheduler state dump
This is likely a leftover from the i686-only days.
Also rename the get_eip function to get_pc to be more arch-agnostic.
2024-07-23 09:03:31 -04:00
Liav A.
4aec3f4ef9 Kernel+Userland: Simplify loading of an ELF interpreter path
The LibELF validate_program_headers method tried to do too many things
at once, and as a result, we had an awkward return type from it.

To be able to simplify it, we no longer allow passing a StringBuilder*
but instead we require to pass an Optional<Elf_Phdr> by reference so
it could be filled with actual ELF program header that corresponds to
an INTERP header if such found.

As a result, we ensure that only certain implementations that actually
care about the ELF interpreter path will actually try to load it on
their own and if they fail, they can have better diagnostics for an
invalid INTERP header.

This change also fixes a bug that on which we failed to execute an ELF
program if the INTERP header is located outside the first 4KiB page of
the ELF file, as the kernel previously didn't have support for looking
beyond that for that header.
2024-07-21 15:38:52 +02:00
Liav A.
c0f55d4b11 Kernel: Add a check on ELF interpreter to verify we open a regular file
While extremely unlikely, it's possible to change the dynamic loader
to a non regular file, which will result in a kernel panic upon VERIFY
of the `interpreter_description->inode()` statement.
2024-07-21 15:38:52 +02:00
Liav A.
98160e33c4 Kernel: Add a conversion method from KBuffer to UserOrKernelBuffer 2024-07-21 15:38:52 +02:00
Liav A.
03ae9fdb0a Kernel: Check condition earlier for ELF file type
It makes no sense to do all of the loading work just to figure out that
the ELF file is an object file that is a result of compiling and not
an actual executable.

In addition to that, we should disallow running coredumps as well, so
the condition is changed now to only allow ET_DYN or ET_EXEC ELF files.
2024-07-21 15:38:52 +02:00
Liav A.
3699c2e8ac Kernel/GPU: Remove legacy VGA text mode support
Plain old VGA text mode functionality was introduced in 1987, and is
obviously still used on some (even modern) x86 machines.

However, it's very limited in what it gives to us, because by using a
80x25 text mode console, it's guaranteed that no desktop functionality
is available during such OS runtime session.

It's also quite complicated to handle access arbitration on the VGA ISA
ports which means that only one VGA card can work in VGA mode, which
makes it very cumbersome to manage multiple cards at once.

Since we never relied on the VGA text mode console for anything serious,
as booting on a QEMU machine always gives a proper framebuffer to work
with, VGA text mode console was used in bare metal sessions due to lack
of drivers.
However, since we "force" multiboot-compatible bootloaders to provide us
a framebuffer, it's basically a non-issue to have a functional console
on bare metal machines even if we don't have the required drivers.
2024-07-21 12:21:02 +02:00
Liav A.
efb8063c76 Kernel: Add the BootDummyConsole class
This class will be used in a situation where we simply don't have a
working framebuffer console, but we still want to boot (without having a
screen being attached, or an actual proper GPU driver on bare metal, for
example).
2024-07-21 12:21:02 +02:00
Liav A.
0e6624dc86 Kernel: Introduce the unshare syscall family
These 2 syscalls are responsible for unsharing resources in the system,
such as hostname, VFS root contexts and process lists.

Together with an appropriate userspace implementation, these syscalls
could be used for creating a sandbox environment (containers) for user
programs.
2024-07-21 11:44:23 +02:00
Liav A.
e52abd4c09 Kernel: Introduce the HostnameContext class
Similarly to VFSRootContext and ScopedProcessList, this class intends
to form resource isolation as well.
We add this class as an infrastructure preparation of hostname contexts
which should allow processes to obtain different hostnames on the same
machine.
2024-07-21 11:44:23 +02:00
Liav A.
3692af528e Kernel: Move most of VirtualFileSystem code to be in a namespace
There's no point in constructing an object just for the sake of keeping
a state that can be touched by anything in the kernel code.

Let's reduce everything to be in a C++ namespace called with the
previous name "VirtualFileSystem" and keep a smaller textual-footprint
struct called "VirtualFileSystemDetails".

This change also cleans up old "friend class" statements that were no
longer needed, and move methods from the VirtualFileSystem code to more
appropriate places as well.
Please note that the method of locking all filesystems during shutdown
is removed, as in that place there's no meaning to actually locking all
filesystems because of running in kernel mode entirely.
2024-07-21 11:44:23 +02:00
Liav A.
4370bbb3ad Kernel+Userland: Introduce the copy_mount syscall
This new syscall will be used by the upcoming runc (run-container)
utility.

In addition to that, this syscall allows userspace to neatly copy RAMFS
instances to other places, which was not possible in the past.
2024-07-21 11:44:23 +02:00
Liav A.
dd59fe35c7 Kernel+Userland: Reduce jails to be a simple boolean flag
The whole concept of Jails was far more complicated than I actually want
it to be, so let's reduce the complexity of how it works from now on.
Please note that we always leaked the attach count of a Jail object in
the fork syscall if it failed midway.
Instead, we should have attach to the jail just before registering the
new Process, so we don't need to worry about unsuccessful Process
creation.

The reduction of complexity in regard to jails means that instead of
relying on jails to provide PID isolation, we could simplify the whole
idea of them to be a simple SetOnce, and let the ProcessList (now called
ScopedProcessList) to be responsible for this type of isolation.

Therefore, we apply the following changes to do so:
- We make the Jail concept no longer a class of its own. Instead, we
  simplify the idea of being jailed to a simple ProtectedValues boolean
  flag. This means that we no longer check of matching jail pointers
  anywhere in the Kernel code.
  To set a process as jailed, a new prctl option was added to set a
  Kernel SetOnce boolean flag (so it cannot change ever again).
- We provide Process & Thread methods to iterate over process lists.
  A process can either iterate on the global process list, or if it's
  attached to a scoped process list, then only over that list.
  This essentially replaces the need of checking the Jail pointer of a
  process when iterating over process lists.
2024-07-21 11:44:23 +02:00
Liav A.
91c87c5b77 Kernel+Userland: Prepare for considering VFSRootContext when mounting
Expose some initial interfaces in the mount-related syscalls to select
the desired VFSRootContext, by specifying the VFSRootContext index
number.

For now there's still no way to create a different VFSRootContext, so
the only valid IDs are -1 (for currently attached VFSRootContext) or 1
for the first userspace VFSRootContext.
2024-07-21 11:44:23 +02:00
Liav A.
01e1af732b Kernel/FileSystem: Introduce the VFSRootContext class
The VFSRootContext class, as its name suggests, holds a context for a
root directory with its mount table and the root custody/inode in the
same class.

The idea is derived from the Linux mount namespace mechanism.
It mimicks the concept of the ProcessList object, but it is adjusted for
a root directory tree context.
In contrast to the ProcessList concept, processes that share the default
VFSRootContext can't see other VFSRootContext related properties such as
as the mount table and root custody/inode.

To accommodate to this change progressively, we internally create 2 main
VFS root contexts for now - one for kernel processes (as they don't need
to care about VFS root contexts for the most part), and another for all
userspace programs.
This separation allows us to continue pretending for userspace that
everything is "normal" as it is used to be, until we introduce proper
interfaces in the mount-related syscalls as well as in the SysFS.

We make VFSRootContext objects being listed, as another preparation
before we could expose interfaces to userspace.
As a result, the PowerStateSwitchTask now iterates on all contexts
and tear them down one by one.
2024-07-21 11:44:23 +02:00
brody-qq
6340658005 Kernel/FileSystem: Clean up duplicated if statements
This commit merges 2 if statements that check the same condition in
OpenFileDescription::~OpenFileDescription().
2024-07-15 20:26:45 -04:00
brody-qq
2a164dc923 Kernel/Memory: Fix overcommit when cloning anonymous mmap objects
AnonymousVMObject::try_clone() computed how many shared cow pages to
commit by counting all VMObject pages that were not shared_zero_pages.

This means that lazy_committed_pages were also being included in the
count. This is a problem because the page fault handling code for
lazy_committed_pages does not allocate from
m_shared_committed_cow_pages. So more pages than necessary were being
committed.

This fixes this overcommitting problem by skipping lazy_committed_pages
when counting how many pages to commit.
2024-07-12 08:52:06 -04:00
brody-qq
faa6395a11 Kernel/Memory: Add more efficient method for remapping single page
This commit introduces VMObject::remap_regions_single_page(). This
method remaps a single page in all regions associated with a VMObject.
This is intended to be a more efficient replacement for remap_regions()
in cases where only a single page needs to be remapped.

This commit also updates the cow page fault handling code to use this
new method.
2024-07-12 08:52:06 -04:00
brody-qq
e14f954988 Kernel/Memory: Fix shared anonymous mmap changes not being shared
Writes to a MAP_SHARED | MAP_ANONYMOUS mmap region were not visible to
other processes sharing the mmap region. This was happening because the
page fault handler was not remapping the VMObject's m_regions after
allocating a new page.

This commit fixes the problem by calling remap_regions() after assigning
a new page to the VMObject in the page fault handler. This remapping
only occurs for shared Regions.
2024-07-12 08:52:06 -04:00
brody-qq
781ded408b Kernel/Memory: Small refactor of handle_zero_fault()
This commit makes the following minor changes to handle_zero_fault():
* cleans up a call to static_cast(), replacing it with a reference (a
  future commit will also use this reference).
* replaces a call to vmobject() with the new reference mentioned above.
* moves the definition of already_handled to inside the block where
  already_handled is used.
2024-07-12 08:52:06 -04:00
brody-qq
8812410617 Kernel/Memory: Fix redundant page faults on anonymous mmaps after fork
After a fork(), page faults on anonymous mmaps can cause a redundant
page fault to occur.

This happens because VMObjects for anonymous mmaps are initially filled
with references to the lazy_committed_page or shared_zero_page. If there
is a fork, VMObject::try_clone() is called and all pages of the VMObject
are marked as cow (via the m_cow_map).

Page faults on a zero/lazy page are handled by handle_zero_fault().
handle_zero_fault() does not update m_cow_map, so if the page was marked
cow before the fault, it will still be marked cow after the fault. This
causes a second (redundant) page fault when the CPU retries the write.

This commit removes the redundant page fault by not marking zero/lazy
pages as cow in m_cow_map.
2024-07-12 08:52:06 -04:00
brody-qq
2278b17c42 Kernel/Memory: Remove cow map updates from try_allocate_split_region()
AddressSpace::try_allocate_split_region() was updating the cow map of
new_region based on the cow map of source_region.

The problem is that both new_region and source_region reference the
same vmobject and the same cow map, so these cow map updates didn't
actually change anything.

This commit:
* removes the cow map updates from try_allocate_split_region()
* removes Region::set_should_cow() since it is no longer used
2024-07-12 08:52:06 -04:00
brody-qq
3e9b269bcd Kernel/Memory: Make mmap objects track dirty pages
InodeVMObjects now track dirty and clean pages. This tracking of
dirty and clean pages is used by the msync and purge syscalls.

dirty page tracking works using the following rules:
* when a new InodeVMObject is made, all pages are marked clean.
* writes to clean InodeVMObject pages will cause a page fault,
  the fault handler will mark the page as dirty.
* writes to dirty InodeVMObject pages do not cause page faults.
* if msync is called, only dirty pages are flushed to storage (and
  marked clean).
* if purge syscall is called, only clean pages are discarded.
2024-07-07 18:25:32 +02:00
Liav A.
e89726562b Kernel: Remove the AllMiceDevice class
This device was a short-lived solution to allow userspace (WindowServer)
to easily support hotplugging mouse devices with presumably very small
modifications on userspace side.

Now that we have a proper mechanism to propagate hotplug events from the
DeviceMapper program to any program that needs to get such events, we no
longer need this device, so let's remove it.
2024-07-06 21:42:32 +02:00
Liav A.
a1a2470c1e Documentation: Add a small guide on how to allocate new major numbers
Contributors that want to add new types of character or block devices
must follow these guidelines in order to keep everything intact.
2024-07-06 21:42:32 +02:00
Liav A.
24c1e93afb Kernel/SysFS: Expose device major number allocations to userspace
After the previous commit, we are able to create a comprehensive list of
all devices' major number allocations.

To help userspace to distinguish between character and block devices, we
expose 2 sysfs nodes so userspace can decide which list it needs to open
in order to iterate on it.
2024-07-06 21:42:32 +02:00
Liav A.
16244c490a Kernel: Allocate all device major numbers within one known header file
We used to allocate major numbers quite randomly, with no common place
to look them up if needed.
This commit is changing that by placing all major number allocations
under a new C++ namespace, in the API/MajorNumberAllocation.h file.

We also add the foundations of what is needed before we can publish this
information (allocated numbers for block and char devices) to userspace.
2024-07-06 21:42:32 +02:00
Liav A.
7f5a2c1466 Kernel: Register block and character devices in separate HashMaps
Instead of putting everything in one hash map, let's distinguish between
the devices based on their type.

This change makes the devices semantically separated, and is considered
a preparation before we could expose a comprehensive list of allocations
per major numbers and their purpose.
2024-07-06 21:42:32 +02:00
Liav A.
fdff05cc97 Kernel+Userland: Simplify minor number allocation for virtual consoles
There is simply no advantage with putting both virtual console devices
and serial TTY devices on the same major number.

Putting them on separate major numbers greatly simplifies the allocation
mechanism on the DeviceMapper code, because it no longer needs to
calculate offsets of minor numbers, and should start from number 0 to
theoretically infinite amount of device nodes.
2024-07-06 21:42:32 +02:00
Liav A.
6795e74f1f Kernel/FileSystem: Mark DevLoopFS inodes as block devices
I accidentally marked them as char devices, so they're not usable on
their own when trying to mount with them.
2024-07-06 21:42:32 +02:00
Liav A.
ef243d42fc Kernel: Remove the ConsoleManagement singleton
We don't really need it, and the entire functionality can be organically
intergrated into the VirtualConsole class, to switch between the Virtual
consoles, and manage initialization of all consoles in the global array.
2024-07-04 22:20:35 +02:00
Ryan Castellucci
a2a6bc5348 Documentation: Fix some minor ESL grammar issues
There are a few instances where comments and documentation have minor
grammar issues likely resulting from English being the author's second
language.

This PR fixes several such cases, changing to idiomatic English and
resolving where it is unclear whether the user or program/code is
being referred to.
2024-07-03 00:17:46 +02:00
brody-qq
e254810d0a Kernel/Memory: Remove duplicate code in try_create_purgeable_with_size()
The methods try_create_with_size() and try_create_purgeable_with_size()
on AnonymousVMObject are almost identical, other than one member
that gets set (m_purgeable). This patch makes
try_create_purgeable_with_size() call try_create_with_size() so that
both methods re-use the same code.
2024-07-01 12:47:32 +02:00
Liav A.
bd474dab14 Prekernel: Move the generate_secure_seed function out of init.cpp
As part of a commit series trying to make the prekernel nicer, we should
move and refactor functions out of the init.cpp file if possible.
2024-06-29 19:56:45 +02:00
Liav A.
f6e01aae9a Prekernel: Add support for assertion printing
This is done by using a FixedStringBuffer as the foundation to perform
string formatting, which ensures that we avoid memory allocations in
the prekernel stage.
2024-06-29 19:56:45 +02:00
Liav A.
00c9a57345 Prekernel: Add stub methods to handle memory allocations
These methods do basically nothing right now, because we don't allocate
memory in the prekernel stage.
It's only here for a later commit when we bring up assertion formatting
and printing.
2024-06-29 19:56:45 +02:00
Liav A.
f003c37596 Kernel/Library: Move mini-stdlib functions into their own header file
This will be useful when integrating them later on in the prekernel
stage.
2024-06-29 19:56:45 +02:00
implicitfield
1bf7f99a7b Kernel/Ext2FS: Support writing holes
With this change, we no longer preallocate blocks when an inode's size
is updated, and instead only allocate the minimum amount of blocks when
the inode is actually written to.
2024-06-29 19:16:08 +02:00
implicitfield
180f3f29ab Kernel/Ext2FS: Refactor computing and flushing blocks
This is a large commit, since this is essentially a complete rewrite of
the key low-level functions that handle reading/writing blocks. This is,
however, a necessary prerequisite of being able to write holes.

The previous version of `flush_block_list()` (along with its numerous
helper functions) was entirely reliant on all blocks being sequential.
In contrast to the previous implementation, the new version
of `flush_block_list()` simply writes out the difference between the old
block list and the new block list by calculating the correct indirect
block(s) to update based on the relevant block's logical index.

`compute_block_list()` has also been rewritten, since the estimated
amount of meta blocks was incorrectly calculated for files with holes as
a result of the estimated amount of blocks being a function of the file
size. Since it isn't possible to accurately compute the shape of the
block list without traversing it, we no longer try to perform such a
computation, and instead simply search through all of the allocated
indirect blocks.

`compute_block_list_with_meta_blocks()` has also been removed in favor
of the new `compute_meta_blocks()`, since meta blocks are fundamentally
distinct from data blocks due to there being no mapping between any
logical block index and the physical block index.
2024-06-29 19:16:08 +02:00
implicitfield
06d4672564 Kernel/Ext2FS: Store the block list as a HashMap rather than a Vector
Since we now only store blocks that are actually allocated, it is
entirely valid for the block list to be empty, so this commit lifts the
restrictions on accessing inodes with an empty block list.
2024-06-29 19:16:08 +02:00
implicitfield
ba96a0e4f8 Kernel/Ext2FS: Simplify read/write loops
This removes removes the need to know the last block in advance, and
makes the loops slightly easier to reason about by depending on fewer
conditions.
2024-06-29 19:16:08 +02:00
Sönke Holz
facca92780 Kernel/Storage: Dump storage devices to the framebuffer console as well
This is helps bringing up bare metal devices without having to use the
serial console.
2024-06-26 08:47:00 +02:00
Idan Horowitz
3aa1bd520b Kernel: Support re-mapping MMIOVMObject-backed regions
This is required for example when write combine is enabled on a region
after the initial mapping.
2024-06-25 17:46:37 +02:00
brody-qq
5058873d45 Kernel/Memory: Make release_all_clean_pages use try_release_clean_pages
The methods try_release_clean_pages() and release_all_clean_pages() in
InodeVMObject are almost identical. This commit makes them both use the
same code path.
2024-06-09 14:00:41 -04:00
brody-qq
a4ca757db9 Kernel: Add method to clean up remapping region loops
In the VMObject code there are multiple examples of loops over
the VMObject's regions (using for_each_region()) that call remap()
on each region.

To clean up usage of this pattern, this patch adds a method in
VMObject that does this remapping loop. VMObject code that needs
to remap its regions call the new method.
2024-06-08 22:36:03 +01:00
brody-qq
6f6966fb55 Kernel: Remove redundant VERIFY()
Removes a VERIFY() that is already checked earlier in the function
2024-06-05 20:18:44 +01:00
implicitfield
ef766b0b5f Kernel/FUSE: Allow buffering multiple requests
It can be possible for a request to be blocked on another request, so
this patch allows us to send more requests even when a request is
already pending.
2024-06-01 14:47:58 -06:00
implicitfield
727881f3d1 Kernel/FUSE: Log IDs of mismatched requests 2024-06-01 14:47:58 -06:00
implicitfield
7acc5763ed Kernel/FUSE: Fill in uid, gid, and pid records 2024-06-01 14:47:58 -06:00
implicitfield
a343c7cde4 Kernel/FUSE: Clarify the license of Definitions.h 2024-06-01 14:47:58 -06:00
Liav A.
ecc9c5409d Kernel: Ignore dirfd if absolute path is given in VFS-related syscalls
To be able to do this, we add a new class called CustodyBase, which can
be resolved on-demand internally in the VirtualFileSystem resolving path
code.

When being resolved, CustodyBase will return a known custody if it was
constructed with such, if that's not the case it will provide the root
custody if the original path is absolute.
Lastly, if that's not the case as well, it will resolve the given dirfd
to provide a Custody object.
2024-06-01 19:25:15 +02:00
Idan Horowitz
b4cdd6a55c Kernel: Prevent integer overflow in USB::Hub::check_for_port_updates()
The maximum valid value is 255, so max + 1 doesn't fit in a u8.
2024-05-27 17:35:42 +02:00
Sönke Holz
de02a2680f Kernel/riscv64: Handle breakpoint traps
This means that userspace breakpoint traps no longer panic the kernel.
This also causes us to no longer panic on failed assertions in userspace
when using gcc, as gcc compiles __builtin_trap to breakpoint
instructions on RISC-V.
2024-05-23 14:11:36 -06:00
Sönke Holz
018a28cf4a Kernel/HID: Add support for virtio input devices 2024-05-23 11:16:57 -06:00
Liav A.
c48d540230 Kernel: Move VGATextModeConsole code to the Arch/x86_64/ISABus directory
This code is specific to x86 machines, as virtually no other computer
architecture has any compatibility with old VGA legacy functionality.
2024-05-23 05:07:56 -06:00
Kirill Nikolaev
99f6528009 Kernel: Implement virtio-blk driver 2024-05-23 00:59:39 -06:00
Liav A.
3ba5daeca9 Kernel: Actually set physical base pointer correctly in prekernel stage
I did a mistake and set the kernel_physical_base value to be just on
the actual linked kernel ELF start offset, while this value should
represent together with KERNEL_MAPPING_BASE the actual higher-half load
address.

By changing this value, we resolve a bug in which disabling KASLR
doesn't work and will cause the prekernel to hang on this statement:
```c++
VERIFY(kernel_load_base >= kernel_mapping_base + 0x200000);
```
2024-05-22 23:25:51 +02:00
Dan Klishch
38b51b791e AK+Kernel+LibVideo: Include workarounds for missing P0960 only in Xcode
With this change, ".*make.*" function family now does error checking
earlier, which improves experience while using clangd. Note that the
change also make them instantiate classes a bit more eagerly, so in
LibVideo/PlaybackManager, we have to first define SeekingStateHandler
and only then make() it.

Co-Authored-By: stelar7 <dudedbz@gmail.com>
2024-05-21 14:24:59 +02:00
Idan Horowitz
26cff62a0a Kernel: Rename Memory::PhysicalPage to Memory::PhysicalRAMPage
Since these are now only used to represent RAM pages, (and not MMIO
pages) rename them to make their purpose more obvious.
2024-05-17 15:38:28 -06:00
Idan Horowitz
827322c139 Kernel: Stop allocating physical pages for mapped MMIO regions
As MMIO is placed at fixed physical addressed, and does not need to be
backed by real RAM physical pages, there's no need to use PhysicalPage
instances to track their pages.
This results in slightly reduced allocations, but more importantly
makes MMIO addresses which end up after the normal RAM ranges work,
like 64-bit PCI BARs usually are.
2024-05-17 15:38:28 -06:00
Liav A.
5f3ef1aa9e Kernel: Remove includes of PCI API.h file
This file will be removed in a future commit, so let's get rid of what
we can right now.
2024-05-14 15:42:29 -06:00
Liav A.
e1d435d0b0 Kernel/x86_64: Rename PCI HostBridge => PIIX4HostBridge
This code is actually for the old PIIX4 PCI host bridge, which requires
to use legacy x86 IO instructions.
2024-05-14 15:42:29 -06:00
Liav A.
69a3602237 Kernel/GPU: Rename GenericGraphicsAdapter => GPUDevice
GenericGraphicsAdapter is mouthful. Also, the idea is to move towards a
more advanced subsystem that handles GPUs, not merely graphics adapters.
2024-05-14 15:42:29 -06:00
Liav A
6014ce0552 Kernel/PCI: Add small access spinlock to each HostController
Prepare to remove biglock on PCI::Access in a future commit, so we can
ensure we only lock a spinlock on a precise PCI HostController if needed
instead of the entire subsystem.
2024-05-14 15:42:29 -06:00
Liav A.
0bab9a9313 Kernel: Move VirtIO RNG implementation to the Security/Random directory 2024-05-14 15:42:29 -06:00
Liav A.
bbb749ab47 Kernel: Move VirtIO console code to the Devices/Serial/VirtIO directory 2024-05-14 15:42:29 -06:00
Liav A.
cb558f4459 Kernel/Devices: Remove SerialDevice::initialize method
We can just do the initialization sequence in the constructor.
2024-05-14 15:42:29 -06:00
Liav A.
b4c218168f Kernel/Storage: Remove StorageController reset and shutdown methods
We never used these virtual methods outside their own implementation,
so let's stop pretending that we should be able to utilize this for
unknown purpose.
2024-05-14 15:42:29 -06:00
Liav A.
eadf2bf29f Kernel/Devices: Remove UNMAP_AFTER_INIT from SerialDevice code 2024-05-14 15:42:29 -06:00
Liav A.
136d5b12d5 Kernel/VirtIO: Remove stale detect method 2024-05-14 15:42:29 -06:00
Liav A.
d73c82d746 Kernel: Remove UNMAP_AFTER_INIT from VGA text mode console 2024-05-14 15:42:29 -06:00
Liav A
d068af89d5 Kernel/x86: Bake the Prekernel and the Kernel into one image
The new baked image is a Prekernel and a Kernel baked together now, so
essentially we no longer need to pass the Prekernel as -kernel and the
actual kernel image as -initrd to QEMU, leaving the option to pass an
actual initrd or initramfs module later on with multiboot.
2024-05-14 23:37:38 +02:00
implicitfield
4574a8c334 Kernel+LibC+LibCore: Implement mknodat(2) 2024-05-14 22:30:39 +02:00
implicitfield
05cf1327ed Kernel: Make utimensat ignore the dirfd when given an absolute path 2024-05-14 22:30:39 +02:00
Sönke Holz
fe12a413a1 Kernel: Use AK::unwind_stack_from_frame_pointer 2024-05-14 14:02:06 -06:00
Liav A.
5194ab59b5 Kernel/Memory: Make has_been_{r,w,x} flags clearly being set
Before of this change, actually setting the m_access to contain the
HasBeen{Readeable,Writable,Executable} bits was done by the method of
Region set_access_bit which added ORing with (access << 4) when enabling
a certain access bit to achieve this.

Now this is changed and when calling set_{readeable,writable,executable}
methods, they will set an appropriate SetOnce flag that could be checked
later.
2024-05-14 12:41:51 -06:00
Liav A.
15ddc1f17a Kernel+Userland: Reject W->X prot region transition after a prctl call
We add a prctl option which would be called once after the dynamic
loader has finished to do text relocations before calling the actual
program entry point.

This change makes it much more obvious when we are allowed to change
a region protection access from being writable to executable.
The dynamic loader should be able to do this, but after a certain point
it is obvious that such mechanism should be disabled.
2024-05-14 12:41:51 -06:00
Liav A.
e756567341 Kernel+Userland: Convert process syscall region enforce flag to SetOnce
This flag is set only once, and should never reset once it has been set,
making it an ideal SetOnce use-case.
It also simplifies the expected conditions for the enabling prctl call,
as we don't expect a boolean flag, but rather the specific prctl option
will always set (enable) Process' AddressSpace syscall region enforcing.
2024-05-14 12:41:51 -06:00
Liav A.
2cb86c1309 Kernel/Storage: Remove ATA IDE support
Nobody uses this functionality. I used this code on my old 2007 ICH7
test machine about a year ago, but bare metal is a small aspect of the
project, so it's safe to assume that nobody really tests this piece of
code.
Therefore, let's drop this for good and focus on more modern hardware.
2024-05-14 12:38:05 -06:00
Matthew Olsson
4ae7bbda52 Lagom: Add ClangPlugins to the build system 2024-05-13 16:50:54 -06:00
Timothy Flynn
3ff1d7da59 Kernel: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There was a recent release of clang-format version 18.1.5 which fixes
errant spaces around `->` in these files.
2024-05-12 15:44:27 -04:00
Isaac
3d2fcf4244 Kernel/net: Add tracking of dropped packets per adapter 2024-05-09 12:02:26 +02:00
Liav A.
f7a85401bb Kernel/Storage: Remove a stale StorageDevice constructor method
ramdisk devices are long gone by now, so this is a stale method.
2024-05-07 17:02:09 -06:00
implicitfield
a08d1637e2 Kernel: Add FUSE support
This adds both the fuse device (used for communication between the
kernel and the filesystem) and filesystem implementation itself.
2024-05-07 16:54:27 -06:00
Dan Klishch
cc5bacf886 Kernel: Allow annotating initially loaded executable segments
This allows marking regions as VirtualMemoryRangeFlags::SyscallCode in
static executables.
2024-05-07 16:36:38 -06:00
Hendiadyoin1
b17f080dcc Kernel/riscv: Use new DeviceTree helpers in PCI initializations
This also changes the PCI interface slightly to be a bit nicer to work
with.
2024-05-02 07:44:13 -06:00
Hendiadyoin1
8ea8b7a6e5 Kernel/MM: Parse /memreserve/ blocks in FDT based memory mapping mode
These seem to be actually used in the RPi FDTs
2024-05-02 07:44:13 -06:00
Hendiadyoin1
2b13769dd5 Kernel/MM: Skip non static reserved memory regions instead of crashing
Crashing seems a bit harsh, so let's just skip them instead, as they
actually show up in the device tree of RPis.
2024-05-02 07:44:13 -06:00
Sönke Holz
b363abb082 Kernel/aarch64: Explicitly allow float instrs in {load,store}_fpu_state
LLVM 18 otherwise throws errors, as we use '-mgeneral-regs-only' in the
kernel.
The functions had to be moved into a .S, as there is no
'-mno-general-regs-only' and also no nice way to remove
'-mgeneral-regs-only' for a single .cpp file.
2024-04-30 06:32:58 -06:00
Idan Horowitz
dfa2c98497 Kernel: Support the RISC-V PLIC
By supporting the RISC-V PLIC (Platform-Level Interrupt Controller)
we can now handle device (external) interrupts.
2024-04-30 06:01:26 -06:00
Idan Horowitz
0a2d520b15 Kernel: Handle CLINT interrupts separately from normal interrupts
Since CLINT interrupts are wired directly into the hart, instead of
going through an interrupt controller (the PLIC), trying to handle them
through the normal numbered-interrupt mechanism will just complicate it
for no reason.
Instead we now handle them directly in the trap handler.
2024-04-30 06:01:26 -06:00
Idan Horowitz
002bba4a97 Kernel: Configure PCI interrupt routing based on the FDT 2024-04-30 06:01:26 -06:00
Idan Horowitz
7102d90b2b Kernel: Verify we are running on hart 0
This is already an implicit assumption when we initialize our CPU id.
2024-04-30 06:01:26 -06:00
Idan Horowitz
d3e285c253 Kernel: Deduplicate HardwareTimerBase::frequency()/ticks_per_second() 2024-04-30 06:01:26 -06:00
Liav A.
b9df8deba2 Kernel/USB: Don't include UHCIController.h in USBPipe.h
The USB::Pipe is abstracted from the actual USB host controller
implementation, so don't include the UHCIController.h file.
Also, we missed an include to UserOrKernelBuffer.h, so this is added to
ensure the code can still compile.
2024-04-28 22:30:48 +02:00
Liav A.
2bba9411ca Kernel: Use the AK SetOnce container class in various cases
We have many places in the kernel code that we have boolean flags that
are only set once, and never reset again but are checked multiple times
before and after the time they're being set, which matches the purpose
of the SetOnce class.
2024-04-26 23:46:23 -06:00
Sönke Holz
01f1d2daaa Kernel/riscv64: Don't clobber the boot info argument in enable_paging
"register asm" variables don't preserve the register value, so the call
to calculate_physical_to_link_time_address_offset in the asm input
operands is allowed to clobber a0.
2024-04-26 15:01:31 -06:00
Timothy Flynn
ab602cfc2c Kernel: Colorize log message for capabilities that have not been pledged
The log message can be hard to spot in a sea of debug messages. Colorize
it to make the message more immediately pop out.
2024-04-26 09:29:02 -04:00
Idan Horowitz
7339409575 Kernel: Properly initialize NVMe admin queue depth
We were reading the value instead of setting it (as required by the
specification). This worked only when we booted with a bootloader which
initialized NVMe before us.
2024-04-26 09:52:56 +02:00
Idan Horowitz
a2b2209ea5 Kernel: Fix definition of CAP_TO_MASK
The default type for integer literals is signed int, so we were
accidentally smearing those bits to the upper 32 bit of the result.
This resulted in extremely unreasonable timeouts.
2024-04-26 09:52:56 +02:00
Idan Horowitz
543fc4d0fc Kernel: Support automatic configuration of PCI bridges based on the FDT
This let's us actually boot with RISC-V.
2024-04-26 09:52:56 +02:00
Idan Horowitz
08d4b231e1 Kernel: Take EnumerableDeviceIdentifier by const ref instead of by value
It's 48 bytes.
2024-04-26 09:52:56 +02:00
Idan Horowitz
f6ae9f8a6d Kernel: Reset enumerated buses bitmap before enumerating PCI devices
This allows this method to be used more than once.
2024-04-26 09:52:56 +02:00
Idan Horowitz
95aff1cf13 Kernel: Remove unused IterationDecision in enumerate_attached_devices 2024-04-26 09:52:56 +02:00
Idan Horowitz
e350d3b2c6 Kernel: Use PCI:Class:ID::Bridge instead of magic value 2024-04-26 09:52:56 +02:00
Idan Horowitz
519be6e626 Kernel: Use correctly-sized read when checking PCI host bridge function
We were accidentally doing a 16-bit read instead of an 8-bit read,
meaning we would also read the 'CACHE_LINE_SIZE' field immediately
following it, and never actually continue.
2024-04-26 09:52:56 +02:00
Timothy Flynn
fecd08ce64 Everywhere: Remove 'clang-format off' comments that are no longer needed 2024-04-24 16:50:01 -04:00
Timothy Flynn
ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
Sönke Holz
511e411def Kernel/riscv64: Implement Processor::read_cpu_counter
This simply reads the current cycle count from the cycle CSR.
x86-64 uses the similar rdtsc instruction here, which also may or may
not tick at a constant rate.
2024-04-21 13:37:32 -06:00
Sönke Holz
c57e39d52b Kernel/riscv64: Don't flush the entire TLB in Processor::flush_tlb_local 2024-04-21 13:37:06 -06:00
implicitfield
c15b473c1a Kernel/FATFS: Only read the requested blocks in read_bytes_locked()
This dramatically improves performance when working with large files,
since we no longer re-read the entire file for each read.
2024-04-21 15:34:33 +02:00
implicitfield
5bc87ad1a5 Kernel/FATFS: Free an inode's clusters upon removal 2024-04-21 15:34:33 +02:00
implicitfield
32692f032c Kernel/FATFS: Keep the FSInfo sector's free cluster count in sync 2024-04-21 15:34:33 +02:00
implicitfield
bd76dd2dc2 Kernel/FATFS: Initialize special directory entries 2024-04-21 15:34:33 +02:00
implicitfield
66e1f8812f Kernel/FATFS: Don't ignore special entries when traversing directories 2024-04-21 15:34:33 +02:00
Undefine
31174c43bf Kernel/FATFS: Implement a hacky replace_child
This is not a proper implementation, but it's good enough to get
the write support fully working.
2024-04-21 15:34:33 +02:00
Undefine
511b298a1d Kernel/FATFS: Implement remove_child 2024-04-21 15:34:33 +02:00
Undefine
3b39a2f71b Kernel/FATFS: Implement add_child 2024-04-21 15:34:33 +02:00
Undefine
2952401c58 Kernel/FATFS: Implement create_child
This is a large commit because it implements a lot of stuff to make
add_child simpler to get working. This allows us to create new files
on a FAT partition.
2024-04-21 15:34:33 +02:00
Undefine
098518cc57 Kernel/FATFS: Implement file modification
This is the first part of write support, it allows for full file
modification, but no creating or removing files yet.

Co-Authored-By: implicitfield <114500360+implicitfield@users.noreply.github.com>
2024-04-21 15:34:33 +02:00