include_directories(${COREPAL_SOURCE_DIR}/../inc)
add_compile_options(-fexceptions)
+add_definitions(-DUSE_STL)
add_subdirectory(src)
#include "pal/palinternal.h"
#include "pal/dbgmsg.h"
+#include <algorithm>
SET_DEFAULT_DEBUG_CHANNEL(CRT);
ret = (unsigned char *) string;
if (GetCPInfo(CP_ACP, &cpinfo) && cpinfo.MaxCharSize == 1)
{
- ret += min(count, strlen((const char*)string));
+ ret += std::min(count, strlen((const char*)string));
}
else
{
/*******************************************************************************
Function:
- Internal_AddPaddingA
-
-Parameters:
- Out
- - buffer to place padding and given string (In)
- Count
- - maximum chars to be copied so as not to overrun given buffer
- In
- - string to place into (Out) accompanied with padding
- Padding
- - number of padding chars to add
- Flags
- - padding style flags (PRINTF_FORMAT_FLAGS)
-*******************************************************************************/
-BOOL Internal_AddPaddingA(LPSTR *Out, INT Count, LPSTR In,
- INT Padding, INT Flags)
-{
- LPSTR OutOriginal = *Out;
- INT PaddingOriginal = Padding;
- INT LengthInStr;
- LengthInStr = strlen(In);
-
-
- if (Padding < 0)
- {
- /* this is used at the bottom to determine if the buffer ran out */
- PaddingOriginal = 0;
- }
- if (Flags & PFF_MINUS) /* pad on right */
- {
- if (strncpy_s(*Out, Count, In, min(LengthInStr + 1, Count)) != SAFECRT_SUCCESS)
- {
- return FALSE;
- }
-
- *Out += min(LengthInStr, Count);
- }
- if (Padding > 0)
- {
- if (Flags & PFF_ZERO) /* '0', pad with zeros */
- {
- while (Padding-- && Count > *Out - OutOriginal)
- {
- *(*Out)++ = '0';
- }
- }
- else /* pad left with spaces */
- {
- while (Padding-- && Count > *Out - OutOriginal)
- {
- *(*Out)++ = ' ';
- }
- }
- }
- if (!(Flags & PFF_MINUS)) /* put 'In' after padding */
- {
- if (strncpy_s(*Out, Count, In,
- min(LengthInStr + 1, Count - (*Out - OutOriginal))) != SAFECRT_SUCCESS)
- {
- return FALSE;
- }
-
- *Out += min(LengthInStr, Count - (*Out - OutOriginal));
- }
-
- if (LengthInStr + PaddingOriginal > Count)
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
-}
-
-/*******************************************************************************
-Function:
PAL_printf_arg_remover
Parameters:
/*******************************************************************************
Function:
- Internal_AddPaddingW
-
-Parameters:
- Out
- - buffer to place padding and given string (In)
- Count
- - maximum chars to be copied so as not to overrun given buffer
- In
- - string to place into (Out) accompanied with padding
- Padding
- - number of padding chars to add
- Flags
- - padding style flags (PRINTF_FORMAT_FLAGS)
-*******************************************************************************/
-
-BOOL Internal_AddPaddingW(LPWSTR *Out, INT Count, LPWSTR In, INT Padding, INT Flags)
-{
- LPWSTR OutOriginal = *Out;
- INT PaddingOriginal = Padding;
- INT LengthInStr;
- LengthInStr = PAL_wcslen(In);
-
-
- if (Padding < 0)
- {
- /* this is used at the bottom to determine if the buffer ran out */
- PaddingOriginal = 0;
- }
- if (Flags & PFF_MINUS) /* pad on right */
- {
- if (wcsncpy_s(*Out, Count, In, min(LengthInStr + 1, Count - 1)) != SAFECRT_SUCCESS)
- {
- return FALSE;
- }
-
- *Out += min(LengthInStr, Count - 1);
- }
- if (Padding > 0)
- {
- if (Flags & PFF_ZERO) /* '0', pad with zeros */
- {
- while (Padding-- && Count > *Out - OutOriginal)
- {
- *(*Out)++ = '0';
- }
- }
- else /* pad left with spaces */
- {
- while (Padding-- && Count > *Out - OutOriginal)
- {
- *(*Out)++ = ' ';
- }
- }
- }
- if (!(Flags & PFF_MINUS)) /* put 'In' after padding */
- {
- if (wcsncpy_s(*Out, Count - (*Out - OutOriginal), In,
- min(LengthInStr, Count - (*Out - OutOriginal) - 1)) != SAFECRT_SUCCESS)
- {
- return FALSE;
- }
-
- *Out += min(LengthInStr, Count - (*Out - OutOriginal) - 1);
- }
-
- if (LengthInStr + PaddingOriginal > Count - 1)
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
-}
-
-/*******************************************************************************
-Function:
Internal_AddPaddingVfprintf
Parameters:
#endif
#include <errno.h>
+#include <algorithm>
SET_DEFAULT_DEBUG_CHANNEL(CRT);
strDest, strSource, strSource, (unsigned long) count);
memset( strDest, 0, length );
- length = min( count, PAL_wcslen( strSource ) ) * sizeof( wchar_16 );
+ length = std::min( count, PAL_wcslen( strSource ) ) * sizeof( wchar_16 );
memcpy( strDest, strSource, length );
LOGEXIT("wcsncpy returning (wchar_16*): %p\n", strDest);
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
-
-// Define the std::move so that we don't have to include the <utility> header
-// which on some platforms pulls in STL stuff that collides with PAL stuff.
-// The std::move is needed to enable using move constructor and assignment operator
-// for PAL_SEHException.
-namespace std
-{
- template<typename T>
- struct remove_reference
- {
- typedef T type;
- };
-
- template<typename T>
- struct remove_reference<T&>
- {
- typedef T type;
- };
-
- template<typename T>
- struct remove_reference<T&&>
- {
- typedef T type;
- };
-
- template<class T> inline
- typename remove_reference<T>::type&& move(T&& arg)
- { // forward arg as movable
- return ((typename remove_reference<T>::type&&)arg);
- }
-}
+#include <utility>
using namespace CorUnix;
/*******************************************************************************
Function:
- Internal_AddPaddingA
-
-Parameters:
- Out
- - buffer to place padding and given string (In)
- Count
- - maximum chars to be copied so as not to overrun given buffer
- In
- - string to place into (Out) accompanied with padding
- Padding
- - number of padding chars to add
- Flags
- - padding style flags (PRINTF_FORMAT_FLAGS)
-*******************************************************************************/
-BOOL Internal_AddPaddingA(LPSTR *Out, INT Count, LPSTR In, INT Padding, INT Flags);
-
-/*******************************************************************************
-Function:
PAL_printf_arg_remover
Parameters:
#include <stdarg.h>
#include <stdlib.h>
+#include <new>
extern "C"
{
);
}
-inline void* operator new(size_t, void* p) throw () { return p; }
-inline void* operator new[](size_t, void* p) throw () { return p; }
-
namespace CorUnix{
void *
#define _ENABLE_DEBUG_MESSAGES_ 0
#endif
+/* Include type_traits before including the pal.h. On newer glibcxx versions,
+ the type_traits fail to compile if we redefine the wchar_t before including
+ the header */
+#include <type_traits>
+
#ifdef PAL_PERF
#include "pal_perf.h"
#endif
#undef ctime
+#undef min
+#undef max
+
#undef SCHAR_MIN
#undef SCHAR_MAX
#undef UCHAR_MAX
#include <kvm.h>
#endif
+#include <algorithm>
+
using namespace CorUnix;
//
if (errno == 0)
{
- g_defaultStackSize = max(size, PTHREAD_STACK_MIN);
+ g_defaultStackSize = std::max(size, (long int)PTHREAD_STACK_MIN);
}
}
#include "pal/palinternal.h"
#include <sys/resource.h>
#include "pal/virtual.h"
+#include <algorithm>
#define PROC_MOUNTINFO_FILENAME "/proc/self/mountinfo"
#define PROC_CGROUP_FILENAME "/proc/self/cgroup"
{
rlimit_soft_limit = curr_rlimit.rlim_cur;
}
- physical_memory_limit = min(physical_memory_limit, rlimit_soft_limit);
+ physical_memory_limit = std::min(physical_memory_limit, rlimit_soft_limit);
// Ensure that limit is not greater than real memory size
long pages = sysconf(_SC_PHYS_PAGES);
long pageSize = sysconf(_SC_PAGE_SIZE);
if (pageSize != -1)
{
- physical_memory_limit = min(physical_memory_limit,
- (size_t)pages * pageSize);
+ physical_memory_limit = std::min(physical_memory_limit,
+ (size_t)(pages * pageSize));
}
}
#include "pal/dbgmsg.h"
+#include <algorithm>
SET_DEFAULT_DEBUG_CHANNEL(MISC);
size_t cacheSize = 0;
#ifdef _SC_LEVEL1_DCACHE_SIZE
- cacheSize = max(cacheSize, sysconf(_SC_LEVEL1_DCACHE_SIZE));
+ cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL1_DCACHE_SIZE));
#endif
#ifdef _SC_LEVEL2_CACHE_SIZE
- cacheSize = max(cacheSize, sysconf(_SC_LEVEL2_CACHE_SIZE));
+ cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL2_CACHE_SIZE));
#endif
#ifdef _SC_LEVEL3_CACHE_SIZE
- cacheSize = max(cacheSize, sysconf(_SC_LEVEL3_CACHE_SIZE));
+ cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL3_CACHE_SIZE));
#endif
#ifdef _SC_LEVEL4_CACHE_SIZE
- cacheSize = max(cacheSize, sysconf(_SC_LEVEL4_CACHE_SIZE));
+ cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL4_CACHE_SIZE));
#endif
#if defined(_ARM64_)
size_t size;
if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index0/size", &size))
- cacheSize = max(cacheSize, size);
+ cacheSize = std::max(cacheSize, size);
if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index1/size", &size))
- cacheSize = max(cacheSize, size);
+ cacheSize = std::max(cacheSize, size);
if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index2/size", &size))
- cacheSize = max(cacheSize, size);
+ cacheSize = std::max(cacheSize, size);
if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index3/size", &size))
- cacheSize = max(cacheSize, size);
+ cacheSize = std::max(cacheSize, size);
if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index4/size", &size))
- cacheSize = max(cacheSize, size);
+ cacheSize = std::max(cacheSize, size);
}
if(cacheSize == 0)
// Assume L3$/CPU grows linearly from 256K to 1.5M/CPU as logicalCPUs grows from 2 to 12 CPUs
DWORD logicalCPUs = PAL_GetLogicalCpuCountFromOS();
- cacheSize = logicalCPUs*min(1536, max(256, logicalCPUs*128))*1024;
+ cacheSize = logicalCPUs*std::min(1536, std::max(256, logicalCPUs*128))*1024;
}
#endif
#include <pthread.h>
#include <dlfcn.h>
+#include <algorithm>
+
#include "numashim.h"
using namespace CorUnix;
if (st == 0)
{
- for (int i = 0; i < min(8 * sizeof(KAFFINITY), g_possibleCpuCount); i++)
+ for (int i = 0; i < std::min(8 * (int)sizeof(KAFFINITY), g_possibleCpuCount); i++)
{
if (CPU_ISSET(i, &prevCpuSet))
{
PERF_EXIT(SetThreadIdealProcessorEx);
return success;
-}
\ No newline at end of file
+}
#include "pal/fakepoll.h"
#endif // HAVE_POLL
+#include <algorithm>
+
+const int CorUnix::CThreadSynchronizationInfo::PendingSignalingsArraySize;
+
// We use the synchronization manager's worker thread to handle
// process termination requests. It does so by calling the
// registered handler function.
ERROR("Failed creating thread synchronization mutex [error=%d (%s)]\n", iRet, strerror(iRet));
if (EAGAIN == iRet && MaxUnavailableResourceRetries >= ++iEagains)
{
- poll(NULL, 0, min(100,10*iEagains));
+ poll(NULL, 0, std::min(100,10*iEagains));
goto Mutex_retry;
}
else if (ENOMEM == iRet)
"[error=%d (%s)]\n", iRet, strerror(iRet));
if (EAGAIN == iRet && MaxUnavailableResourceRetries >= ++iEagains)
{
- poll(NULL, 0, min(100,10*iEagains));
+ poll(NULL, 0, std::min(100,10*iEagains));
goto Cond_retry;
}
else if (ENOMEM == iRet)
if (0 < m_lPendingSignalingCount)
{
- LONG lArrayPendingSignalingCount = min(PendingSignalingsArraySize, m_lPendingSignalingCount);
+ LONG lArrayPendingSignalingCount = std::min(PendingSignalingsArraySize, m_lPendingSignalingCount);
LONG lIdx = 0;
PAL_ERROR palTempErr;