mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-30 14:35:17 -04:00
Delete libstratosphere in prep for submodule
This commit is contained in:
parent
3b8bb325e8
commit
5ef01edab5
36 changed files with 0 additions and 4320 deletions
|
@ -1,235 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
|
||||
void HosMessageQueue::Send(uintptr_t data) {
|
||||
/* Acquire mutex, wait sendable. */
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
|
||||
while (this->IsFull()) {
|
||||
this->cv_not_full.Wait(&this->queue_lock);
|
||||
}
|
||||
|
||||
/* Send, signal. */
|
||||
this->SendInternal(data);
|
||||
this->cv_not_empty.WakeAll();
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TrySend(uintptr_t data) {
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
if (this->IsFull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Send, signal. */
|
||||
this->SendInternal(data);
|
||||
this->cv_not_empty.WakeAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TimedSend(uintptr_t data, u64 timeout) {
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
TimeoutHelper timeout_helper(timeout);
|
||||
|
||||
while (this->IsFull()) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->cv_not_full.TimedWait(timeout, &this->queue_lock);
|
||||
}
|
||||
|
||||
/* Send, signal. */
|
||||
this->SendInternal(data);
|
||||
this->cv_not_empty.WakeAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
void HosMessageQueue::SendNext(uintptr_t data) {
|
||||
/* Acquire mutex, wait sendable. */
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
|
||||
while (this->IsFull()) {
|
||||
this->cv_not_full.Wait(&this->queue_lock);
|
||||
}
|
||||
|
||||
/* Send, signal. */
|
||||
this->SendNextInternal(data);
|
||||
this->cv_not_empty.WakeAll();
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TrySendNext(uintptr_t data) {
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
if (this->IsFull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Send, signal. */
|
||||
this->SendNextInternal(data);
|
||||
this->cv_not_empty.WakeAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TimedSendNext(uintptr_t data, u64 timeout) {
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
TimeoutHelper timeout_helper(timeout);
|
||||
|
||||
while (this->IsFull()) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->cv_not_full.TimedWait(timeout, &this->queue_lock);
|
||||
}
|
||||
|
||||
/* Send, signal. */
|
||||
this->SendNextInternal(data);
|
||||
this->cv_not_empty.WakeAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
void HosMessageQueue::Receive(uintptr_t *out) {
|
||||
/* Acquire mutex, wait receivable. */
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
|
||||
while (this->IsEmpty()) {
|
||||
this->cv_not_empty.Wait(&this->queue_lock);
|
||||
}
|
||||
|
||||
/* Receive, signal. */
|
||||
*out = this->ReceiveInternal();
|
||||
this->cv_not_full.WakeAll();
|
||||
}
|
||||
bool HosMessageQueue::TryReceive(uintptr_t *out) {
|
||||
/* Acquire mutex, wait receivable. */
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
|
||||
if (this->IsEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Receive, signal. */
|
||||
*out = this->ReceiveInternal();
|
||||
this->cv_not_full.WakeAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TimedReceive(uintptr_t *out, u64 timeout) {
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
TimeoutHelper timeout_helper(timeout);
|
||||
|
||||
while (this->IsEmpty()) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->cv_not_empty.TimedWait(timeout, &this->queue_lock);
|
||||
}
|
||||
|
||||
/* Receive, signal. */
|
||||
*out = this->ReceiveInternal();
|
||||
this->cv_not_full.WakeAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
void HosMessageQueue::Peek(uintptr_t *out) {
|
||||
/* Acquire mutex, wait receivable. */
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
|
||||
while (this->IsEmpty()) {
|
||||
this->cv_not_empty.Wait(&this->queue_lock);
|
||||
}
|
||||
|
||||
/* Peek. */
|
||||
*out = this->PeekInternal();
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TryPeek(uintptr_t *out) {
|
||||
/* Acquire mutex, wait receivable. */
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
|
||||
if (this->IsEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Peek. */
|
||||
*out = this->PeekInternal();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HosMessageQueue::TimedPeek(uintptr_t *out, u64 timeout) {
|
||||
std::scoped_lock<HosMutex> lock(this->queue_lock);
|
||||
TimeoutHelper timeout_helper(timeout);
|
||||
|
||||
while (this->IsEmpty()) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->cv_not_empty.TimedWait(timeout, &this->queue_lock);
|
||||
}
|
||||
|
||||
/* Peek. */
|
||||
*out = this->PeekInternal();
|
||||
return true;
|
||||
}
|
||||
|
||||
void HosMessageQueue::SendInternal(uintptr_t data) {
|
||||
/* Ensure we don't corrupt the queue, but this should never happen. */
|
||||
if (this->count >= this->capacity) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
/* Write data to tail of queue. */
|
||||
this->buffer[(this->count++ + this->offset) % this->capacity] = data;
|
||||
}
|
||||
|
||||
void HosMessageQueue::SendNextInternal(uintptr_t data) {
|
||||
/* Ensure we don't corrupt the queue, but this should never happen. */
|
||||
if (this->count >= this->capacity) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
/* Write data to head of queue. */
|
||||
this->offset = (this->offset + this->capacity - 1) % this->capacity;
|
||||
this->buffer[this->offset] = data;
|
||||
this->count++;
|
||||
}
|
||||
|
||||
uintptr_t HosMessageQueue::ReceiveInternal() {
|
||||
/* Ensure we don't corrupt the queue, but this should never happen. */
|
||||
if (this->count == 0) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
uintptr_t data = this->buffer[this->offset];
|
||||
this->offset = (this->offset + 1) % this->capacity;
|
||||
this->count--;
|
||||
return data;
|
||||
}
|
||||
|
||||
uintptr_t HosMessageQueue::PeekInternal() {
|
||||
/* Ensure we don't corrupt the queue, but this should never happen. */
|
||||
if (this->count == 0) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
return this->buffer[this->offset];
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
static std::vector<u64> g_known_pids;
|
||||
static std::vector<u64> g_known_tids;
|
||||
static HosMutex g_pid_tid_mutex;
|
||||
|
||||
Result MitmQueryUtils::GetAssociatedTidForPid(u64 pid, u64 *tid) {
|
||||
Result rc = 0xCAFE;
|
||||
std::scoped_lock lk{g_pid_tid_mutex};
|
||||
for (unsigned int i = 0; i < g_known_pids.size(); i++) {
|
||||
if (g_known_pids[i] == pid) {
|
||||
*tid = g_known_tids[i];
|
||||
rc = 0x0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
void MitmQueryUtils::AssociatePidToTid(u64 pid, u64 tid) {
|
||||
std::scoped_lock lk{g_pid_tid_mutex};
|
||||
g_known_pids.push_back(pid);
|
||||
g_known_tids.push_back(tid);
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <switch/arm/atomics.h>
|
||||
#include <stratosphere/mitm/sm_mitm.h>
|
||||
|
||||
static Handle g_smMitmHandle = INVALID_HANDLE;
|
||||
static u64 g_refCnt;
|
||||
|
||||
Result smMitMInitialize(void) {
|
||||
atomicIncrement64(&g_refCnt);
|
||||
|
||||
if (g_smMitmHandle != INVALID_HANDLE)
|
||||
return 0;
|
||||
|
||||
Result rc = svcConnectToNamedPort(&g_smMitmHandle, "sm:");
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 zero;
|
||||
u64 reserved[2];
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 0;
|
||||
raw->zero = 0;
|
||||
|
||||
rc = ipcDispatch(g_smMitmHandle);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
}
|
||||
|
||||
if (R_FAILED(rc))
|
||||
smExit();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void smMitMExit(void) {
|
||||
if (atomicDecrement64(&g_refCnt) == 0) {
|
||||
svcCloseHandle(g_smMitmHandle);
|
||||
g_smMitmHandle = INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
Result smMitMGetService(Service* service_out, const char *name_str)
|
||||
{
|
||||
u64 name = smEncodeName(name_str);
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 service_name;
|
||||
u64 reserved[2];
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 1;
|
||||
raw->service_name = name;
|
||||
|
||||
Result rc = ipcDispatch(g_smMitmHandle);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
service_out->type = ServiceType_Normal;
|
||||
service_out->handle = r.Handles[0];
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
Result smMitMInstall(Handle *handle_out, Handle *query_out, const char *name) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 service_name;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 65000;
|
||||
raw->service_name = smEncodeName(name);
|
||||
|
||||
Result rc = ipcDispatch(g_smMitmHandle);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*handle_out = r.Handles[0];
|
||||
*query_out = r.Handles[1];
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result smMitMUninstall(const char *name) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 service_name;
|
||||
u64 reserved;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 65001;
|
||||
raw->service_name = smEncodeName(name);
|
||||
|
||||
Result rc = ipcDispatch(g_smMitmHandle);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <switch/arm/atomics.h>
|
||||
#include <stratosphere/services/smm_ams.h>
|
||||
|
||||
static Service g_smManagerAmsSrv;
|
||||
static u64 g_smManagerAmsRefcnt;
|
||||
|
||||
Result smManagerAmsInitialize(void) {
|
||||
atomicIncrement64(&g_smManagerAmsRefcnt);
|
||||
|
||||
if (serviceIsActive(&g_smManagerAmsSrv))
|
||||
return 0;
|
||||
|
||||
return smGetService(&g_smManagerAmsSrv, "sm:m");
|
||||
}
|
||||
|
||||
void smManagerAmsExit(void) {
|
||||
if (atomicDecrement64(&g_smManagerAmsRefcnt) == 0)
|
||||
serviceClose(&g_smManagerAmsSrv);
|
||||
}
|
||||
|
||||
Result smManagerAmsEndInitialDefers(void) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(&g_smManagerAmsSrv, &c, sizeof(*raw));
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 65000;
|
||||
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_smManagerAmsSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp;
|
||||
|
||||
serviceIpcParse(&g_smManagerAmsSrv, &r, sizeof(*resp));
|
||||
resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue