kern: SvcGetLastThreadInfo, SvcGetDebugFutureThreadInfo

This commit is contained in:
Michael Scire 2020-07-30 16:31:58 -07:00 committed by SciresM
parent 0993ae0685
commit 51084c0837
13 changed files with 325 additions and 18 deletions

View file

@ -26,6 +26,22 @@ namespace ams::kern::arch::arm64 {
u32 write;
u64 tpidr;
u64 reserved;
constexpr void GetSvcThreadContext(ams::svc::LastThreadContext *out) const {
if ((this->psr & 0x10) == 0) {
/* aarch64 thread. */
out->fp = this->x[29];
out->sp = this->sp;
out->lr = this->x[30];
out->pc = this->pc;
} else {
/* aarch32 thread. */
out->fp = this->x[11];
out->sp = this->x[13];
out->lr = this->x[14];
out->pc = this->pc;
}
}
};
static_assert(sizeof(KExceptionContext) == 0x120);

View file

@ -42,6 +42,8 @@ namespace ams::kern {
Result ReadMemory(KProcessAddress buffer, KProcessAddress address, size_t size);
Result WriteMemory(KProcessAddress buffer, KProcessAddress address, size_t size);
Result GetRunningThreadInfo(ams::svc::LastThreadContext *out_context, u64 *out_thread_id);
Result GetDebugEventInfo(ams::svc::lp64::DebugEventInfo *out);
Result GetDebugEventInfo(ams::svc::ilp32::DebugEventInfo *out);

View file

@ -246,6 +246,8 @@ namespace ams::kern {
constexpr KHandleTable &GetHandleTable() { return this->handle_table; }
constexpr const KHandleTable &GetHandleTable() const { return this->handle_table; }
KWaitObject *GetWaitObjectPointer() { return std::addressof(this->wait_object); }
size_t GetUsedUserPhysicalMemorySize() const;
size_t GetTotalUserPhysicalMemorySize() const;
size_t GetUsedNonSystemUserPhysicalMemorySize() const;
@ -284,6 +286,9 @@ namespace ams::kern {
}
}
constexpr KThread *GetRunningThread(s32 core) const { return this->running_threads[core]; }
constexpr u64 GetRunningThreadIdleCount(s32 core) const { return this->running_thread_idle_counts[core]; }
void RegisterThread(KThread *thread);
void UnregisterThread(KThread *thread);

View file

@ -83,10 +83,18 @@ namespace ams::kern {
}
}
ALWAYS_INLINE u64 GetIdleCount() const {
return this->state.idle_count;
}
ALWAYS_INLINE KThread *GetIdleThread() const {
return this->idle_thread;
}
ALWAYS_INLINE KThread *GetPreviousThread() const {
return this->prev_thread;
}
ALWAYS_INLINE s64 GetLastContextSwitchTime() const {
return this->last_context_switch_time;
}

View file

@ -543,4 +543,12 @@ namespace ams::kern {
}
};
ALWAYS_INLINE KExceptionContext *GetExceptionContext(KThread *thread) {
return reinterpret_cast<KExceptionContext *>(reinterpret_cast<uintptr_t>(thread->GetKernelStackTop()) - sizeof(KThread::StackParameters) - sizeof(KExceptionContext));
}
ALWAYS_INLINE const KExceptionContext *GetExceptionContext(const KThread *thread) {
return reinterpret_cast<const KExceptionContext *>(reinterpret_cast<uintptr_t>(thread->GetKernelStackTop()) - sizeof(KThread::StackParameters) - sizeof(KExceptionContext));
}
}

View file

@ -25,13 +25,42 @@ namespace ams::kern {
using Entry = KThread::QueueEntry;
private:
Entry root;
bool uses_timer;
bool timer_used;
public:
constexpr KWaitObject() : root(), uses_timer() { /* ... */ }
constexpr KWaitObject() : root(), timer_used() { /* ... */ }
virtual void OnTimer() override;
Result Synchronize(s64 timeout);
private:
constexpr ALWAYS_INLINE void Enqueue(KThread *add) {
/* Get the entry associated with the added thread. */
Entry &add_entry = add->GetSleepingQueueEntry();
/* TODO: Member functions */
/* Get the entry associated with the end of the queue. */
KThread *tail = this->root.GetPrev();
Entry &tail_entry = (tail != nullptr) ? tail->GetSleepingQueueEntry() : this->root;
/* Link the entries. */
add_entry.SetPrev(tail);
add_entry.SetNext(nullptr);
tail_entry.SetNext(add);
this->root.SetPrev(add);
}
constexpr ALWAYS_INLINE void Remove(KThread *remove) {
/* Get the entry associated with the thread. */
Entry &remove_entry = remove->GetSleepingQueueEntry();
/* Get the entries associated with next and prev. */
KThread *prev = remove_entry.GetPrev();
KThread *next = remove_entry.GetNext();
Entry &prev_entry = (prev != nullptr) ? prev->GetSleepingQueueEntry() : this->root;
Entry &next_entry = (next != nullptr) ? next->GetSleepingQueueEntry() : this->root;
/* Unlink. */
prev_entry.SetNext(next);
next_entry.SetPrev(prev);
}
};
}

View file

@ -58,8 +58,8 @@ namespace ams::kern::svc {
/* 126 */ using ::ams::svc::ResultReservedUsed;
/* 127 */ using ::ams::svc::ResultNotSupported;
/* 128 */ using ::ams::svc::ResultDebug;
/* 129 */ using ::ams::svc::ResultThreadNotOwned;
/* 129 */ using ::ams::svc::ResultNoThread;
/* 130 */ using ::ams::svc::ResultUnknownThread;
/* 131 */ using ::ams::svc::ResultPortClosed;
/* 132 */ using ::ams::svc::ResultLimitReached;
/* 133 */ using ::ams::svc::ResultInvalidMemoryPool;