kern: SvcGetThreadList

This commit is contained in:
Michael Scire 2020-07-30 16:52:11 -07:00 committed by SciresM
parent 51084c0837
commit 96c3dfee14
6 changed files with 100 additions and 20 deletions

View file

@ -1189,4 +1189,31 @@ namespace ams::kern {
return std::addressof(this->GetContext());
}
Result KThread::GetThreadList(s32 *out_num_threads, ams::kern::svc::KUserPointer<u64 *> out_thread_ids, s32 max_out_count) {
/* Lock the list. */
KThread::ListAccessor accessor;
const auto end = accessor.end();
/* Iterate over the list. */
s32 count = 0;
for (auto it = accessor.begin(); it != end; ++it) {
/* If we're within array bounds, write the id. */
if (count < max_out_count) {
/* Get the thread id. */
KThread *thread = static_cast<KThread *>(std::addressof(*it));
const u64 id = thread->GetId();
/* Copy the id to userland. */
R_TRY(out_thread_ids.CopyArrayElementFrom(std::addressof(id), count));
}
/* Increment the count. */
++count;
}
/* We successfully iterated the list. */
*out_num_threads = count;
return ResultSuccess();
}
}