2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 22:43:11 -04:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 13:54:46 -05:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2016-10-22 15:03:07 +02:00
|
|
|
#include <cstddef>
|
2014-02-17 05:18:15 -05:00
|
|
|
#include <string>
|
2015-05-08 17:28:03 -04:00
|
|
|
#include <vector>
|
2014-02-17 05:18:15 -05:00
|
|
|
|
|
|
|
|
#include "Common/ChunkFile.h"
|
2016-10-22 15:03:07 +02:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
#include "Common/Logging/Log.h"
|
2017-01-18 13:50:28 +01:00
|
|
|
#include "Core/IOS/IPC.h"
|
2010-09-02 04:17:23 +00:00
|
|
|
|
2017-01-17 15:01:30 -05:00
|
|
|
namespace IOS
|
|
|
|
|
{
|
|
|
|
|
namespace HLE
|
|
|
|
|
{
|
2017-01-19 19:07:56 +01:00
|
|
|
enum ReturnCode : s32
|
2016-12-09 20:29:12 +01:00
|
|
|
{
|
2017-03-28 19:43:47 +02:00
|
|
|
IPC_SUCCESS = 0, // Success
|
|
|
|
|
IPC_EACCES = -1, // Permission denied
|
|
|
|
|
IPC_EEXIST = -2, // File exists
|
|
|
|
|
IPC_EINVAL = -4, // Invalid argument or fd
|
|
|
|
|
IPC_ENOENT = -6, // File not found
|
|
|
|
|
IPC_EQUEUEFULL = -8, // Queue full
|
|
|
|
|
IPC_EIO = -12, // ECC error
|
|
|
|
|
IPC_ENOMEM = -22, // Alloc failed during request
|
|
|
|
|
FS_EINVAL = -101, // Invalid path
|
|
|
|
|
FS_EACCESS = -102, // Permission denied
|
|
|
|
|
FS_ECORRUPT = -103, // Corrupted NAND
|
|
|
|
|
FS_EEXIST = -105, // File exists
|
|
|
|
|
FS_ENOENT = -106, // No such file or directory
|
|
|
|
|
FS_ENFILE = -107, // Too many fds open
|
|
|
|
|
FS_EFBIG = -108, // Max block count reached?
|
|
|
|
|
FS_EFDEXHAUSTED = -109, // Too many fds open
|
|
|
|
|
FS_ENAMELEN = -110, // Pathname is too long
|
|
|
|
|
FS_EFDOPEN = -111, // FD is already open
|
|
|
|
|
FS_EIO = -114, // ECC error
|
|
|
|
|
FS_ENOTEMPTY = -115, // Directory not empty
|
|
|
|
|
FS_EDIRDEPTH = -116, // Max directory depth exceeded
|
|
|
|
|
FS_EBUSY = -118, // Resource busy
|
|
|
|
|
ES_SHORT_READ = -1009, // Short read
|
|
|
|
|
ES_EIO = -1010, // Write failure
|
|
|
|
|
ES_FD_EXHAUSTED = -1016, // Max of 3 ES handles exceeded
|
|
|
|
|
ES_EINVAL = -1017, // Invalid argument
|
|
|
|
|
ES_DEVICE_ID_MISMATCH = -1018,
|
|
|
|
|
ES_HASH_MISMATCH = -1022, // Decrypted content hash doesn't match with the hash from the TMD
|
|
|
|
|
ES_ENOMEM = -1024, // Alloc failed during request
|
|
|
|
|
ES_EACCES = -1026, // Incorrect access rights (according to TMD)
|
|
|
|
|
ES_INVALID_TMD_SIGNATURE_TYPE = -1027,
|
|
|
|
|
ES_NO_TICKET = -1028,
|
|
|
|
|
ES_INVALID_TICKET = -1029,
|
|
|
|
|
IOSC_EACCES = -2000,
|
|
|
|
|
IOSC_EEXIST = -2001,
|
|
|
|
|
IOSC_EINVAL = -2002,
|
|
|
|
|
IOSC_EMAX = -2003,
|
|
|
|
|
IOSC_ENOENT = -2004,
|
|
|
|
|
IOSC_INVALID_OBJTYPE = -2005,
|
|
|
|
|
IOSC_INVALID_RNG = -2006,
|
|
|
|
|
IOSC_INVALID_FLAG = -2007,
|
|
|
|
|
IOSC_INVALID_FORMAT = -2008,
|
|
|
|
|
IOSC_INVALID_VERSION = -2009,
|
|
|
|
|
IOSC_INVALID_SIGNER = -2010,
|
|
|
|
|
IOSC_FAIL_CHECKVALUE = -2011,
|
|
|
|
|
IOSC_FAIL_INTERNAL = -2012,
|
|
|
|
|
IOSC_FAIL_ALLOC = -2013,
|
|
|
|
|
IOSC_INVALID_SIZE = -2014,
|
|
|
|
|
IOSC_INVALID_ADDR = -2015,
|
|
|
|
|
IOSC_INVALID_ALIGN = -2016,
|
|
|
|
|
USB_ECANCELED = -7022, // USB OH0 insertion hook cancelled
|
2016-12-09 20:29:12 +01:00
|
|
|
};
|
2010-09-02 04:17:23 +00:00
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
struct Request
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
u32 address = 0;
|
|
|
|
|
IPCCommandType command = IPC_CMD_OPEN;
|
|
|
|
|
u32 fd = 0;
|
2017-01-19 19:07:56 +01:00
|
|
|
explicit Request(u32 address);
|
|
|
|
|
virtual ~Request() = default;
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
};
|
|
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
enum OpenMode : s32
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
IOS_OPEN_READ = 1,
|
|
|
|
|
IOS_OPEN_WRITE = 2,
|
|
|
|
|
IOS_OPEN_RW = (IOS_OPEN_READ | IOS_OPEN_WRITE)
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
struct OpenRequest final : Request
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
std::string path;
|
2017-01-19 19:07:56 +01:00
|
|
|
OpenMode flags = IOS_OPEN_READ;
|
2017-04-24 23:48:05 +02:00
|
|
|
// The UID and GID are not part of the IPC request sent from the PPC to the Starlet,
|
|
|
|
|
// but they are set after they reach IOS and are dispatched to the appropriate module.
|
|
|
|
|
u32 uid = 0;
|
|
|
|
|
u16 gid = 0;
|
2017-01-19 19:07:56 +01:00
|
|
|
explicit OpenRequest(u32 address);
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
};
|
|
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
struct ReadWriteRequest final : Request
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
u32 buffer = 0;
|
|
|
|
|
u32 size = 0;
|
2017-01-19 19:07:56 +01:00
|
|
|
explicit ReadWriteRequest(u32 address);
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
};
|
|
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
struct SeekRequest final : Request
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
enum SeekMode
|
|
|
|
|
{
|
|
|
|
|
IOS_SEEK_SET = 0,
|
|
|
|
|
IOS_SEEK_CUR = 1,
|
|
|
|
|
IOS_SEEK_END = 2,
|
|
|
|
|
};
|
|
|
|
|
u32 offset = 0;
|
|
|
|
|
SeekMode mode = IOS_SEEK_SET;
|
2017-01-19 19:07:56 +01:00
|
|
|
explicit SeekRequest(u32 address);
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
};
|
|
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
struct IOCtlRequest final : Request
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
u32 request = 0;
|
|
|
|
|
u32 buffer_in = 0;
|
|
|
|
|
u32 buffer_in_size = 0;
|
|
|
|
|
// Contrary to the name, the output buffer can also be used for input.
|
|
|
|
|
u32 buffer_out = 0;
|
|
|
|
|
u32 buffer_out_size = 0;
|
2017-01-19 19:07:56 +01:00
|
|
|
explicit IOCtlRequest(u32 address);
|
2017-01-18 20:38:44 +01:00
|
|
|
void Log(const std::string& description, LogTypes::LOG_TYPE type = LogTypes::IOS,
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
LogTypes::LOG_LEVELS level = LogTypes::LINFO) const;
|
2017-01-18 20:38:44 +01:00
|
|
|
void Dump(const std::string& description, LogTypes::LOG_TYPE type = LogTypes::IOS,
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
LogTypes::LOG_LEVELS level = LogTypes::LINFO) const;
|
2017-01-18 20:38:44 +01:00
|
|
|
void DumpUnknown(const std::string& description, LogTypes::LOG_TYPE type = LogTypes::IOS,
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
LogTypes::LOG_LEVELS level = LogTypes::LERROR) const;
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-19 19:07:56 +01:00
|
|
|
struct IOCtlVRequest final : Request
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
{
|
|
|
|
|
struct IOVector
|
|
|
|
|
{
|
|
|
|
|
u32 address = 0;
|
|
|
|
|
u32 size = 0;
|
|
|
|
|
};
|
|
|
|
|
u32 request = 0;
|
|
|
|
|
// In vectors are *mostly* used for input buffers. Sometimes they are also used as
|
|
|
|
|
// output buffers (notably in the network code).
|
|
|
|
|
// IO vectors are *mostly* used for output buffers. However, as indicated in the name,
|
|
|
|
|
// they're also used as input buffers.
|
|
|
|
|
// So both of them are technically IO vectors. But we're keeping them separated because
|
|
|
|
|
// merging them into a single std::vector would make using the first out vector more complicated.
|
|
|
|
|
std::vector<IOVector> in_vectors;
|
|
|
|
|
std::vector<IOVector> io_vectors;
|
2017-01-19 19:07:56 +01:00
|
|
|
explicit IOCtlVRequest(u32 address);
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
bool HasInputVectorWithAddress(u32 vector_address) const;
|
2016-11-13 14:23:09 +01:00
|
|
|
bool HasNumberOfValidVectors(size_t in_count, size_t io_count) const;
|
2017-01-18 20:38:44 +01:00
|
|
|
void Dump(const std::string& description, LogTypes::LOG_TYPE type = LogTypes::IOS,
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
LogTypes::LOG_LEVELS level = LogTypes::LINFO) const;
|
2017-01-18 20:38:44 +01:00
|
|
|
void DumpUnknown(const std::string& description, LogTypes::LOG_TYPE type = LogTypes::IOS,
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
LogTypes::LOG_LEVELS level = LogTypes::LERROR) const;
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-18 20:27:51 +01:00
|
|
|
namespace Device
|
|
|
|
|
{
|
|
|
|
|
class Device
|
2008-12-08 04:46:09 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2016-12-28 19:26:27 +01:00
|
|
|
enum class DeviceType : u32
|
|
|
|
|
{
|
|
|
|
|
Static, // Devices which appear in s_device_map.
|
|
|
|
|
FileIO, // FileIO devices which are created dynamically.
|
2016-11-13 14:23:09 +01:00
|
|
|
OH0, // OH0 child devices which are created dynamically.
|
2016-12-28 19:26:27 +01:00
|
|
|
};
|
|
|
|
|
|
2017-01-18 20:27:51 +01:00
|
|
|
Device(u32 device_id, const std::string& device_name, DeviceType type = DeviceType::Static);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-01-18 20:27:51 +01:00
|
|
|
virtual ~Device() = default;
|
2016-06-24 10:43:46 +02:00
|
|
|
// Release any resources which might interfere with savestating.
|
|
|
|
|
virtual void PrepareForState(PointerWrap::Mode mode) {}
|
2016-10-22 15:03:07 +02:00
|
|
|
virtual void DoState(PointerWrap& p);
|
2016-06-24 10:43:46 +02:00
|
|
|
void DoStateShared(PointerWrap& p);
|
|
|
|
|
|
2016-12-03 22:53:47 +01:00
|
|
|
const std::string& GetDeviceName() const { return m_name; }
|
|
|
|
|
u32 GetDeviceID() const { return m_device_id; }
|
2017-01-18 20:27:51 +01:00
|
|
|
// Replies to Open and Close requests are sent by the IPC request handler (HandleCommand),
|
|
|
|
|
// not by the devices themselves.
|
2017-01-19 19:07:56 +01:00
|
|
|
virtual ReturnCode Open(const OpenRequest& request);
|
IOS HLE: Add resource request structs
This adds well-defined structs that are responsible for parsing
resource requests, instead of duplicating the logic and offsets all
over IOS HLE. Command handler functions are now passed parsed requests
instead of a command address.
This may not seem like a very important change, but it removes the
need to remember all of the struct offsets or copy/paste existing
struct request variables. It also prevents nasty bugs which have
occurred in the past, such as parsing an ioctl as if it were an ioctlv
(that's way too easy to do if you pass command addresses directly);
or writing something to 0x0, which can easily happen by mistake with
a close handler that can be called with invalid command addresses.
Bonus changes:
- The return code is not an obscure Memory::Write_U32 anymore, but an
explicit, more obvious SetReturnValue() call. (Which correctly takes
a s32 instead of a u32, since return codes are signed.)
- Open handlers are now only responsible for returning an IOS ret code,
and Close handlers don't return anything and don't have to worry
about checking whether the request is a real one anymore.
- DumpAsync was moved to the ioctlv request struct, because it did
not really make sense to make it part of the IOS device and it only
works for ioctlvs.
All current usages have been removed; they will be readded in a
later commit.
As of this commit, nothing uses the structs yet. Usages will be
migrated progressively.
2017-01-14 22:09:09 +01:00
|
|
|
virtual void Close();
|
2017-01-19 19:07:56 +01:00
|
|
|
virtual IPCCommandResult Seek(const SeekRequest& seek) { return Unsupported(seek); }
|
|
|
|
|
virtual IPCCommandResult Read(const ReadWriteRequest& read) { return Unsupported(read); }
|
|
|
|
|
virtual IPCCommandResult Write(const ReadWriteRequest& write) { return Unsupported(write); }
|
|
|
|
|
virtual IPCCommandResult IOCtl(const IOCtlRequest& ioctl) { return Unsupported(ioctl); }
|
|
|
|
|
virtual IPCCommandResult IOCtlV(const IOCtlVRequest& ioctlv) { return Unsupported(ioctlv); }
|
2017-01-11 13:43:29 +01:00
|
|
|
virtual void Update() {}
|
2017-01-21 19:08:17 +01:00
|
|
|
virtual void UpdateWantDeterminism(bool new_want_determinism) {}
|
2016-12-28 19:26:27 +01:00
|
|
|
virtual DeviceType GetDeviceType() const { return m_device_type; }
|
2016-12-03 22:53:47 +01:00
|
|
|
virtual bool IsOpened() const { return m_is_active; }
|
2017-01-17 00:28:22 +01:00
|
|
|
static IPCCommandResult GetDefaultReply(s32 return_value);
|
2016-10-22 15:03:07 +02:00
|
|
|
static IPCCommandResult GetNoReply();
|
|
|
|
|
|
2009-11-26 09:50:50 +00:00
|
|
|
protected:
|
2016-12-28 19:26:27 +01:00
|
|
|
std::string m_name;
|
2016-06-24 10:43:46 +02:00
|
|
|
// STATE_TO_SAVE
|
2016-12-03 22:53:47 +01:00
|
|
|
u32 m_device_id;
|
2016-12-28 19:26:27 +01:00
|
|
|
DeviceType m_device_type;
|
2016-12-03 22:53:47 +01:00
|
|
|
bool m_is_active = false;
|
2017-01-15 13:49:12 +01:00
|
|
|
|
|
|
|
|
private:
|
2017-01-19 19:07:56 +01:00
|
|
|
IPCCommandResult Unsupported(const Request& request);
|
2010-09-03 17:03:06 +00:00
|
|
|
};
|
2017-01-18 20:27:51 +01:00
|
|
|
} // namespace Device
|
2017-01-17 15:01:30 -05:00
|
|
|
} // namespace HLE
|
|
|
|
|
} // namespace IOS
|