kern: partially implement Receive half of ReplyAndReceive

This commit is contained in:
Michael Scire 2020-07-10 00:03:50 -07:00
parent 1b2203d102
commit 84b1be1d58
5 changed files with 315 additions and 33 deletions

View file

@ -46,6 +46,8 @@ namespace ams::kern {
static void PostDestroy(uintptr_t arg);
virtual KProcess *GetOwner() const override { return this->owner; }
KReadableEvent &GetReadableEvent() { return this->readable_event; }
KWritableEvent &GetWritableEvent() { return this->writable_event; }
};

View file

@ -155,21 +155,7 @@ namespace ams::kern {
}
}
template<typename T = KAutoObject>
ALWAYS_INLINE KScopedAutoObject<T> GetObjectForIpc(ams::svc::Handle handle) const {
static_assert(!std::is_base_of<KInterruptEvent, T>::value);
/* Handle pseudo-handles. */
if constexpr (std::is_base_of<T, KProcess>::value) {
if (handle == ams::svc::PseudoHandle::CurrentProcess) {
return GetCurrentProcessPointer();
}
} else if constexpr (std::is_base_of<T, KThread>::value) {
if (handle == ams::svc::PseudoHandle::CurrentThread) {
return GetCurrentThreadPointer();
}
}
ALWAYS_INLINE KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(ams::svc::Handle handle) const {
/* Lock and look up in table. */
KScopedDisableDispatch dd;
KScopedSpinLock lk(this->lock);
@ -178,15 +164,20 @@ namespace ams::kern {
if (obj->DynamicCast<KInterruptEvent *>() != nullptr) {
return nullptr;
}
if constexpr (std::is_same<T, KAutoObject>::value) {
return obj;
} else {
if (auto *obj = this->GetObjectImpl(handle); obj != nullptr) {
return obj->DynamicCast<T*>();
} else {
return nullptr;
}
return obj;
}
ALWAYS_INLINE KScopedAutoObject<KAutoObject> GetObjectForIpc(ams::svc::Handle handle, KThread *cur_thread) const {
/* Handle pseudo-handles. */
if (handle == ams::svc::PseudoHandle::CurrentProcess) {
return static_cast<KAutoObject *>(static_cast<void *>(cur_thread->GetOwnerProcess()));
}
if (handle == ams::svc::PseudoHandle::CurrentThread) {
return static_cast<KAutoObject *>(cur_thread);
}
return GetObjectForIpcWithoutPseudoHandle(handle);
}
ALWAYS_INLINE KScopedAutoObject<KAutoObject> GetObjectByIndex(ams::svc::Handle *out_handle, size_t index) const {

View file

@ -128,6 +128,11 @@ namespace ams::kern {
size_t GetSize() const { return this->size; }
KProcess *GetServerProcess() const { return this->server; }
void SetServerProcess(KProcess *process) {
this->server = process;
this->server->Open();
}
void ClearThread() { this->thread = nullptr; }
void ClearEvent() { this->event = nullptr; }