diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 1d194a38b3..ea7fa22fea 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -16,6 +16,7 @@ #ifdef KERNEL # include # include +# include #endif namespace AK { @@ -498,9 +499,24 @@ inline RefPtr try_create(Args&&... args) return adopt_ref_if_nonnull(new (nothrow) T { forward(args)... }); } +#ifdef KERNEL +template +inline Kernel::KResultOr> adopt_nonnull_ref_or_enomem(T* object) +{ + auto result = adopt_ref_if_nonnull(object); + if (!result) + return ENOMEM; + return result.release_nonnull(); +} +#endif + } using AK::adopt_ref_if_nonnull; using AK::RefPtr; using AK::static_ptr_cast; using AK::try_create; + +#ifdef KERNEL +using AK::adopt_nonnull_ref_or_enomem; +#endif