Kernel: pass Kernel ref in Event

master
Weiyi Wang 2018-10-11 15:48:16 +07:00
parent 734be98966
commit eec11a94cb
33 changed files with 104 additions and 80 deletions

@ -7,16 +7,16 @@
#include <vector>
#include "common/assert.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/thread.h"
namespace Kernel {
Event::Event() {}
Event::Event(KernelSystem& kernel) {}
Event::~Event() {}
SharedPtr<Event> Event::Create(ResetType reset_type, std::string name) {
SharedPtr<Event> evt(new Event);
SharedPtr<Event> KernelSystem::CreateEvent(ResetType reset_type, std::string name) {
SharedPtr<Event> evt(new Event(*this));
evt->signaled = false;
evt->reset_type = reset_type;

@ -12,13 +12,6 @@ namespace Kernel {
class Event final : public WaitObject {
public:
/**
* Creates an event
* @param reset_type ResetType describing how to create event
* @param name Optional name of event
*/
static SharedPtr<Event> Create(ResetType reset_type, std::string name = "Unknown");
std::string GetTypeName() const override {
return "Event";
}
@ -47,13 +40,15 @@ public:
void Clear();
private:
Event();
explicit Event(KernelSystem& kernel);
~Event() override;
ResetType reset_type; ///< Current ResetType
bool signaled; ///< Whether the event has already been signaled
std::string name; ///< Name of event (optional)
friend class KernelSystem;
};
} // namespace Kernel

@ -6,6 +6,7 @@
#include <vector>
#include "common/assert.h"
#include "common/common_types.h"
#include "core/core.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/hle_ipc.h"
@ -55,7 +56,8 @@ SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
cmd_buff.size() * sizeof(u32));
};
auto event = Kernel::Event::Create(Kernel::ResetType::OneShot, "HLE Pause Event: " + reason);
auto event = Core::System::GetInstance().Kernel().CreateEvent(Kernel::ResetType::OneShot,
"HLE Pause Event: " + reason);
thread->status = ThreadStatus::WaitHleEvent;
thread->wait_objects = {event};
event->AddWaitingThread(thread);

@ -11,6 +11,13 @@
namespace Kernel {
class AddressArbiter;
class Event;
enum class ResetType {
OneShot,
Sticky,
Pulse,
};
template <typename T>
using SharedPtr = boost::intrusive_ptr<T>;
@ -27,6 +34,13 @@ public:
* @returns The created AddressArbiter.
*/
SharedPtr<AddressArbiter> CreateAddressArbiter(std::string name = "Unknown");
/**
* Creates an event
* @param reset_type ResetType describing how to create event
* @param name Optional name of event
*/
SharedPtr<Event> CreateEvent(ResetType reset_type, std::string name = "Unknown");
};
} // namespace Kernel

@ -35,12 +35,6 @@ enum {
DEFAULT_STACK_SIZE = 0x4000,
};
enum class ResetType {
OneShot,
Sticky,
Pulse,
};
class Object : NonCopyable {
public:
virtual ~Object();

@ -942,8 +942,8 @@ static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, u32
/// Create an event
static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) {
SharedPtr<Event> evt = Event::Create(static_cast<ResetType>(reset_type),
fmt::format("event-{:08x}", Core::CPU().GetReg(14)));
SharedPtr<Event> evt = Core::System::GetInstance().Kernel().CreateEvent(
static_cast<ResetType>(reset_type), fmt::format("event-{:08x}", Core::CPU().GetReg(14)));
CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(evt)));
LOG_TRACE(Kernel_SVC, "called reset_type=0x{:08X} : created handle=0x{:08X}", reset_type,

@ -572,9 +572,9 @@ AppletManager::AppletManager(Core::System& system) : system(system) {
slot_data.registered = false;
slot_data.loaded = false;
slot_data.notification_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Notification");
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "APT:Notification");
slot_data.parameter_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Parameter");
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "APT:Parameter");
}
HLE::Applets::Init();
}

@ -903,15 +903,16 @@ void Module::Interface::GetNsDataNewFlagPrivileged(Kernel::HLERequestContext& ct
Module::Interface::Interface(std::shared_ptr<Module> boss, const char* name, u32 max_session)
: ServiceFramework(name, max_session), boss(std::move(boss)) {}
Module::Module() {
Module::Module(Core::System& system) {
using namespace Kernel;
// TODO: verify ResetType
task_finish_event = Event::Create(Kernel::ResetType::OneShot, "BOSS::task_finish_event");
task_finish_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "BOSS::task_finish_event");
}
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
auto boss = std::make_shared<Module>();
auto boss = std::make_shared<Module>(system);
std::make_shared<BOSS_P>(boss)->InstallAsService(service_manager);
std::make_shared<BOSS_U>(boss)->InstallAsService(service_manager);
}

@ -15,7 +15,7 @@ namespace Service::BOSS {
class Module final {
public:
Module();
explicit Module(Core::System& system);
~Module() = default;
class Interface : public ServiceFramework<Interface> {

@ -1019,14 +1019,15 @@ void Module::Interface::DriverFinalize(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_CAM, "called");
}
Module::Module() {
Module::Module(Core::System& system) {
using namespace Kernel;
for (PortConfig& port : ports) {
port.completion_event = Event::Create(ResetType::Sticky, "CAM::completion_event");
port.completion_event =
system.Kernel().CreateEvent(ResetType::Sticky, "CAM::completion_event");
port.buffer_error_interrupt_event =
Event::Create(ResetType::OneShot, "CAM::buffer_error_interrupt_event");
system.Kernel().CreateEvent(ResetType::OneShot, "CAM::buffer_error_interrupt_event");
port.vsync_interrupt_event =
Event::Create(ResetType::OneShot, "CAM::vsync_interrupt_event");
system.Kernel().CreateEvent(ResetType::OneShot, "CAM::vsync_interrupt_event");
}
completion_event_callback = CoreTiming::RegisterEvent(
"CAM::CompletionEventCallBack",
@ -1061,7 +1062,7 @@ std::shared_ptr<Module> GetModule(Core::System& system) {
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
auto cam = std::make_shared<Module>();
auto cam = std::make_shared<Module>(system);
std::make_shared<CAM_U>(cam)->InstallAsService(service_manager);
std::make_shared<CAM_S>(cam)->InstallAsService(service_manager);

@ -241,7 +241,7 @@ static_assert(sizeof(PackageParameterWithContextDetail) == 28,
class Module final {
public:
Module();
explicit Module(Core::System& system);
~Module();
void ReloadCameraDevices();

@ -1351,10 +1351,11 @@ Module::SessionData::~SessionData() {
Module::Interface::Interface(std::shared_ptr<Module> cecd, const char* name, u32 max_session)
: ServiceFramework(name, max_session), cecd(std::move(cecd)) {}
Module::Module() {
Module::Module(Core::System& system) {
using namespace Kernel;
cecinfo_event = Event::Create(Kernel::ResetType::OneShot, "CECD::cecinfo_event");
change_state_event = Event::Create(Kernel::ResetType::OneShot, "CECD::change_state_event");
cecinfo_event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::cecinfo_event");
change_state_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::change_state_event");
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
@ -1433,7 +1434,7 @@ Module::~Module() = default;
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
auto cecd = std::make_shared<Module>();
auto cecd = std::make_shared<Module>(system);
std::make_shared<CECD_NDM>(cecd)->InstallAsService(service_manager);
std::make_shared<CECD_S>(cecd)->InstallAsService(service_manager);
std::make_shared<CECD_U>(cecd)->InstallAsService(service_manager);

@ -23,7 +23,7 @@ namespace Service::CECD {
class Module final {
public:
Module();
explicit Module(Core::System& system);
~Module();
enum class CecCommand : u32 {

@ -350,7 +350,7 @@ bool DSP_DSP::HasTooManyEventsRegistered() const {
return number >= max_number_of_interrupt_events;
}
DSP_DSP::DSP_DSP() : ServiceFramework("dsp::DSP", DefaultMaxSessions) {
DSP_DSP::DSP_DSP(Core::System& system) : ServiceFramework("dsp::DSP", DefaultMaxSessions) {
static const FunctionInfo functions[] = {
// clang-format off
{0x00010040, &DSP_DSP::RecvData, "RecvData"},
@ -391,7 +391,8 @@ DSP_DSP::DSP_DSP() : ServiceFramework("dsp::DSP", DefaultMaxSessions) {
RegisterHandlers(functions);
semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event");
semaphore_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event");
}
DSP_DSP::~DSP_DSP() {
@ -401,7 +402,7 @@ DSP_DSP::~DSP_DSP() {
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
auto dsp = std::make_shared<DSP_DSP>();
auto dsp = std::make_shared<DSP_DSP>(system);
dsp->InstallAsService(service_manager);
Core::DSP().SetServiceToInterrupt(std::move(dsp));
}

@ -17,7 +17,7 @@ namespace Service::DSP {
class DSP_DSP final : public ServiceFramework<DSP_DSP> {
public:
DSP_DSP();
explicit DSP_DSP(Core::System& system);
~DSP_DSP();
/// There are three types of interrupts

@ -364,11 +364,11 @@ Module::Module(Core::System& system) : system(system) {
0, MemoryRegion::BASE, "HID:SharedMemory");
// Create event handles
event_pad_or_touch_1 = Event::Create(ResetType::OneShot, "HID:EventPadOrTouch1");
event_pad_or_touch_2 = Event::Create(ResetType::OneShot, "HID:EventPadOrTouch2");
event_accelerometer = Event::Create(ResetType::OneShot, "HID:EventAccelerometer");
event_gyroscope = Event::Create(ResetType::OneShot, "HID:EventGyroscope");
event_debug_pad = Event::Create(ResetType::OneShot, "HID:EventDebugPad");
event_pad_or_touch_1 = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventPadOrTouch1");
event_pad_or_touch_2 = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventPadOrTouch2");
event_accelerometer = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventAccelerometer");
event_gyroscope = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventGyroscope");
event_debug_pad = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventDebugPad");
// Register update callbacks
pad_update_event =

@ -16,10 +16,10 @@ void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
std::make_shared<IR_U>()->InstallAsService(service_manager);
auto ir_user = std::make_shared<IR_USER>();
auto ir_user = std::make_shared<IR_USER>(system);
ir_user->InstallAsService(service_manager);
auto ir_rst = std::make_shared<IR_RST>();
auto ir_rst = std::make_shared<IR_RST>(system);
ir_rst->InstallAsService(service_manager);
}

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
@ -144,14 +145,14 @@ void IR_RST::Shutdown(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_IR, "called");
}
IR_RST::IR_RST() : ServiceFramework("ir:rst", 1) {
IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1) {
using namespace Kernel;
// Note: these two kernel objects are even available before Initialize service function is
// called.
shared_memory =
SharedMemory::Create(nullptr, 0x1000, MemoryPermission::ReadWrite, MemoryPermission::Read,
0, MemoryRegion::BASE, "IRRST:SharedMemory");
update_event = Event::Create(ResetType::OneShot, "IRRST:UpdateEvent");
update_event = system.Kernel().CreateEvent(ResetType::OneShot, "IRRST:UpdateEvent");
update_callback_id =
CoreTiming::RegisterEvent("IRRST:UpdateCallBack", [this](u64 userdata, s64 cycles_late) {

@ -39,7 +39,7 @@ union PadState {
/// Interface to "ir:rst" service
class IR_RST final : public ServiceFramework<IR_RST> {
public:
IR_RST();
explicit IR_RST(Core::System& system);
~IR_RST();
void ReloadInputDevices();

@ -6,6 +6,7 @@
#include <boost/crc.hpp>
#include "common/string_util.h"
#include "common/swap.h"
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/shared_memory.h"
@ -380,7 +381,7 @@ void IR_USER::ReleaseReceivedData(Kernel::HLERequestContext& ctx) {
LOG_TRACE(Service_IR, "called, count={}", count);
}
IR_USER::IR_USER() : ServiceFramework("ir:USER", 1) {
IR_USER::IR_USER(Core::System& system) : ServiceFramework("ir:USER", 1) {
const FunctionInfo functions[] = {
{0x00010182, nullptr, "InitializeIrNop"},
{0x00020000, &IR_USER::FinalizeIrNop, "FinalizeIrNop"},
@ -413,9 +414,9 @@ IR_USER::IR_USER() : ServiceFramework("ir:USER", 1) {
using namespace Kernel;
conn_status_event = Event::Create(ResetType::OneShot, "IR:ConnectionStatusEvent");
send_event = Event::Create(ResetType::OneShot, "IR:SendEvent");
receive_event = Event::Create(ResetType::OneShot, "IR:ReceiveEvent");
conn_status_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ConnectionStatusEvent");
send_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:SendEvent");
receive_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ReceiveEvent");
extra_hid =
std::make_unique<ExtraHID>([this](const std::vector<u8>& data) { PutToReceive(data); });

@ -55,7 +55,7 @@ private:
/// Interface to "ir:USER" service
class IR_USER final : public ServiceFramework<IR_USER> {
public:
IR_USER();
explicit IR_USER(Core::System& system);
~IR_USER();
void ReloadInputDevices();

@ -29,6 +29,11 @@ enum class SampleRate : u8 {
};
struct MIC_U::Impl {
explicit Impl(Core::System& system) {
buffer_full_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "MIC_U::buffer_full_event");
}
void MapSharedMem(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx, 0x01, 1, 2};
const u32 size = rp.Pop<u32>();
@ -187,8 +192,7 @@ struct MIC_U::Impl {
}
u32 client_version = 0;
Kernel::SharedPtr<Kernel::Event> buffer_full_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "MIC_U::buffer_full_event");
Kernel::SharedPtr<Kernel::Event> buffer_full_event;
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
u8 mic_gain = 0;
bool mic_power = false;
@ -266,7 +270,8 @@ void MIC_U::SetClientVersion(Kernel::HLERequestContext& ctx) {
impl->SetClientVersion(ctx);
}
MIC_U::MIC_U() : ServiceFramework{"mic:u", 1}, impl{std::make_unique<Impl>()} {
MIC_U::MIC_U(Core::System& system)
: ServiceFramework{"mic:u", 1}, impl{std::make_unique<Impl>(system)} {
static const FunctionInfo functions[] = {
{0x00010042, &MIC_U::MapSharedMem, "MapSharedMem"},
{0x00020000, &MIC_U::UnmapSharedMem, "UnmapSharedMem"},
@ -293,7 +298,7 @@ MIC_U::~MIC_U() = default;
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
std::make_shared<MIC_U>()->InstallAsService(service_manager);
std::make_shared<MIC_U>(system)->InstallAsService(service_manager);
}
} // namespace Service::MIC

@ -16,7 +16,7 @@ namespace Service::MIC {
class MIC_U final : public ServiceFramework<MIC_U> {
public:
MIC_U();
explicit MIC_U(Core::System& system);
~MIC_U();
private:

@ -140,18 +140,18 @@ Module::Interface::Interface(std::shared_ptr<Module> nfc, const char* name, u32
Module::Interface::~Interface() = default;
Module::Module() {
Module::Module(Core::System& system) {
tag_in_range_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_in_range_event");
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "NFC::tag_in_range_event");
tag_out_of_range_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "NFC::tag_out_range_event");
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "NFC::tag_out_range_event");
}
Module::~Module() = default;
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
auto nfc = std::make_shared<Module>();
auto nfc = std::make_shared<Module>(system);
std::make_shared<NFC_M>(nfc)->InstallAsService(service_manager);
std::make_shared<NFC_U>(nfc)->InstallAsService(service_manager);
}

@ -41,7 +41,7 @@ enum class CommunicationStatus : u8 {
class Module final {
public:
Module();
explicit Module(Core::System& system);
~Module();
class Interface : public ServiceFramework<Interface> {

@ -14,7 +14,7 @@ void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
std::make_shared<NIM_AOC>()->InstallAsService(service_manager);
std::make_shared<NIM_S>()->InstallAsService(service_manager);
std::make_shared<NIM_U>()->InstallAsService(service_manager);
std::make_shared<NIM_U>(system)->InstallAsService(service_manager);
}
} // namespace Service::NIM

@ -2,13 +2,14 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
#include "core/hle/service/nim/nim_u.h"
namespace Service::NIM {
NIM_U::NIM_U() : ServiceFramework("nim:u", 2) {
NIM_U::NIM_U(Core::System& system) : ServiceFramework("nim:u", 2) {
const FunctionInfo functions[] = {
{0x00010000, nullptr, "StartSysUpdate"},
{0x00020000, nullptr, "GetUpdateDownloadProgress"},
@ -20,7 +21,7 @@ NIM_U::NIM_U() : ServiceFramework("nim:u", 2) {
};
RegisterHandlers(functions);
nim_system_update_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "NIM System Update Event");
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "NIM System Update Event");
}
NIM_U::~NIM_U() = default;

@ -6,11 +6,15 @@
#include "core/hle/service/service.h"
namespace Core {
class System;
}
namespace Service::NIM {
class NIM_U final : public ServiceFramework<NIM_U> {
public:
NIM_U();
explicit NIM_U(Core::System& system);
~NIM_U();
private:

@ -839,7 +839,7 @@ void NWM_UDS::Bind(Kernel::HLERequestContext& ctx) {
}
// Create a new event for this bind node.
auto event = Kernel::Event::Create(Kernel::ResetType::OneShot,
auto event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot,
"NWM::BindNodeEvent" + std::to_string(bind_node_id));
std::lock_guard<std::mutex> lock(connection_status_mutex);
@ -1355,7 +1355,7 @@ static void BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
beacon_broadcast_event, 0);
}
NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS") {
NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(system) {
static const FunctionInfo functions[] = {
{0x000102C2, nullptr, "Initialize (deprecated)"},
{0x00020000, nullptr, "Scrap"},
@ -1388,7 +1388,7 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS") {
{0x00220402, nullptr, "ScanOnConnection"},
};
connection_status_event =
Kernel::Event::Create(Kernel::ResetType::OneShot, "NWM::connection_status_event");
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "NWM::connection_status_event");
RegisterHandlers(functions);

@ -112,6 +112,8 @@ public:
~NWM_UDS();
private:
Core::System& system;
void UpdateNetworkAttribute(Kernel::HLERequestContext& ctx);
/**

@ -632,7 +632,7 @@ void Y2R_U::GetPackageParameter(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_Y2R, "called");
}
Y2R_U::Y2R_U() : ServiceFramework("y2r:u", 1) {
Y2R_U::Y2R_U(Core::System& system) : ServiceFramework("y2r:u", 1) {
static const FunctionInfo functions[] = {
{0x00010040, &Y2R_U::SetInputFormat, "SetInputFormat"},
{0x00020000, &Y2R_U::GetInputFormat, "GetInputFormat"},
@ -682,14 +682,14 @@ Y2R_U::Y2R_U() : ServiceFramework("y2r:u", 1) {
};
RegisterHandlers(functions);
completion_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "Y2R:Completed");
completion_event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "Y2R:Completed");
}
Y2R_U::~Y2R_U() = default;
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
std::make_shared<Y2R_U>()->InstallAsService(service_manager);
std::make_shared<Y2R_U>(system)->InstallAsService(service_manager);
}
} // namespace Service::Y2R

@ -149,7 +149,7 @@ static_assert(sizeof(ConversionParameters) == 12, "ConversionParameters struct h
class Y2R_U final : public ServiceFramework<Y2R_U> {
public:
Y2R_U();
explicit Y2R_U(Core::System& system);
~Y2R_U() override;
private:

@ -15,7 +15,8 @@
namespace Kernel {
static SharedPtr<Object> MakeObject() {
return Event::Create(ResetType::OneShot);
static Kernel::KernelSystem kernel(0);
return kernel.CreateEvent(ResetType::OneShot);
}
TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") {