mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-09 05:57:59 +00:00
kern: fix bugs caused by UB + transition to -Os
This commit is contained in:
parent
1b164613a6
commit
3c8e7de915
4 changed files with 49 additions and 45 deletions
|
@ -25,7 +25,7 @@ namespace ams::kern::arch::arm64 {
|
||||||
public:
|
public:
|
||||||
constexpr KNotAlignedSpinLock() : packed_tickets(0) { /* ... */ }
|
constexpr KNotAlignedSpinLock() : packed_tickets(0) { /* ... */ }
|
||||||
|
|
||||||
void Lock() {
|
ALWAYS_INLINE void Lock() {
|
||||||
u32 tmp0, tmp1, tmp2;
|
u32 tmp0, tmp1, tmp2;
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
@ -52,7 +52,7 @@ namespace ams::kern::arch::arm64 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unlock() {
|
ALWAYS_INLINE void Unlock() {
|
||||||
const u32 value = this->packed_tickets + 1;
|
const u32 value = this->packed_tickets + 1;
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
" stlrh %w[value], %[packed_tickets]\n"
|
" stlrh %w[value], %[packed_tickets]\n"
|
||||||
|
@ -71,7 +71,7 @@ namespace ams::kern::arch::arm64 {
|
||||||
public:
|
public:
|
||||||
constexpr KAlignedSpinLock() : current_ticket(0), next_ticket(0) { /* ... */ }
|
constexpr KAlignedSpinLock() : current_ticket(0), next_ticket(0) { /* ... */ }
|
||||||
|
|
||||||
void Lock() {
|
ALWAYS_INLINE void Lock() {
|
||||||
u32 tmp0, tmp1, got_lock;
|
u32 tmp0, tmp1, got_lock;
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
@ -94,7 +94,7 @@ namespace ams::kern::arch::arm64 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unlock() {
|
ALWAYS_INLINE void Unlock() {
|
||||||
const u32 value = this->current_ticket + 1;
|
const u32 value = this->current_ticket + 1;
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
" stlrh %w[value], %[current_ticket]\n"
|
" stlrh %w[value], %[current_ticket]\n"
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace ams::kern {
|
||||||
u32 prev_intr_state;
|
u32 prev_intr_state;
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE KScopedInterruptDisable() : prev_intr_state(KInterruptManager::DisableInterrupts()) { /* ... */ }
|
ALWAYS_INLINE KScopedInterruptDisable() : prev_intr_state(KInterruptManager::DisableInterrupts()) { /* ... */ }
|
||||||
~KScopedInterruptDisable() { KInterruptManager::RestoreInterrupts(prev_intr_state); }
|
ALWAYS_INLINE ~KScopedInterruptDisable() { KInterruptManager::RestoreInterrupts(prev_intr_state); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class KScopedInterruptEnable {
|
class KScopedInterruptEnable {
|
||||||
|
@ -52,7 +52,7 @@ namespace ams::kern {
|
||||||
u32 prev_intr_state;
|
u32 prev_intr_state;
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE KScopedInterruptEnable() : prev_intr_state(KInterruptManager::EnableInterrupts()) { /* ... */ }
|
ALWAYS_INLINE KScopedInterruptEnable() : prev_intr_state(KInterruptManager::EnableInterrupts()) { /* ... */ }
|
||||||
~KScopedInterruptEnable() { KInterruptManager::RestoreInterrupts(prev_intr_state); }
|
ALWAYS_INLINE ~KScopedInterruptEnable() { KInterruptManager::RestoreInterrupts(prev_intr_state); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||||
/* Disable interrupts while making the call. */
|
/* Disable interrupts while making the call. */
|
||||||
KScopedInterruptDisable intr_disable;
|
KScopedInterruptDisable intr_disable;
|
||||||
|
|
||||||
|
{
|
||||||
/* Backup the current thread pointer. */
|
/* Backup the current thread pointer. */
|
||||||
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
||||||
|
|
||||||
|
@ -69,7 +70,6 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||||
|
|
||||||
/* Restore the current thread pointer into X18. */
|
/* Restore the current thread pointer into X18. */
|
||||||
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
||||||
}
|
|
||||||
|
|
||||||
/* Store arguments to output. */
|
/* Store arguments to output. */
|
||||||
args.x[0] = x0;
|
args.x[0] = x0;
|
||||||
|
@ -81,6 +81,8 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||||
args.x[6] = x6;
|
args.x[6] = x6;
|
||||||
args.x[7] = x7;
|
args.x[7] = x7;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CallUserSecureMonitorFunction(ams::svc::lp64::SecureMonitorArguments *args) {
|
void CallUserSecureMonitorFunction(ams::svc::lp64::SecureMonitorArguments *args) {
|
||||||
/* Load arguments into registers. */
|
/* Load arguments into registers. */
|
||||||
|
@ -98,10 +100,11 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||||
/* Disable interrupts while making the call. */
|
/* Disable interrupts while making the call. */
|
||||||
KScopedInterruptDisable intr_disable;
|
KScopedInterruptDisable intr_disable;
|
||||||
|
|
||||||
|
{
|
||||||
/* Backup the current thread pointer. */
|
/* Backup the current thread pointer. */
|
||||||
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
||||||
|
|
||||||
__asm__ __volatile__("smc #0"
|
__asm__ __volatile__("smc #1"
|
||||||
: "+r"(x0), "+r"(x1), "+r"(x2), "+r"(x3), "+r"(x4), "+r"(x5), "+r"(x6), "+r"(x7)
|
: "+r"(x0), "+r"(x1), "+r"(x2), "+r"(x3), "+r"(x4), "+r"(x5), "+r"(x6), "+r"(x7)
|
||||||
:
|
:
|
||||||
: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "cc", "memory"
|
: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "cc", "memory"
|
||||||
|
@ -109,7 +112,6 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||||
|
|
||||||
/* Restore the current thread pointer into X18. */
|
/* Restore the current thread pointer into X18. */
|
||||||
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
||||||
}
|
|
||||||
|
|
||||||
/* Store arguments to output. */
|
/* Store arguments to output. */
|
||||||
args->r[0] = x0;
|
args->r[0] = x0;
|
||||||
|
@ -121,6 +123,8 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||||
args->r[6] = x6;
|
args->r[6] = x6;
|
||||||
args->r[7] = x7;
|
args->r[7] = x7;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CallPrivilegedSecureMonitorFunctionForInit(SecureMonitorArguments &args) {
|
void CallPrivilegedSecureMonitorFunctionForInit(SecureMonitorArguments &args) {
|
||||||
/* Load arguments into registers. */
|
/* Load arguments into registers. */
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace ams::kern {
|
||||||
}
|
}
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case ThreadType_HighPriority:
|
case ThreadType_HighPriority:
|
||||||
{
|
if (type != ThreadType_Main) {
|
||||||
MESOSPHERE_ASSERT(phys_core == GetCurrentCoreId());
|
MESOSPHERE_ASSERT(phys_core == GetCurrentCoreId());
|
||||||
}
|
}
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
Loading…
Reference in a new issue