Skip to content

Commit a4d6bcc

Browse files
authored
Merge pull request #1954 from yaz0r/gdb_sharedmem
Add monitor command to retrieve the shared memory name. Only for wram so far
2 parents 1b0cbe5 + 390ccf6 commit a4d6bcc

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/core/gdb-server.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,16 @@ void PCSX::GdbClient::processMonitorCommand(const std::string& cmd) {
760760
g_emulator->m_cdrom->setIso(new CDRIso(pathView));
761761
g_emulator->m_cdrom->check();
762762
}
763+
} else if (words[0] == "sharedmem") {
764+
if (words.size() != 2) {
765+
writeEscaped("Usage: sharedmem <type>");
766+
} else {
767+
if (words[1] == "wram") {
768+
writeEscaped(g_emulator->m_mem->m_wramShared.getSharedName());
769+
} else {
770+
writeEscaped("Unknown type. Valid types: wram");
771+
}
772+
}
763773
}
764774
write("OK");
765775
}

src/core/psxmem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class Memory {
307307
uint32_t m_biosCRC = 0;
308308

309309
// Shared memory wrappers, pointers below point to these where appropriate
310+
friend class GdbClient;
310311
SharedMem m_wramShared;
311312

312313
uint32_t m_BIU = 0;

src/support/sharedmem-windows.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ bool PCSX::SharedMem::init(const char* id, size_t size, bool initToZero) {
3737
// Try to create a shared memory mapping, if an id is provided
3838
if (id != nullptr) {
3939
// Build the full name to share as
40-
std::string fullname = getSharedName(id, static_cast<uint32_t>(GetCurrentProcessId()));
40+
m_sharedName = getSharedName(id, static_cast<uint32_t>(GetCurrentProcessId()));
4141
// Create the memory mapping handle
4242
m_fileHandle =
4343
CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, static_cast<uint32_t>(size >> 32),
44-
static_cast<uint32_t>(size), fullname.c_str());
44+
static_cast<uint32_t>(size), m_sharedName.c_str());
4545
if (m_fileHandle != INVALID_HANDLE_VALUE) {
4646
// Create a view of the memory mapping at 0 offset
4747
void* basePointer = MapViewOfFileEx(m_fileHandle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, size, nullptr);
@@ -56,9 +56,11 @@ bool PCSX::SharedMem::init(const char* id, size_t size, bool initToZero) {
5656
} else {
5757
CloseHandle(m_fileHandle);
5858
m_fileHandle = nullptr;
59+
m_sharedName.clear();
5960
}
6061
} else {
6162
m_fileHandle = nullptr;
63+
m_sharedName.clear();
6264
}
6365
}
6466
// Alloc memory directly if we opted out or had problems creating the memory map
@@ -76,6 +78,7 @@ PCSX::SharedMem::~SharedMem() {
7678
m_mem = nullptr;
7779
CloseHandle(m_fileHandle);
7880
m_fileHandle = nullptr;
81+
m_sharedName.clear();
7982
} else {
8083
free(m_mem);
8184
}

src/support/sharedmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class SharedMem {
4949
uint8_t* getPtr() { return m_mem; }
5050
size_t getSize() { return m_size; }
5151

52+
const std::string& getSharedName() { return m_sharedName; }
53+
5254
private:
5355
std::string getSharedName(const char* id, uint32_t pid);
5456

0 commit comments

Comments
 (0)