Move all UID constants to a single file

Keeps them all next to each other and deduplicates a few constants,
notably the PPC UIDs. Apparently I forgot that I already added them
for SetupStreamKey.
This commit is contained in:
Léo Lam 2018-05-09 20:52:35 +02:00
parent 169e1d3368
commit e56387970a
11 changed files with 67 additions and 48 deletions

View File

@ -25,6 +25,7 @@
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/IOSC.h"
#include "Core/IOS/Uids.h"
#include "Core/IOS/VersionInfo.h"
namespace IOS
@ -55,8 +56,8 @@ constexpr std::array<DirectoryToCreate, 9> s_directories_to_create = {{
{"/shared2", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite},
{"/tmp", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite},
{"/import", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::None},
{"/meta", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite,
IOS::ES::FIRST_PPC_UID, 0x1},
{"/meta", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite, SYSMENU_UID,
SYSMENU_GID},
{"/wfs", 0, FS::Mode::ReadWrite, FS::Mode::None, FS::Mode::None, PID_UNKNOWN, PID_UNKNOWN},
}};
@ -684,8 +685,6 @@ s32 ES::DIVerify(const IOS::ES::TMDReader& tmd, const IOS::ES::TicketReader& tic
0, FS::Mode::ReadWrite, FS::Mode::None, FS::Mode::None));
}
constexpr u32 FIRST_PPC_UID = 0x1000;
ReturnCode ES::CheckStreamKeyPermissions(const u32 uid, const u8* ticket_view,
const IOS::ES::TMDReader& tmd) const
{

View File

@ -28,6 +28,7 @@
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/IOS.h"
#include "Core/IOS/IOSC.h"
#include "Core/IOS/Uids.h"
namespace IOS
{
@ -407,7 +408,7 @@ std::array<u8, 16> TicketReader::GetTitleKey(const HLE::IOSC& iosc) const
std::array<u8, 16> key;
iosc.Decrypt(common_key_handle, iv, &m_bytes[offsetof(Ticket, title_key)], 16, key.data(),
HLE::PID_ES);
PID_ES);
return key;
}
@ -495,8 +496,7 @@ SharedContentMap::SharedContentMap(std::shared_ptr<HLE::FS::FileSystem> fs) : m_
static_assert(sizeof(Entry) == 28, "SharedContentMap::Entry has the wrong size");
Entry entry;
const auto file =
fs->OpenFile(HLE::PID_KERNEL, HLE::PID_KERNEL, CONTENT_MAP_PATH, HLE::FS::Mode::Read);
const auto file = fs->OpenFile(PID_KERNEL, PID_KERNEL, CONTENT_MAP_PATH, HLE::FS::Mode::Read);
while (file && file->Read(&entry, 1))
{
m_entries.push_back(entry);
@ -560,13 +560,13 @@ bool SharedContentMap::WriteEntries() const
const std::string temp_path = "/tmp/content.map";
// Atomically write the new content map.
{
const auto file = m_fs->CreateAndOpenFile(HLE::PID_KERNEL, HLE::PID_KERNEL, temp_path,
HLE::FS::Mode::ReadWrite, HLE::FS::Mode::ReadWrite,
HLE::FS::Mode::None);
const auto file =
m_fs->CreateAndOpenFile(PID_KERNEL, PID_KERNEL, temp_path, HLE::FS::Mode::ReadWrite,
HLE::FS::Mode::ReadWrite, HLE::FS::Mode::None);
if (!file || !file->Write(m_entries.data(), m_entries.size()))
return false;
}
return m_fs->Rename(HLE::PID_KERNEL, HLE::PID_KERNEL, temp_path, CONTENT_MAP_PATH) ==
return m_fs->Rename(PID_KERNEL, PID_KERNEL, temp_path, CONTENT_MAP_PATH) ==
HLE::FS::ResultCode::Success;
}
@ -586,8 +586,7 @@ static std::pair<u32, u64> ReadUidSysEntry(const HLE::FS::FileHandle& file)
static const std::string UID_MAP_PATH = "/sys/uid.sys";
UIDSys::UIDSys(std::shared_ptr<HLE::FS::FileSystem> fs) : m_fs{fs}
{
if (const auto file =
fs->OpenFile(HLE::PID_KERNEL, HLE::PID_KERNEL, UID_MAP_PATH, HLE::FS::Mode::Read))
if (const auto file = fs->OpenFile(PID_KERNEL, PID_KERNEL, UID_MAP_PATH, HLE::FS::Mode::Read))
{
while (true)
{
@ -635,9 +634,9 @@ u32 UIDSys::GetOrInsertUIDForTitle(const u64 title_id)
const u64 swapped_title_id = Common::swap64(title_id);
const u32 swapped_uid = Common::swap32(uid);
const auto file = m_fs->CreateAndOpenFile(HLE::PID_KERNEL, HLE::PID_KERNEL, UID_MAP_PATH,
HLE::FS::Mode::ReadWrite, HLE::FS::Mode::ReadWrite,
HLE::FS::Mode::None);
const auto file =
m_fs->CreateAndOpenFile(PID_KERNEL, PID_KERNEL, UID_MAP_PATH, HLE::FS::Mode::ReadWrite,
HLE::FS::Mode::ReadWrite, HLE::FS::Mode::None);
if (!file || !file->Seek(0, HLE::FS::SeekMode::End) || !file->Write(&swapped_title_id, 1) ||
!file->Write(&swapped_uid, 1))
{

View File

@ -271,8 +271,6 @@ private:
std::shared_ptr<HLE::FS::FileSystem> m_fs;
};
constexpr u32 FIRST_PPC_UID = 0x1000;
class UIDSys final
{
public:

View File

@ -10,6 +10,7 @@
#include "Common/Logging/Log.h"
#include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/Uids.h"
namespace IOS
{

View File

@ -18,6 +18,7 @@
#include "Common/StringUtil.h"
#include "Core/IOS/ES/ES.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/Uids.h"
namespace IOS
{

View File

@ -12,6 +12,7 @@
#include "Common/MsgHandler.h"
#include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/Uids.h"
namespace IOS
{

View File

@ -20,6 +20,7 @@
#include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/Uids.h"
namespace IOS
{

View File

@ -57,30 +57,6 @@ enum IPCCommandType : u32
IPC_REPLY = 8,
};
enum ProcessId : u32
{
PID_KERNEL = 0,
PID_ES = 1,
PID_FS = 2,
PID_DI = 3,
PID_OH0 = 4,
PID_OH1 = 5,
PID_EHCI = 6,
PID_SDI = 7,
PID_USBETH = 8,
PID_NET = 9,
PID_WD = 10,
PID_WL = 11,
PID_KD = 12,
PID_NCD = 13,
PID_STM = 14,
PID_PPCBOOT = 15,
PID_SSL = 16,
PID_USB = 17,
PID_P2P = 18,
PID_UNKNOWN = 19,
};
void WriteReturnValue(s32 value, u32 address);
// HLE for the IOS kernel: IPC, device management, syscalls, and Dolphin-specific, IOS-wide calls.

View File

@ -12,6 +12,7 @@
#include "Core/HW/Memmap.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/IOS.h"
#include "Core/IOS/Uids.h"
namespace IOS
{

View File

@ -0,0 +1,41 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include "Common/CommonTypes.h"
namespace IOS
{
// IOS processes have their UID and GID set to their (hardcoded) PID.
enum IOSUid : u32
{
PID_KERNEL = 0,
PID_ES = 1,
PID_FS = 2,
PID_DI = 3,
PID_OH0 = 4,
PID_OH1 = 5,
PID_EHCI = 6,
PID_SDI = 7,
PID_USBETH = 8,
PID_NET = 9,
PID_WD = 10,
PID_WL = 11,
PID_KD = 12,
PID_NCD = 13,
PID_STM = 14,
PID_PPCBOOT = 15,
PID_SSL = 16,
PID_USB = 17,
PID_P2P = 18,
PID_UNKNOWN = 19,
};
constexpr u32 FIRST_PPC_UID = 0x1000;
constexpr u32 SYSMENU_UID = FIRST_PPC_UID;
constexpr u16 SYSMENU_GID = 1;
} // namespace IOS

View File

@ -15,6 +15,7 @@
#include "Common/Logging/Log.h"
#include "Common/Swap.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/Uids.h"
constexpr size_t SYSCONF_SIZE = 0x4000;
@ -196,17 +197,17 @@ bool SysConf::Save() const
// Write the new data.
const std::string temp_file = "/tmp/SYSCONF";
constexpr u32 SYSMENU_UID = 0x1000;
constexpr u16 SYSMENU_GID = 1;
constexpr auto rw_mode = IOS::HLE::FS::Mode::ReadWrite;
{
m_fs->CreateFile(SYSMENU_UID, SYSMENU_GID, temp_file, 0, rw_mode, rw_mode, rw_mode);
auto file = m_fs->OpenFile(SYSMENU_UID, SYSMENU_GID, temp_file, IOS::HLE::FS::Mode::Write);
auto file = m_fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, temp_file, rw_mode,
rw_mode, rw_mode);
if (!file || !file->Write(buffer.data(), buffer.size()))
return false;
}
m_fs->CreateDirectory(SYSMENU_UID, SYSMENU_GID, "/shared2/sys", 0, rw_mode, rw_mode, rw_mode);
const auto result = m_fs->Rename(SYSMENU_UID, SYSMENU_GID, temp_file, "/shared2/sys/SYSCONF");
m_fs->CreateDirectory(IOS::SYSMENU_UID, IOS::SYSMENU_GID, "/shared2/sys", 0, rw_mode, rw_mode,
rw_mode);
const auto result =
m_fs->Rename(IOS::SYSMENU_UID, IOS::SYSMENU_GID, temp_file, "/shared2/sys/SYSCONF");
return result == IOS::HLE::FS::ResultCode::Success;
}