mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-31 06:48:22 -04:00
kern: SvcConnectToNamedPort
This commit is contained in:
parent
a2eb93fde8
commit
7400a8ff68
15 changed files with 376 additions and 15 deletions
|
@ -177,10 +177,12 @@ namespace ams::kern {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template<typename T> requires std::derived_from<T, KAutoObject>
|
||||
class KScopedAutoObject {
|
||||
static_assert(std::is_base_of<KAutoObject, T>::value);
|
||||
NON_COPYABLE(KScopedAutoObject);
|
||||
private:
|
||||
template<typename U>
|
||||
friend class KScopedAutoObject;
|
||||
private:
|
||||
T *obj;
|
||||
private:
|
||||
|
@ -202,12 +204,32 @@ namespace ams::kern {
|
|||
this->obj = nullptr;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE KScopedAutoObject(KScopedAutoObject &&rhs) {
|
||||
this->obj = rhs.obj;
|
||||
rhs.obj = nullptr;
|
||||
template<typename U>
|
||||
constexpr ALWAYS_INLINE KScopedAutoObject(KScopedAutoObject<U> &&rhs) {
|
||||
if constexpr (std::same_as<T, U>) {
|
||||
this->obj = rhs.obj;
|
||||
rhs.obj = nullptr;
|
||||
} else {
|
||||
T *derived = rhs.obj->template DynamicCast<T *>();
|
||||
if (derived == nullptr) {
|
||||
rhs.obj->Close();
|
||||
}
|
||||
|
||||
this->obj = derived;
|
||||
rhs.obj = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE KScopedAutoObject &operator=(KScopedAutoObject &&rhs) {
|
||||
template<typename U>
|
||||
constexpr ALWAYS_INLINE KScopedAutoObject &operator=(KScopedAutoObject<U> &&rhs) {
|
||||
if constexpr (!std::same_as<T, U>) {
|
||||
T *derived = rhs.obj->template DynamicCast<T *>();
|
||||
if (derived == nullptr) {
|
||||
rhs.obj->Close();
|
||||
}
|
||||
rhs.obj = nullptr;
|
||||
}
|
||||
|
||||
rhs.Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
namespace ams::kern {
|
||||
|
||||
class KPort;
|
||||
class KSession;
|
||||
class KClientSession;
|
||||
class KLightSession;
|
||||
class KLightClientSession;
|
||||
|
||||
class KClientPort final : public KSynchronizationObject {
|
||||
MESOSPHERE_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject);
|
||||
|
@ -33,6 +37,8 @@ namespace ams::kern {
|
|||
virtual ~KClientPort() { /* ... */ }
|
||||
|
||||
void Initialize(KPort *parent, s32 max_sessions);
|
||||
void OnSessionFinalized();
|
||||
void OnServerClosed();
|
||||
|
||||
constexpr const KPort *GetParent() const { return this->parent; }
|
||||
|
||||
|
@ -43,6 +49,7 @@ namespace ams::kern {
|
|||
virtual bool IsSignaled() const override;
|
||||
|
||||
/* TODO: More of KClientPort. */
|
||||
Result CreateSession(KClientSession **out);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ namespace ams::kern {
|
|||
constexpr const KSession *GetParent() const { return this->parent; }
|
||||
|
||||
/* TODO: More of KClientSession. */
|
||||
void OnServerClosed();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,11 @@ namespace ams::kern {
|
|||
|
||||
return Delete(obj.GetPointerUnsafe(), name);
|
||||
}
|
||||
|
||||
template<typename Derived> requires std::derived_from<Derived, KAutoObject>
|
||||
static KScopedAutoObject<Derived> Find(const char *name) {
|
||||
return Find(name);
|
||||
}
|
||||
private:
|
||||
static KScopedAutoObject<KAutoObject> FindImpl(const char *name);
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
|
||||
namespace ams::kern {
|
||||
|
||||
class KServerSession;
|
||||
class KLightServerSession;
|
||||
|
||||
class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
|
||||
MESOSPHERE_AUTOOBJECT_TRAITS(KPort, KAutoObject);
|
||||
private:
|
||||
|
@ -50,7 +53,8 @@ namespace ams::kern {
|
|||
uintptr_t GetName() const { return this->name; }
|
||||
bool IsLight() const { return this->is_light; }
|
||||
|
||||
/* TODO: More of KPort */
|
||||
Result EnqueueSession(KServerSession *session);
|
||||
Result EnqueueSession(KLightServerSession *session);
|
||||
|
||||
KClientPort &GetClientPort() { return this->client; }
|
||||
KServerPort &GetServerPort() { return this->server; }
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace ams::kern {
|
|||
virtual ~KServerPort() { /* ... */ }
|
||||
|
||||
void Initialize(KPort *parent);
|
||||
void EnqueueSession(KServerSession *session);
|
||||
void EnqueueSession(KLightServerSession *session);
|
||||
|
||||
constexpr const KPort *GetParent() const { return this->parent; }
|
||||
|
||||
|
@ -47,7 +49,7 @@ namespace ams::kern {
|
|||
virtual void Destroy() override;
|
||||
virtual bool IsSignaled() const override;
|
||||
|
||||
/* TODO: More of KClientPort. */
|
||||
/* TODO: More of KServerPort. */
|
||||
private:
|
||||
void CleanupSessions();
|
||||
/* TODO: This is a placeholder definition. */
|
||||
|
|
|
@ -36,13 +36,16 @@ namespace ams::kern {
|
|||
constexpr KServerSession() : parent(), request_list(), current_request(), lock() { /* ... */ }
|
||||
virtual ~KServerSession() { /* ... */ }
|
||||
|
||||
void Initialize(KSession *parent);
|
||||
void Initialize(KSession *p) { this->parent = p; }
|
||||
|
||||
constexpr const KSession *GetParent() const { return this->parent; }
|
||||
|
||||
virtual bool IsSignaled() const override { MESOSPHERE_UNIMPLEMENTED(); }
|
||||
|
||||
/* TODO: More of KServerSession. */
|
||||
Result OnRequest(KSessionRequest *request);
|
||||
|
||||
void OnClientClosed();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -51,12 +51,21 @@ namespace ams::kern {
|
|||
|
||||
virtual ~KSession() { /* ... */ }
|
||||
|
||||
void Initialize(KClientPort *client_port, uintptr_t name);
|
||||
virtual void Finalize() override;
|
||||
|
||||
virtual bool IsInitialized() const override { return this->initialized; }
|
||||
virtual uintptr_t GetPostDestroyArgument() const override { return reinterpret_cast<uintptr_t>(this->process); }
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
|
||||
/* TODO: This is a placeholder definition. */
|
||||
void OnServerClosed();
|
||||
void OnClientClosed();
|
||||
|
||||
bool IsServerClosed() const { return this->state != State::Normal; }
|
||||
bool IsClientClosed() const { return this->state != State::Normal; }
|
||||
|
||||
Result OnRequest(KSessionRequest *request) { return this->server.OnRequest(request); }
|
||||
|
||||
KClientSession &GetClientSession() { return this->client; }
|
||||
KServerSession &GetServerSession() { return this->server; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue