21.0.0: Difference between revisions

No edit summary
Add 20 -> 21 kernel diff
Line 343: Line 343:


The anti-downgrade fuses were [[Fuses#Anti-downgrade|updated]].
The anti-downgrade fuses were [[Fuses#Anti-downgrade|updated]].
==== Kernel ====
* Compiler was upgraded (to clang 18.1.0+).
** Besides the usual reordering, this is now most noticeable in the following:
*** Many atomic st(l)xrs now use cmp + csetm + tbz instead of cbnz.
**** Testing on godbolt indicates this seems to be a change made in clang 18.1.0+ (not present in 17.0.1).
*** Many cases where they previously did some_condition ? m_a : m_b now have different assembly.
**** Previously: add Xn, Xz, #A; add Xm, Xz, #B; csel Xn, Xn, Xm; ldr Xn, [Xn]
**** Now: mov Xn, #A; mov Xn, #B; csel Xn, Xn, Xm; ldr Xn, [Xz, Xn]
*** Many cases of booleans now explicitly test for 1 instead of <any non-zero value>
**** Previously: ldrb w8, [x8]; cbz w8, some_loc
**** Now: ldrb w8, [x8]; cmp w8, #1; b.ne some_loc
** Many, many cases of superfluous red-black-tree iteration prior to calls to KIntrusiveRedBlackTree::Remove have finally been optimized out.
*** Basically, KIntrusiveRedBlackTree::erase returns an iterator to the next item in the tree.
*** Previously, the table walk to find the next item was being performed even when the result was discarded/not-used, which was almost every case.
*** Now, it's successfully getting optimized out.
* KAutoObject's class token has been devirtualized.
** It is now stored as a 16-bit value in previously unused padding bytes, after the reference count.
** KAutoObject::Create() sets this to the correct value when setting refcount=1.
** This implementation is generally identical to the one already present in mesosphere.
* HandleFloatingPointException now sets a previously unused StackParameters flag (+0x2F) to 1.
** This flag doesn't seem to be referenced/used anywhere else in the kernel?
* KInterruptManager/Controller was changed:
** KInterruptController::LocalState now stores the private spendsgir, which is also now saved/restored by KInterruptController::SaveLocalState/RestoreLocalState
** KSleepManager now spins for 100 microseconds before calling KInterruptManager::Save, after synchronizing all cores.
* cpu::DoCoreInterruptBarrier now uses a global KLightLock; this prevents more than one thread from performing an interrupt barrier at the same time.
* KThread StackParameter exception_flags bitflags are now volatile and mostly atomic; many bits now use atomic read-modify-write loops to set and clear bits.
** This is not done for bit 0 ("is in svc"), accesses specifically for bit 0 continue to use non-atomic reads/writes.
** This generates pretty terrible assembly for GetThreadUserContext, which now must perform a volatile read of this value over and over in a loop.
* KIoRegion fields were reordered to save 8 bytes.
** The 8-byte size/alignment lock field is no longer wedged inbetween two 1-byte booleans.
* KScheduler::SwitchThread now writes a tick differential (thread->GetCpuTime() - context_switch_time) to user-tls + 0x108.
** NOTE: This is an ABI change which will not affect official software, but will force any homebrew software which uses TLS-slots to need re-compile.
* UserspaceAccess::CopyMemoryToUserSize32Bit now takes in a 32-bit word to write, instead of a kernel-pointer-to-32-bit-word.
* Nintendo appears to have done something akin to marking nn::Result nodiscard + gone through and fixed literally every instance of Result return values not being used.
** This results in sweeping changes (many Result-return functions are now void return, many new kernel panics, some changed behaviors), including e,g,
** KInterruptManager::ClearInterrupt no longer checks if a handler has been registered, and always clear the table entry.
** KInterruptManager::UnbindHandler is now void-return instead of Result; it no longer checks if the handler has been registered, and unconditionally clears to unbound state.
** KPageTableBase::InitializeForKernel now returns void, and panics if the KMemoryBlockManager::Initialize fails.
** KDebugBase::OnExitProcess/OnTerminateProcess now return void instead of Result.
** KEvent/KReadableEvent::Signal/Clear now return void instead of Result; svc::ClearEvent/SignalEvent now just calls the relevant function and returns ResultSuccess.
** KThreadLocalPage::Finalize now returns void + kernel-panics if unmapping the page fails; KProcess::DeleteThreadLocalRegion now returns void instead of Result.
** Every kernel-use of KInterruptManager::BindHandler now panics on failure.
** Every kernel-use of cpu::StoreDataCache and cpu::FlushDataCache and cpu::InvalidateDataCache now panics on failure.
** Every kernel-use of KThread::Initialize now panics on failure
** Every kernel-use of KThread::Run now panics on failure.
** The kernel-use of KDynamicSlabHeapPageAllocator::Initialize in resource manager init now panics on failure
** There are more cases, too many to fully enumerate with high confidence.


=== [[LDN_services|ldn]] ===
=== [[LDN_services|ldn]] ===