New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOS HLE: Deduplicate the request parsing code #4661
Conversation
45ba37c
to
b4a9f88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks a lot nicer than the old stuff; but this "request has the return value" thing feels off in my head. I don't want to block this PR if you have other plans for it tho.
{ | ||
// async | ||
m_event.addr = _CommandAddress; | ||
Memory::Write_U32(0, _CommandAddress + 0x4); | ||
// Check if the condition is already true | ||
EventNotify(); | ||
return GetNoReply(); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
u32 fd = 0; | ||
explicit IOSRequest(u32 address); | ||
virtual ~IOSRequest() = default; | ||
void SetReturnValue(s32 new_return_value) const; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
{ | ||
struct IOVector | ||
{ | ||
u32 addr = 0; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Now that everything has been changed to use the new structs, the old methods and structs can be removed. And while I was changing the base device class, I also moved the "unsupported command" code to a separate function. It was pretty silly to copy the same 3 lines for ~5 commands.
This makes more sense than setting the return code on the request struct first before replying. Ref: dolphin-emu#4661 (comment)
b4a9f88
to
25f89cc
Compare
@BhaaLseN I've made the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much nicer this way, thanks a lot! :)
|
||
IPCCommandResult reply = GetDefaultReply(); | ||
IPCCommandResult reply = GetDefaultReply(IPC_SUCCESS); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This moves the resource request parsing code into well-defined structs instead of duplicating it all over IOS HLE. Command handler functions are now passed parsed resource 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 more likely, copy/paste existing struct request variables. It also makes it harder to introduce 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.
Some other notable 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 return code, and Close handlers don't return anything and don't have to worry about checking whether the request is a real one anymore.
Dump
was moved to the relevant request structs, because it did not really make sense to make it part of the IOS device especially when it only works for ioctl/ioctlv requests.This was split from #4488 so it has already been tested by JMC47.