Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
ffee875
Remove PAL_exit as the only usages are in places where we don't use P…
jkoritzinsky Feb 12, 2024
04ea4b4
Remove rand PAL API as no one uses it.
jkoritzinsky Feb 12, 2024
2527c50
Remove PAL_realloc as no usage of it would ever pass an alloc size of 0.
jkoritzinsky Feb 12, 2024
610d49f
Remove PAL_free as it just forwards to free.
jkoritzinsky Feb 12, 2024
6f5d947
Remove malloc PAL API and update the few places that could have passe…
jkoritzinsky Feb 12, 2024
33f3224
Remove AMD64 processor PAL functions
jkoritzinsky Feb 12, 2024
86f4ea7
Remove time PAL as it's unused
jkoritzinsky Feb 12, 2024
865eefb
Explicitly use the PAL's getenv implementation in the few places we w…
jkoritzinsky Feb 12, 2024
188b02d
Suppress bad static-analysis warning
jkoritzinsky Feb 12, 2024
57e6a10
Remove bsearch and qsort PAL APIs as they only forward to the underly…
jkoritzinsky Feb 12, 2024
b528590
Remove CRT PAL, CLR STL PAL, and enable including CRT and STL headers.
jkoritzinsky Feb 13, 2024
309e330
Various changes to fix the Windows build.
jkoritzinsky Feb 13, 2024
108f83d
Remove min/max macros from NativeAOT and fix other build failures on …
jkoritzinsky Feb 13, 2024
16a04e0
Remove duplicate definitions, fix callconv build failure. Disable war…
jkoritzinsky Feb 13, 2024
d8afe1d
Force C++ linkage when including the C++ standard headers (some files…
jkoritzinsky Feb 16, 2024
e8c8846
Add missing includes/usings.
jkoritzinsky Feb 16, 2024
ce1f3e3
Fix some build errors
jkoritzinsky Feb 20, 2024
03963c5
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Feb 20, 2024
c7e6dc3
Remove malloc wrapper and simplify InternalNew
jkoritzinsky Feb 20, 2024
03a06fb
Remove cruntime/misc.cpp PAL APIs and inline usages of _gcvt_s
jkoritzinsky Feb 20, 2024
54d2c8e
Fix more build failures
jkoritzinsky Feb 20, 2024
90ad1fe
Fix various build failures.
jkoritzinsky Feb 23, 2024
a024484
Fix various build failures.
jkoritzinsky Feb 26, 2024
d3aec5e
Fix define and fix more community-leg failures.
jkoritzinsky Feb 26, 2024
27fd400
Various osx and gcc fixes
jkoritzinsky Mar 8, 2024
0c4e83a
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Mar 8, 2024
5cfe483
Define RC_INVOKED when preprocessing RC files and fix more NULL->TADD…
jkoritzinsky Mar 8, 2024
d49ae0c
Disable the NULL arithmetic and conversion warnings in CoreCLR to avo…
jkoritzinsky Mar 11, 2024
75529ac
One more malloc header fix.
jkoritzinsky Mar 11, 2024
83a4d19
Various build fixes/adjustments
jkoritzinsky Mar 11, 2024
2d195d1
Further build fixes
jkoritzinsky Mar 11, 2024
110965d
Apply format patch
jkoritzinsky Mar 11, 2024
141f08c
Fix GCC build and continue to work on the linux-x86 build
jkoritzinsky Mar 12, 2024
ab910e6
Ensure that we're doing an unsigned compare with the result of unsign…
jkoritzinsky Mar 12, 2024
2ae3160
Remove malloc.h include except for where we're pulling it in for _alloca
jkoritzinsky Mar 12, 2024
2e45f86
Undo unsigned largestAlignmentRequirement
jkoritzinsky Mar 12, 2024
a11db1d
Explicitly use the C++ abs signature as we did in the rest of the jit
jkoritzinsky Mar 12, 2024
bae9c94
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Mar 12, 2024
cf9efb2
Remove constant manipulation as that wasn't the problem and add missi…
jkoritzinsky Mar 13, 2024
eb0180d
Include malloc.h on windows for the whole JIT
jkoritzinsky Mar 13, 2024
fb30172
Fix PAL tests and update pal test script's usage information.
jkoritzinsky Mar 14, 2024
93c34c4
Remove PAL_STDCPP_COMPAT and remove min/max macro in the GC space and…
jkoritzinsky Mar 14, 2024
d5b82a1
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Mar 14, 2024
1a0ee6c
Various build fixes and PR feedback
jkoritzinsky Mar 14, 2024
57ed663
Fix build errors
jkoritzinsky Mar 14, 2024
705bf68
Set NOMINMAX globally and move the CoreCLR and NativeAOT builds to ne…
jkoritzinsky Mar 15, 2024
12a6143
Move standard headers to the top to avoid having the "debug return" m…
jkoritzinsky Mar 15, 2024
a686376
Use `set_property` to append the RC_INVOKED define instead of overwri…
jkoritzinsky Mar 15, 2024
cef5418
Undef __fastcall to fix FreeBSD
jkoritzinsky Mar 15, 2024
23f2792
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Mar 15, 2024
283f254
Add more min/max casts to fix GCC build.
jkoritzinsky Mar 15, 2024
ee084ec
Add more casts to fix GCC and windows x86 builds
jkoritzinsky Mar 15, 2024
aa54b3f
More min/max fixes...
jkoritzinsky Mar 15, 2024
03b42c6
More signedness mismatch fixes in gc.
jkoritzinsky Mar 18, 2024
80c56da
Remove USE_STL
jkoritzinsky Apr 1, 2024
0092a92
PR feedback
jkoritzinsky Apr 1, 2024
93be569
Remove custom min/max from SuperPMI
jkoritzinsky Apr 1, 2024
5dddd14
Remove custom min/max from the JIT
jkoritzinsky Apr 1, 2024
f9647e5
Remove min/max in the GC
jkoritzinsky Apr 1, 2024
25c9976
Fix more cases that only pop in 64-bit windows builds.
jkoritzinsky Apr 2, 2024
7315beb
Fix failures on linux-x64 and when using a compiler that can actually…
jkoritzinsky Apr 2, 2024
3b8e067
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Apr 2, 2024
e71df2d
Fix build
jkoritzinsky Apr 2, 2024
140313a
PR feedback
jkoritzinsky Apr 3, 2024
e9c5d90
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Apr 3, 2024
fca86d3
Convert (TADDR)NULL to (TADDR)0 in places where (TADDR)NULL was not a…
jkoritzinsky Apr 3, 2024
3701d49
Merge dotnet/runtime into jkoritzinsky/misc-pal
jkoritzinsky Apr 3, 2024
a0e2e3d
Merge branch 'main' of github.com:dotnet/runtime into misc-pal
jkoritzinsky Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove malloc wrapper and simplify InternalNew
  • Loading branch information
jkoritzinsky committed Feb 20, 2024
commit c7e6dc376468ef6aedcbcd78c566bf496acaff61
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ OutputDebugStringW(
}

/* strLen includes the null terminator */
if ((lpOutputStringA = (LPSTR) InternalMalloc((strLen * sizeof(CHAR)))) == NULL)
if ((lpOutputStringA = (LPSTR) malloc((strLen * sizeof(CHAR)))) == NULL)
{
ERROR("Insufficient memory available !\n");
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2881,7 +2881,7 @@ GetTempFileNameW(
prefix_stringPS.CloseBuffer(prefix_size - 1);
}

tempfile_name = (char*)InternalMalloc(MAX_LONGPATH);
tempfile_name = (char*)malloc(MAX_LONGPATH);
if (tempfile_name == NULL)
{
pThread->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/file/find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ FindFirstFileA(
goto done;
}

find_data = (find_obj *)InternalMalloc(sizeof(find_obj));
find_data = (find_obj *)malloc(sizeof(find_obj));
if ( find_data == NULL )
{
ERROR("Unable to allocate memory for find_data\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/handlemgr/handlemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CSimpleHandleManager::Initialize(
field, with the head in the global 'm_hiFreeListStart'. */
m_dwTableSize = m_dwTableGrowthRate;

m_rghteHandleTable = reinterpret_cast<HANDLE_TABLE_ENTRY*>(InternalMalloc((m_dwTableSize * sizeof(HANDLE_TABLE_ENTRY))));
m_rghteHandleTable = reinterpret_cast<HANDLE_TABLE_ENTRY*>(malloc((m_dwTableSize * sizeof(HANDLE_TABLE_ENTRY))));
if(NULL == m_rghteHandleTable)
{
ERROR("Unable to create initial handle table array");
Expand Down
76 changes: 7 additions & 69 deletions src/coreclr/pal/src/include/pal/malloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,86 +27,24 @@ Module Name:
#include <new>

namespace CorUnix{
inline void *
InternalMalloc(
size_t szSize
)
// Define "new" style allocators (which allocate then call a constructor).
template<class T, class... Ts>
T* InternalNew(Ts... args)
{
void *pvMem;
T* pMem = (T*)malloc(sizeof(T));

if (szSize == 0)
{
// malloc may return null for a requested size of zero bytes. Force a nonzero size to get a valid pointer.
szSize = 1;
}

pvMem = (void*)malloc(szSize);
return pvMem;
}

// Define common code for "new" style allocators below.
#define INTERNAL_NEW_COMMON() \
T *pMem = (T*)InternalMalloc(sizeof(T)); \
if (pMem == NULL) \
if (pMem == NULL)
return NULL;

// Define "new" style allocators (which allocate then call a constructor) for different numbers of
// constructor arguments. Added based on usage.

// Default constructor (0 args) case.
template<class T>
T* InternalNew()
{
INTERNAL_NEW_COMMON();
return new (pMem) T();
}

// 1 arg case.
template<class T, class A1>
T* InternalNew(A1 arg1)
{
INTERNAL_NEW_COMMON();
return new (pMem) T(arg1);
}

// 2 args case.
template<class T, class A1, class A2>
T* InternalNew(A1 arg1, A2 arg2)
{
INTERNAL_NEW_COMMON();
return new (pMem) T(arg1, arg2);
}

// 3 args case.
template<class T, class A1, class A2, class A3>
T* InternalNew(A1 arg1, A2 arg2, A3 arg3)
{
INTERNAL_NEW_COMMON();
return new (pMem) T(arg1, arg2, arg3);
}

// 4 args case.
template<class T, class A1, class A2, class A3, class A4>
T* InternalNew(A1 arg1, A2 arg2, A3 arg3, A4 arg4)
{
INTERNAL_NEW_COMMON();
return new (pMem) T(arg1, arg2, arg3, arg4);
}

// 5 args case.
template<class T, class A1, class A2, class A3, class A4, class A5>
T* InternalNew(A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
{
INTERNAL_NEW_COMMON();
return new (pMem) T(arg1, arg2, arg3, arg4, arg5);
return new (pMem) T(args...);
}

template<class T> T* InternalNewArray(size_t cElements)
{
size_t cbSize = (cElements * sizeof(T)) + sizeof(size_t);
T *pMem;

pMem = (T*)InternalMalloc(cbSize);
pMem = (T*)malloc(cbSize);

if (pMem == NULL)
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/pal/src/init/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ static LPWSTR INIT_FormatCommandLine (int argc, const char * const *argv)
length+=3;
length+=strlen(argv[i])*2;
}
command_line = reinterpret_cast<LPSTR>(InternalMalloc(length));
command_line = reinterpret_cast<LPSTR>(malloc(length != 0 ? length : 1));

if(!command_line)
{
Expand Down Expand Up @@ -1222,7 +1222,7 @@ static LPWSTR INIT_FormatCommandLine (int argc, const char * const *argv)
return nullptr;
}

retval = reinterpret_cast<LPWSTR>(InternalMalloc((sizeof(WCHAR)*i)));
retval = reinterpret_cast<LPWSTR>(malloc((sizeof(WCHAR)*i)));
if(retval == nullptr)
{
ERROR("can't allocate memory for Unicode command line!\n");
Expand Down Expand Up @@ -1278,7 +1278,7 @@ static LPWSTR INIT_GetCurrentEXEPath()
return nullptr;
}

return_value = reinterpret_cast<LPWSTR>(InternalMalloc((return_size*sizeof(WCHAR))));
return_value = reinterpret_cast<LPWSTR>(malloc((return_size*sizeof(WCHAR))));
if (nullptr == return_value)
{
ERROR("Not enough memory to create full path\n");
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/pal/src/loader/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ static MODSTRUCT *LOADAllocModule(NATIVE_LIBRARY_HANDLE dl_handle, LPCSTR name)
LPWSTR wide_name;

/* no match found : try to create a new module structure */
module = (MODSTRUCT *)InternalMalloc(sizeof(MODSTRUCT));
module = (MODSTRUCT *)malloc(sizeof(MODSTRUCT));
if (nullptr == module)
{
ERROR("malloc() failed! errno is %d (%s)\n", errno, strerror(errno));
Expand Down Expand Up @@ -1805,11 +1805,11 @@ MODSTRUCT *LOADGetPalLibrary()
if (g_szCoreCLRPath == nullptr)
{
size_t cbszCoreCLRPath = strlen(info.dli_fname) + 1;
g_szCoreCLRPath = (char*) InternalMalloc(cbszCoreCLRPath);
g_szCoreCLRPath = (char*) malloc(cbszCoreCLRPath);

if (g_szCoreCLRPath == nullptr)
{
ERROR("LOADGetPalLibrary: InternalMalloc failed!");
ERROR("LOADGetPalLibrary: malloc failed!");
goto exit;
}

Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ CorUnix::InternalMapViewOfFile(
// the global list.
//

PMAPPED_VIEW_LIST pNewView = (PMAPPED_VIEW_LIST)InternalMalloc(sizeof(*pNewView));
PMAPPED_VIEW_LIST pNewView = (PMAPPED_VIEW_LIST)malloc(sizeof(*pNewView));
if (NULL != pNewView)
{
pNewView->lpAddress = pvBaseAddress;
Expand Down Expand Up @@ -1833,7 +1833,7 @@ static PMAPPED_VIEW_LIST FindSharedMappingReplacement(
/* The new desired mapping is fully contained in the
one just found: we can reuse this one */

pNewView = (PMAPPED_VIEW_LIST)InternalMalloc(sizeof(MAPPED_VIEW_LIST));
pNewView = (PMAPPED_VIEW_LIST)malloc(sizeof(MAPPED_VIEW_LIST));
if (pNewView)
{
memcpy(pNewView, pView, sizeof(*pNewView));
Expand Down Expand Up @@ -1868,7 +1868,7 @@ static NativeMapHolder * NewNativeMapHolder(CPalThread *pThread, LPVOID address,
}

pThisMapHolder =
(NativeMapHolder *)InternalMalloc(sizeof(NativeMapHolder));
(NativeMapHolder *)malloc(sizeof(NativeMapHolder));

if (pThisMapHolder)
{
Expand Down Expand Up @@ -1934,7 +1934,7 @@ MAPRecordMapping(

PAL_ERROR palError = NO_ERROR;
PMAPPED_VIEW_LIST pNewView;
pNewView = (PMAPPED_VIEW_LIST)InternalMalloc(sizeof(*pNewView));
pNewView = (PMAPPED_VIEW_LIST)malloc(sizeof(*pNewView));
if (NULL != pNewView)
{
pNewView->lpAddress = addr;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static BOOL VIRTUALStoreAllocationInfo(
return FALSE;
}

if (!(pNewEntry = (PCMI)InternalMalloc(sizeof(*pNewEntry))))
if (!(pNewEntry = (PCMI)malloc(sizeof(*pNewEntry))))
{
ERROR( "Unable to allocate memory for the structure.\n");
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/misc/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CPalString::CopyString(
_ASSERTE(psSource->GetMaxLength() > psSource->GetStringLength());

WCHAR *pwsz = reinterpret_cast<WCHAR*>(
InternalMalloc(psSource->GetMaxLength() * sizeof(WCHAR))
malloc(psSource->GetMaxLength() * sizeof(WCHAR))
);

if (NULL != pwsz)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/pal/src/objmgr/palobjbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CPalObjectBase::Initialize(

if (0 != m_pot->GetImmutableDataSize())
{
m_pvImmutableData = InternalMalloc(m_pot->GetImmutableDataSize());
m_pvImmutableData = malloc(m_pot->GetImmutableDataSize());
if (NULL != m_pvImmutableData)
{
ZeroMemory(m_pvImmutableData, m_pot->GetImmutableDataSize());
Expand All @@ -80,7 +80,7 @@ CPalObjectBase::Initialize(
goto InitializeExit;
}

m_pvLocalData = InternalMalloc(m_pot->GetProcessLocalDataSize());
m_pvLocalData = malloc(m_pot->GetProcessLocalDataSize());
if (NULL != m_pvLocalData)
{
ZeroMemory(m_pvLocalData, m_pot->GetProcessLocalDataSize());
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/objmgr/shmobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ CSharedMemoryObject::Initialize(
// Allocate local memory to hold the shared data
//

m_pvSharedData = InternalMalloc(m_pot->GetSharedDataSize());
m_pvSharedData = malloc(m_pot->GetSharedDataSize());
if (NULL == m_pvSharedData)
{
ERROR("Failure allocating m_pvSharedData (local copy)\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/sharedmemory/sharedmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const UINT64 SharedMemoryHelpers::InvalidSharedThreadId = static_cast<UINT64>(-1

void *SharedMemoryHelpers::Alloc(SIZE_T byteCount)
{
void *buffer = InternalMalloc(byteCount);
void *buffer = malloc(byteCount != 0 ? byteCount : 1);
if (buffer == nullptr)
{
throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::OutOfMemory));
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/synchmgr/synchmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ namespace CorUnix
class CPalSynchronizationManager : public IPalSynchronizationManager
{
friend class CPalSynchMgrController;
template <class T> friend T *CorUnix::InternalNew();
template <class T, class... Ts> friend T *CorUnix::InternalNew(Ts... args);

public:
// types
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ CorUnix::InternalCreateProcess(
}
}
EnvironmentEntries++;
EnvironmentArray = (char **)InternalMalloc(EnvironmentEntries * sizeof(char *));
EnvironmentArray = (char **)malloc(EnvironmentEntries * sizeof(char *));

EnvironmentEntries = 0;
// Convert the environment block to array of strings
Expand Down Expand Up @@ -2028,7 +2028,7 @@ PROCNotifyProcessShutdownDestructor()
char*
PROCFormatInt(ULONG32 value)
{
char* buffer = (char*)InternalMalloc(128);
char* buffer = (char*)malloc(128);
if (buffer != nullptr)
{
if (sprintf_s(buffer, 128, "%d", value) == -1)
Expand All @@ -2050,7 +2050,7 @@ PROCFormatInt(ULONG32 value)
char*
PROCFormatInt64(ULONG64 value)
{
char* buffer = (char*)InternalMalloc(128);
char* buffer = (char*)malloc(128);
if (buffer != nullptr)
{
if (sprintf_s(buffer, 128, "%lld", value) == -1)
Expand Down Expand Up @@ -2089,7 +2089,7 @@ PROCBuildCreateDumpCommandLine(
}
const char* DumpGeneratorName = "createdump";
int programLen = strlen(g_szCoreCLRPath) + strlen(DumpGeneratorName) + 1;
char* program = *pprogram = (char*)InternalMalloc(programLen);
char* program = *pprogram = (char*)malloc(programLen);
if (program == nullptr)
{
return FALSE;
Expand Down Expand Up @@ -2833,7 +2833,7 @@ CorUnix::InitializeProcessCommandLine(
size_t n = PAL_wcslen(lpwstrFullPath) + 1;

size_t iLen = n;
initial_dir = reinterpret_cast<LPWSTR>(InternalMalloc(iLen*sizeof(WCHAR)));
initial_dir = reinterpret_cast<LPWSTR>(malloc(iLen*sizeof(WCHAR)));
if (NULL == initial_dir)
{
ERROR("malloc() failed! (initial_dir) \n");
Expand Down Expand Up @@ -3760,7 +3760,7 @@ buildArgv(
pThread = InternalGetCurrentThread();
/* make sure to allocate enough space, up for the worst case scenario */
int iLength = (iWlen + lpAppPath.GetCount() + 2);
lpAsciiCmdLine = (char *) InternalMalloc(iLength);
lpAsciiCmdLine = (char *) malloc(iLength);

if (lpAsciiCmdLine == NULL)
{
Expand Down Expand Up @@ -3940,7 +3940,7 @@ buildArgv(

/* allocate lppargv according to the number of arguments
in the command line */
lppArgv = (char **) InternalMalloc((((*pnArg)+1) * sizeof(char *)));
lppArgv = (char **) malloc((((*pnArg)+1) * sizeof(char *)));

if (lppArgv == NULL)
{
Expand Down