Fix build issues in make_object; fix linkage issues

This commit is contained in:
TuxSH 2018-11-06 16:48:07 +01:00 committed by Michael Scire
parent c47a9931d9
commit 504c74bc57
5 changed files with 39 additions and 25 deletions

View file

@ -13,17 +13,17 @@ namespace mesosphere
template<typename T, typename ...Args> template<typename T, typename ...Args>
auto MakeObjectRaw(Args&& ...args) auto MakeObjectRaw(Args&& ...args)
{ {
Result res = ResultSuccess; Result res = ResultSuccess();
KCoreContext &cctx = KCoreContext::GetCurrentInstance(); KCoreContext &cctx = KCoreContext::GetCurrentInstance();
auto reslimit = cctx.GetCurrentProcess()->GetResourceLimit(); auto reslimit = cctx.GetCurrentProcess()->GetResourceLimit();
bool doReslimitCleanup = false; bool doReslimitCleanup = false;
T *obj = nullptr; T *obj = nullptr;
if constexpr (std::is_base_of_v<ILimitedResource<T>, T>) { if constexpr (std::is_base_of_v<ILimitedResource<T>, T>) {
if (reslimit != nullptr) { if (reslimit != nullptr) {
if (reslimit->Reserve(KResourceLimit::GetCategoryOf<T>(), 1, maxResourceAcqWaitTime)) { if (reslimit->Reserve(KResourceLimit::categoryOf<T>, 1, T::maxResourceAcqWaitTime)) {
doReslimitCleanup = true; doReslimitCleanup = true;
} else { } else {
return ResultKernelOutOfResource(); return std::tuple<Result, T *>{ResultKernelOutOfResource(), nullptr};
} }
} }
} }
@ -34,7 +34,7 @@ auto MakeObjectRaw(Args&& ...args)
goto cleanup; goto cleanup;
} }
res = T::Initialize(std::forward<Args>(args)...); res = obj->Initialize(std::forward<Args>(args)...);
if (res.IsSuccess()) { if (res.IsSuccess()) {
doReslimitCleanup = false; doReslimitCleanup = false;
if constexpr (std::is_base_of_v<ISetAllocated<T>, T>) { if constexpr (std::is_base_of_v<ISetAllocated<T>, T>) {
@ -43,27 +43,29 @@ auto MakeObjectRaw(Args&& ...args)
} }
cleanup: cleanup:
if (doReslimitCleanup) { if (doReslimitCleanup) {
reslimit->Release(KResourceLimit::GetCategoryOf<T>(), 1, 1); reslimit->Release(KResourceLimit::categoryOf<T>, 1, 1);
} }
return std::tuple{res, obj}; return std::tuple{res, obj};
} }
template<typename T, typename = std::enable_if_t<!std::is_base_of_v<IClientServerParentTag, T>>, typename ...Args> template<typename T, typename std::enable_if_t<!std::is_base_of_v<IClientServerParentTag, T>> * = nullptr, typename ...Args>
auto MakeObject(Args&& ...args) auto MakeObject(Args&& ...args)
{ {
auto [res, obj] = MakeObjectRaw(std::forward<Args>(args)...); auto [res, obj] = MakeObjectRaw(std::forward<Args>(args)...);
return std::tuple{res, SharedPtr{obj}}; return std::tuple<Result, SharedPtr<T>>{res, SharedPtr<T>{obj}};
} }
template<typename T, typename = std::enable_if_t<std::is_base_of_v<IClientServerParentTag, T>>, typename ...Args> template<typename T, typename std::enable_if_t<std::is_base_of_v<IClientServerParentTag, T>> * = nullptr, typename ...Args>
auto MakeObject(Args&& ...args) auto MakeObject(Args&& ...args)
{ {
// Bug in type inference?
using RetType = std::tuple<Result, SharedPtr<typename T::ServerClass>, SharedPtr<typename T::ClientClass>>;
auto [res, obj] = MakeObjectRaw(std::forward<Args>(args)...); auto [res, obj] = MakeObjectRaw(std::forward<Args>(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 T, typename = std::enable_if_t<!std::is_base_of_v<IClientServerParentTag, T>>, typename ...Args> template<typename T, typename std::enable_if_t<!std::is_base_of_v<IClientServerParentTag, T>> * = nullptr, typename ...Args>
auto MakeObjectWithHandle(Args&& ...args) auto MakeObjectWithHandle(Args&& ...args)
{ {
KCoreContext &cctx = KCoreContext::GetCurrentInstance(); KCoreContext &cctx = KCoreContext::GetCurrentInstance();
@ -78,7 +80,7 @@ auto MakeObjectWithHandle(Args&& ...args)
return tbl.Generate(obj); return tbl.Generate(obj);
} }
template<typename T, typename = std::enable_if_t<std::is_base_of_v<IClientServerParentTag, T>>, typename ...Args> template<typename T, typename std::enable_if_t<std::is_base_of_v<IClientServerParentTag, T>> * = nullptr, typename ...Args>
auto MakeObjectWithHandle(Args&& ...args) auto MakeObjectWithHandle(Args&& ...args)
{ {
KCoreContext &cctx = KCoreContext::GetCurrentInstance(); KCoreContext &cctx = KCoreContext::GetCurrentInstance();

View file

@ -39,10 +39,7 @@ class KResourceLimit final :
} }
} }
template<typename T> Category GetCategoryOf() template<typename T> static constexpr Category categoryOf = GetCategory(T::typeId);
{
return GetCategory(T::typeId);
}
static KResourceLimit &GetDefaultInstance() { return defaultInstance; } static KResourceLimit &GetDefaultInstance() { return defaultInstance; }

View file

@ -1,4 +1,4 @@
/* Note: copied from newlib */ /* Note: copied from newlib or libgcc */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -86,15 +86,6 @@ __libc_fini_array (void)
} }
#endif #endif
int
__cxa_atexit (void (*fn) (void *),
void *arg,
void *d)
{
return 0;
}
void *__dso_handle = 0;
/* /*
FUNCTION FUNCTION
<<memmove>>---move possibly overlapping memory <<memmove>>---move possibly overlapping memory

View file

@ -3,4 +3,21 @@
void *operator new(std::size_t) { for(;;); } void *operator new(std::size_t) { for(;;); }
void *operator new[](std::size_t) { for(;;); } void *operator new[](std::size_t) { for(;;); }
void operator delete(void *) { } void operator delete(void *) { }
void operator delete(void *, std::size_t) { }
void operator delete[](void *) { } 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 (;;); }
}

View file

@ -1,4 +1,11 @@
#include <mesosphere/core/make_object.hpp>
#include <mesosphere/processes/KEvent.hpp>
using namespace mesosphere;
int main(void) { int main(void) {
auto obj = MakeObjectRaw<KEvent>();
(void)obj;
for(;;); for(;;);
return 0; return 0;
} }