-
Notifications
You must be signed in to change notification settings - Fork 7
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
Redesign memory access functions #17
Conversation
I have reviewed the design (this was written over a year ago) and I dislike some of the choices:
However, this allows MMIO and we still have almost 10k leaky-allocations before memory reaches 30MB+. I've also fixed a small issue in dbg.py with the first commit. Both commits have been tested and worked fine. I think we should merge this as-is and then address the issues later. |
dbgd.c
Outdated
res->size = 1; /* FIXME: add word, dword, qword support */ | ||
res->has_size = 1; | ||
res->data.len = req->size; | ||
res->data.data = malloc(res->data.len); |
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.
free
?
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.
See "Known problems" in first post. We discussed this in 2017 when I prototyped this PR but I never got a response.
I know this is bad code, but without this feature (MMIO compatible read/write) nxdk-rdt is pretty useless. I don't really want to spend another few hours to rewrite this differently - this code already exists and at least makes nxdk-rdt functional.
We can iterate and make nxdk-rdt less leaky and more stable later.
I like this PR but prefer not to merge it until the leak is fixed. If memory serves me correct |
We do run into this issue (see my previous post, also contains the same 4k logic).
I already have a long backlog for XQEMU. |
I added a simple work-around by using a single growing buffer. As the buffer is never My tests still reliably crashed within the first minute - but so does running: # Print something to the screen
while True:
xbox.debug_print("Hello!") (So this is probably not the PRs fault, but #5 or another issue) I did not confirm if the code works correctly (so I did not add debug-prints to trace the current buffer address / size / malloc / free), so please review that function. I also did not try to |
@@ -30,6 +30,20 @@ | |||
#define HTTPD_DEBUG LWIP_DBG_OFF | |||
#endif | |||
|
|||
static void* get_transfer_buffer(uint32_t size) { | |||
static uint32_t buffer_size = 0; |
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.
Be aware using static variables kills multithreaded use.
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.
This was more of a workaround to avoid a leak and get this merged quickly.
I agree that we should eventually have an object for each connection.
I'll create an issue about improving this after merge. Thanks for pointing it out.
This redesigns the memory read / write functionality.
By giving it a deterministic data read/write behaviour it becomes useful for MMIO.
The proposed behaviour of the reads / writes is:
Logically, it's not possible to get more than one 2 byte write and one 1 byte write.
The
while
loops were still kept to make the repeating pattern in the code more obvious + someone might want to disable the 4 byte write or extend the function in the future.I did consider design alternatives, but this setup works for most cases. Most MMIO registers are 4 byte on Xbox, so we can write a bunch of them at once (using a single packet / more or less atomic operation) if need-be. We can also read and write large blocks of data at okish-speeds, still.
Known problem
The protobufbytes
type probably doesn't free the allocated data anywhere. Therefore, this probably leaks memory.An issue should be created after merge, so someone should look into this in the future.Fixed.
The second commit is a design decision: Instead of using the existing
xbox.mem
function, this turns it intoxbox.mem_read
andxbox.mem_write
.This reflects the actual protobuf function names and avoids possible conflicts (where size and data can both be supplied for example).
I did consider naming the new functions just
read
andwrite
to be more like the Python stream (file/socket) operations. However, we might wantxbox.io_write
andxbox.io_read
later, so I decided to keep the protobuf names with themem_
prefix.Closes #2