diff --git a/mesosphere/include/mesosphere/core/make_object.hpp b/mesosphere/include/mesosphere/core/make_object.hpp index 0b154ae7b..e401a2938 100644 --- a/mesosphere/include/mesosphere/core/make_object.hpp +++ b/mesosphere/include/mesosphere/core/make_object.hpp @@ -13,17 +13,17 @@ namespace mesosphere template auto MakeObjectRaw(Args&& ...args) { - Result res = ResultSuccess; + Result res = ResultSuccess(); KCoreContext &cctx = KCoreContext::GetCurrentInstance(); auto reslimit = cctx.GetCurrentProcess()->GetResourceLimit(); bool doReslimitCleanup = false; T *obj = nullptr; if constexpr (std::is_base_of_v, T>) { if (reslimit != nullptr) { - if (reslimit->Reserve(KResourceLimit::GetCategoryOf(), 1, maxResourceAcqWaitTime)) { + if (reslimit->Reserve(KResourceLimit::categoryOf, 1, T::maxResourceAcqWaitTime)) { doReslimitCleanup = true; } else { - return ResultKernelOutOfResource(); + return std::tuple{ResultKernelOutOfResource(), nullptr}; } } } @@ -34,7 +34,7 @@ auto MakeObjectRaw(Args&& ...args) goto cleanup; } - res = T::Initialize(std::forward(args)...); + res = obj->Initialize(std::forward(args)...); if (res.IsSuccess()) { doReslimitCleanup = false; if constexpr (std::is_base_of_v, T>) { @@ -43,27 +43,29 @@ auto MakeObjectRaw(Args&& ...args) } cleanup: if (doReslimitCleanup) { - reslimit->Release(KResourceLimit::GetCategoryOf(), 1, 1); + reslimit->Release(KResourceLimit::categoryOf, 1, 1); } return std::tuple{res, obj}; } -template>, typename ...Args> +template> * = nullptr, typename ...Args> auto MakeObject(Args&& ...args) { auto [res, obj] = MakeObjectRaw(std::forward(args)...); - return std::tuple{res, SharedPtr{obj}}; + return std::tuple>{res, SharedPtr{obj}}; } -template>, typename ...Args> +template> * = nullptr, typename ...Args> auto MakeObject(Args&& ...args) { + // Bug in type inference? + using RetType = std::tuple, SharedPtr>; auto [res, obj] = MakeObjectRaw(std::forward(args)...); - return res.IsSuccess() ? std::tuple{res, SharedPtr{&obj.GetServer()}, SharedPtr{&obj.GetClient()}} : std::tuple{res, nullptr, nullptr}; + return res.IsSuccess() ? RetType{res, &obj.GetServer(), &obj.GetClient()} : RetType{res, nullptr, nullptr}; } -template>, typename ...Args> +template> * = nullptr, typename ...Args> auto MakeObjectWithHandle(Args&& ...args) { KCoreContext &cctx = KCoreContext::GetCurrentInstance(); @@ -78,7 +80,7 @@ auto MakeObjectWithHandle(Args&& ...args) return tbl.Generate(obj); } -template>, typename ...Args> +template> * = nullptr, typename ...Args> auto MakeObjectWithHandle(Args&& ...args) { KCoreContext &cctx = KCoreContext::GetCurrentInstance(); diff --git a/mesosphere/include/mesosphere/kresources/KResourceLimit.hpp b/mesosphere/include/mesosphere/kresources/KResourceLimit.hpp index 8229249f9..cdcae0362 100644 --- a/mesosphere/include/mesosphere/kresources/KResourceLimit.hpp +++ b/mesosphere/include/mesosphere/kresources/KResourceLimit.hpp @@ -39,10 +39,7 @@ class KResourceLimit final : } } - template Category GetCategoryOf() - { - return GetCategory(T::typeId); - } + template static constexpr Category categoryOf = GetCategory(T::typeId); static KResourceLimit &GetDefaultInstance() { return defaultInstance; } diff --git a/mesosphere/source/my_libc.c b/mesosphere/source/my_libc.c index f4d12c296..bc9bdce8b 100644 --- a/mesosphere/source/my_libc.c +++ b/mesosphere/source/my_libc.c @@ -1,4 +1,4 @@ -/* Note: copied from newlib */ +/* Note: copied from newlib or libgcc */ #ifdef __cplusplus extern "C" { #endif @@ -86,15 +86,6 @@ __libc_fini_array (void) } #endif -int -__cxa_atexit (void (*fn) (void *), - void *arg, - void *d) -{ - return 0; -} -void *__dso_handle = 0; - /* FUNCTION <>---move possibly overlapping memory diff --git a/mesosphere/source/my_libstdc++.cpp b/mesosphere/source/my_libstdc++.cpp index f7c31cb94..1da6b1503 100644 --- a/mesosphere/source/my_libstdc++.cpp +++ b/mesosphere/source/my_libstdc++.cpp @@ -3,4 +3,21 @@ void *operator new(std::size_t) { for(;;); } void *operator new[](std::size_t) { for(;;); } void operator delete(void *) { } +void operator delete(void *, std::size_t) { } void operator delete[](void *) { } +void operator delete[](void *, std::size_t) { } + +extern "C" { + +int +__cxa_atexit (void (*fn) (void *), + void *arg, + void *d) +{ + return 0; +} +void *__dso_handle = 0; + +[[noreturn]] void __cxa_pure_virtual() { for (;;); } + +} \ No newline at end of file diff --git a/mesosphere/source/test.cpp b/mesosphere/source/test.cpp index 1032bc844..65e907997 100644 --- a/mesosphere/source/test.cpp +++ b/mesosphere/source/test.cpp @@ -1,4 +1,11 @@ +#include +#include + +using namespace mesosphere; + int main(void) { + auto obj = MakeObjectRaw(); + (void)obj; for(;;); return 0; }