From 83c1cef2082a1c8ca636d58f00fb14a5589931b1 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 13 Feb 2022 17:33:46 +0100 Subject: [PATCH] Replace DCFlushRange with OSMemoryBarrier --- src/FSDirReplacements.cpp | 2 +- src/FSWrapper.cpp | 23 ++++++++++------------- src/RPXLoading.cpp | 8 ++++---- src/main.cpp | 6 +++--- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/FSDirReplacements.cpp b/src/FSDirReplacements.cpp index a7780e7..3ba0624 100644 --- a/src/FSDirReplacements.cpp +++ b/src/FSDirReplacements.cpp @@ -168,7 +168,7 @@ DECL_FUNCTION(FSStatus, FSChangeDirAsync, FSClient *client, FSCmdBlock *block, c gReplacementInfo.contentReplacementInfo.workingDir[len - 1] = '/'; gReplacementInfo.contentReplacementInfo.workingDir[len] = 0; } - DCFlushRange(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir)); + OSMemoryBarrier(); return real_FSChangeDirAsync(client, block, path, errorMask, asyncData); } diff --git a/src/FSWrapper.cpp b/src/FSWrapper.cpp index c20804a..41203a5 100644 --- a/src/FSWrapper.cpp +++ b/src/FSWrapper.cpp @@ -63,8 +63,7 @@ int getNewFileHandleIndex() { OSFatal("Failed to alloc memory for mutex"); } OSInitMutex(file_handles[i].mutex); - DCFlushRange(file_handles[i].mutex, sizeof(OSMutex)); - DCFlushRange(&file_handles[i], sizeof(fileMagic_t)); + OSMemoryBarrier(); } break; } @@ -93,8 +92,7 @@ int32_t getNewDirHandleIndex() { if (!dir_handles[i].mutex) { OSFatal("Failed to alloc memory for mutex"); } - DCFlushRange(dir_handles[i].mutex, sizeof(OSMutex)); - DCFlushRange(&dir_handles[i], sizeof(dirMagic_t)); + OSMemoryBarrier(); } break; } @@ -114,7 +112,7 @@ void freeFileHandle(uint32_t handle) { free(file_handles[handle].mutex); file_handles[handle].mutex = nullptr; } - DCFlushRange(&file_handles[handle], sizeof(fileMagic_t)); + OSMemoryBarrier(); file_handle_mutex.unlock(); } @@ -130,7 +128,7 @@ void freeDirHandle(uint32_t handle) { dir_handles[handle].mutex = nullptr; } dir_handles[handle] = {}; - DCFlushRange(&dir_handles[handle], sizeof(dirMagic_t)); + OSMemoryBarrier(); dir_handle_mutex.unlock(); } @@ -198,7 +196,7 @@ FSStatus FSOpenDirWrapper(char *path, } else { DEBUG_FUNCTION_LINE("Global FSClient or FSCmdBlock were null"); } - DCFlushRange(dir_info, sizeof(dirMagic_t)); + OSMemoryBarrier(); } OSUnlockMutex(dir_handles[handle_index].mutex); @@ -252,7 +250,7 @@ FSStatus FSReadDirWrapper(FSDirectoryHandle handle, dir_info->readResultCapacity = 1; } } - DCFlushRange(dir_info, sizeof(dirMagic_t)); + OSMemoryBarrier(); } struct dirent *entry_ = readdir(dir); @@ -296,8 +294,7 @@ FSStatus FSReadDirWrapper(FSDirectoryHandle handle, memcpy(&dir_info->readResult[dir_info->readResultNumberOfEntries], entry, sizeof(FSDirectoryEntry)); dir_info->readResultNumberOfEntries++; - DCFlushRange(dir_info->readResult, sizeof(FSDirectoryEntry) * dir_info->readResultNumberOfEntries); - DCFlushRange(dir_info, sizeof(dirMagic_t)); + OSMemoryBarrier(); } result = FS_STATUS_OK; @@ -393,7 +390,7 @@ FSStatus FSCloseDirWrapper(FSDirectoryHandle handle, dir_info->readResultCapacity = 0; dir_info->readResultNumberOfEntries = 0; } - DCFlushRange(dir_info, sizeof(dirMagic_t)); + OSMemoryBarrier(); } OSUnlockMutex(dir_handles[handle_index].mutex); @@ -441,7 +438,7 @@ FSStatus FSRewindDirWrapper(FSDirectoryHandle handle, DEBUG_FUNCTION_LINE("Global FSClient or FSCmdBlock were null"); } } - DCFlushRange(dir_info, sizeof(dirMagic_t)); + OSMemoryBarrier(); } OSUnlockMutex(dir_handles[handle_index].mutex); @@ -544,7 +541,7 @@ FSStatus FSOpenFileWrapper(char *path, *handle = file_handles[handle_index].handle; file_handles[handle_index].fd = fd; file_handles[handle_index].in_use = true; - DCFlushRange(&file_handles[handle_index], sizeof(fileMagic_t)); + OSMemoryBarrier(); } else { DEBUG_FUNCTION_LINE("File not found %s", pathForCheck); if (gReplacementInfo.contentReplacementInfo.fallbackOnError) { diff --git a/src/RPXLoading.cpp b/src/RPXLoading.cpp index 6046adf..13eaad5 100644 --- a/src/RPXLoading.cpp +++ b/src/RPXLoading.cpp @@ -179,7 +179,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { request.path[0] = '\0'; strncat(request.path, bundle_path, sizeof(request.path) - 1); - DCFlushRange(&request, sizeof(request)); + OSMemoryBarrier(); int success = false; int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0); @@ -193,7 +193,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { IOS_Close(mcpFd); } - DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); + OSMemoryBarrier(); if (!success) { gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced = false; @@ -229,7 +229,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { } } - DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); + OSMemoryBarrier(); return true; } @@ -251,7 +251,7 @@ bool RL_UnmountCurrentRunningBundle() { DEBUG_FUNCTION_LINE("Unmount /vol/content"); romfsUnmount("rom"); gReplacementInfo.contentReplacementInfo.bundleMountInformation.isMounted = false; - DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); + OSMemoryBarrier(); return true; } } diff --git a/src/main.cpp b/src/main.cpp index ef2d500..4493c44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ WUMS_APPLICATION_ENDS() { DEBUG_FUNCTION_LINE("Unmount /vol/content"); romfsUnmount("rom"); gReplacementInfo.contentReplacementInfo.bundleMountInformation.isMounted = false; - DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); + OSMemoryBarrier(); } } gReplacementInfo.rpxReplacementInfo.isRPXReplaced = false; @@ -94,7 +94,7 @@ WUMS_APPLICATION_STARTS() { DEBUG_FUNCTION_LINE("Set mode to CONTENTREDIRECT_NONE and replaceSave to false"); gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_NONE; gReplacementInfo.contentReplacementInfo.replaceSave = false; - DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); + OSMemoryBarrier(); } else { if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_WUHB_BUNDLE) { uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath); @@ -137,6 +137,6 @@ WUMS_APPLICATION_STARTS() { } } - DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); + OSMemoryBarrier(); } }