From 524d217d52780cf9b0bce33a91e8d7266447d5bb Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 11 Nov 2024 23:32:02 -0800 Subject: [PATCH] Remove CoreCLR PAL's InternalNew/Delete and just use new/delete with std::nothrow (#109659) --- src/coreclr/pal/src/debug/debug.cpp | 1 - .../pal/src/exception/machexception.cpp | 1 - src/coreclr/pal/src/exception/machmessage.cpp | 1 - src/coreclr/pal/src/exception/seh.cpp | 1 - src/coreclr/pal/src/file/file.cpp | 1 - src/coreclr/pal/src/file/find.cpp | 1 - src/coreclr/pal/src/file/path.cpp | 1 - src/coreclr/pal/src/handlemgr/handlemgr.cpp | 1 - src/coreclr/pal/src/include/pal/handlemgr.hpp | 1 - src/coreclr/pal/src/include/pal/malloc.hpp | 80 ------------------- .../pal/src/include/pal/synchcache.hpp | 8 +- .../pal/src/include/pal/threadsusp.hpp | 8 -- src/coreclr/pal/src/init/pal.cpp | 6 +- src/coreclr/pal/src/loader/module.cpp | 1 - src/coreclr/pal/src/map/map.cpp | 1 - src/coreclr/pal/src/map/virtual.cpp | 1 - src/coreclr/pal/src/misc/dbgmsg.cpp | 1 - src/coreclr/pal/src/misc/environ.cpp | 1 - src/coreclr/pal/src/misc/strutil.cpp | 1 - .../pal/src/misc/tracepointprovider.cpp | 1 - src/coreclr/pal/src/objmgr/palobjbase.cpp | 3 +- src/coreclr/pal/src/objmgr/palobjbase.hpp | 2 - src/coreclr/pal/src/objmgr/shmobject.cpp | 3 +- src/coreclr/pal/src/objmgr/shmobject.hpp | 4 - .../pal/src/objmgr/shmobjectmanager.cpp | 8 +- .../pal/src/sharedmemory/sharedmemory.cpp | 9 +-- src/coreclr/pal/src/sync/cs.cpp | 5 +- src/coreclr/pal/src/synchmgr/synchmanager.cpp | 21 ++--- src/coreclr/pal/src/synchmgr/synchmanager.hpp | 1 - src/coreclr/pal/src/synchmgr/wait.cpp | 10 +-- src/coreclr/pal/src/thread/thread.cpp | 2 +- 31 files changed, 36 insertions(+), 150 deletions(-) delete mode 100644 src/coreclr/pal/src/include/pal/malloc.hpp diff --git a/src/coreclr/pal/src/debug/debug.cpp b/src/coreclr/pal/src/debug/debug.cpp index 360391e8cf414..8783ff4860321 100644 --- a/src/coreclr/pal/src/debug/debug.cpp +++ b/src/coreclr/pal/src/debug/debug.cpp @@ -32,7 +32,6 @@ SET_DEFAULT_DEBUG_CHANNEL(DEBUG); // some headers have code with asserts, so do #include "pal/context.h" #include "pal/debug.h" #include "pal/environ.h" -#include "pal/malloc.hpp" #include "pal/module.h" #include "pal/stackstring.hpp" #include "pal/virtual.h" diff --git a/src/coreclr/pal/src/exception/machexception.cpp b/src/coreclr/pal/src/exception/machexception.cpp index 7ed8ae4c83d31..cfa8269cc86a3 100644 --- a/src/coreclr/pal/src/exception/machexception.cpp +++ b/src/coreclr/pal/src/exception/machexception.cpp @@ -26,7 +26,6 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do #include "pal/init.h" #include "pal/utils.h" #include "pal/context.h" -#include "pal/malloc.hpp" #include "pal/process.h" #include "pal/virtual.h" #include "pal/map.hpp" diff --git a/src/coreclr/pal/src/exception/machmessage.cpp b/src/coreclr/pal/src/exception/machmessage.cpp index ec0c4085743d0..96fbd08bd0aea 100644 --- a/src/coreclr/pal/src/exception/machmessage.cpp +++ b/src/coreclr/pal/src/exception/machmessage.cpp @@ -16,7 +16,6 @@ Module Name: #include "config.h" #include "pal/dbgmsg.h" #include "pal/environ.h" -#include "pal/malloc.hpp" #include "pal/thread.hpp" #include "machmessage.h" diff --git a/src/coreclr/pal/src/exception/seh.cpp b/src/coreclr/pal/src/exception/seh.cpp index 63fd3649674ed..02a540734001b 100644 --- a/src/coreclr/pal/src/exception/seh.cpp +++ b/src/coreclr/pal/src/exception/seh.cpp @@ -25,7 +25,6 @@ Module Name: #include "pal/debug.h" #include "pal/init.h" #include "pal/process.h" -#include "pal/malloc.hpp" #include "pal/signal.hpp" #include "pal/virtual.h" diff --git a/src/coreclr/pal/src/file/file.cpp b/src/coreclr/pal/src/file/file.cpp index 9d868f1e5b58a..382a448c659fc 100644 --- a/src/coreclr/pal/src/file/file.cpp +++ b/src/coreclr/pal/src/file/file.cpp @@ -18,7 +18,6 @@ SET_DEFAULT_DEBUG_CHANNEL(FILE); // some headers have code with asserts, so do t #include "pal/thread.hpp" #include "pal/file.hpp" -#include "pal/malloc.hpp" #include "pal/stackstring.hpp" #include "pal/palinternal.h" diff --git a/src/coreclr/pal/src/file/find.cpp b/src/coreclr/pal/src/file/find.cpp index ead5c4335e76e..e0717970cf547 100644 --- a/src/coreclr/pal/src/file/find.cpp +++ b/src/coreclr/pal/src/file/find.cpp @@ -20,7 +20,6 @@ Revision History: --*/ #include "pal/thread.hpp" -#include "pal/malloc.hpp" #include "pal/file.hpp" #include "pal/stackstring.hpp" diff --git a/src/coreclr/pal/src/file/path.cpp b/src/coreclr/pal/src/file/path.cpp index 62418b240d3fe..671180397f8ab 100644 --- a/src/coreclr/pal/src/file/path.cpp +++ b/src/coreclr/pal/src/file/path.cpp @@ -23,7 +23,6 @@ Revision History: #include "pal/palinternal.h" #include "pal/dbgmsg.h" #include "pal/file.h" -#include "pal/malloc.hpp" #include "pal/stackstring.hpp" #include diff --git a/src/coreclr/pal/src/handlemgr/handlemgr.cpp b/src/coreclr/pal/src/handlemgr/handlemgr.cpp index 09405f1ec514b..7a3b5c20912aa 100644 --- a/src/coreclr/pal/src/handlemgr/handlemgr.cpp +++ b/src/coreclr/pal/src/handlemgr/handlemgr.cpp @@ -20,7 +20,6 @@ Module Name: #include "pal/thread.hpp" #include "pal/handlemgr.hpp" #include "pal/cs.hpp" -#include "pal/malloc.hpp" #include "pal/dbgmsg.h" using namespace CorUnix; diff --git a/src/coreclr/pal/src/include/pal/handlemgr.hpp b/src/coreclr/pal/src/include/pal/handlemgr.hpp index 94b40e72ce0e3..f6a3b5d163747 100644 --- a/src/coreclr/pal/src/include/pal/handlemgr.hpp +++ b/src/coreclr/pal/src/include/pal/handlemgr.hpp @@ -24,7 +24,6 @@ Module Name: #include "corunix.hpp" #include "cs.hpp" #include "pal/thread.hpp" -#include "pal/malloc.hpp" /* Pseudo handles constant for current thread and process */ diff --git a/src/coreclr/pal/src/include/pal/malloc.hpp b/src/coreclr/pal/src/include/pal/malloc.hpp deleted file mode 100644 index 65715fa9387ae..0000000000000 --- a/src/coreclr/pal/src/include/pal/malloc.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - pal/malloc.hpp - -Abstract: - Declarations for suspension safe memory allocation functions - - - ---*/ - -#ifndef _MALLOC_HPP -#define _MALLOC_HPP - -#include "pal/corunix.hpp" -#include "pal/thread.hpp" - -#include -#include -#include - -namespace CorUnix{ - // Define "new" style allocators (which allocate then call a constructor). - template - T* InternalNew(Ts... args) - { - T* pMem = (T*)malloc(sizeof(T)); - - if (pMem == NULL) - return NULL; - - return new (pMem) T(args...); - } - - template T* InternalNewArray(size_t cElements) - { - size_t cbSize = (cElements * sizeof(T)) + sizeof(size_t); - T *pMem; - - pMem = (T*)malloc(cbSize); - - if (pMem == NULL) - return NULL; - - *(size_t*)pMem = cElements; - pMem = (T*)((size_t*)pMem + 1); - - return new (pMem) T[cElements](); - } - - template void InternalDelete(T *p) - { - if (p) - { - p->~T(); - free(p); - } - } - - template void InternalDeleteArray(T *p) - { - if (p) - { - size_t *pRealMem = (size_t*)p - 1; - size_t cElements = *pRealMem; - for (size_t i = 0; i < cElements; i++) - p[i].~T(); - free(pRealMem); - } - } -} - -#endif // _MALLOC_HPP diff --git a/src/coreclr/pal/src/include/pal/synchcache.hpp b/src/coreclr/pal/src/include/pal/synchcache.hpp index 821f5096a7440..89ee48c42e944 100644 --- a/src/coreclr/pal/src/include/pal/synchcache.hpp +++ b/src/coreclr/pal/src/include/pal/synchcache.hpp @@ -21,7 +21,7 @@ Module Name: #define _SYNCH_CACHE_H_ #include "pal/thread.hpp" -#include "pal/malloc.hpp" +#include namespace CorUnix { @@ -116,7 +116,7 @@ namespace CorUnix for (j=i;j(); + pvObjRaw = (void *) new(std::nothrow) USynchCacheStackNode(); if (NULL == pvObjRaw) break; #ifdef _DEBUG @@ -159,7 +159,7 @@ namespace CorUnix } else { - InternalDelete((char *)pNode); + delete (char *)pNode; } Unlock(pthrCurrent); } @@ -184,7 +184,7 @@ namespace CorUnix { pTemp = pNode; pNode = pNode->next; - InternalDelete((char *)pTemp); + delete (char *)pTemp; } } }; diff --git a/src/coreclr/pal/src/include/pal/threadsusp.hpp b/src/coreclr/pal/src/include/pal/threadsusp.hpp index d9441372a5a27..4608ea372c2f4 100644 --- a/src/coreclr/pal/src/include/pal/threadsusp.hpp +++ b/src/coreclr/pal/src/include/pal/threadsusp.hpp @@ -22,14 +22,6 @@ Module Name: // Need this ifdef since this header is included by .c files so they can use the diagnostic function. #ifdef __cplusplus -// Note: do not include malloc.hpp from this header. The template InternalDelete -// needs to know the layout of class CPalThread, which includes a member of type -// CThreadSuspensionInfo, which is defined later in this header, and it is not -// yet known at this point. -// If any future change should bring this issue back, the circular dependency can -// be further broken by making the InternalDelete's CPalThread argument a -// templatized argument, so that type checking on it takes place only at -// instantiation time. #include "pal/threadinfo.hpp" #include "pal/thread.hpp" #include "pal/mutex.hpp" diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index 14a869e13293d..072fd79ce8c25 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -361,7 +361,7 @@ Initialize( // The gSharedFilesPath is allocated dynamically so its destructor does not get // called unexpectedly during cleanup - gSharedFilesPath = InternalNew(); + gSharedFilesPath = new(std::nothrow) PathCharString(); if (gSharedFilesPath == nullptr) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -482,7 +482,7 @@ Initialize( // Initialize the object manager // - pshmom = InternalNew(); + pshmom = new(std::nothrow) CSharedMemoryObjectManager(); if (nullptr == pshmom) { ERROR("Unable to allocate new object manager\n"); @@ -494,7 +494,7 @@ Initialize( if (NO_ERROR != palError) { ERROR("object manager initialization failed!\n"); - InternalDelete(pshmom); + delete pshmom; goto CLEANUP1b; } diff --git a/src/coreclr/pal/src/loader/module.cpp b/src/coreclr/pal/src/loader/module.cpp index e553077d846d1..fe43edcc0b97c 100644 --- a/src/coreclr/pal/src/loader/module.cpp +++ b/src/coreclr/pal/src/loader/module.cpp @@ -21,7 +21,6 @@ Module Name: SET_DEFAULT_DEBUG_CHANNEL(LOADER); // some headers have code with asserts, so do this first #include "pal/thread.hpp" -#include "pal/malloc.hpp" #include "pal/file.hpp" #include "pal/palinternal.h" #include "pal/module.h" diff --git a/src/coreclr/pal/src/map/map.cpp b/src/coreclr/pal/src/map/map.cpp index 4734986d78716..5abfebe117ddf 100644 --- a/src/coreclr/pal/src/map/map.cpp +++ b/src/coreclr/pal/src/map/map.cpp @@ -28,7 +28,6 @@ Module Name: #include "pal/map.hpp" #include "pal/thread.hpp" #include "pal/file.hpp" -#include "pal/malloc.hpp" #include #include diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index 7e7b9242428d2..16df9848d9b77 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -23,7 +23,6 @@ SET_DEFAULT_DEBUG_CHANNEL(VIRTUAL); // some headers have code with asserts, so d #include "pal/thread.hpp" #include "pal/cs.hpp" -#include "pal/malloc.hpp" #include "pal/file.hpp" #include "pal/seh.hpp" #include "pal/virtual.h" diff --git a/src/coreclr/pal/src/misc/dbgmsg.cpp b/src/coreclr/pal/src/misc/dbgmsg.cpp index 38f101d147f67..4c22dfb4e4716 100644 --- a/src/coreclr/pal/src/misc/dbgmsg.cpp +++ b/src/coreclr/pal/src/misc/dbgmsg.cpp @@ -16,7 +16,6 @@ Module Name: /* PAL headers */ #include "pal/thread.hpp" -#include "pal/malloc.hpp" #include "pal/file.hpp" #include "config.h" diff --git a/src/coreclr/pal/src/misc/environ.cpp b/src/coreclr/pal/src/misc/environ.cpp index 4980d213fa3bc..53729118a8921 100644 --- a/src/coreclr/pal/src/misc/environ.cpp +++ b/src/coreclr/pal/src/misc/environ.cpp @@ -23,7 +23,6 @@ Revision History: #include "pal/critsect.h" #include "pal/dbgmsg.h" #include "pal/environ.h" -#include "pal/malloc.hpp" #if HAVE_CRT_EXTERNS_H #include diff --git a/src/coreclr/pal/src/misc/strutil.cpp b/src/coreclr/pal/src/misc/strutil.cpp index e665e22b65291..585fbeb37b63f 100644 --- a/src/coreclr/pal/src/misc/strutil.cpp +++ b/src/coreclr/pal/src/misc/strutil.cpp @@ -18,7 +18,6 @@ Module Name: #include "pal/corunix.hpp" #include "pal/thread.hpp" -#include "pal/malloc.hpp" #include "pal/dbgmsg.h" SET_DEFAULT_DEBUG_CHANNEL(PAL); diff --git a/src/coreclr/pal/src/misc/tracepointprovider.cpp b/src/coreclr/pal/src/misc/tracepointprovider.cpp index 3cfc5e0690e20..dae1e0f73170c 100644 --- a/src/coreclr/pal/src/misc/tracepointprovider.cpp +++ b/src/coreclr/pal/src/misc/tracepointprovider.cpp @@ -20,7 +20,6 @@ Revision History: #include "pal/file.h" #include "pal/process.h" #include "pal/module.h" -#include "pal/malloc.hpp" #include "pal/stackstring.hpp" #include diff --git a/src/coreclr/pal/src/objmgr/palobjbase.cpp b/src/coreclr/pal/src/objmgr/palobjbase.cpp index c39b5df7e268f..3ae07f78074f9 100644 --- a/src/coreclr/pal/src/objmgr/palobjbase.cpp +++ b/src/coreclr/pal/src/objmgr/palobjbase.cpp @@ -17,7 +17,6 @@ Module Name: --*/ #include "palobjbase.hpp" -#include "pal/malloc.hpp" #include "pal/dbgmsg.h" SET_DEFAULT_DEBUG_CHANNEL(PAL); @@ -323,7 +322,7 @@ CPalObjectBase::ReleaseReference( (*m_pot->GetProcessLocalDataCleanupRoutine())(pthr, static_cast(this)); } - InternalDelete(this); + delete this; pthr->ReleaseThreadReference(); } diff --git a/src/coreclr/pal/src/objmgr/palobjbase.hpp b/src/coreclr/pal/src/objmgr/palobjbase.hpp index e05aaf0cd7a00..724b005cc31bf 100644 --- a/src/coreclr/pal/src/objmgr/palobjbase.hpp +++ b/src/coreclr/pal/src/objmgr/palobjbase.hpp @@ -85,8 +85,6 @@ namespace CorUnix class CPalObjectBase : public IPalObject { - template friend void InternalDelete(T *p); - protected: LONG m_lRefCount; diff --git a/src/coreclr/pal/src/objmgr/shmobject.cpp b/src/coreclr/pal/src/objmgr/shmobject.cpp index 282dd113da2e2..7c8ce5db015b8 100644 --- a/src/coreclr/pal/src/objmgr/shmobject.cpp +++ b/src/coreclr/pal/src/objmgr/shmobject.cpp @@ -17,7 +17,6 @@ Module Name: --*/ #include "shmobject.hpp" -#include "pal/malloc.hpp" #include "pal/cs.hpp" #include "pal/dbgmsg.h" @@ -527,7 +526,7 @@ CSharedMemoryObject::CleanupForProcessShutdown( m_pthrCleanup = pthr; pthr->AddThreadReference(); - InternalDelete(this); + delete this; pthr->ReleaseThreadReference(); diff --git a/src/coreclr/pal/src/objmgr/shmobject.hpp b/src/coreclr/pal/src/objmgr/shmobject.hpp index f50d10e0bb842..bdc81e9072fe2 100644 --- a/src/coreclr/pal/src/objmgr/shmobject.hpp +++ b/src/coreclr/pal/src/objmgr/shmobject.hpp @@ -77,8 +77,6 @@ namespace CorUnix class CSharedMemoryObject : public CPalObjectBase { - template friend void InternalDelete(T *p); - protected: // @@ -298,8 +296,6 @@ namespace CorUnix class CSharedMemoryWaitableObject : public CSharedMemoryObject { - template friend void InternalDelete(T *p); - protected: VOID *m_pvSynchData; diff --git a/src/coreclr/pal/src/objmgr/shmobjectmanager.cpp b/src/coreclr/pal/src/objmgr/shmobjectmanager.cpp index ca960617da4ac..de60e9f4bd2ee 100644 --- a/src/coreclr/pal/src/objmgr/shmobjectmanager.cpp +++ b/src/coreclr/pal/src/objmgr/shmobjectmanager.cpp @@ -162,11 +162,11 @@ CSharedMemoryObjectManager::AllocateObject( if (CObjectType::WaitableObject == pot->GetSynchronizationSupport()) { - pshmobj = InternalNew(pot, &m_csListLock); + pshmobj = new(std::nothrow) CSharedMemoryWaitableObject(pot, &m_csListLock); } else { - pshmobj = InternalNew(pot, &m_csListLock); + pshmobj = new(std::nothrow) CSharedMemoryObject(pot, &m_csListLock); } if (NULL != pshmobj) @@ -1025,7 +1025,7 @@ CSharedMemoryObjectManager::ImportSharedObjectIntoProcess( if (CObjectType::WaitableObject == pot->GetSynchronizationSupport()) { - pshmobj = InternalNew(pot, + pshmobj = new(std::nothrow) CSharedMemoryWaitableObject(pot, &m_csListLock, shmSharedObjectData, psmod, @@ -1033,7 +1033,7 @@ CSharedMemoryObjectManager::ImportSharedObjectIntoProcess( } else { - pshmobj = InternalNew(pot, + pshmobj = new(std::nothrow) CSharedMemoryObject(pot, &m_csListLock, shmSharedObjectData, psmod, diff --git a/src/coreclr/pal/src/sharedmemory/sharedmemory.cpp b/src/coreclr/pal/src/sharedmemory/sharedmemory.cpp index ba9447b889c39..0a878084615a6 100644 --- a/src/coreclr/pal/src/sharedmemory/sharedmemory.cpp +++ b/src/coreclr/pal/src/sharedmemory/sharedmemory.cpp @@ -7,7 +7,6 @@ SET_DEFAULT_DEBUG_CHANNEL(SHMEM); // some headers have code with asserts, so do #include "pal/sharedmemory.h" #include "pal/file.hpp" -#include "pal/malloc.hpp" #include "pal/thread.hpp" #include "pal/virtual.h" #include "pal/process.h" @@ -1227,7 +1226,7 @@ void SharedMemoryProcessDataHeader::Close() { if (m_data != nullptr) { - InternalDelete(m_data); + delete m_data; } if (releaseSharedData) @@ -1338,7 +1337,7 @@ void SharedMemoryProcessDataHeader::DecRefCount() return; } - InternalDelete(this); + delete this; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1360,8 +1359,8 @@ bool SharedMemoryManager::StaticInitialize() { InitializeCriticalSection(&s_creationDeletionProcessLock); - s_runtimeTempDirectoryPath = InternalNew(); - s_sharedMemoryDirectoryPath = InternalNew(); + s_runtimeTempDirectoryPath = new(std::nothrow) PathCharString(); + s_sharedMemoryDirectoryPath = new(std::nothrow) PathCharString(); if (s_runtimeTempDirectoryPath && s_sharedMemoryDirectoryPath) { diff --git a/src/coreclr/pal/src/sync/cs.cpp b/src/coreclr/pal/src/sync/cs.cpp index d04b2c13bb68a..032ff1c189f3c 100644 --- a/src/coreclr/pal/src/sync/cs.cpp +++ b/src/coreclr/pal/src/sync/cs.cpp @@ -13,7 +13,6 @@ #include "pal/thread.hpp" #include "pal/cs.hpp" -#include "pal/malloc.hpp" #include "pal/list.h" #include "pal/dbgmsg.h" #include "pal/init.h" @@ -421,7 +420,7 @@ VOID InternalDeleteCriticalSection( #endif // PAL_TRACK_CRITICAL_SECTIONS_DATA - InternalDelete(pPalCriticalSection->DebugInfo); + delete pPalCriticalSection->DebugInfo; pPalCriticalSection->DebugInfo = NULL; } #endif // _DEBUG @@ -592,7 +591,7 @@ namespace CorUnix CPalThread * pThread = (PALIsThreadDataInitialized() ? GetCurrentPalThread() : NULL); - pPalCriticalSection->DebugInfo = InternalNew(); + pPalCriticalSection->DebugInfo = new(std::nothrow) CRITICAL_SECTION_DEBUG_INFO(); _ASSERT_MSG(NULL != pPalCriticalSection->DebugInfo, "Failed to allocate debug info for new CS\n"); diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/pal/src/synchmgr/synchmanager.cpp index 07cbfa302d420..b0fd95355fc74 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.cpp @@ -40,6 +40,7 @@ SET_DEFAULT_DEBUG_CHANNEL(SYNC); // some headers have code with asserts, so do t #endif // HAVE_POLL #include +#include const int CorUnix::CThreadSynchronizationInfo::PendingSignalingsArraySize; @@ -1447,7 +1448,7 @@ namespace CorUnix InternalInitializeCriticalSection(&s_csSynchProcessLock); InternalInitializeCriticalSection(&s_csMonitoredProcessesLock); - pSynchManager = InternalNew(); + pSynchManager = new(std::nothrow) CPalSynchronizationManager(); if (NULL == pSynchManager) { ERROR("Failed to allocate memory for Synchronization Manager"); @@ -1480,7 +1481,7 @@ namespace CorUnix s_pObjSynchMgr = NULL; g_pSynchronizationManager = NULL; - InternalDelete(pSynchManager); + delete pSynchManager; } return palErr; @@ -2428,7 +2429,7 @@ namespace CorUnix // If the array is full, add the target thread object at the end // of the overflow list DeferredSignalingListNode * pdsln = - InternalNew(); + new(std::nothrow) DeferredSignalingListNode(); if (pdsln) { @@ -3115,7 +3116,7 @@ namespace CorUnix } else { - pmpln = InternalNew(); + pmpln = new(std::nothrow) MonitoredProcessesListNode(); if (NULL == pmpln) { ERROR("No memory to allocate MonitoredProcessesListNode structure\n"); @@ -3219,7 +3220,7 @@ namespace CorUnix m_lMonitoredProcessesCount--; pmpln->pProcessObject->ReleaseReference(pthrCurrent); pmpln->psdSynchData->Release(pthrCurrent); - InternalDelete(pmpln); + delete pmpln; } } else @@ -3428,7 +3429,7 @@ namespace CorUnix pNode->psdSynchData->Release(pthrCurrent); // Delete the node - InternalDelete(pNode); + delete pNode; // Go to the next pNode = pNext; @@ -3476,7 +3477,7 @@ namespace CorUnix m_pmplnMonitoredProcesses = pNode->pNext; pNode->pProcessObject->ReleaseReference(pthrCurrent); pNode->psdSynchData->Release(pthrCurrent); - InternalDelete(pNode); + delete pNode; } // Release the monitored processes lock @@ -3811,7 +3812,7 @@ namespace CorUnix { int i; - rgshridWTLNodes = InternalNewArray(ulcWaitingThreads); + rgshridWTLNodes = new (std::nothrow) SharedID[ulcWaitingThreads]; if (NULL == rgshridWTLNodes) { palError = ERROR_OUTOFMEMORY; @@ -4020,7 +4021,7 @@ namespace CorUnix if (NULL != rgshridWTLNodes) { - InternalDeleteArray(rgshridWTLNodes); + delete[] rgshridWTLNodes; } return palError; @@ -4445,7 +4446,7 @@ namespace CorUnix pdsln->pthrTarget->ReleaseThreadReference(); // Delete the node - InternalDelete(pdsln); + delete pdsln; lIdx += 1; } diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.hpp b/src/coreclr/pal/src/synchmgr/synchmanager.hpp index ce325f75ecc1e..72dada69af0ce 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.hpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.hpp @@ -496,7 +496,6 @@ namespace CorUnix class CPalSynchronizationManager : public IPalSynchronizationManager { friend class CPalSynchMgrController; - template friend T *CorUnix::InternalNew(Ts... args); public: // types diff --git a/src/coreclr/pal/src/synchmgr/wait.cpp b/src/coreclr/pal/src/synchmgr/wait.cpp index 5ae53759fa2be..495d86b1cd5cd 100644 --- a/src/coreclr/pal/src/synchmgr/wait.cpp +++ b/src/coreclr/pal/src/synchmgr/wait.cpp @@ -26,8 +26,8 @@ Revision History: #include "pal/event.hpp" #include "pal/mutex.hpp" #include "pal/semaphore.hpp" -#include "pal/malloc.hpp" #include "pal/dbgmsg.h" +#include SET_DEFAULT_DEBUG_CHANNEL(SYNC); @@ -390,8 +390,8 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx( wtWaitType = fWAll ? MultipleObjectsWaitAll : MultipleObjectsWaitOne; if (nCount > MAXIMUM_STACK_WAITOBJ_ARRAY_SIZE) { - ppIPalObjs = InternalNewArray(nCount); - ppISyncWaitCtrlrs = InternalNewArray(nCount); + ppIPalObjs = new(std::nothrow) IPalObject*[nCount]; + ppISyncWaitCtrlrs = new(std::nothrow) ISynchWaitController*[nCount]; if ((NULL == ppIPalObjs) || (NULL == ppISyncWaitCtrlrs)) { ERROR("Out of memory allocating internal structures\n"); @@ -707,8 +707,8 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx( WFMOExIntExit: if (nCount > MAXIMUM_STACK_WAITOBJ_ARRAY_SIZE) { - InternalDeleteArray(ppIPalObjs); - InternalDeleteArray(ppISyncWaitCtrlrs); + delete[] ppIPalObjs; + delete[] ppISyncWaitCtrlrs; } return dwRet; diff --git a/src/coreclr/pal/src/thread/thread.cpp b/src/coreclr/pal/src/thread/thread.cpp index 37083d1eb10cc..bec3f7f7e62e9 100644 --- a/src/coreclr/pal/src/thread/thread.cpp +++ b/src/coreclr/pal/src/thread/thread.cpp @@ -203,7 +203,7 @@ VOID TLSCleanup() --*/ CPalThread* AllocTHREAD() { - return InternalNew(); + return new(std::nothrow) CPalThread(); } /*++