summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2020-11-29LibCrypto: Require intent parameter in CTR constructorLuke
This was preventing clang from building.
2020-11-26Kernel: Enable VMWareBackdoor immediately at bootTom
Rather than waiting until we get the first mouse packet, enable the absolute mode immediately. This avoids having to click first to be able to move the mouse.
2020-11-24Kernel: Reduce ByteBuffer thrashing in inode block list generationAndreas Kling
Instead of creating and destroying a new ByteBuffer for every block we process during block list generation, just use stack memory instead.
2020-11-24Kernel: Fix SharedBuffer reference counting on forkTom
We need to not only add a record for a reference, but we need to copy the reference count on fork as well, because the code in the fork assumes that it has the same amount of references, still. Also, once all references are dropped when a process is disowned, delete the shared buffer. Fixes #4076
2020-11-24Kernel: Use a doubly-linked list for the BlockBasedFS cacheAndreas Kling
This makes misses in the BlockBasedFS's LRU block cache faster by storing the cache entries in one of two doubly-linked list. Dirty and clean cache entries are kept in two separate lists, and move between them when their state changes. This can probably be improved upon further.
2020-11-24Ext2FS: Oops, fix forgotten assignment in Ext2FSInode::resize()Andreas Kling
If the inode's block list cache is empty, we forgot to assign the result of computing the block list. The fact that this worked anyway makes me wonder when we actually don't have a cache.. Thanks to szyszkienty for spotting this! :^)
2020-11-24Kernel: Add a fast lookup table to the BlockBasedFS disk cacheAndreas Kling
Instead of doing a linear scan of the entire cache when doing a lookup, we now have a nice O(1) HashMap in front of the cache. The cache miss case can still be improved, this patch really only helps the cache hit case. This dramatically improves cached filesystem I/O. :^)
2020-11-24Ext2FS: Use cached inode block list in resize() if availableAndreas Kling
If we have already cached the block list of an Ext2FSInode, we can save a lot of time by not regenerating it.
2020-11-24Kernel: Remove unnecessary SmapDisablers in FileDescriptionAndreas Kling
Since we're using UserOrKernelBuffers, SMAP will be automatically disabled when we actually access the buffer later on. There's no need to disable it wholesale across the entire read/write operations.
2020-11-23Kernel: Add unveil('b')Sergey Bugaev
This is a new "browse" permission that lets you open (and subsequently list contents of) directories underneath the path, but not regular files or any other types of files.
2020-11-23Kernel: Don't resume thread into Running state directly on SIGCONTTom
We should never resume a thread by directly setting it to Running state. Instead, if a thread was in Running state when stopped, record the state as Runnable. Fixes #4150
2020-11-23ProcFS: Take the "all inodes" lock when generating /proc/inodesAndreas Kling
Otherwise the kernel asserts.
2020-11-23Kernel: Don't leak ref on executable inode in sys$execve()Andreas Kling
We were leaking a ref on the executed inode in successful calls to sys$execve(). This meant that once a binary had ever been executed, it was impossible to remove it from the file system. The execve system call is particularly finicky since the function does not return normally on success, so extra care must be taken to ensure nothing is kept alive by stack variables. There is a big NOTE comment about this, and yet the bug still got in. It would be nice to enforce this, but I'm unsure how.
2020-11-23Ext2FS: Move some EXT2_DEBUG logging behind EXT2_VERY_DEBUGAndreas Kling
This makes the build actually somewhat usable with EXT2_DEBUG. :^)
2020-11-23Kernel: Convert dbg() to dbgln() in Syscall.cppAndreas Kling
2020-11-23Ext2FS: Clear out the direct block list when an inode is resized to 0Andreas Kling
e2fsck was complaining about blocks being allocated in an inode's list of direct blocks while at the same time being free in the block bitmap. It was easy to reproduce by creating a file with non-zero length and then truncating it. This fixes the issue by clearing out the direct block list when resizing a file to 0.
2020-11-23Kernel: Inherit shared buffers when forkingTom
We need to create a reference for the new PID for each shared buffer that the process had a reference to. If the process subsequently get replaced through exec, those references will be dropped again. But if exec for some reason fails then other code, such as global destructors could still expect having access to them. Fixes #4076
2020-11-22Kernel: Make CLOCK_MONOTONIC respect the system tick frequencyAndreas Kling
The time returned by sys$clock_gettime() was not aligned with the delay calculations in sys$clock_nanosleep(). This patch fixes that by taking the system's ticks_per_second value into account in both functions. This patch also removes the need for Thread::sleep_until() and uses Thread::sleep() for both absolute and relative sleeps. This was causing the nesalizer emulator port to sleep for a negative amount of time at the end of each frame, making it run way too fast.
2020-11-20MACAddress: AK::Array as member variable instead of C-arrayLenny Maiorani
Problem: - C-style arrays do not automatically provide bounds checking and are less type safe overall. - `__builtin_memcmp` is not a constant expression in the current gcc. Solution: - Change private m_data to be AK::Array. - Eliminate constructor from C-style array. - Change users of the C-style array constructor to use the default constructor. - Change `operator==()` to be a hand-written comparison loop and let the optimizer figure out to use `memcmp`.
2020-11-14Kernel: Fix mouse lag when VMWareBackdoor absolute mode is enabledTom
We won't be receiving full PS/2 mouse packets when the VMWareBackdoor absolute mouse mode is enabled. So, read just one byte every time and retrieve the latest mouse packet from VMWareBackdoor immediately. Fixes #4086
2020-11-14Revert "Kernel: Keep reading from i8042 until the buffer is empty"Tom
This reverts commit 467f6c74a4d2bfd46fdd04c7ef3ff35ab88e1384.
2020-11-14Kernel: Keep reading from i8042 until the buffer is emptyAndreas Kling
Otherwise we might not drain the mouse buffer until the next IRQ.
2020-11-14TmpFS: Set the root inode's timestamp to the current timeAndreas Kling
cc @bcoles :^)
2020-11-12Kernel: Implement an asynchronous device request stackTom
This allows issuing asynchronous requests for devices and waiting on the completion of the request. The requests can cascade into multiple sub-requests. Since IRQs may complete at any time, if the current process is no longer the same that started the process, we need to swich the paging context before accessing user buffers. Change the PATA driver to use this model.
2020-11-12Kernel: Add I8042Controller to detect and manage PS/2 devicesTom
Rework the PS/2 keyboard and mouse drivers to use a common 8042 controller driver. Also, reset and reconfigure the 8042 controller as they are not guaranteed to be in the state that we expect.
2020-11-12Kernel: Assume 8042 controller is present if ACPI FADT revision <= 1Tom
This field wasn't specified until revision 2 and should be assumed to be set on older versions.
2020-11-12Kernel: Fix race during thread destruction if it is preemptedTom
This fixes a lot of crashes in Bochs, which is more likely to preempt thread destruction.
2020-11-11Kernel: Fix deadlock when unicasting/broadcasting SMP messageTom
When two processors send each others a SMP message at the same time they need to process messages while waiting for delivery of the message they just sent, or they will deadlock.
2020-11-11Kernel: Implement capturing stack trace on a different CPUTom
When trying to get a stack trace of a thread on another CPU we send a SMP message to that processor to capture the stack trace for us.
2020-11-11Kernel: Protect the PageDirectory from concurrent accessTom
2020-11-11Kernel: Add locks around RangeAllocatorTom
We need to keep multiple processors from changing it at the same time.
2020-11-11Kernel: Minor Lock optimizationTom
2020-11-11Kernel: Minor SpinLock improvementsTom
2020-11-11Kernel: Make m_halt_requested an atomic variableTom
We need to make sure the change to this variable is visible to all processors instantly.
2020-11-11Kernel: Lock needs to call Processor::wait_check while loopingTom
We need to process SMP messages while looping.
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
2020-11-10Kernel+LibC: Add adjtime(2)Nico Weber
Most systems (Linux, OpenBSD) adjust 0.5 ms per second, or 0.5 us per 1 ms tick. That is, the clock is sped up or slowed down by at most 0.05%. This means adjusting the clock by 1 s takes 2000 s, and the clock an be adjusted by at most 1.8 s per hour. FreeBSD adjusts 5 ms per second if the remaining time adjustment is >= 1 s (0.5%) , else it adjusts by 0.5 ms as well. This allows adjusting by (almost) 18 s per hour. Since Serenity OS can lose more than 22 s per hour (#3429), this picks an adjustment rate up to 1% for now. This allows us to adjust up to 36s per hour, which should be sufficient to adjust the clock fast enough to keep up with how much time the clock currently loses. Once we have a fancier NTP implementation that can adjust tick rate in addition to offset, we can think about reducing this. adjtime is a bit old-school and most current POSIX-y OSs instead implement adjtimex/ntp_adjtime, but a) we have to start somewhere b) ntp_adjtime() is a fairly gnarly API. OpenBSD's adjfreq looks like it might provide similar functionality with a nicer API. But before worrying about all this, it's probably a good idea to get to a place where the kernel APIs are (barely) good enough so that we can write an ntp service, and once we have that we should write a way to automatically evaluate how well it keeps the time adjusted, and only then should we add improvements ot the adjustment mechanism.
2020-11-10Kernel: Prevent `unveil` returning ENOENT with cpath permissionsJesse Buhagiar
This addresses the issue first enountered in #3644. If a path is first unveiled with "c" permissions, we should NOT return ENOENT if the node does not exist on the disk, as the program will most likely be creating it at a later time.
2020-11-07Kernel: Update TimeManagement::m_epoch_time directly in ↵Nico Weber
increment_time_since_boot
2020-11-07Ext2FS: Zero out inode metadata when deleting themAndreas Kling
This isn't strictly necessary but it seems like a reasonable thing to be doing. Note that we still populate the dtime field with the time of deletion.
2020-11-07Ext2FS: Deallocate block list meta blocks when freeing an inodeAndreas Kling
When computing the list of blocks to deallocate when freeing an inode, we would stop collecting blocks after reaching the inode's block count. Since we're getting rid of the inode, we need to also include the meta blocks used by the on-disk block list itself.
2020-11-06Kernel: Fix HPET timer not firing in BochsTom
* Change the register structures to use the volatile keyword explicitly on the register values. This avoids accidentally omitting it as any access will be guaranteed volatile. * Don't assume we can read/write 64 bit value to the main counter and the comparator. Not all HPET implementations may support this. So, just use 32 bit words to access the registers. This ultimately works around a bug in Bochs 2.6.11 that loses 32 bits of a 64 bit write to a timer's comparator register (it internally writes one half and clears the Tn_VAL_SET_CNF bit, and then because it's cleared it fails to write the second half). * Properly calculate the tick duration in calculate_ticks_in_nanoseconds * As per specification, changing the frequency of one periodic timer requires a restart of all periodic timers as it requires the main counter to be reset.
2020-11-04Revert "Kernel: Implement an asynchronous device request stack"Andreas Kling
This reverts commit 2fd5ce1eb06e5cbbb180cba64a567e99f0cd846c. This broke booting without SMP. (PR was #3921)
2020-11-04Kernel: Implement an asynchronous device request stackTom
This allows issuing asynchronous requests for devices and waiting on the completion of the request. The requests can cascade into multiple sub-requests. Since IRQs may complete at any time, if the current process is no longer the same that started the process, we need to swich the paging context before accessing user buffers. Change the PATA driver to use this model.
2020-11-04Kernel: Remove dead code from BlockDeviceTom
2020-11-04Kernel: Defer kmalloc heap contractionTom
Because allocating/freeing regions may require locks that need to wait on other processors for completion, this needs to be delayed until it's safer. Otherwise it is possible to deadlock because we're holding the global heap lock.
2020-11-04Kernel: Add mechanism to queue deferred function callsTom
Function calls that are deferred will be executed before a thread enters a pre-emptable state (meaning it is not in a critical section and it is not in an irq handler). If it is not already in such a state, it will be called immediately. This is meant to be used from e.g. IRQ handlers where we might want to block a thread until an interrupt happens.
2020-11-02AK+Kernel: Escape JSON keys & valuesAndreas Kling
Grab the escaping logic from JSON string value serialization and use it for serializing all keys and values. Fixes #3917.
2020-11-01Kernel+LibC: Don't allow a directory to become a subdirectory of itselfAndreas Kling
If you try to do this (e.g "mv directory directory"), sys$rename() will now fail with EDIRINTOSELF. Dr. POSIX says we should return EINVAL for this, but a custom error code allows us to print a much more helpful error message when this problem occurs. :^)
2020-11-01Kernel: Flush TLB when quick-mapping PD/PT that was mapped on other CPUTom
If a PD/PT was quick-mapped by another CPU we still need to flush the TLB on the current CPU. Fixes #3885