summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2021-09-05Kernel: Declare syscall handlers with "using" instead of "typedef"Brian Gianforcaro
Also use bit_cast to avoid -Wcast-function-type warning.
2021-09-05Kernel: Declare type aliases with "using" instead of "typedef"Brian Gianforcaro
This is the idiomatic way to declare type aliases in modern C++. Flagged by Sonar Cloud as a "Code Smell", but I happen to agree with this particular one. :^)
2021-09-05Kernel: Improve names in the ARP table thread blockerAndreas Kling
More instances of functions named "unblock()" that don't actually unblock in all cases being renamed to something more precise.
2021-09-05Kernel: Rename FileBlocker::unblock() => unblock_if_conditions_are_met()Andreas Kling
Since this may not actually unblock, the old name was very confusing.
2021-09-05Kernel: Tidy up InodeWatcher constructionAndreas Kling
- Rename create() => try_create() - Use adopt_nonnull_ref_or_enomem()
2021-09-05Kernel: Remove UserOrKernelBuffer::copy_into_string()Andreas Kling
All former users of this API have been converted to use KString. :^)
2021-09-05Kernel/Plan9FS: Use KString instead of String in one placeAndreas Kling
2021-09-05Kernel/Ext2FS: Remove a String allocation in debug loggingAndreas Kling
We were creating a temporary String just to log the target when writing a symlink directly into inline storage.
2021-09-04Kernel: Tidy up UDPSocket creation a bitAndreas Kling
- Rename create() => try_create() - Use adopt_nonnull_ref_or_enomem()
2021-09-04Kernel: Tidy up TCPSocket creation a bitAndreas Kling
- Rename create() => try_create() - Use adopt_nonnull_ref_or_enomem()
2021-09-04Kernel: Handle ProcessGroup allocation failures betterAndreas Kling
- Rename create* => try_create* - Don't null out existing process group on allocation failure
2021-09-04Kernel: Make Process::try_create() propagate errors betterAndreas Kling
2021-09-04Kernel: Tidy up Process::try_create_user_process()Andreas Kling
This function is currently only ever used to create the init process (SystemServer). It had a few idiosyncratic things about it that this patch cleans up: - Errors were returned in an int& out-param. - It had a path for non-0 process PIDs which was never taken.
2021-09-04Kernel: Move pledge verification into Process member functionsAndreas Kling
REQUIRE_PROMISE and REQUIRE_NO_PROMISES were macros for some reason, and used all over the place. This patch adds require_promise(Pledge) and require_no_promises() to Process and makes the macros call these on the current process instead of inlining code everywhere.
2021-09-04Kernel: Rename Thread::clone() => try_clone() and propagate errorsAndreas Kling
2021-09-04Kernel: Add missing error check after Process::try_create()Andreas Kling
As the name now suggests, this API can fail. :^)
2021-09-04Kernel: Rename Process::create() => try_create()Andreas Kling
2021-09-04Kernel: Add x2APIC supportTom
This allows addressing all cores on more modern processors. For now, we still have a hardcoded limit of 64 due to s_processors being a static array.
2021-09-04Kernel: Allow specifying ecx with CPUIDTom
Some CPUID functions (e.g. 0xb) require input values in ecx.
2021-09-04Kernel/VirtIO: Determine VirtIO device class also with the PCI device IDLiav A
According to the VirtIO 1.0 specification: "Non-transitional devices SHOULD have a PCI Device ID in the range 0x1040 to 0x107f. Non-transitional devices SHOULD have a PCI Revision ID of 1 or higher. Non-transitional devices SHOULD have a PCI Subsystem Device ID of 0x40 or higher." It also says that: "Transitional devices MUST have a PCI Revision ID of 0. Transitional devices MUST have the PCI Subsystem Device ID matching the Virtio Device ID, as indicated in section 5. Transitional devices MUST have the Transitional PCI Device ID in the range 0x1000 to 0x103f." So, for legacy devices, we know that revision ID in the PCI header won't be 1, so we probe for PCI_SUBSYSTEM_ID value. Instead of using the subsystem device ID, we can probe the DEVICE_ID value directly in case it's not a legacy device. This should cover all possibilities for identifying VirtIO devices, both per the specification of 0.9.5, and future revisions from 1.0 onwards.
2021-09-04Kernel/VirtIO: Defer initialization of device out of the constructorLiav A
This ensures we safely handle interrupts (which can call virtual functions), so they don't happen in the constructor - this pattern can lead to a crash, if we are still in the constructor context because not all methods are available for usage (some are pure virtual, so it's possible to call __cxa_pure_virtual). Also, under some conditions like adding a PCI device via PCI-passthrough mechanism in QEMU, it became exposed to the eye that the code asserts on RNG::handle_device_config_change(). That device has no configuration but if the hypervisor still misbehaves and tries to configure it, we should simply return false to indicate nothing happened.
2021-09-04Kernel/SysFS: Ensure data stability when reading from InodesLiav A
Like with the ProcFS, description data can change at anytime, so it's wise to ensure that when the userland reads from an Inode, data is consistent unless the userland indicated it wants to refresh the data (by seeking to offset 0, or re-attaching the Inode). Otherwise, if the data changes in the middle of the reading, it can cause silent corruption in output which can lead to random crashes.
2021-09-04Kernel/DevFS: Remove unnecessary includeLiav A
2021-09-04Kernel/Devices: Remove unnecessary virtual methodLiav A
The is_disk_device method is not being overrided by any class or called by anyone, so let's just remove it.
2021-09-04Kernel: Delete the rvalue-ref qualified version of KResultOr::value()Andreas Kling
This makes calling value() on a temporary KResultOr be a compile-time error. This exposed a number of missing error checks (fixed in the preceding commits.)
2021-09-04Kernel: Add missing error check when opening TTY for a new processAndreas Kling
2021-09-04Kernel: Add missing error check when opening root file systemAndreas Kling
2021-09-04Kernel/VirtIO: Add two missing error checks in VirtIO::ConsolePortAndreas Kling
2021-09-03Everywhere: Prevent risky implicit casts of (Nonnull)RefPtrDaniel Bertalan
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
2021-09-03Kernel: Convert Routing to east-const stylebrapru
2021-09-03Kernel: Don't use {:p} when printing out invalid userspace stack pointerLuke Wilde
`userspace_esp` is a virtual address and thus using `{:p}` on it is invalid and will cause an assertion failure. I ran into this while testing #9772.
2021-09-03Kernel/VirtIO: Stop leaking VirtIO::ConsolePort objectsAndreas Kling
2021-09-03AK: Rename create<T> => make_ref_counted<T>Andreas Kling
And also try_create<T> => try_make_ref_counted<T>. A global "create" was a bit much. The new name matches make<T> better, which we've used for making single-owner objects since forever.
2021-09-01Kernel: Use = default for empty destructorsBrian Gianforcaro
2021-09-01Kernel: Don't cast to NetworkOrdered<u16>* from random dataBrian Gianforcaro
NetworkOrdered is a non trivial type, and it's undefined behavior to cast a random pointer to it and then pretend it's that type. Instead just call AK::convert_between_host_and_network_endian on the individual u16*. This suppresses static analysis warnings. I don't think there was a "bug" in the previous code, it worked, but it was very brittle.
2021-09-01Kernel: Convert UserOrKernelBuffer callbacks to use AK::BytesBrian Gianforcaro
2021-09-01Kernel: Convert random bytes interface to use AK::BytesBrian Gianforcaro
2021-09-01Kernel: Pass InodeMetadata by reference in TmpFSInode::createBrian Gianforcaro
This struct is non-trivially large, it makes sense to pass it by reference instead of by value in the factory method. Found by Sonar Cloud.
2021-09-01Kernel: Only unlock Mutex once in execve when PT_TRACE_ME is enabledAndrew Kaster
Fixes a regression introduced in 70518e6. Fixes #9704.
2021-09-01Everywhere: Use my cool new @serenityos.org email addressPeter Elliott
2021-08-31Kernel/VirtIO: Don't expose constructors as public methodLiav A
This leads to a bad pattern where anyone could create an RNG or a Console object. Instead, let's just use the common pattern of a static method to instantiate a new object and return it wrapped by a NonnullRefPtr.
2021-08-31Kernel/VirtIO: Remove redundant VirtIO word from filenamesLiav A
Now that all related VirtIO classes are in the VirtIO namespace, let's just remove the redundant VirtIO word from filenames.
2021-08-31Kernel/VirtIO: Move everything into the VirtIO namespaceLiav A
Before of this change, many specific classes to VirtIO were in the Kernel namespace, which polluted it. Everything should be more organized now, but there's still room for improvement later.
2021-08-31Kernel/VirtIO: Remove the m_class_name memberLiav A
This class member was used only to determine the device type when printing messages to the debug log. Instead, remove this class member, and add a quick way to find the device type according to how the VirtIO specification says to do that. This simplifies construction of VirtIODevices a bit, because now the constructor doesn't need to ask for a String identified with the device type.
2021-08-31Kernel/PCI: Fix offset error of the PCI_SUBSYSTEM valuesLiav A
Apparently both PCI_SUBSYSTEM_ID and PCI_SUBSYSTEM_VENDOR_ID offsets should be swapped from one to another to be correct.
2021-08-31Kernel/VirtIO: Make RNG device to not be a CharacterDeviceLiav A
This class as a CharacterDevice really was not useful, because you couldn't even read from it. Also, the random number generator interface should be the /dev/random, so any other interface to get random numbers is generally not a good idea. Instead, let's keep this functionality as an entropy source for random numbers generation, but without exposing a device node.
2021-08-31Kernel: Ignore zero-sized PT_LOAD headers when loading ELF imagesAndreas Kling
2021-08-31Kernel/Userland: Expose usb device address and use it in `lsusb`Jesse Buhagiar
We now expose the `USBDevice`'s address in the SysFS object. This means that device addresses are no longer determined by the name of the file in the `/bus/usb/` directory. This was an incorrect way of determining device address, as a standard PC can have multiple USB controllers (and hence multiple buses) that can have overlapping device IDs.
2021-08-31Kernel: Don't VERIFY_NOT_REACHED in LocalSocket::has_attached_peer()Owen Smith
Invoking sendmsg on a listening socket triggers this assertion as sendto calls has_attached_peer before checking the result of send_buffer_for.
2021-08-30Kernel: Fix shift sometimes staying pressed after releasing the keyLepkoQQ
Previous implementation sometimes didn't release the key after pressing and holding shift due to repeating key updates when holding keys. This meant repeating updates would set/unset `m_both_shift_keys_pressed` repeatedly, sometimes resulting in shift still being considered pressed even after you released it. Simplify left and right shift key pressed logic by tracking both key states separately and always updating modifiers based on them.