summaryrefslogtreecommitdiff
path: root/src/pal/src/misc
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-02-10 20:35:12 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-02-10 20:35:12 +0900
commit4b11dc566a5bbfa1378d6266525c281b028abcc8 (patch)
treeb48831a898906734f8884d08b6e18f1144ee2b82 /src/pal/src/misc
parentdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (diff)
downloadcoreclr-4b11dc566a5bbfa1378d6266525c281b028abcc8.tar.gz
coreclr-4b11dc566a5bbfa1378d6266525c281b028abcc8.tar.bz2
coreclr-4b11dc566a5bbfa1378d6266525c281b028abcc8.zip
Imported Upstream version 1.0.0.9910upstream/1.0.0.9910
Diffstat (limited to 'src/pal/src/misc')
-rw-r--r--src/pal/src/misc/dbgmsg.cpp10
-rw-r--r--src/pal/src/misc/fmtmessage.cpp3
-rw-r--r--src/pal/src/misc/perftrace.cpp179
-rw-r--r--src/pal/src/misc/sysinfo.cpp18
-rw-r--r--src/pal/src/misc/utils.cpp6
5 files changed, 11 insertions, 205 deletions
diff --git a/src/pal/src/misc/dbgmsg.cpp b/src/pal/src/misc/dbgmsg.cpp
index 488e61494e..d6f173f160 100644
--- a/src/pal/src/misc/dbgmsg.cpp
+++ b/src/pal/src/misc/dbgmsg.cpp
@@ -528,8 +528,8 @@ int DBG_printf_gcc(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader,
va_start(args, format);
- output_size+=Silent_PAL_vsnprintf(buffer_ptr, DBG_BUFFER_SIZE-output_size,
- format, args);
+ output_size+=_vsnprintf_s(buffer_ptr, DBG_BUFFER_SIZE-output_size, _TRUNCATE,
+ format, args);
va_end(args);
if( output_size > DBG_BUFFER_SIZE )
@@ -633,8 +633,8 @@ int DBG_printf_c99(DBG_CHANNEL_ID channel, DBG_LEVEL_ID level, BOOL bHeader,
}
va_start(args, format);
- output_size+=Silent_PAL_vsnprintf(buffer_ptr, DBG_BUFFER_SIZE-output_size,
- format, args);
+ output_size+=_vsnprintf_s(buffer_ptr, DBG_BUFFER_SIZE-output_size, _TRUNCATE,
+ format, args);
va_end(args);
if(output_size>DBG_BUFFER_SIZE)
@@ -960,7 +960,7 @@ void PAL_DisplayDialogFormatted(const char *szTitle, const char *szTextFormat, .
const int cchBuffer = 4096;
char *szBuffer = (char*)alloca(cchBuffer);
- PAL__vsnprintf(szBuffer, cchBuffer, szTextFormat, args);
+ _vsnprintf_s(szBuffer, cchBuffer, _TRUNCATE, szTextFormat, args);
PAL_DisplayDialog(szTitle, szBuffer);
va_end(args);
diff --git a/src/pal/src/misc/fmtmessage.cpp b/src/pal/src/misc/fmtmessage.cpp
index 46e0af6e0d..70b854aa9c 100644
--- a/src/pal/src/misc/fmtmessage.cpp
+++ b/src/pal/src/misc/fmtmessage.cpp
@@ -205,7 +205,7 @@ static LPWSTR FMTMSG_ProcessPrintf( wchar_t c ,
UINT nFormatLength = 0;
int nBufferLength = 0;
- TRACE( "FMTMSG_ProcessPrintf( %C, %S, %S )\n", c,
+ TRACE( "FMTMSG_ProcessPrintf( %C, %S, %p )\n", c,
lpPrintfString, lpInsertString );
switch ( c )
@@ -299,7 +299,6 @@ FormatMessageW(
LPWSTR lpReturnString = NULL;
LPWSTR lpWorkingString = NULL;
-
PERF_ENTRY(FormatMessageW);
ENTRY( "FormatMessageW(dwFlags=%#x, lpSource=%p, dwMessageId=%#x, "
"dwLanguageId=%#x, lpBuffer=%p, nSize=%u, va_list=%p)\n",
diff --git a/src/pal/src/misc/perftrace.cpp b/src/pal/src/misc/perftrace.cpp
index d4fba3367a..fdefdf6694 100644
--- a/src/pal/src/misc/perftrace.cpp
+++ b/src/pal/src/misc/perftrace.cpp
@@ -23,26 +23,6 @@ Abstract:
#ifdef PAL_PERF
-#ifndef PLATFORM_UNIX
-/* PAL Headers */
-#include "perftrace.h"
-
-/* Standard Headers */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#define snprintf _snprintf
-#define MiscGetenv getenv
-#define pthread_getspecific TlsGetValue
-#define THREADSilentGetCurrentThreadId GetCurrentThreadId
-#define getpid GetCurrentProcessId
-#define PAL_fgets fgets // on Windows, we want fgets.
-#define PAL_fwrite fwrite // on Windows, we want fwrite.
-#define PAL_fseek fseek // on Windows, we want fseek.
-
-#else
/* PAL Headers */
#include "pal/palinternal.h"
#include "pal/perftrace.h"
@@ -60,7 +40,6 @@ Abstract:
#include <unistd.h>
SET_DEFAULT_DEBUG_CHANNEL(MISC);
-#endif //End of PLATFORM_UNIX
#define PAL_PERF_MAX_LOGLINE 0x400 /* 1K */
@@ -110,21 +89,12 @@ typedef struct _pal_perf_program_info
ULONGLONG total_duration; /* Total CPU clock ticks of all the threads */
ULONGLONG pal_duration; /* Total CPU clock ticks spent inside PAL */
-#ifndef PLATFORM_UNIX
- DWORD process_id;
-#else
pid_t process_id;
-#endif
char start_time[32]; /* must be at least 26 characters */
} pal_perf_program_info;
-#ifndef PLATFORM_UNIX
-typedef FILE PERF_FILE;
-#define PERF_FILEFN(x) x
-#else
typedef PAL_FILE PERF_FILE;
#define PERF_FILEFN(x) PAL_ ## x
-#endif
static ULONGLONG PERFGetTicks();
static double PERFComputeStandardDeviation(pal_perf_api_info *api);
@@ -144,11 +114,7 @@ typedef char PAL_API_NAME[PAL_PERF_MAX_FUNCTION_NAME];
static PAL_API_NAME API_list[PAL_API_NUMBER] ;
static pal_perf_program_info program_info;
-#ifndef PLATFORM_UNIX
-static DWORD PERF_tlsTableKey=0 ;
-#else
static pthread_key_t PERF_tlsTableKey=0 ;
-#endif
static pal_thread_list_node * process_pal_thread_list=NULL;
static BOOL pal_profile_on=FALSE;
@@ -199,19 +165,11 @@ static const char PAL_PERF_HISTOGRAM_SIZE[]="PAL_PERF_HISTOGRAM_SIZE";
static const char PAL_PERF_HISTOGRAM_STEP[]="PAL_PERF_HISTOGRAM_STEP";
static const char traced_apis_filename[]="PerfTracedAPIs.txt";
static const char perf_enabled_filename[]="AllPerfEnabledAPIs.txt";
-#ifndef PLATFORM_UNIX
-static const char PATH_SEPARATOR[] = "\\";
-#else
static const char PATH_SEPARATOR[] = "/";
-#endif
-#ifndef PLATFORM_UNIX
-#define LLFORMAT "%I64u"
-#else
#define LLFORMAT "%llu"
-#endif
static
ULONGLONG
@@ -231,11 +189,7 @@ PERFGetTicks(){
#endif
return ((ULONGLONG)((unsigned int)(d)) << 32) | (unsigned int)(a);
#else
-#ifdef __sparc__
- return (ULONGLONG)gethrtime();
-#else
return 0; // on non-BSD and non-Windows, we'll return 0 for now.
-#endif // __sparc__
#endif // _X86_
}
@@ -283,11 +237,7 @@ BOOL
PERFInitProgramInfo(LPWSTR command_line, LPWSTR exe_path)
{
ULONGLONG start_tick;
-#ifndef PLATFORM_UNIX
- time_t tv;
-#else
struct timeval tv;
-#endif
if (WideCharToMultiByte(CP_ACP, 0, command_line, -1,
program_info.command_line, PAL_PERF_MAX_LOGLINE-1, NULL, NULL) == 0)
@@ -299,23 +249,14 @@ PERFInitProgramInfo(LPWSTR command_line, LPWSTR exe_path)
gethostname(program_info.hostname, PAL_PERF_MAX_FUNCTION_NAME);
program_info.process_id = getpid();
-#ifndef PLATFORM_UNIX
- time( &tv );
- strcpy(program_info.start_time, ctime( &tv ));
-#else
gettimeofday(&tv, NULL);
ctime_r(&tv.tv_sec, program_info.start_time);
-#endif
// estimate the cpu clock cycles
start_tick = PERFGetTicks();
if (start_tick != 0)
{
-#ifndef PLATFORM_UNIX
- Sleep(1000); //Sleep on Windows takes milliseconds as argument
-#else
sleep(1);
-#endif
program_info.cpu_clock_frequency = (double) (PERFGetTicks() - start_tick);
}
else
@@ -379,13 +320,8 @@ PERFInitialize(LPWSTR command_line, LPWSTR exe_path)
pal_profile_on = FALSE; // turn it off until we setup everything.
// allocate the TLS index for structures
-#ifndef PLATFORM_UNIX
- if( ( PERF_tlsTableKey = TlsAlloc() ) == -1 )
- ret = FALSE;
-#else
if( pthread_key_create(&PERF_tlsTableKey , NULL) != 0 )
ret = FALSE;
-#endif
if( ret == TRUE )
{
@@ -399,11 +335,7 @@ PERFInitialize(LPWSTR command_line, LPWSTR exe_path)
else
{
-#ifndef PLATFORM_UNIX
- TlsFree(PERF_tlsTableKey );
-#else
pthread_key_delete(PERF_tlsTableKey );
-#endif
ret = FALSE;
}
}
@@ -426,11 +358,7 @@ void PERFTerminate( )
return;
PERFlushAllLogs();
-#ifndef PLATFORM_UNIX
- TlsFree(PERF_tlsTableKey );
-#else
- pthread_key_delete(PERF_tlsTableKey );
-#endif
+ pthread_key_delete(PERF_tlsTableKey );
PAL_free(pal_function_map);
}
@@ -516,13 +444,8 @@ BOOL PERFAllocThreadInfo( )
local_info->start_ticks = 0;
memset(log_buf, 0, PAL_PERF_PROFILE_BUFFER_SIZE);
-#ifndef PLATFORM_UNIX
- if ( TlsSetValue(PERF_tlsTableKey, local_info) == 0)
- ret = FALSE;
-#else
if (pthread_setspecific(PERF_tlsTableKey, local_info) != 0)
ret = FALSE;
-#endif
PERFAllocThreadInfoExit:
if (ret == TRUE)
@@ -799,11 +722,7 @@ PERFReadSetting( )
char * pal_perf_histogram_size_env;
char * pal_perf_histogram_step_env;
-#ifdef PLATFORM_UNIX
PAL_FILE * hFile;
-#else
- FILE * hFile;
-#endif
if((pal_function_map == NULL) || (PAL_API_NUMBER < 0) )
{
@@ -936,11 +855,7 @@ PERFReadSetting( )
if(input_file_name)
{
-#ifdef PLATFORM_UNIX
hFile = PAL_fopen(input_file_name, "r+");
-#else
- hFile = fopen(input_file_name, "r+");
-#endif
if ( hFile == NULL )
{
memset(pal_function_map, 1, PAL_API_NUMBER);
@@ -979,11 +894,7 @@ PERFReadSetting( )
}
-#ifdef PLATFORM_UNIX
PAL_fclose(hFile);
-#else
- fclose(hFile);
-#endif
ret = TRUE;
}
}
@@ -1031,11 +942,7 @@ PERFReadSetting( )
return ret;
}
-#ifdef PLATFORM_UNIX
hFile = PAL_fopen(input_file_name, "r+");
-#else
- hFile = fopen(input_file_name, "r+");
-#endif
if ( hFile != NULL )
{
@@ -1065,11 +972,7 @@ PERFReadSetting( )
}
}
-#ifdef PLATFORM_UNIX
PAL_fclose(hFile);
-#else
- fclose(hFile);
-#endif
}
return ret;
@@ -1126,13 +1029,7 @@ PERFLogFunctionEntry(unsigned int pal_api_id, ULONGLONG *pal_perf_start_tick )
short bufused = 0;
-#ifndef PLATFORM_UNIX
- DWORD tv;
- DWORD last_error;
- last_error = GetLastError();
-#else
struct timeval tv;
-#endif
if(!pal_perf_enabled || pal_function_map==NULL || !pal_profile_on ) // haven't initialize, just quit.
@@ -1163,28 +1060,17 @@ PERFLogFunctionEntry(unsigned int pal_api_id, ULONGLONG *pal_perf_start_tick )
PERFFlushLog(local_info, FALSE);
}
-#ifndef PLATFORM_UNIX
- tv = GetTickCount();
-#else
gettimeofday(&tv, NULL);
-#endif
buf_off = local_info->buf_offset;
-#ifndef PLATFORM_UNIX
- bufused = snprintf(&write_buf[buf_off], PAL_PERF_MAX_LOGLINE, "----> %d %lu entry.\n", pal_api_id, tv );
-#else
bufused = snprintf(&write_buf[buf_off], PAL_PERF_MAX_LOGLINE, "----> %d %lu %06u entry.\n", pal_api_id, tv.tv_sec, tv.tv_usec );
-#endif
local_info->buf_offset += bufused;
}
if(nested_tracing)
local_info->profile_enabled = TRUE;
*pal_perf_start_tick = PERFGetTicks();
}
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
return;
}
@@ -1223,14 +1109,8 @@ PERFLogFunctionExit(unsigned int pal_api_id, ULONGLONG *pal_perf_start_tick )
short bufused = 0;
DWORD off;
ULONGLONG duration = 0;
-#ifndef PLATFORM_UNIX
- DWORD timev;
- DWORD last_error;
- last_error = GetLastError();
-#else
struct timeval timev;
-#endif
if(!pal_perf_enabled || (pal_function_map == NULL) || !pal_profile_on ) // haven't initiallize yet, just quit.
return;
@@ -1257,17 +1137,10 @@ PERFLogFunctionExit(unsigned int pal_api_id, ULONGLONG *pal_perf_start_tick )
if(summary_only)
{
local_info->profile_enabled = TRUE;
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
return;
}
-#ifndef PLATFORM_UNIX
- timev = GetTickCount();
-#else
gettimeofday(&timev, NULL);
-#endif
buf = local_info->pal_write_buf;
if(local_info->buf_offset >= PAL_PERF_BUFFER_FULL)
@@ -1276,17 +1149,10 @@ PERFLogFunctionExit(unsigned int pal_api_id, ULONGLONG *pal_perf_start_tick )
}
off = local_info->buf_offset;
-#ifndef PLATFORM_UNIX
- bufused = snprintf(&buf[off], PAL_PERF_MAX_LOGLINE, "<---- %d %lu exit. \n", pal_api_id, timev);
-#else
bufused = snprintf(&buf[off], PAL_PERF_MAX_LOGLINE, "<---- %d %lu %06u exit. \n", pal_api_id, timev.tv_sec, timev.tv_usec );
-#endif
local_info->buf_offset += bufused;
local_info->profile_enabled = TRUE;
}
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
return;
}
@@ -1295,10 +1161,6 @@ PERFNoLatencyProfileEntry(unsigned int pal_api_id )
{
pal_perf_thread_info * local_info=NULL;
pal_perf_api_info * table;
-#ifndef PLATFORM_UNIX
- DWORD last_error;
- last_error = GetLastError();
-#endif
if(!pal_perf_enabled || pal_function_map==NULL || !pal_profile_on ) // haven't initialize, just quit.
return;
@@ -1307,9 +1169,6 @@ PERFNoLatencyProfileEntry(unsigned int pal_api_id )
local_info= (pal_perf_thread_info * )pthread_getspecific(PERF_tlsTableKey);
if (local_info==NULL )
{
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
return;
}
else{
@@ -1317,9 +1176,6 @@ PERFNoLatencyProfileEntry(unsigned int pal_api_id )
table[pal_api_id].entries++;
}
}
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
return;
}
@@ -1328,10 +1184,6 @@ void
PERFEnableThreadProfile(BOOL isInternal)
{
pal_perf_thread_info * local_info;
-#ifndef PLATFORM_UNIX
- DWORD last_error;
- last_error = GetLastError();
-#endif
if (!pal_perf_enabled)
return;
if (NULL != (local_info = (pal_perf_thread_info*)pthread_getspecific(PERF_tlsTableKey)))
@@ -1341,9 +1193,6 @@ PERFEnableThreadProfile(BOOL isInternal)
local_info->start_ticks = PERFGetTicks();
}
}
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
}
@@ -1351,10 +1200,6 @@ void
PERFDisableThreadProfile(BOOL isInternal)
{
pal_perf_thread_info * local_info;
-#ifndef PLATFORM_UNIX
- DWORD last_error;
- last_error = GetLastError();
-#endif
if (!pal_perf_enabled)
return;
if (NULL != (local_info = (pal_perf_thread_info*)pthread_getspecific(PERF_tlsTableKey)))
@@ -1364,9 +1209,6 @@ PERFDisableThreadProfile(BOOL isInternal)
local_info->total_duration = PERFGetTicks() - local_info->start_ticks;
}
}
-#ifndef PLATFORM_UNIX
- SetLastError( last_error );
-#endif
}
@@ -1406,29 +1248,17 @@ static
char *
PERFIsValidPath( const char * path )
{
-#ifndef PLATFORM_UNIX
- DWORD result;
-#else
DIR * dir;
-#endif
if(( path==NULL) || (strlen(path)==0))
return NULL;
-#ifndef PLATFORM_UNIX
- result = GetFileAttributesA( path );
- if ((result != INVALID_FILE_ATTRIBUTES) && (result & FILE_ATTRIBUTE_DIRECTORY))
- {
- return ((char *) path );
- }
-#else
dir = opendir(path);
if( dir!=NULL)
{
closedir(dir);
return ((char *)path);
}
-#endif
return NULL;
}
@@ -1508,13 +1338,6 @@ PAL_GetCpuTickCount(VOID)
return PERFGetTicks();
}
-#ifndef PLATFORM_UNIX
-#undef snprintf
-#undef MiscGetenv
-#undef pthread_key_t
-#undef pthread_getspecific
-#endif /* ifndef PLATFORM_UNIX definitions */
-
#endif /* PAL_PERF */
diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp
index e7589e8583..3ccb35ab81 100644
--- a/src/pal/src/misc/sysinfo.cpp
+++ b/src/pal/src/misc/sysinfo.cpp
@@ -76,11 +76,6 @@ Revision History:
SET_DEFAULT_DEBUG_CHANNEL(MISC);
-#if defined(_HPUX_) && ( defined (_IA64_) || defined (__hppa__) )
-#include <sys/pstat.h>
-#include <sys/vmparam.h>
-#endif
-
#ifndef __APPLE__
#if HAVE_SYSCONF && HAVE__SC_AVPHYS_PAGES
#define SYSCONF_PAGES _SC_AVPHYS_PAGES
@@ -135,22 +130,11 @@ GetSystemInfo(
lpSystemInfo->dwActiveProcessorMask_PAL_Undefined = 0;
#if HAVE_SYSCONF
-#if defined(_HPUX_) && ( defined (_IA64_) || defined (__hppa__) )
- struct pst_dynamic psd;
- if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1) {
- nrcpus = psd.psd_proc_cnt;
- }
- else {
- ASSERT("pstat_getdynamic failed (%d)\n", errno);
- }
-
-#else // !__hppa__
nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
if (nrcpus < 1)
{
ASSERT("sysconf failed for _SC_NPROCESSORS_ONLN (%d)\n", errno);
}
-#endif // __hppa__
#elif HAVE_SYSCTL
int rc;
size_t sz;
@@ -171,7 +155,7 @@ GetSystemInfo(
#ifdef VM_MAXUSER_ADDRESS
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) VM_MAXUSER_ADDRESS;
-#elif defined(__sun__) || defined(_AIX) || defined(__hppa__) || ( defined (_IA64_) && defined (_HPUX_) ) || defined(__linux__)
+#elif defined(__linux__)
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47);
#elif defined(USERLIMIT)
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) USERLIMIT;
diff --git a/src/pal/src/misc/utils.cpp b/src/pal/src/misc/utils.cpp
index 1e333d19ac..f0ff63439f 100644
--- a/src/pal/src/misc/utils.cpp
+++ b/src/pal/src/misc/utils.cpp
@@ -18,21 +18,21 @@ Abstract:
--*/
+#include "pal/dbgmsg.h"
+SET_DEFAULT_DEBUG_CHANNEL(MISC); // some headers have code with asserts, so do this first
+
#include "pal/palinternal.h"
#if HAVE_VM_ALLOCATE
#include <mach/message.h>
#endif //HAVE_VM_ALLOCATE
#include "pal/utils.h"
-#include "pal/dbgmsg.h"
#include "pal/file.h"
#include <errno.h>
#include <string.h>
-SET_DEFAULT_DEBUG_CHANNEL(MISC);
-
// In safemath.h, Template SafeInt uses macro _ASSERTE, which need to use variable
// defdbgchan defined by SET_DEFAULT_DEBUG_CHANNEL. Therefore, the include statement
// should be placed after the SET_DEFAULT_DEBUG_CHANNEL(MISC)