mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
os: fix various regressions since 1.3.1
This commit is contained in:
parent
b1367942a2
commit
d85875b910
4 changed files with 47 additions and 26 deletions
|
@ -32,9 +32,9 @@ namespace ams::os::impl {
|
||||||
|
|
||||||
static constexpr size_t ForbiddenRegionCount = 2;
|
static constexpr size_t ForbiddenRegionCount = 2;
|
||||||
private:
|
private:
|
||||||
static u64 GetAslrInfo(svc::InfoType type) {
|
static u64 GetAslrInfo(os::NativeHandle process_handle, svc::InfoType type) {
|
||||||
u64 value;
|
u64 value;
|
||||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), type, svc::PseudoHandle::CurrentProcess, 0));
|
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), type, process_handle, 0));
|
||||||
|
|
||||||
static_assert(std::same_as<size_t, uintptr_t>);
|
static_assert(std::same_as<size_t, uintptr_t>);
|
||||||
AMS_ASSERT(value <= std::numeric_limits<size_t>::max());
|
AMS_ASSERT(value <= std::numeric_limits<size_t>::max());
|
||||||
|
@ -45,8 +45,11 @@ namespace ams::os::impl {
|
||||||
AddressSpaceAllocatorForbiddenRegion m_forbidden_regions[ForbiddenRegionCount];
|
AddressSpaceAllocatorForbiddenRegion m_forbidden_regions[ForbiddenRegionCount];
|
||||||
public:
|
public:
|
||||||
AslrSpaceManagerHorizonImpl() {
|
AslrSpaceManagerHorizonImpl() {
|
||||||
m_forbidden_regions[0] = { .address = GetHeapSpaceBeginAddress(), .size = GetHeapSpaceSize() };
|
this->InitializeForbiddenRegions(svc::PseudoHandle::CurrentProcess);
|
||||||
m_forbidden_regions[1] = { .address = GetAliasSpaceBeginAddress(), .size = GetAliasSpaceSize() };
|
}
|
||||||
|
|
||||||
|
AslrSpaceManagerHorizonImpl(os::NativeHandle process_handle) {
|
||||||
|
this->InitializeForbiddenRegions(process_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
const AddressSpaceAllocatorForbiddenRegion *GetForbiddenRegions() const {
|
const AddressSpaceAllocatorForbiddenRegion *GetForbiddenRegions() const {
|
||||||
|
@ -57,28 +60,33 @@ namespace ams::os::impl {
|
||||||
return ForbiddenRegionCount;
|
return ForbiddenRegionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetHeapSpaceBeginAddress() {
|
static u64 GetHeapSpaceBeginAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
|
||||||
return GetAslrInfo(svc::InfoType_HeapRegionAddress);
|
return GetAslrInfo(process_handle, svc::InfoType_HeapRegionAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetHeapSpaceSize() {
|
static u64 GetHeapSpaceSize(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
|
||||||
return GetAslrInfo(svc::InfoType_HeapRegionSize);
|
return GetAslrInfo(process_handle, svc::InfoType_HeapRegionSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetAliasSpaceBeginAddress() {
|
static u64 GetAliasSpaceBeginAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
|
||||||
return GetAslrInfo(svc::InfoType_AliasRegionAddress);
|
return GetAslrInfo(process_handle, svc::InfoType_AliasRegionAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetAliasSpaceSize() {
|
static u64 GetAliasSpaceSize(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
|
||||||
return GetAslrInfo(svc::InfoType_AliasRegionSize);
|
return GetAslrInfo(process_handle, svc::InfoType_AliasRegionSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetAslrSpaceBeginAddress() {
|
static u64 GetAslrSpaceBeginAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
|
||||||
return GetAslrInfo(svc::InfoType_AslrRegionAddress);
|
return GetAslrInfo(process_handle, svc::InfoType_AslrRegionAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetAslrSpaceEndAddress() {
|
static u64 GetAslrSpaceEndAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
|
||||||
return GetAslrInfo(svc::InfoType_AslrRegionAddress) + GetAslrInfo(svc::InfoType_AslrRegionSize);
|
return GetAslrInfo(process_handle, svc::InfoType_AslrRegionAddress) + GetAslrInfo(process_handle, svc::InfoType_AslrRegionSize);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void InitializeForbiddenRegions(os::NativeHandle process_handle) {
|
||||||
|
m_forbidden_regions[0] = { .address = GetHeapSpaceBeginAddress(process_handle), .size = GetHeapSpaceSize(process_handle) };
|
||||||
|
m_forbidden_regions[1] = { .address = GetAliasSpaceBeginAddress(process_handle), .size = GetAliasSpaceSize(process_handle) };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,16 @@ namespace ams::os::impl {
|
||||||
Impl m_impl;
|
Impl m_impl;
|
||||||
Allocator m_allocator;
|
Allocator m_allocator;
|
||||||
public:
|
public:
|
||||||
template<typename... Args>
|
AslrSpaceManagerTemplate() : m_impl(), m_allocator(m_impl.GetAslrSpaceBeginAddress(), m_impl.GetAslrSpaceEndAddress(), AslrSpaceGuardSize, m_impl.GetForbiddenRegions(), m_impl.GetForbiddenRegionCount()) {
|
||||||
AslrSpaceManagerTemplate(Args &&... args) : m_impl(), m_allocator(m_impl.GetAslrSpaceBeginAddress(), m_impl.GetAslrSpaceEndAddress(), AslrSpaceGuardSize, m_impl.GetForbiddenRegions(), m_impl.GetForbiddenRegionCount(), std::forward<Args>(args)...) {
|
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||||
|
AslrSpaceManagerTemplate(os::NativeHandle process_handle) : m_impl(process_handle), m_allocator(m_impl.GetAslrSpaceBeginAddress(process_handle), m_impl.GetAslrSpaceEndAddress(process_handle), AslrSpaceGuardSize, m_impl.GetForbiddenRegions(), m_impl.GetForbiddenRegionCount(), process_handle) {
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AddressType AllocateSpace(SizeType size, SizeType align_offset) {
|
AddressType AllocateSpace(SizeType size, SizeType align_offset) {
|
||||||
/* Try to allocate a large-aligned space, if we can. */
|
/* Try to allocate a large-aligned space, if we can. */
|
||||||
if (align_offset || (size / AslrSpaceLargeAlign) != 0) {
|
if (align_offset || (size / AslrSpaceLargeAlign) != 0) {
|
||||||
|
|
|
@ -29,6 +29,18 @@ namespace ams::os::impl {
|
||||||
/* Add each holder to the object list, and try to find one that's signaled. */
|
/* Add each holder to the object list, and try to find one that's signaled. */
|
||||||
MultiWaitHolderBase *signaled_holder = this->AddToEachObjectListAndCheckObjectState();
|
MultiWaitHolderBase *signaled_holder = this->AddToEachObjectListAndCheckObjectState();
|
||||||
|
|
||||||
|
/* When we're done, cleanup and set output. */
|
||||||
|
ON_SCOPE_EXIT {
|
||||||
|
/* Remove each holder from the current object list. */
|
||||||
|
this->RemoveFromEachObjectList();
|
||||||
|
|
||||||
|
/* Clear cancel wait. */
|
||||||
|
m_target_impl.ClearCurrentThreadHandleForCancelWait();
|
||||||
|
|
||||||
|
/* Set output holder. */
|
||||||
|
*out = signaled_holder;
|
||||||
|
};
|
||||||
|
|
||||||
/* Check if we've been signaled. */
|
/* Check if we've been signaled. */
|
||||||
{
|
{
|
||||||
std::scoped_lock lk(m_cs_wait);
|
std::scoped_lock lk(m_cs_wait);
|
||||||
|
@ -43,6 +55,8 @@ namespace ams::os::impl {
|
||||||
if constexpr (AllowReply) {
|
if constexpr (AllowReply) {
|
||||||
/* Try to reply to the reply target. */
|
/* Try to reply to the reply target. */
|
||||||
if (reply_target != os::InvalidNativeHandle) {
|
if (reply_target != os::InvalidNativeHandle) {
|
||||||
|
ON_RESULT_FAILURE { signaled_holder = nullptr; };
|
||||||
|
|
||||||
s32 index;
|
s32 index;
|
||||||
R_TRY(m_target_impl.TimedReplyAndReceive(std::addressof(index), nullptr, 0, 0, reply_target, TimeSpan::FromNanoSeconds(0)));
|
R_TRY(m_target_impl.TimedReplyAndReceive(std::addressof(index), nullptr, 0, 0, reply_target, TimeSpan::FromNanoSeconds(0)));
|
||||||
}
|
}
|
||||||
|
@ -52,14 +66,6 @@ namespace ams::os::impl {
|
||||||
R_TRY(this->InternalWaitAnyImpl<AllowReply>(std::addressof(signaled_holder), infinite, timeout, reply_target));
|
R_TRY(this->InternalWaitAnyImpl<AllowReply>(std::addressof(signaled_holder), infinite, timeout, reply_target));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove each holder from the current object list. */
|
|
||||||
this->RemoveFromEachObjectList();
|
|
||||||
|
|
||||||
/* Clear cancel wait. */
|
|
||||||
m_target_impl.ClearCurrentThreadHandleForCancelWait();
|
|
||||||
|
|
||||||
/* Set output holder. */
|
|
||||||
*out = signaled_holder;
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,8 @@ namespace ams::os::impl {
|
||||||
R_THROW(os::ResultInvalidCurrentMemoryState());
|
R_THROW(os::ResultInvalidCurrentMemoryState());
|
||||||
}
|
}
|
||||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||||
|
|
||||||
|
mapped_size += regions[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
|
|
Loading…
Reference in a new issue