summaryrefslogtreecommitdiff
path: root/Kernel/Thread.h
AgeCommit message (Collapse)Author
2023-06-04Kernel: Move all tasks-related code to the Tasks subdirectoryLiav A
2023-05-24AK: Rename Time to Durationkleines Filmröllchen
That's what this class really is; in fact that's what the first line of the comment says it is. This commit does not rename the main files, since those will contain other time-related classes in a little bit.
2023-04-04Kernel: Stop using *LockRefPtr for Kernel::TimerAndreas Kling
2023-04-04Kernel: Stop using *LockRefPtr for ProcessGroupAndreas Kling
Had to wrap Process::m_pg in a SpinlockProtected for this to be safe.
2023-04-04Kernel: Stop using *LockRefPtr for ThreadAndreas Kling
These were stored in a bunch of places. The main one that's a bit iffy is the Mutex::m_holder one, which I'm going to simplify in a subsequent commit. In Plan9FS and WorkQueue, we can't make the NNRPs const due to initialization order problems. That's probably doable with further cleanup, but left as an exercise for our future selves. Before starting this, I expected the thread blockers to be a problem, but as it turns out they were super straightforward (for once!) as they don't mutate the thread after initiating a block, so they can just use simple const-ified NNRPs.
2023-04-04Kernel: Stop using *LockRefPtr for Process pointersAndreas Kling
The only persistent one of these was Thread::m_process and that never changes after initialization. Make it const to enforce this and switch everything over to RefPtr & NonnullRefPtr.
2023-03-09Kernel: Switch LockRefPtr<Inode> to RefPtr<Inode>Andreas Kling
The main place where this is a little iffy is in RAMFS where inodes have a LockWeakPtr to their parent inode. I've left that as a LockWeakPtr for now.
2023-03-07Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescriptionAndreas Kling
This patch switches away from {Nonnull,}LockRefPtr to the non-locking smart pointers throughout the kernel. I've looked at the handful of places where these were being persisted and I don't see any race situations. Note that the process file descriptor table (Process::m_fds) was already guarded via MutexProtected.
2023-03-01Kernel+LibC: Move the FD_SETSIZE declaration to API/POSIX/select.h fileLiav A
2023-02-06Kernel: Protect Thread::m_name with a spinlockSam Atkins
This replaces manually grabbing the thread's main lock. This lets us remove the `get_thread_name` and `set_thread_name` syscalls from the big lock. :^)
2023-01-27Kernel: Factor our PreviousMode into RegisterState::previous_modeTimon Kruiper
Various places in the kernel were manually checking the cs register for x86_64, however to share this with aarch64 a function in RegisterState is added, and the call-sites are updated. While we're here the PreviousMode enum is renamed to ExecutionMode.
2023-01-21Kernel+LibC: Move LibC/signal_numbers.h to Kernel/API/POSIXAndrew Kaster
Make Userland and Tests users just include signal.h, and move Kernel users to the new API file.
2023-01-04Everywhere: Remove some redundant `inline` keywordsNico Weber
Functions defined inside class bodies (including static functions) are implicitly inline, no need to type it out.
2023-01-02Kernel: Turn lock ranks into template parameterskleines Filmröllchen
This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
2022-12-29Kernel: Move ThreadRegisters into arch-specific directoryTimon Kruiper
These are architecture-specific anyway, so they belong in the Arch directory. This commit also adds ThreadRegisters::set_initial_state to factor out the logic in Thread.cpp.
2022-12-28Kernel: Remove i686 supportLiav A
2022-12-11Kernel: Allow dead threads to be joinedkleines Filmröllchen
Joining dead threads is allowed for two main reasons: - Thread join behavior should not be racy when a thread is joined and exiting at roughly the same time. This is common behavior when threads are given a signal to end (meaning they are going to exit ASAP) and then joined. - POSIX requires that exited threads are joinable (at least, there is no language in the specification forbidding it). The behavior is still well-defined; e.g. it doesn't allow a dead detached thread to be joined or a thread to be joined more than once.
2022-10-27Kernel+LibC: Report correct scheduling priority limitskleines Filmröllchen
The priority range was changed several years ago, but the userland-reported limits were just forgotten :skeleyak:. Move the thread priority constants into an API header so that userland can use it properly.
2022-08-26Kernel: Show more (b)locking info when dumping the process listTim Schumacher
2022-08-26Kernel: Use InterruptsState in Spinlock codeTimon Kruiper
This commit updates the lock function from Spinlock and RecursiveSpinlock to return the InterruptsState of the processor, instead of the processor flags. The unlock functions would only look at the interrupt flag of the processor flags, so we now use the InterruptsState enum to clarify the intent, and such that we can use the same Spinlock code for the aarch64 build. To not break the build, all the call sites are updated aswell.
2022-08-24Kernel: Remove unnecessary forward declaration of s_mm_lockAndreas Kling
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-08-19Kernel: Require lock rank for Spinlock constructionkleines Filmröllchen
All users which relied on the default constructor use a None lock rank for now. This will make it easier to in the future remove LockRank and actually annotate the ranks by searching for None.
2022-08-19Kernel: Don't lock scheduler while updating thread scheduling timesAndreas Kling
We can use simple atomic variables with relaxed ordering for this, and avoid locking altogether.
2022-08-15Kernel: Shrink default userspace stack size from 4 MiB to 1 MiBAndreas Kling
This knocks 70 MiB off our idle footprint, (from 350 MiB to 280 MiB.)
2022-07-21Kernel: Support F_SETLKW in fcntlIdan Horowitz
2022-07-10Kernel: Remove unused WriteNotOpen File BlockFlagIdan Horowitz
2022-07-10Kernel: Report POLLNVAL events in sys$poll instead of returning EBADFIdan Horowitz
As required by Dr. Posix.
2022-07-08Kernel: Unblock SignalBlocker if a signal was just unmarked as pendingTim Schumacher
When updating the signal mask, there is a small frame where we might set up the receiving process for handing the signal and therefore remove that signal from the list of pending signals before SignalBlocker has a chance to block. In turn, this might cause SignalBlocker to never notice that the signal arrives and it will never unblock once blocked. Track the currently handled signal separately and include it when determining if SignalBlocker should be unblocking.
2022-04-12Kernel: Increase the default userspace stack size to 4 MiBTim Schumacher
This makes the main thread stack size the same as the default stack size when creating new threads.
2022-04-06Kernel: Track big lock blocked threads in separate listJelle Raaijmakers
When we lock a mutex, eventually `Thread::block` is invoked which could in turn invoke `Process::big_lock().restore_exclusive_lock()`. This would then try to add the current thread to a different blocked thread list then the one in use for the original mutex being locked, and because it's an intrusive list, the thread is removed from its original list during the `.append()`. When the original mutex eventually unblocks, we no longer have the thread in the intrusive blocked threads list and we panic. Solve this by making the big lock mutex special and giving it its own blocked thread list. Because the process big lock is temporary and is being actively removed from e.g. syscalls, it's a matter of time before we can also remove the fix introduced by this commit. Fixes issue #9401.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-04Kernel: Fill some siginfo and ucontext fields on SA_SIGINFOAli Mohammad Pur
There's no reason to fill in any of these fields if SA_SIGINFO is not given, as the signal handler won't be reading from them at all.
2022-03-04Kernel: Move signal handlers from being thread state to process stateAli Mohammad Pur
POSIX requires that sigaction() and friends set a _process-wide_ signal handler, so move signal handlers and flags inside Process. This also fixes a "pid/tid confusion" FIXME, as we can now send the signal to the process and let that decide which thread should get the signal (which is the thread with tid==pid, but that's now the Process's problem). Note that each thread still retains its signal mask, as that is local to each thread.
2022-01-30Kernel: Update terminology around Thread's "blocking mutex"Andreas Kling
It's more accurate to say that we're blocking on a mutex, rather than blocking on a lock. The previous terminology made sense when this code was using something called Kernel::Lock, but since it was renamed to Kernel::Mutex, this updates brings the language back in sync.
2022-01-30Kernel: Make Thread::State an `enum class` and use it consistentlyAndreas Kling
It was annoyingly hard to spot these when we were using them with different amounts of qualification everywhere. This patch uses Thread::State::Foo everywhere instead of Thread::Foo or just Foo.
2022-01-30Kernel: Don't dispatch signals in Processor::enter_current()Andreas Kling
Signal dispatch is already taken care of elsewhere, so there appears to be no need for the hack in enter_current(). This also allows us to remove the Thread::m_in_block flag, simplifying thread blocking logic somewhat. Verified with the original repro for #4336 which this was meant to fix.
2022-01-30Kernel: Remove unnecessary includes from Thread.hAndreas Kling
...and deal with the fallout by adding missing includes everywhere.
2022-01-30Kernel: Move Thread::block<BlockerType>() out of the Thread.h headerAndreas Kling
This function is large and unwieldy and forces Thread.h to #include a bunch of things. The only reason it was in the header is because we need to instantiate a blocker based on the templated BlockerType. We actually keep block<BlockerType>() in the header, but move the bulk of the function body out of line into Thread::block_impl(). To preserve destructor ordering, we add Blocker::finalize() which is called where we'd previously destroy the Blocker.
2022-01-26Kernel: Remove always-false Thread::drop_thread_count boolean parameterIdan Horowitz
2022-01-12Kernel: Make Thread::backtrace() fallible using KStringIdan Horowitz
2022-01-11Kernel: Allow preventing kmalloc and kfreekleines Filmröllchen
For "destructive" disallowance of allocations throughout the system, Thread gains a member that controls whether allocations are currently allowed or not. kmalloc checks this member on both allocations and deallocations (with the exception of early boot) and panics the kernel if allocations are disabled. This will allow for critical sections that can't be allowed to allocate to fail-fast, making for easier debugging. PS: My first proper Kernel commit :^)
2022-01-04Kernel: Make Thread::m_kernel_stack_region a NonnullOwnPtrIdan Horowitz
This OwnPtr is always non-null, so let's enforce it statically.
2021-12-29Kernel: Add verification promise violations are propagated properlyBrian Gianforcaro
This change adds a thread member variable to track if we have a pending promise violation on a kernel thread. This ensures that all code properly propagates promise violations up to the syscall handler. Suggested-by: Andreas Kling <kling@serenityos.org>
2021-12-29Kernel: Support Mutex Protected lists in ListedRefCountedIdan Horowitz
This will allow us to support Mutex Protected lists like the custodies list as well.
2021-12-23Kernel: Don't honor userspace SIGSTOP requests in Thread::block()Andreas Kling
Instead, wait until we transition back to userspace. This stops userspace from being able to suspend a thread indefinitely while it's running in kernelspace (potentially holding some blocking mutex.)
2021-12-12Kernel+LibC: Implement sigtimedwait()Idan Horowitz
This includes a new Thread::Blocker called SignalBlocker which blocks until a signal of a matching type is pending. The current Blocker implementation in the Kernel is very complicated, but cleaning it up is a different yak for a different day.
2021-12-12Kernel: Preserve pending signals across execve(2)sIdan Horowitz
As required by posix. Also rename Thread::clear_signals to Thread::reset_signals_for_exec since it doesn't actually clear any pending signals, but rather does execve related signal book-keeping.
2021-12-05Kernel: Add support for the POLLWRBAND poll eventIdan Horowitz
2021-12-01Kernel: Dispatch handle-able signals instead of crashing if possibleIdan Horowitz
This matches the behaviour of the other *nixs and allows processes to try and recover from such signals in userland.