1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-23 02:42:09 +00:00

fixes for previous two commits

This commit is contained in:
Michael Scire 2020-01-15 23:47:14 -08:00
parent d1fbd64235
commit 0751db5d12
5 changed files with 87 additions and 74 deletions

View file

@ -1,4 +1,4 @@
TOPTARGETS := all clean dist
TOPTARGETS := all clean dist-no-debug dist
AMSBRANCH := $(shell git symbolic-ref --short HEAD)
AMSHASH := $(shell git rev-parse --short HEAD)
AMSREV := $(AMSBRANCH)-$(AMSHASH)
@ -39,7 +39,7 @@ clean:
$(MAKE) -C fusee clean
rm -rf out
dist: all
dist-no-debug: all
$(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \
| tr -s [:blank:] \
| cut -d' ' -f3))
@ -91,6 +91,21 @@ dist: all
cp troposphere/reboot_to_payload/reboot_to_payload.nro atmosphere-$(AMSVER)/switch/reboot_to_payload.nro
cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER).zip ./*; cd ../;
rm -r atmosphere-$(AMSVER)
mkdir out
mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER).zip
cp fusee/fusee-primary/fusee-primary.bin out/fusee-primary.bin
dist: dist-no-debug
$(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \
| tr -s [:blank:] \
| cut -d' ' -f3))
$(eval MINORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MINOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \
| tr -s [:blank:] \
| cut -d' ' -f3))
$(eval MICROVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MICRO\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \
| tr -s [:blank:] \
| cut -d' ' -f3))
$(eval AMSVER = $(MAJORVER).$(MINORVER).$(MICROVER)-$(AMSREV))
rm -rf atmosphere-$(AMSVER)-debug
mkdir atmosphere-$(AMSVER)-debug
cp fusee/fusee-primary/fusee-primary.elf atmosphere-$(AMSVER)-debug/fusee-primary.elf
@ -118,10 +133,7 @@ dist: all
cp stratosphere/spl/spl.elf atmosphere-$(AMSVER)-debug/spl.elf
cd atmosphere-$(AMSVER)-debug; zip -r ../atmosphere-$(AMSVER)-debug.zip ./*; cd ../;
rm -r atmosphere-$(AMSVER)-debug
mkdir out
mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER).zip
mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER)-debug.zip
cp fusee/fusee-primary/fusee-primary.bin out/fusee-primary.bin
mv atmosphere-$(AMSVER)-debug.zip out/atmosphere-$(AMSVER)-debug.zip
.PHONY: $(TOPTARGETS) $(COMPONENTS)

View file

@ -34,12 +34,9 @@ namespace ams::util {
IntrusiveListNode *prev;
IntrusiveListNode *next;
public:
IntrusiveListNode() {
this->prev = this;
this->next = this;
}
constexpr IntrusiveListNode() : prev(this), next(this) { /* ... */ }
bool IsLinked() const {
constexpr bool IsLinked() const {
return this->next != this;
}
private:
@ -102,6 +99,7 @@ namespace ams::util {
return this->next;
}
};
static_assert(std::is_literal_type<IntrusiveListNode>::value);
namespace impl {

View file

@ -28,8 +28,9 @@ namespace ams::util {
template<class, class, class>
friend class IntrusiveRedBlackTree;
public:
IntrusiveRedBlackTreeNode() { /* ... */}
constexpr IntrusiveRedBlackTreeNode() : entry() { /* ... */}
};
static_assert(std::is_literal_type<IntrusiveRedBlackTreeNode>::value);
template<class T, class Traits, class Comparator>
class IntrusiveRedBlackTree {

View file

@ -16,6 +16,7 @@
#pragma once
#include "../defines.hpp"
#include "util_typed_storage.hpp"
namespace ams::util {
@ -54,7 +55,7 @@ namespace ams::util {
union Union {
char c;
UnionHolder first_union;
ParentType parent;
TYPED_STORAGE(ParentType) parent;
/* This coerces the active member to be c. */
constexpr Union() : c() { /* ... */ }
@ -75,7 +76,7 @@ namespace ams::util {
template<typename CurUnion>
static constexpr std::ptrdiff_t OffsetOfImpl(MemberType ParentType::*member, CurUnion &cur_union) {
constexpr size_t Offset = CurUnion::GetOffset();
const auto target = std::addressof(U.parent.*member);
const auto target = std::addressof(GetPointer(U.parent)->*member);
const auto start = std::addressof(cur_union.data.members[0]);
const auto next = GetNextAddress(start, target);
@ -116,6 +117,7 @@ namespace ams::util {
using DeducedParentType = GetParentType<MemberPtr>;
using MemberType = GetMemberType<MemberPtr>;
static_assert(std::is_base_of<DeducedParentType, RealParentType>::value || std::is_same<RealParentType, DeducedParentType>::value);
static_assert(std::is_literal_type<MemberType>::value);
return OffsetOfCalculator<RealParentType, MemberType>::OffsetOf(MemberPtr);
}();
@ -125,17 +127,13 @@ namespace ams::util {
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
constexpr ALWAYS_INLINE RealParentType &GetParentReference(impl::GetMemberType<MemberPtr> *member) {
constexpr std::ptrdiff_t Offset = impl::OffsetOf<MemberPtr, RealParentType>;
uint8_t *addr = static_cast<uint8_t *>(static_cast<void *>(member));
addr -= Offset;
return *static_cast<RealParentType *>(static_cast<void *>(addr));
return *static_cast<RealParentType *>(static_cast<void *>(static_cast<uint8_t *>(static_cast<void *>(member)) - Offset));
}
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
constexpr ALWAYS_INLINE RealParentType const &GetParentReference(impl::GetMemberType<MemberPtr> const *member) {
constexpr std::ptrdiff_t Offset = impl::OffsetOf<MemberPtr, RealParentType>;
const uint8_t *addr = static_cast<const uint8_t *>(static_cast<const void *>(member));
addr -= Offset;
return *static_cast<const RealParentType *>(static_cast<const void *>(addr));
return *static_cast<const RealParentType *>(static_cast<const void *>(static_cast<const uint8_t *>(static_cast<const void *>(member)) - Offset));
}
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
@ -148,6 +146,35 @@ namespace ams::util {
return std::addressof(GetParentReference<MemberPtr, RealParentType>(member));
}
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
constexpr ALWAYS_INLINE RealParentType &GetParentReference(impl::GetMemberType<MemberPtr> &member) {
return GetParentReference<MemberPtr, RealParentType>(std::addressof(member));
}
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
constexpr ALWAYS_INLINE RealParentType const &GetParentReference(impl::GetMemberType<MemberPtr> const &member) {
return GetParentReference<MemberPtr, RealParentType>(std::addressof(member));
}
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
constexpr ALWAYS_INLINE RealParentType *GetParentPointer(impl::GetMemberType<MemberPtr> &member) {
return std::addressof(GetParentReference<MemberPtr, RealParentType>(member));
}
template<auto MemberPtr, typename RealParentType = impl::GetParentType<MemberPtr>>
constexpr ALWAYS_INLINE RealParentType const *GetParentPointer(impl::GetMemberType<MemberPtr> const &member) {
return std::addressof(GetParentReference<MemberPtr, RealParentType>(member));
}
/* Defines, for use by other code. */
#define OFFSETOF(parent, member) (::ams::util::OffsetOf<&parent::member, parent>)
#define GET_PARENT_PTR(parent, member, _arg) (::ams::util::GetParentPointer<&parent::member, parent>(_arg))
#define GET_PARENT_REF(parent, member, _arg) (::ams::util::GetParentReference<&parent::member, parent>(_arg))
namespace test {
struct Struct1 {
@ -174,9 +201,12 @@ namespace ams::util {
constexpr Struct3 TestStruct3 = {};
static_assert(std::addressof(TestStruct3) == GetParentPointer<&Struct3::a, Struct3>(std::addressof(TestStruct3.a)));
static_assert(std::addressof(TestStruct3) == GetParentPointer<&Struct3::b, Struct3>(std::addressof(TestStruct3.b)));
static_assert(std::addressof(TestStruct3) == GetParentPointer<&Struct3::c, Struct3>(std::addressof(TestStruct3.c)));
static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, a, TestStruct3.a));
static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, a, std::addressof(TestStruct3.a)));
static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, b, TestStruct3.b));
static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, b, std::addressof(TestStruct3.b)));
static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, c, TestStruct3.c));
static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, c, std::addressof(TestStruct3.c)));
struct CharArray {
char c0;
@ -200,51 +230,23 @@ namespace ams::util {
constexpr CharArray TestCharArray = {};
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c0>(std::addressof(TestCharArray.c0)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c1>(std::addressof(TestCharArray.c1)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c2>(std::addressof(TestCharArray.c2)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c3>(std::addressof(TestCharArray.c3)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c4>(std::addressof(TestCharArray.c4)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c5>(std::addressof(TestCharArray.c5)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c6>(std::addressof(TestCharArray.c6)));
static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c7>(std::addressof(TestCharArray.c7)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c0, TestCharArray.c0));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c0, std::addressof(TestCharArray.c0)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c1, TestCharArray.c1));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c1, std::addressof(TestCharArray.c1)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c2, TestCharArray.c2));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c2, std::addressof(TestCharArray.c2)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c3, TestCharArray.c3));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c3, std::addressof(TestCharArray.c3)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c4, TestCharArray.c4));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c4, std::addressof(TestCharArray.c4)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c5, TestCharArray.c5));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c5, std::addressof(TestCharArray.c5)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c6, TestCharArray.c6));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c6, std::addressof(TestCharArray.c6)));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c7, TestCharArray.c7));
static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c7, std::addressof(TestCharArray.c7)));
}
}
/* Defines, for use by other code. */
#define OFFSETOF(parent, member) (::ams::util::OffsetOf<&parent::member, parent>)
#define AMS_GET_PARENT_TYPE_IMPL(parent, argt) typename std::conditional<std::is_pointer<argt>::value, \
typename std::conditional<std::is_const<typename std::remove_pointer<argt>::type>::value, \
const parent, \
parent \
>::type, \
typename std::conditional<std::is_const<typename std::remove_reference<argt>::type>::value, \
const parent, \
parent \
>::type \
>::type
#define GET_PARENT_PTR(parent, member, _arg) ([]<typename GetParentPtrArgType>(GetParentPtrArgType &arg) ALWAYS_INLINE_LAMBDA -> AMS_GET_PARENT_TYPE_IMPL(parent, GetParentPtrArgType) * { \
using ParentPtrType = typename std::conditional<std::is_const<GetParentPtrArgType>::value, const parent, parent>::type *; \
if constexpr (std::is_pointer<GetParentPtrArgType>::value) { \
static_assert(std::is_same<typename std::remove_cv<decltype(parent::member)>::type, typename std::remove_cv<typename std::remove_pointer<GetParentPtrArgType>::type>::type>::value); \
return ::ams::util::GetParentPointer<&parent::member, parent>(arg); \
} else { \
static_assert(std::is_same<typename std::remove_cv<decltype(parent::member)>::type, typename std::remove_cv<typename std::remove_reference<GetParentPtrArgType>::type>::type>::value); \
return ::ams::util::GetParentPointer<&parent::member, parent>(std::addressof(arg)); \
} \
}(_arg))
#define GET_PARENT_REF(parent, member, _arg) ([]<typename GetParentPtrArgType>(GetParentPtrArgType &arg) ALWAYS_INLINE_LAMBDA -> AMS_GET_PARENT_TYPE_IMPL(parent, GetParentPtrArgType) & { \
if constexpr (std::is_pointer<GetParentPtrArgType>::value) { \
static_assert(std::is_same<typename std::remove_cv<decltype(parent::member)>::type, typename std::remove_cv<typename std::remove_pointer<GetParentPtrArgType>::type>::type>::value); \
return ::ams::util::GetParentReference<&parent::member, parent>(arg); \
} else { \
static_assert(std::is_same<typename std::remove_cv<decltype(parent::member)>::type, typename std::remove_cv<typename std::remove_reference<GetParentPtrArgType>::type>::type>::value); \
return ::ams::util::GetParentReference<&parent::member, parent>(std::addressof(arg)); \
} \
}(_arg))

View file

@ -24,25 +24,25 @@ namespace ams::util {
typename std::aligned_storage<Size, Align>::type _storage;
};
#define TYPED_STORAGE(T) ::ams::util::TypedStorage<T, sizeof(T), alignof(T)>
#define TYPED_STORAGE(...) ::ams::util::TypedStorage<__VA_ARGS__, sizeof(__VA_ARGS__), alignof(__VA_ARGS__)>
template<typename T>
static constexpr inline __attribute__((always_inline)) T *GetPointer(TYPED_STORAGE(T) &ts) {
return reinterpret_cast<T *>(&ts._storage);
static constexpr ALWAYS_INLINE T *GetPointer(TYPED_STORAGE(T) &ts) {
return static_cast<T *>(static_cast<void *>(std::addressof(ts._storage)));
}
template<typename T>
static constexpr inline __attribute__((always_inline)) const T *GetPointer(const TYPED_STORAGE(T) &ts) {
return reinterpret_cast<const T *>(&ts._storage);
static constexpr ALWAYS_INLINE const T *GetPointer(const TYPED_STORAGE(T) &ts) {
return static_cast<const T *>(static_cast<const void *>(std::addressof(ts._storage)));
}
template<typename T>
static constexpr inline __attribute__((always_inline)) T &GetReference(TYPED_STORAGE(T) &ts) {
static constexpr ALWAYS_INLINE T &GetReference(TYPED_STORAGE(T) &ts) {
return *GetPointer(ts);
}
template<typename T>
static constexpr inline __attribute__((always_inline)) const T &GetReference(const TYPED_STORAGE(T) &ts) {
static constexpr ALWAYS_INLINE const T &GetReference(const TYPED_STORAGE(T) &ts) {
return *GetPointer(ts);
}