summaryrefslogtreecommitdiff
path: root/Kernel/Library
AgeCommit message (Collapse)Author
2022-06-15Kernel+AK: Split Weakable.h into userspace and kernel variantsAndreas Kling
Only the kernel expects AK::Weakable to lock its refcount manipulation, so let's not force userspace to pay for that as well.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-17Everywhere: Switch from EnableIf to requiresLenny Maiorani
C++20 provides the `requires` clause which simplifies the ability to limit overload resolution. Prefer it over `EnableIf` With all uses of `EnableIf` being removed, also remove the implementation so future devs are not tempted.
2022-02-13Kernel: Remove dead code from ThreadSafeWeakPtrIdan Horowitz
This is a Kernel-only header, so any #ifndef KERNEL code is essentially dead.
2022-02-13Kernel: Remove make_weak_ptr()Idan Horowitz
New users of WeakPtr in the kernel should use try_make_weak_ptr instead
2022-02-13Kernel: Use try_make_weak_ptr() instead of make_weak_ptr()Idan Horowitz
2022-02-13AK+Kernel: Add an OOM-fallible try variant make_weak_ptr()Idan Horowitz
This will allow us to propagate allocation errors that may be raised by the construction of the WeakLink.
2022-02-13AK+Kernel: Rename try_make_weak_ptr to make_weak_ptr_if_nonnullIdan Horowitz
This matches the likes of the adopt_{own, ref}_if_nonnull family and also frees up the name to allow us to eventually add OOM-fallible versions of these functions.
2022-02-03Kernel: Remove the infallible make_ref_counted<T> factory functionIdan Horowitz
This function had no users, nor should it ever be used, as all allocation failures in the Kernel should be explicitly checked.
2022-02-03Kernel: Convert try_make_ref_counted to use ErrorOrIdan Horowitz
This allows more ergonomic memory allocation failure related error checking using the TRY macro.
2022-01-11AK+Kernel: Remove one_ref_left() footgunAndreas Kling
This mechanism was unsafe to use in any multithreaded context, since the hook function was invoked on a raw pointer *after* decrementing the local ref count. Since we don't use it for anything anymore, let's just get rid of it.
2022-01-11Kernel: Make ListedRefCounted::unref() call optional list removal helperAndreas Kling
Look for remove_from_secondary_lists() and call it on the ref-counting target if present *while the lock is held*. This allows listed-ref-counted objects to be present in multiple lists and still have synchronized removal on final unref.
2022-01-08Kernel: Unbreak ref counting hooks in ListedRefCounted & RefCountedAndreas Kling
We have to mind the constness of the pointer when using "requires" to check if a member function can be invoked. I regressed this in c4a0f01b02d84117e644f2aff4396bdac1bcf40d.
2022-01-08Kernel: Lock weak pointer revocation during listed-ref-counted unrefAndreas Kling
When doing the last unref() on a listed-ref-counted object, we keep the list locked while mutating the ref count. The destructor itself is invoked after unlocking the list. This was racy with weakable classes, since their weak pointer factory still pointed to the object after we'd decided to destroy it. That opened a small time window where someone could try to strong-ref a weak pointer to an object after it was removed from the list, but just before the destructor got invoked. This patch closes the race window by explicitly revoking all weak pointers while the list is locked.
2022-01-08AK+Kernel: Use requires expression when invoking ref counting hooksAndreas Kling
Replace some old-school template trickery with C++20 requires. :^)
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-05Kernel: Mark kernel smart-pointer classes as [[nodiscard]]Sam Atkins
And cast the unused return values to void.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-14Kernel: Avoid else after return in Process and ThreadSafeRefCountedAndrew Kaster
2021-11-14Kernel: Resolve clang-tidy readability-implicit-bool-conversion warningsAndrew Kaster
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14AK+Kernel: Suppress clang-tidy warnings from the cert-* categoryAndrew Kaster
cert-dcl50-cpp: No variadic functions, suppressed in RefCounted and ThreadSafeRefCounted for implementing the magic one_ref_left and will_be_destroyed functions. cert-dcl58-cpp: No opening ::std, suppressed in the places we put names in ::std to aid tools (move, forward, nullptr_t, align_val_t, etc).
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-10-15Kernel: Split ScopedCritical so header is platform independentJames Mintram
A new header file has been created in the Arch/ folder while the implementation has been moved into a CPP living in the X86 folder.
2021-10-14Kernel: Add per platform Processor.h headersJames Mintram
The platform independent Processor.h file includes the shared processor code and includes the specific platform header file. All references to the Arch/x86/Processor.h file have been replaced with a reference to Arch/Processor.h.
2021-10-07Kernel: Note if the page fault address is a destroyed smart pointerLuke Wilde
While I was working on LibWeb, I got a page fault at 0xe0e0e0e4. This indicates a destroyed RefPtr if compiled with SANITIZE_PTRS defined. However, the page fault handler didn't print out this indication. This makes the page fault handler print out a note if the faulting address looks like a recently destroyed RefPtr, OwnPtr, NonnullRefPtr, NonnullOwnPtr, ThreadSafeRefPtr or ThreadSafeNonnullRefPtr. It will only do this if SANITIZE_PTRS is defined, as smart pointers don't get scrubbed without it being defined.
2021-10-07AK+Kernel: Make automatically locking RefPtr & co a kernel-only thingAndreas Kling
Some time ago, automatic locking was added to the AK smart pointers to paper over various race conditions in the kernel. Until we've actually solved the issues in the kernel, we're stuck with the locking. However, we don't need to punish single-threaded userspace programs with the high cost of locking. This patch moves the thread-safe variants of RefPtr, NonnullRefPtr, WeakPtr and RefCounted into Kernel/Library/.
2021-09-07Kernel: Stop leaking TmpFS inodesAndreas Kling
TmpFS inodes rely on the call to Inode::one_ref_left() to unregister themselves from the inode cache in TmpFS. When moving various kernel classes to ListedRefCounted for safe unref() while participating on lists, I forgot to make ListedRefCounted check for (and call) one_ref_left() & will_be_destroyed() on the CRTP class.
2021-08-22Kernel: Rename SpinLock => SpinlockAndreas Kling
2021-08-22Kernel: Rename SpinLockProtectedValue<T> => SpinLockProtected<T>Andreas Kling
2021-08-17Kernel: Add a little explainer comment to ListedRefCountedAndreas Kling
2021-08-17Kernel: Add ListedRefCounted<T> template classAndreas Kling
This class implements the emerging "ref-counted object that participates in a lock-protected list that requires safe removal on unref()" pattern as a base class that can be inherited in place of RefCounted<T>.