diff --git a/source/utils/CarlaBridgeUtils.cpp b/source/utils/CarlaBridgeUtils.cpp index c04bb7307..663683cde 100644 --- a/source/utils/CarlaBridgeUtils.cpp +++ b/source/utils/CarlaBridgeUtils.cpp @@ -22,10 +22,10 @@ #include "jackbridge/JackBridge.hpp" #if defined(CARLA_OS_WIN) && defined(BUILDING_CARLA_FOR_WINDOWS) -# define PLUGIN_BRIDGE_NAMEPREFIX_AUDIO_POOL "Global\\carla-bridge_shm_ap_" -# define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "Global\\carla-bridge_shm_rtC_" -# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_CLIENT "Global\\carla-bridge_shm_nonrtC_" -# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_SERVER "Global\\carla-bridge_shm_nonrtS_" +# define PLUGIN_BRIDGE_NAMEPREFIX_AUDIO_POOL "Local\\carla-bridge_shm_ap_" +# define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "Local\\carla-bridge_shm_rtC_" +# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_CLIENT "Local\\carla-bridge_shm_nonrtC_" +# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_SERVER "Local\\carla-bridge_shm_nonrtS_" #else # define PLUGIN_BRIDGE_NAMEPREFIX_AUDIO_POOL "/crlbrdg_shm_ap_" # define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "/crlbrdg_shm_rtC_" @@ -179,7 +179,6 @@ bool BridgeRtClientControl::initializeServer() noexcept filename = tmpFileBase; isServer = true; - needsSemDestroy = true; if (! mapData()) { @@ -207,6 +206,7 @@ bool BridgeRtClientControl::initializeServer() noexcept return false; } + needsSemDestroy = true; return true; } diff --git a/source/utils/CarlaBridgeUtils.hpp b/source/utils/CarlaBridgeUtils.hpp index 605240662..a4f785b0e 100644 --- a/source/utils/CarlaBridgeUtils.hpp +++ b/source/utils/CarlaBridgeUtils.hpp @@ -22,16 +22,6 @@ #include "CarlaMutex.hpp" #include "CarlaString.hpp" -#if defined(CARLA_OS_WIN) && defined(BUILDING_CARLA_FOR_WINDOWS) -# define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "Global\\carla-bridge_shm_rtC_" -# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_CLIENT "Global\\carla-bridge_shm_nonrtC_" -# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_SERVER "Global\\carla-bridge_shm_nonrtS_" -#else -# define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "/crlbrdg_shm_rtC_" -# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_CLIENT "/crlbrdg_shm_nonrtC_" -# define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_SERVER "/crlbrdg_shm_nonrtS_" -#endif - // ------------------------------------------------------------------------------------------------------------------- static inline diff --git a/source/utils/CarlaShmUtils.hpp b/source/utils/CarlaShmUtils.hpp index fc4771027..bc58e70f5 100644 --- a/source/utils/CarlaShmUtils.hpp +++ b/source/utils/CarlaShmUtils.hpp @@ -173,17 +173,37 @@ void* carla_shm_map(carla_shm_t& shm, const std::size_t size) noexcept HANDLE map; if (shm.isServer) - map = ::CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE|SEC_COMMIT, 0, size, shm.filename); + { + SECURITY_ATTRIBUTES sa; + carla_zeroStruct(sa); + sa.nLength = sizeof(sa); + sa.bInheritHandle = TRUE; + + map = ::CreateFileMappingA(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE|SEC_COMMIT, 0, size, shm.filename); + + if (map == nullptr || map == INVALID_HANDLE_VALUE) + { + const DWORD errorCode = ::GetLastError(); + carla_stderr2("CreateFileMapping failed for '%s', size:%lu, isServer:%i, errorCode:%x", + shm.filename, size, shm.isServer, errorCode); + return nullptr; + } + } else - map = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm.filename); + { + map = ::OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, shm.filename); - CARLA_SAFE_ASSERT_RETURN(map != INVALID_HANDLE_VALUE, nullptr); + CARLA_SAFE_ASSERT_RETURN(map != nullptr, nullptr); + CARLA_SAFE_ASSERT_RETURN(map != INVALID_HANDLE_VALUE, nullptr); + } - void* const ptr(::MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, size)); + void* const ptr = ::MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, size); if (ptr == nullptr) { - carla_safe_assert("ptr != nullptr", __FILE__, __LINE__); + const DWORD errorCode = ::GetLastError(); + carla_stderr2("MapViewOfFile failed for '%s', size:%lu, isServer:%i, errorCode:%u", + shm.filename, size, shm.isServer, errorCode); ::CloseHandle(map); return nullptr; }