mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 10:52:13 +00:00
kern: skeleton SvcReplyAndReceive
This commit is contained in:
parent
be98aaa185
commit
f4fd4cbbb2
6 changed files with 131 additions and 5 deletions
|
@ -123,6 +123,7 @@ namespace ams::kern {
|
||||||
virtual ~KProcess() { /* ... */ }
|
virtual ~KProcess() { /* ... */ }
|
||||||
|
|
||||||
Result Initialize(const ams::svc::CreateProcessParameter ¶ms, const KPageGroup &pg, const u32 *caps, s32 num_caps, KResourceLimit *res_limit, KMemoryManager::Pool pool);
|
Result Initialize(const ams::svc::CreateProcessParameter ¶ms, const KPageGroup &pg, const u32 *caps, s32 num_caps, KResourceLimit *res_limit, KMemoryManager::Pool pool);
|
||||||
|
void Exit();
|
||||||
|
|
||||||
constexpr const char *GetName() const { return this->name; }
|
constexpr const char *GetName() const { return this->name; }
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,17 @@ namespace ams::kern {
|
||||||
|
|
||||||
constexpr const KSession *GetParent() const { return this->parent; }
|
constexpr const KSession *GetParent() const { return this->parent; }
|
||||||
|
|
||||||
virtual bool IsSignaled() const override { MESOSPHERE_UNIMPLEMENTED(); }
|
virtual bool IsSignaled() const override;
|
||||||
|
|
||||||
/* TODO: More of KServerSession. */
|
/* TODO: More of KServerSession. */
|
||||||
Result OnRequest(KSessionRequest *request);
|
Result OnRequest(KSessionRequest *request);
|
||||||
|
|
||||||
|
Result ReceiveRequest(uintptr_t message, uintptr_t buffer_size, KPhysicalAddress message_paddr);
|
||||||
|
Result SendReply(uintptr_t message, uintptr_t buffer_size, KPhysicalAddress message_paddr);
|
||||||
|
|
||||||
void OnClientClosed();
|
void OnClientClosed();
|
||||||
|
private:
|
||||||
|
bool IsSignaledImpl() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,10 @@ namespace ams::kern {
|
||||||
MESOSPHERE_UNIMPLEMENTED();
|
MESOSPHERE_UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KProcess::Exit() {
|
||||||
|
MESOSPHERE_UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
Result KProcess::CreateThreadLocalRegion(KProcessAddress *out) {
|
Result KProcess::CreateThreadLocalRegion(KProcessAddress *out) {
|
||||||
KThreadLocalPage *tlp = nullptr;
|
KThreadLocalPage *tlp = nullptr;
|
||||||
KProcessAddress tlr = Null<KProcessAddress>;
|
KProcessAddress tlr = Null<KProcessAddress>;
|
||||||
|
|
|
@ -48,6 +48,34 @@ namespace ams::kern {
|
||||||
MESOSPHERE_UNIMPLEMENTED();
|
MESOSPHERE_UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result KServerSession::ReceiveRequest(uintptr_t message, uintptr_t buffer_size, KPhysicalAddress message_paddr) {
|
||||||
|
MESOSPHERE_UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KServerSession::SendReply(uintptr_t message, uintptr_t buffer_size, KPhysicalAddress message_paddr) {
|
||||||
|
MESOSPHERE_UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KServerSession::IsSignaledImpl() const {
|
||||||
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
MESOSPHERE_ASSERT(KScheduler::IsSchedulerLockedByCurrentThread());
|
||||||
|
|
||||||
|
/* If the client is closed, we're always signaled. */
|
||||||
|
if (this->parent->IsClientClosed()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, we're signaled if we have a request and aren't handling one. */
|
||||||
|
return !this->request_list.empty() && this->current_request == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KServerSession::IsSignaled() const {
|
||||||
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
MESOSPHERE_ASSERT(KScheduler::IsSchedulerLockedByCurrentThread());
|
||||||
|
|
||||||
|
return this->IsSignaledImpl();
|
||||||
|
}
|
||||||
|
|
||||||
void KServerSession::OnClientClosed() {
|
void KServerSession::OnClientClosed() {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,90 @@ namespace ams::kern::svc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
ALWAYS_INLINE Result ReplyAndReceiveImpl(int32_t *out_index, uintptr_t message, size_t buffer_size, KPhysicalAddress message_paddr, KSynchronizationObject **objs, int32_t num_objects, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
|
/* Reply to the target, if one is specified. */
|
||||||
|
if (reply_target != ams::svc::InvalidHandle) {
|
||||||
|
/* TODO */
|
||||||
|
MESOSPHERE_UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Receive a message. */
|
||||||
|
{
|
||||||
|
/* Convert the timeout from nanoseconds to ticks. */
|
||||||
|
/* NOTE: Nintendo does not use this conversion logic in WaitSynchronization... */
|
||||||
|
s64 timeout;
|
||||||
|
if (timeout_ns > 0) {
|
||||||
|
const ams::svc::Tick offset_tick(TimeSpan::FromNanoSeconds(timeout_ns));
|
||||||
|
if (AMS_LIKELY(offset_tick > 0)) {
|
||||||
|
timeout = KHardwareTimer::GetTick() + offset_tick + 2;
|
||||||
|
if (AMS_UNLIKELY(timeout <= 0)) {
|
||||||
|
timeout = std::numeric_limits<s64>::max();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
timeout = std::numeric_limits<s64>::max();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
timeout = timeout_ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for a message. */
|
||||||
|
while (true) {
|
||||||
|
s32 index;
|
||||||
|
Result result = Kernel::GetSynchronization().Wait(std::addressof(index), objs, num_objects, timeout);
|
||||||
|
if (svc::ResultTimedOut::Includes(result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(result)) {
|
||||||
|
KServerSession *session = objs[index]->DynamicCast<KServerSession *>();
|
||||||
|
if (session != nullptr) {
|
||||||
|
result = session->ReceiveRequest(message, buffer_size, message_paddr);
|
||||||
|
if (svc::ResultNotFound::Includes(result)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_index = index;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE Result ReplyAndReceiveImpl(int32_t *out_index, uintptr_t message, size_t buffer_size, KPhysicalAddress message_paddr, KUserPointer<const ams::svc::Handle *> user_handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
|
/* Ensure number of handles is valid. */
|
||||||
|
R_UNLESS(0 <= num_handles && num_handles <= ams::svc::ArgumentHandleCountMax, svc::ResultOutOfRange());
|
||||||
|
|
||||||
|
/* Get the synchronization context. */
|
||||||
|
auto &handle_table = GetCurrentProcess().GetHandleTable();
|
||||||
|
KSynchronizationObject **objs = GetCurrentThread().GetSynchronizationObjectBuffer();
|
||||||
|
ams::svc::Handle *handles = GetCurrentThread().GetHandleBuffer();
|
||||||
|
|
||||||
|
/* Copy user handles. */
|
||||||
|
if (num_handles > 0) {
|
||||||
|
/* Ensure that we can try to get the handles. */
|
||||||
|
R_UNLESS(GetCurrentProcess().GetPageTable().Contains(KProcessAddress(user_handles.GetUnsafePointer()), num_handles * sizeof(ams::svc::Handle)), svc::ResultInvalidPointer());
|
||||||
|
|
||||||
|
/* Get the handles. */
|
||||||
|
R_TRY(user_handles.CopyArrayTo(handles, num_handles));
|
||||||
|
|
||||||
|
/* Convert the handles to objects. */
|
||||||
|
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs, handles, num_handles), svc::ResultInvalidHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure handles are closed when we're done. */
|
||||||
|
ON_SCOPE_EXIT {
|
||||||
|
for (auto i = 0; i < num_handles; ++i) {
|
||||||
|
objs[i]->Close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return ReplyAndReceiveImpl(out_index, message, buffer_size, message_paddr, objs, num_handles, reply_target, timeout_ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE Result ReplyAndReceive(int32_t *out_index, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
|
return ReplyAndReceiveImpl(out_index, 0, 0, Null<KPhysicalAddress>, handles, num_handles, reply_target, timeout_ns);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +123,7 @@ namespace ams::kern::svc {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ReplyAndReceive64(int32_t *out_index, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
Result ReplyAndReceive64(int32_t *out_index, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
MESOSPHERE_PANIC("Stubbed SvcReplyAndReceive64 was called.");
|
return ReplyAndReceive(out_index, handles, num_handles, reply_target, timeout_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ReplyAndReceiveWithUserBuffer64(int32_t *out_index, ams::svc::Address message_buffer, ams::svc::Size message_buffer_size, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
Result ReplyAndReceiveWithUserBuffer64(int32_t *out_index, ams::svc::Address message_buffer, ams::svc::Size message_buffer_size, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
|
@ -62,7 +145,7 @@ namespace ams::kern::svc {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ReplyAndReceive64From32(int32_t *out_index, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
Result ReplyAndReceive64From32(int32_t *out_index, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
MESOSPHERE_PANIC("Stubbed SvcReplyAndReceive64From32 was called.");
|
return ReplyAndReceive(out_index, handles, num_handles, reply_target, timeout_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ReplyAndReceiveWithUserBuffer64From32(int32_t *out_index, ams::svc::Address message_buffer, ams::svc::Size message_buffer_size, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
Result ReplyAndReceiveWithUserBuffer64From32(int32_t *out_index, ams::svc::Address message_buffer, ams::svc::Size message_buffer_size, KUserPointer<const ams::svc::Handle *> handles, int32_t num_handles, ams::svc::Handle reply_target, int64_t timeout_ns) {
|
||||||
|
|
|
@ -21,6 +21,11 @@ namespace ams::kern::svc {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
void ExitProcess() {
|
||||||
|
GetCurrentProcess().Exit();
|
||||||
|
MESOSPHERE_PANIC("Process survived call to exit");
|
||||||
|
}
|
||||||
|
|
||||||
Result GetProcessId(u64 *out_process_id, ams::svc::Handle handle) {
|
Result GetProcessId(u64 *out_process_id, ams::svc::Handle handle) {
|
||||||
/* Get the object from the handle table. */
|
/* Get the object from the handle table. */
|
||||||
KScopedAutoObject obj = GetCurrentProcess().GetHandleTable().GetObject<KAutoObject>(handle);
|
KScopedAutoObject obj = GetCurrentProcess().GetHandleTable().GetObject<KAutoObject>(handle);
|
||||||
|
@ -54,7 +59,7 @@ namespace ams::kern::svc {
|
||||||
/* ============================= 64 ABI ============================= */
|
/* ============================= 64 ABI ============================= */
|
||||||
|
|
||||||
void ExitProcess64() {
|
void ExitProcess64() {
|
||||||
MESOSPHERE_PANIC("Stubbed SvcExitProcess64 was called.");
|
return ExitProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetProcessId64(uint64_t *out_process_id, ams::svc::Handle process_handle) {
|
Result GetProcessId64(uint64_t *out_process_id, ams::svc::Handle process_handle) {
|
||||||
|
@ -84,7 +89,7 @@ namespace ams::kern::svc {
|
||||||
/* ============================= 64From32 ABI ============================= */
|
/* ============================= 64From32 ABI ============================= */
|
||||||
|
|
||||||
void ExitProcess64From32() {
|
void ExitProcess64From32() {
|
||||||
MESOSPHERE_PANIC("Stubbed SvcExitProcess64From32 was called.");
|
return ExitProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetProcessId64From32(uint64_t *out_process_id, ams::svc::Handle process_handle) {
|
Result GetProcessId64From32(uint64_t *out_process_id, ams::svc::Handle process_handle) {
|
||||||
|
|
Loading…
Reference in a new issue