-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add support for a shared memory mapping on Kernel & User Memory #1468
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1468 +/- ##
==========================================
+ Coverage 8.59% 8.67% +0.07%
==========================================
Files 408 413 +5
Lines 125609 125847 +238
==========================================
+ Hits 10802 10923 +121
- Misses 114807 114924 +117 ☔ View full report in Codecov by Sentry. |
So, several comments here.
Suggestions:
|
…atform-specific implementations for Windows and Linux (not OSX), removed toggle to enable named shared memory
Okay, I've refactored things into something that's hopefully sensible and there's a few questions I have left
VS
|
We could go with sharedmem-unix.cc, and have the guard for it be "not windows". We might want to split it off further at some point in the future, because Linux now has a "better" way to do this using a new API I've never used before, but that's not really important for now.
I'm fine with this for now. I'm thinking maybe we can try and add a casting operator on the SharedMem object and just "use" it as a pointer directly, but I'd need to experiment with this.
First, I'm wondering if we shouldn't just have the Then I think we should go with your second option for now. As per my comment prior this one, this may just be temporary if we manage to pull off a casting operation that'd work everywhere transparently, which would make this problem moot.
Yup!
Let's make this PR just convert |
Should be ready for another pass now 🤞 |
src/core/psxmem.cc
Outdated
@@ -89,7 +89,17 @@ int PCSX::Memory::init() { | |||
m_readLUT = (uint8_t **)calloc(0x10000, sizeof(void *)); | |||
m_writeLUT = (uint8_t **)calloc(0x10000, sizeof(void *)); | |||
|
|||
m_wram = (uint8_t *)calloc(0x00800000, 1); | |||
uint32_t pid = 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.
Looks like this is no longer needed.
@@ -188,6 +189,9 @@ class Memory { | |||
|
|||
// hopefully this should become private eventually, with only certain classes having direct access. | |||
public: | |||
// Shared memory wrappers, pointers below point to these where appropriate | |||
SharedMem m_wramShared; |
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.
Probably keep it private for now.
src/support/sharedmem.h
Outdated
~SharedMem(); | ||
|
||
void init(const char* id, size_t size); | ||
std::string getSharedName(const char* id, uint32_t pid); |
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 is probably private.
src/support/sharedmem-unix.cc
Outdated
g_system->message("ftruncate failed, falling back to memory alloc, size: %zu\n", m_size); | ||
} else { | ||
// ftruncate completed, now map the memory at 0 offset | ||
void* basePointer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd, 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.
nullptr
src/support/sharedmem-unix.cc
Outdated
#if !defined(_WIN32) && !defined(_WIN64) | ||
|
||
#include "support/sharedmem.h" | ||
#include "core/system.h" |
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.
The problem in bringing core/system.h
here is it'd create a cyclic dependency between library projects. We should just not warn if we need to fallback; there's quite nothing the user might be able to do. At best we could imagine having a boolean saying the shared memory worked, and report it up in the UI if we really wanted to.
src/support/sharedmem-windows.cc
Outdated
|
||
#include "support/sharedmem.h" | ||
#include "support/windowswrapper.h" | ||
#include "core/system.h" |
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.
Same comment as with -unix.cc
, we can't use core/system.h
safely from support/*
.
src/core/psxmem.cc
Outdated
#endif | ||
|
||
// Init all memory as named mappings | ||
m_wramShared.init(_("wram"), 0x00800000); |
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.
No, let's avoid making it "wram" a localized string. This would break external scripts depending on the selected locale.
Just one last kind of medium issue: |
The rest is just minor nits, looks good otherwise :) |
This allows me to write to game memory from Unity in realtime, without having to go through GDB, Lua, etc, which are (in my experience) unable to keep up with writes being sent at 50fps+