early-access version 2551

This commit is contained in:
pineappleEA
2022-03-15 03:53:56 +01:00
parent 23843c27a8
commit b92ba8ba26
17 changed files with 298 additions and 31 deletions

View File

@@ -206,17 +206,17 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
// Create an array to represent the gaps between the slabs.
const size_t total_gap_size = CalculateSlabHeapGapSize();
size_t slab_gaps[slab_types.size()];
for (size_t i = 0; i < slab_types.size(); i++) {
std::array<size_t, slab_types.size()> slab_gaps;
for (auto& slab_gap : slab_gaps) {
// Note: This is an off-by-one error from Nintendo's intention, because GenerateRandomRange
// is inclusive. However, Nintendo also has the off-by-one error, and it's "harmless", so we
// will include it ourselves.
slab_gaps[i] = KSystemControl::GenerateRandomRange(0, total_gap_size);
slab_gap = KSystemControl::GenerateRandomRange(0, total_gap_size);
}
// Sort the array, so that we can treat differences between values as offsets to the starts of
// slabs.
for (size_t i = 1; i < slab_types.size(); i++) {
for (size_t i = 1; i < slab_gaps.size(); i++) {
for (size_t j = i; j > 0 && slab_gaps[j - 1] > slab_gaps[j]; j--) {
std::swap(slab_gaps[j], slab_gaps[j - 1]);
}
@@ -226,7 +226,7 @@ void InitializeSlabHeaps(Core::System& system, KMemoryLayout& memory_layout) {
VAddr gap_start = address;
size_t gap_size = 0;
for (size_t i = 0; i < slab_types.size(); i++) {
for (size_t i = 0; i < slab_gaps.size(); i++) {
// Add the random gap to the address.
const auto cur_gap = (i == 0) ? slab_gaps[0] : slab_gaps[i] - slab_gaps[i - 1];
address += cur_gap;

View File

@@ -445,18 +445,18 @@ VAddr KPageTable::FindFreeArea(VAddr region_start, std::size_t region_num_pages,
if (info.state != KMemoryState::Free) {
continue;
}
if (!(region_start <= candidate)) {
if (region_start > candidate) {
continue;
}
if (!(info.GetAddress() + guard_pages * PageSize <= candidate)) {
if (info.GetAddress() + guard_pages * PageSize > candidate) {
continue;
}
if (!(candidate + (num_pages + guard_pages) * PageSize - 1 <=
info.GetLastAddress())) {
const VAddr candidate_end = candidate + (num_pages + guard_pages) * PageSize - 1;
if (candidate_end > info.GetLastAddress()) {
continue;
}
if (!(candidate + (num_pages + guard_pages) * PageSize - 1 <=
region_start + region_num_pages * PageSize - 1)) {
if (candidate_end > region_start + region_num_pages * PageSize - 1) {
continue;
}

View File

@@ -58,7 +58,7 @@ ResultCode KPort::EnqueueSession(KServerSession* session) {
server.EnqueueSession(session);
if (auto session_ptr = server.GetSessionRequestHandler().lock(); session_ptr) {
if (auto session_ptr = server.GetSessionRequestHandler().lock()) {
session_ptr->ClientConnected(server.AcceptSession());
} else {
UNREACHABLE();

View File

@@ -30,7 +30,7 @@ public:
/// Whether or not this server port has an HLE handler available.
bool HasSessionRequestHandler() const {
return session_handler.lock() != nullptr;
return !session_handler.expired();
}
/// Gets the HLE handler for this port.

View File

@@ -28,7 +28,7 @@ public:
static_assert(RegionsPerPage > 0);
public:
explicit KThreadLocalPage(VAddr addr = {}) : m_virt_addr(addr) {
constexpr explicit KThreadLocalPage(VAddr addr = {}) : m_virt_addr(addr) {
m_is_region_free.fill(true);
}
@@ -88,15 +88,15 @@ public:
}
private:
constexpr VAddr GetRegionAddress(size_t i) {
constexpr VAddr GetRegionAddress(size_t i) const {
return this->GetAddress() + i * Svc::ThreadLocalRegionSize;
}
constexpr bool Contains(VAddr addr) {
constexpr bool Contains(VAddr addr) const {
return this->GetAddress() <= addr && addr < this->GetAddress() + PageSize;
}
constexpr size_t GetRegionIndex(VAddr addr) {
constexpr size_t GetRegionIndex(VAddr addr) const {
ASSERT(Common::IsAligned(addr, Svc::ThreadLocalRegionSize));
ASSERT(this->Contains(addr));
return (addr - this->GetAddress()) / Svc::ThreadLocalRegionSize;