Skip to content

Commit

Permalink
Remove unportable SHM savestates in core
Browse files Browse the repository at this point in the history
  • Loading branch information
ughman committed Jul 3, 2019
1 parent 9a1c0f4 commit 79684c9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 82 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -54,7 +54,6 @@ target_include_directories (pcsx-hdbg-core
)
target_link_libraries (pcsx-hdbg-core
PUBLIC "${ZLIB_LIBRARIES}"
PUBLIC "rt"
)

add_library (pcsx-hdbg-spu MODULE
Expand Down
81 changes: 0 additions & 81 deletions core/misc.c
Expand Up @@ -677,90 +677,9 @@ void RewindState() {
GPUFreeze_t *gpufP = NULL;
SPUFreeze_t *spufP = NULL;

/*
Pros of using SHM
+ No need to change SaveState interface (gzip OK)
+ Possibiliy to preserve saves after pcsxr crash
Cons of using SHM
- UNIX only
- Possibility of leaving left over shm files
- Possibly not the quickest way to allocate memory
*/
#if !defined(NO_RT_SHM) && !defined(_WINDOWS) && !defined(_WIN32)
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <fcntl.h> /* For O_* constants */
#include <errno.h>

#define SHM_SS_NAME_TEMPLATE "/pcsxrmemsavestate%.4u"

int SaveStateMem(const u32 id) {
char name[32];
int ret = -1;

snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, id);
int fd = shm_open(name, O_CREAT | O_RDWR | O_TRUNC, 0666);

if (fd >= 0) {
gzFile f = gzdopen(fd, "wb0T"); // Fast and no compression
//gzbuffer(f, 64*1024);
//assert(gzdirect(f) == TRUE);
if (f != NULL) {
ret = SaveStateGz(f, NULL);
//printf("Saved %s/%i (ID: %i SZ: %lik)\n", name, fd, id, size/1024);
} else {
SysMessage("GZ OPEN FAIL %i\n", errno );
}
} else {
SysMessage("FD OPEN FAIL %i\n", errno );
}
return ret;
}

int LoadStateMem(const u32 id) {
char name[32];
int ret = -1;

snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, id);
int fd = shm_open(name, O_RDONLY, 0444);

if (fd >= 0) {
gzFile f = gzdopen(fd, "rb");
if (f != NULL) {
ret = LoadStateGz(f);
//printf("Loaded %s/%i (ID: %i RET: %i)\n", name, fd, id, ret);
shm_unlink(name);
} else {
SysMessage("GZ OPEN FAIL %i\n", errno);
}
} else {
SysMessage("FD OPEN FAIL %i (%s)\n", errno, name);
}
return ret;
}

void CleanupMemSaveStates() {
char name[32];
u32 i;

for (i=0; i <= Config.RewindCount; i++) {
snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, i);
if (shm_unlink(name) != 0) {
//break;
}
}
free(gpufP);
gpufP = NULL;
free(spufP);
spufP = NULL;
}
#else
int SaveStateMem(const u32 id) {return 0;}
int LoadStateMem(const u32 id) {return 0;}
void CleanupMemSaveStates() {}
#endif

int SaveStateGz(gzFile f, long* gzsize) {
int Size;
Expand Down

0 comments on commit 79684c9

Please sign in to comment.