ams_mitm: Implement emummc Nintendo folder redirection
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "os_waitable_holder_of_inter_process_event.hpp"
|
||||
#include "os_waitable_holder_of_interrupt_event.hpp"
|
||||
#include "os_waitable_holder_of_thread.hpp"
|
||||
#include "os_waitable_holder_of_semaphore.hpp"
|
||||
#include "os_waitable_holder_of_message_queue.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
@@ -30,6 +31,7 @@ namespace ams::os::impl {
|
||||
TYPED_STORAGE(WaitableHolderOfInterProcessEvent) holder_of_inter_process_event_storage;
|
||||
TYPED_STORAGE(WaitableHolderOfInterruptEvent) holder_of_interrupt_event_storage;
|
||||
TYPED_STORAGE(WaitableHolderOfThread) holder_of_thread_storage;
|
||||
TYPED_STORAGE(WaitableHolderOfSemaphore) holder_of_semaphore_storage;
|
||||
TYPED_STORAGE(WaitableHolderOfMessageQueueForNotFull) holder_of_mq_for_not_full_storage;
|
||||
TYPED_STORAGE(WaitableHolderOfMessageQueueForNotEmpty) holder_of_mq_for_not_empty_storage;
|
||||
};
|
||||
@@ -43,6 +45,7 @@ namespace ams::os::impl {
|
||||
CHECK_HOLDER(WaitableHolderOfInterProcessEvent);
|
||||
CHECK_HOLDER(WaitableHolderOfInterruptEvent);
|
||||
CHECK_HOLDER(WaitableHolderOfThread);
|
||||
CHECK_HOLDER(WaitableHolderOfSemaphore);
|
||||
CHECK_HOLDER(WaitableHolderOfMessageQueueForNotFull);
|
||||
CHECK_HOLDER(WaitableHolderOfMessageQueueForNotEmpty);
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include "os_waitable_holder_base.hpp"
|
||||
#include "os_waitable_object_list.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class WaitableHolderOfSemaphore : public WaitableHolderOfUserObject {
|
||||
private:
|
||||
Semaphore *semaphore;
|
||||
private:
|
||||
TriBool IsSignaledImpl() const {
|
||||
return this->semaphore->count > 0 ? TriBool::True : TriBool::False;
|
||||
}
|
||||
public:
|
||||
explicit WaitableHolderOfSemaphore(Semaphore *s) : semaphore(s) { /* ... */ }
|
||||
|
||||
/* IsSignaled, Link, Unlink implemented. */
|
||||
virtual TriBool IsSignaled() const override {
|
||||
std::scoped_lock lk(this->semaphore->mutex);
|
||||
return this->IsSignaledImpl();
|
||||
}
|
||||
|
||||
virtual TriBool LinkToObjectList() override {
|
||||
std::scoped_lock lk(this->semaphore->mutex);
|
||||
|
||||
GetReference(this->semaphore->waitlist).LinkWaitableHolder(*this);
|
||||
return this->IsSignaledImpl();
|
||||
}
|
||||
|
||||
virtual void UnlinkFromObjectList() override {
|
||||
std::scoped_lock lk(this->semaphore->mutex);
|
||||
|
||||
GetReference(this->semaphore->waitlist).UnlinkWaitableHolder(*this);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
85
stratosphere/libstratosphere/source/os/os_semaphore.cpp
Normal file
85
stratosphere/libstratosphere/source/os/os_semaphore.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 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 "impl/os_waitable_object_list.hpp"
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
Semaphore::Semaphore(int c, int mc) : count(c), max_count(mc) {
|
||||
new (GetPointer(this->waitlist)) impl::WaitableObjectList();
|
||||
}
|
||||
|
||||
Semaphore::~Semaphore() {
|
||||
GetReference(this->waitlist).~WaitableObjectList();
|
||||
}
|
||||
|
||||
void Semaphore::Acquire() {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
while (this->count == 0) {
|
||||
this->condvar.Wait(&this->mutex);
|
||||
}
|
||||
|
||||
this->count--;
|
||||
}
|
||||
|
||||
bool Semaphore::TryAcquire() {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
if (this->count == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Semaphore::TimedAcquire(u64 timeout) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
TimeoutHelper timeout_helper(timeout);
|
||||
|
||||
while (this->count == 0) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->condvar.TimedWait(&this->mutex, timeout_helper.NsUntilTimeout());
|
||||
}
|
||||
|
||||
this->count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Semaphore::Release() {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
AMS_ASSERT(this->count + 1 <= this->max_count);
|
||||
this->count++;
|
||||
|
||||
this->condvar.Signal();
|
||||
GetReference(this->waitlist).SignalAllThreads();
|
||||
}
|
||||
|
||||
void Semaphore::Release(int count) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
|
||||
AMS_ASSERT(this->count + count <= this->max_count);
|
||||
this->count += count;
|
||||
|
||||
this->condvar.Broadcast();
|
||||
GetReference(this->waitlist).SignalAllThreads();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,6 +70,14 @@ namespace ams::os {
|
||||
this->user_data = 0;
|
||||
}
|
||||
|
||||
WaitableHolder::WaitableHolder(Semaphore *semaphore) {
|
||||
/* Initialize appropriate holder. */
|
||||
new (GetPointer(this->impl_storage)) impl::WaitableHolderOfSemaphore(semaphore);
|
||||
|
||||
/* Set user-data. */
|
||||
this->user_data = 0;
|
||||
}
|
||||
|
||||
WaitableHolder::WaitableHolder(MessageQueue *message_queue, MessageQueueWaitKind wait_kind) {
|
||||
/* Initialize appropriate holder. */
|
||||
switch (wait_kind) {
|
||||
|
||||
Reference in New Issue
Block a user