forked from OSchip/llvm-project
Replace some unsafe API calls with safe alternatives on Windows, prepare code for similar actions on other platforms - wrap unsafe API calls into macros.
llvm-svn: 233915
This commit is contained in:
parent
1362ae750f
commit
74bf17b8ff
|
@ -139,8 +139,8 @@ private:
|
||||||
data = new char[length = _length];
|
data = new char[length = _length];
|
||||||
}
|
}
|
||||||
*(unsigned*)data = length;
|
*(unsigned*)data = length;
|
||||||
memcpy(data + sizeof(unsigned), _data + sizeof(unsigned),
|
KMP_MEMCPY(data + sizeof(unsigned), _data + sizeof(unsigned),
|
||||||
length - sizeof(unsigned));
|
length - sizeof(unsigned));
|
||||||
makeDirectory();
|
makeDirectory();
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -192,7 +192,7 @@ public:
|
||||||
size_t l = str.size();
|
size_t l = str.size();
|
||||||
if(l > 8) {
|
if(l > 8) {
|
||||||
directory.insert(make_pair(str, p - data));
|
directory.insert(make_pair(str, p - data));
|
||||||
memcpy(p, str.c_str(), l);
|
KMP_MEMCPY(p, str.c_str(), l);
|
||||||
p[l] = 0;
|
p[l] = 0;
|
||||||
p += l + 1;
|
p += l + 1;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ public:
|
||||||
if(str.size() <= 8) {
|
if(str.size() <= 8) {
|
||||||
// encoded directly
|
// encoded directly
|
||||||
((char*)&r)[7] = 0;
|
((char*)&r)[7] = 0;
|
||||||
strncpy((char*)&r, str.c_str(), 8);
|
KMP_STRNCPY_S((char*)&r, sizeof(r), str.c_str(), 8);
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
// represented as index into table
|
// represented as index into table
|
||||||
|
|
|
@ -41,13 +41,13 @@ __kmp_affinity_print_mask(char *buf, int buf_len, kmp_affin_mask_t *mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == KMP_CPU_SETSIZE) {
|
if (i == KMP_CPU_SETSIZE) {
|
||||||
sprintf(scan, "{<empty>}");
|
KMP_SNPRINTF(scan, buf_len, "{<empty>}");
|
||||||
while (*scan != '\0') scan++;
|
while (*scan != '\0') scan++;
|
||||||
KMP_ASSERT(scan <= end);
|
KMP_ASSERT(scan <= end);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(scan, "{%ld", (long)i);
|
KMP_SNPRINTF(scan, buf_len, "{%ld", (long)i);
|
||||||
while (*scan != '\0') scan++;
|
while (*scan != '\0') scan++;
|
||||||
i++;
|
i++;
|
||||||
for (; i < KMP_CPU_SETSIZE; i++) {
|
for (; i < KMP_CPU_SETSIZE; i++) {
|
||||||
|
@ -64,14 +64,14 @@ __kmp_affinity_print_mask(char *buf, int buf_len, kmp_affin_mask_t *mask)
|
||||||
if (end - scan < 15) {
|
if (end - scan < 15) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sprintf(scan, ",%-ld", (long)i);
|
KMP_SNPRINTF(scan, buf_len, ",%-ld", (long)i);
|
||||||
while (*scan != '\0') scan++;
|
while (*scan != '\0') scan++;
|
||||||
}
|
}
|
||||||
if (i < KMP_CPU_SETSIZE) {
|
if (i < KMP_CPU_SETSIZE) {
|
||||||
sprintf(scan, ",...");
|
KMP_SNPRINTF(scan, buf_len, ",...");
|
||||||
while (*scan != '\0') scan++;
|
while (*scan != '\0') scan++;
|
||||||
}
|
}
|
||||||
sprintf(scan, "}");
|
KMP_SNPRINTF(scan, buf_len, "}");
|
||||||
while (*scan != '\0') scan++;
|
while (*scan != '\0') scan++;
|
||||||
KMP_ASSERT(scan <= end);
|
KMP_ASSERT(scan <= end);
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -1849,7 +1849,7 @@ __kmp_affinity_create_cpuinfo_map(AddrUnsPair **address2os, int *line,
|
||||||
// FIXME - this will match "node_<n> <garbage>"
|
// FIXME - this will match "node_<n> <garbage>"
|
||||||
//
|
//
|
||||||
unsigned level;
|
unsigned level;
|
||||||
if (sscanf(buf, "node_%d id", &level) == 1) {
|
if (KMP_SSCANF(buf, "node_%d id", &level) == 1) {
|
||||||
if (nodeIdIndex + level >= maxIndex) {
|
if (nodeIdIndex + level >= maxIndex) {
|
||||||
maxIndex = nodeIdIndex + level;
|
maxIndex = nodeIdIndex + level;
|
||||||
}
|
}
|
||||||
|
@ -1968,17 +1968,17 @@ __kmp_affinity_create_cpuinfo_map(AddrUnsPair **address2os, int *line,
|
||||||
CHECK_LINE;
|
CHECK_LINE;
|
||||||
char *p = strchr(buf + sizeof(s1) - 1, ':');
|
char *p = strchr(buf + sizeof(s1) - 1, ':');
|
||||||
unsigned val;
|
unsigned val;
|
||||||
if ((p == NULL) || (sscanf(p + 1, "%u\n", &val) != 1)) goto no_val;
|
if ((p == NULL) || (KMP_SSCANF(p + 1, "%u\n", &val) != 1)) goto no_val;
|
||||||
if (threadInfo[num_avail][osIdIndex] != UINT_MAX) goto dup_field;
|
if (threadInfo[num_avail][osIdIndex] != UINT_MAX) goto dup_field;
|
||||||
threadInfo[num_avail][osIdIndex] = val;
|
threadInfo[num_avail][osIdIndex] = val;
|
||||||
#if KMP_OS_LINUX && USE_SYSFS_INFO
|
#if KMP_OS_LINUX && USE_SYSFS_INFO
|
||||||
char path[256];
|
char path[256];
|
||||||
snprintf(path, sizeof(path),
|
KMP_SNPRINTF(path, sizeof(path),
|
||||||
"/sys/devices/system/cpu/cpu%u/topology/physical_package_id",
|
"/sys/devices/system/cpu/cpu%u/topology/physical_package_id",
|
||||||
threadInfo[num_avail][osIdIndex]);
|
threadInfo[num_avail][osIdIndex]);
|
||||||
__kmp_read_from_file(path, "%u", &threadInfo[num_avail][pkgIdIndex]);
|
__kmp_read_from_file(path, "%u", &threadInfo[num_avail][pkgIdIndex]);
|
||||||
|
|
||||||
snprintf(path, sizeof(path),
|
KMP_SNPRINTF(path, sizeof(path),
|
||||||
"/sys/devices/system/cpu/cpu%u/topology/core_id",
|
"/sys/devices/system/cpu/cpu%u/topology/core_id",
|
||||||
threadInfo[num_avail][osIdIndex]);
|
threadInfo[num_avail][osIdIndex]);
|
||||||
__kmp_read_from_file(path, "%u", &threadInfo[num_avail][coreIdIndex]);
|
__kmp_read_from_file(path, "%u", &threadInfo[num_avail][coreIdIndex]);
|
||||||
|
@ -1990,7 +1990,7 @@ __kmp_affinity_create_cpuinfo_map(AddrUnsPair **address2os, int *line,
|
||||||
CHECK_LINE;
|
CHECK_LINE;
|
||||||
char *p = strchr(buf + sizeof(s2) - 1, ':');
|
char *p = strchr(buf + sizeof(s2) - 1, ':');
|
||||||
unsigned val;
|
unsigned val;
|
||||||
if ((p == NULL) || (sscanf(p + 1, "%u\n", &val) != 1)) goto no_val;
|
if ((p == NULL) || (KMP_SSCANF(p + 1, "%u\n", &val) != 1)) goto no_val;
|
||||||
if (threadInfo[num_avail][pkgIdIndex] != UINT_MAX) goto dup_field;
|
if (threadInfo[num_avail][pkgIdIndex] != UINT_MAX) goto dup_field;
|
||||||
threadInfo[num_avail][pkgIdIndex] = val;
|
threadInfo[num_avail][pkgIdIndex] = val;
|
||||||
continue;
|
continue;
|
||||||
|
@ -2000,7 +2000,7 @@ __kmp_affinity_create_cpuinfo_map(AddrUnsPair **address2os, int *line,
|
||||||
CHECK_LINE;
|
CHECK_LINE;
|
||||||
char *p = strchr(buf + sizeof(s3) - 1, ':');
|
char *p = strchr(buf + sizeof(s3) - 1, ':');
|
||||||
unsigned val;
|
unsigned val;
|
||||||
if ((p == NULL) || (sscanf(p + 1, "%u\n", &val) != 1)) goto no_val;
|
if ((p == NULL) || (KMP_SSCANF(p + 1, "%u\n", &val) != 1)) goto no_val;
|
||||||
if (threadInfo[num_avail][coreIdIndex] != UINT_MAX) goto dup_field;
|
if (threadInfo[num_avail][coreIdIndex] != UINT_MAX) goto dup_field;
|
||||||
threadInfo[num_avail][coreIdIndex] = val;
|
threadInfo[num_avail][coreIdIndex] = val;
|
||||||
continue;
|
continue;
|
||||||
|
@ -2011,17 +2011,17 @@ __kmp_affinity_create_cpuinfo_map(AddrUnsPair **address2os, int *line,
|
||||||
CHECK_LINE;
|
CHECK_LINE;
|
||||||
char *p = strchr(buf + sizeof(s4) - 1, ':');
|
char *p = strchr(buf + sizeof(s4) - 1, ':');
|
||||||
unsigned val;
|
unsigned val;
|
||||||
if ((p == NULL) || (sscanf(p + 1, "%u\n", &val) != 1)) goto no_val;
|
if ((p == NULL) || (KMP_SSCANF(p + 1, "%u\n", &val) != 1)) goto no_val;
|
||||||
if (threadInfo[num_avail][threadIdIndex] != UINT_MAX) goto dup_field;
|
if (threadInfo[num_avail][threadIdIndex] != UINT_MAX) goto dup_field;
|
||||||
threadInfo[num_avail][threadIdIndex] = val;
|
threadInfo[num_avail][threadIdIndex] = val;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned level;
|
unsigned level;
|
||||||
if (sscanf(buf, "node_%d id", &level) == 1) {
|
if (KMP_SSCANF(buf, "node_%d id", &level) == 1) {
|
||||||
CHECK_LINE;
|
CHECK_LINE;
|
||||||
char *p = strchr(buf + sizeof(s4) - 1, ':');
|
char *p = strchr(buf + sizeof(s4) - 1, ':');
|
||||||
unsigned val;
|
unsigned val;
|
||||||
if ((p == NULL) || (sscanf(p + 1, "%u\n", &val) != 1)) goto no_val;
|
if ((p == NULL) || (KMP_SSCANF(p + 1, "%u\n", &val) != 1)) goto no_val;
|
||||||
KMP_ASSERT(nodeIdIndex + level <= maxIndex);
|
KMP_ASSERT(nodeIdIndex + level <= maxIndex);
|
||||||
if (threadInfo[num_avail][nodeIdIndex + level] != UINT_MAX) goto dup_field;
|
if (threadInfo[num_avail][nodeIdIndex + level] != UINT_MAX) goto dup_field;
|
||||||
threadInfo[num_avail][nodeIdIndex + level] = val;
|
threadInfo[num_avail][nodeIdIndex + level] = val;
|
||||||
|
@ -2591,7 +2591,7 @@ __kmp_create_masks(unsigned *maxIndex, unsigned *numUnique,
|
||||||
unsigned leader = 0;
|
unsigned leader = 0;
|
||||||
Address *leaderAddr = &(address2os[0].first);
|
Address *leaderAddr = &(address2os[0].first);
|
||||||
kmp_affin_mask_t *sum
|
kmp_affin_mask_t *sum
|
||||||
= (kmp_affin_mask_t *)alloca(__kmp_affin_mask_size);
|
= (kmp_affin_mask_t *)KMP_ALLOCA(__kmp_affin_mask_size);
|
||||||
KMP_CPU_ZERO(sum);
|
KMP_CPU_ZERO(sum);
|
||||||
KMP_CPU_SET(address2os[0].second, sum);
|
KMP_CPU_SET(address2os[0].second, sum);
|
||||||
for (i = 1; i < numAddrs; i++) {
|
for (i = 1; i < numAddrs; i++) {
|
||||||
|
@ -2913,7 +2913,7 @@ __kmp_affinity_process_proclist(kmp_affin_mask_t **out_masks,
|
||||||
}
|
}
|
||||||
*out_masks
|
*out_masks
|
||||||
= (kmp_affin_mask_t *)__kmp_allocate(nextNewMask * __kmp_affin_mask_size);
|
= (kmp_affin_mask_t *)__kmp_allocate(nextNewMask * __kmp_affin_mask_size);
|
||||||
memcpy(*out_masks, newMasks, nextNewMask * __kmp_affin_mask_size);
|
KMP_MEMCPY(*out_masks, newMasks, nextNewMask * __kmp_affin_mask_size);
|
||||||
__kmp_free(sumMask);
|
__kmp_free(sumMask);
|
||||||
KMP_INTERNAL_FREE(newMasks);
|
KMP_INTERNAL_FREE(newMasks);
|
||||||
}
|
}
|
||||||
|
@ -3319,7 +3319,7 @@ __kmp_affinity_process_placelist(kmp_affin_mask_t **out_masks,
|
||||||
}
|
}
|
||||||
*out_masks
|
*out_masks
|
||||||
= (kmp_affin_mask_t *)__kmp_allocate(nextNewMask * __kmp_affin_mask_size);
|
= (kmp_affin_mask_t *)__kmp_allocate(nextNewMask * __kmp_affin_mask_size);
|
||||||
memcpy(*out_masks, newMasks, nextNewMask * __kmp_affin_mask_size);
|
KMP_MEMCPY(*out_masks, newMasks, nextNewMask * __kmp_affin_mask_size);
|
||||||
__kmp_free(tempMask);
|
__kmp_free(tempMask);
|
||||||
KMP_INTERNAL_FREE(newMasks);
|
KMP_INTERNAL_FREE(newMasks);
|
||||||
}
|
}
|
||||||
|
@ -4398,7 +4398,7 @@ void __kmp_balanced_affinity( int tid, int nthreads )
|
||||||
KMP_DEBUG_ASSERT2(KMP_AFFINITY_CAPABLE(),
|
KMP_DEBUG_ASSERT2(KMP_AFFINITY_CAPABLE(),
|
||||||
"Illegal set affinity operation when not capable");
|
"Illegal set affinity operation when not capable");
|
||||||
|
|
||||||
kmp_affin_mask_t *mask = (kmp_affin_mask_t *)alloca(__kmp_affin_mask_size);
|
kmp_affin_mask_t *mask = (kmp_affin_mask_t *)KMP_ALLOCA(__kmp_affin_mask_size);
|
||||||
KMP_CPU_ZERO(mask);
|
KMP_CPU_ZERO(mask);
|
||||||
|
|
||||||
// Granularity == thread
|
// Granularity == thread
|
||||||
|
@ -4421,7 +4421,7 @@ void __kmp_balanced_affinity( int tid, int nthreads )
|
||||||
__kmp_set_system_affinity( mask, TRUE );
|
__kmp_set_system_affinity( mask, TRUE );
|
||||||
} else { // Non-uniform topology
|
} else { // Non-uniform topology
|
||||||
|
|
||||||
kmp_affin_mask_t *mask = (kmp_affin_mask_t *)alloca(__kmp_affin_mask_size);
|
kmp_affin_mask_t *mask = (kmp_affin_mask_t *)KMP_ALLOCA(__kmp_affin_mask_size);
|
||||||
KMP_CPU_ZERO(mask);
|
KMP_CPU_ZERO(mask);
|
||||||
|
|
||||||
// Number of hyper threads per core in HT machine
|
// Number of hyper threads per core in HT machine
|
||||||
|
|
|
@ -785,7 +785,7 @@ bgetr( kmp_info_t *th, void *buf, bufsize size)
|
||||||
|
|
||||||
KMP_DEBUG_ASSERT(osize > 0);
|
KMP_DEBUG_ASSERT(osize > 0);
|
||||||
|
|
||||||
(void) memcpy((char *) nbuf, (char *) buf, /* Copy the data */
|
(void) KMP_MEMCPY((char *) nbuf, (char *) buf, /* Copy the data */
|
||||||
(size_t) ((size < osize) ? size : osize));
|
(size_t) ((size < osize) ? size : osize));
|
||||||
brel( th, buf );
|
brel( th, buf );
|
||||||
|
|
||||||
|
@ -1178,7 +1178,7 @@ bufdump( kmp_info_t *th, void *buf )
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
(void) sprintf(bhex + i * 3, "%02X ", bdump[i]);
|
(void) KMP_SNPRINTF(bhex + i * 3, sizeof(bhex), "%02X ", bdump[i]);
|
||||||
if (bdump[i] > 0x20 && bdump[i] < 0x7F)
|
if (bdump[i] > 0x20 && bdump[i] < 0x7F)
|
||||||
bascii[ i ] = bdump[ i ];
|
bascii[ i ] = bdump[ i ];
|
||||||
else
|
else
|
||||||
|
|
|
@ -199,7 +199,7 @@ __kmpc_ok_to_fork(ident_t *loc)
|
||||||
return __kmp_par_range < 0;
|
return __kmp_par_range < 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sscanf(semi3 + 1, "%d", &line_no) == 1) {
|
if (KMP_SSCANF(semi3 + 1, "%d", &line_no) == 1) {
|
||||||
if ((line_no >= __kmp_par_range_lb) && (line_no <= __kmp_par_range_ub)) {
|
if ((line_no >= __kmp_par_range_lb) && (line_no <= __kmp_par_range_ub)) {
|
||||||
return __kmp_par_range > 0;
|
return __kmp_par_range > 0;
|
||||||
}
|
}
|
||||||
|
@ -1396,7 +1396,7 @@ void
|
||||||
kmpc_set_defaults( char const * str )
|
kmpc_set_defaults( char const * str )
|
||||||
{
|
{
|
||||||
// __kmp_aux_set_defaults initializes the library if needed
|
// __kmp_aux_set_defaults initializes the library if needed
|
||||||
__kmp_aux_set_defaults( str, strlen( str ) );
|
__kmp_aux_set_defaults( str, KMP_STRLEN( str ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -102,12 +102,12 @@ __kmp_env_get( char const * name ) {
|
||||||
#if KMP_OS_UNIX
|
#if KMP_OS_UNIX
|
||||||
char const * value = getenv( name );
|
char const * value = getenv( name );
|
||||||
if ( value != NULL ) {
|
if ( value != NULL ) {
|
||||||
size_t len = strlen( value ) + 1;
|
size_t len = KMP_STRLEN( value ) + 1;
|
||||||
result = (char *) KMP_INTERNAL_MALLOC( len );
|
result = (char *) KMP_INTERNAL_MALLOC( len );
|
||||||
if ( result == NULL ) {
|
if ( result == NULL ) {
|
||||||
KMP_FATAL( MemoryAllocFailed );
|
KMP_FATAL( MemoryAllocFailed );
|
||||||
}; // if
|
}; // if
|
||||||
strncpy( result, value, len );
|
KMP_STRNCPY_S( result, len, value, len );
|
||||||
}; // if
|
}; // if
|
||||||
#elif KMP_OS_WINDOWS
|
#elif KMP_OS_WINDOWS
|
||||||
/*
|
/*
|
||||||
|
@ -393,19 +393,19 @@ ___kmp_env_blk_parse_windows(
|
||||||
int len; // Length of variable.
|
int len; // Length of variable.
|
||||||
count = 0;
|
count = 0;
|
||||||
var = env; // The first variable starts and beginning of environment block.
|
var = env; // The first variable starts and beginning of environment block.
|
||||||
len = strlen( var );
|
len = KMP_STRLEN( var );
|
||||||
while ( len != 0 ) {
|
while ( len != 0 ) {
|
||||||
++ count;
|
++ count;
|
||||||
size = size + len + 1;
|
size = size + len + 1;
|
||||||
var = var + len + 1; // Move pointer to the beginning of the next variable.
|
var = var + len + 1; // Move pointer to the beginning of the next variable.
|
||||||
len = strlen( var );
|
len = KMP_STRLEN( var );
|
||||||
}; // while
|
}; // while
|
||||||
size = size + 1; // Total size of env block, including terminating zero byte.
|
size = size + 1; // Total size of env block, including terminating zero byte.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy original block to bulk, we will modify bulk, not original block.
|
// Copy original block to bulk, we will modify bulk, not original block.
|
||||||
bulk = (char *) allocate( size );
|
bulk = (char *) allocate( size );
|
||||||
memcpy( bulk, env, size );
|
KMP_MEMCPY_S( bulk, size, env, size );
|
||||||
// Allocate vars array.
|
// Allocate vars array.
|
||||||
vars = (kmp_env_var_t *) allocate( count * sizeof( kmp_env_var_t ) );
|
vars = (kmp_env_var_t *) allocate( count * sizeof( kmp_env_var_t ) );
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ ___kmp_env_blk_parse_windows(
|
||||||
int len; // Length of variable.
|
int len; // Length of variable.
|
||||||
count = 0;
|
count = 0;
|
||||||
var = bulk;
|
var = bulk;
|
||||||
len = strlen( var );
|
len = KMP_STRLEN( var );
|
||||||
while ( len != 0 ) {
|
while ( len != 0 ) {
|
||||||
// Save variable in vars array.
|
// Save variable in vars array.
|
||||||
__kmp_str_split( var, '=', & name, & value );
|
__kmp_str_split( var, '=', & name, & value );
|
||||||
|
@ -424,7 +424,7 @@ ___kmp_env_blk_parse_windows(
|
||||||
++ count;
|
++ count;
|
||||||
// Get the next var.
|
// Get the next var.
|
||||||
var = var + len + 1;
|
var = var + len + 1;
|
||||||
len = strlen( var );
|
len = KMP_STRLEN( var );
|
||||||
}; // while
|
}; // while
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,7 +462,7 @@ ___kmp_env_blk_parse_unix(
|
||||||
count = 0;
|
count = 0;
|
||||||
size = 0;
|
size = 0;
|
||||||
while ( env[ count ] != NULL ) {
|
while ( env[ count ] != NULL ) {
|
||||||
size += strlen( env[ count ] ) + 1;
|
size += KMP_STRLEN( env[ count ] ) + 1;
|
||||||
++ count;
|
++ count;
|
||||||
}; // while
|
}; // while
|
||||||
}
|
}
|
||||||
|
@ -481,8 +481,8 @@ ___kmp_env_blk_parse_unix(
|
||||||
var = bulk;
|
var = bulk;
|
||||||
for ( i = 0; i < count; ++ i ) {
|
for ( i = 0; i < count; ++ i ) {
|
||||||
// Copy variable to bulk.
|
// Copy variable to bulk.
|
||||||
len = strlen( env[ i ] );
|
len = KMP_STRLEN( env[ i ] );
|
||||||
memcpy( var, env[ i ], len + 1 );
|
KMP_MEMCPY_S( var, size, env[ i ], len + 1 );
|
||||||
// Save found variable in vars array.
|
// Save found variable in vars array.
|
||||||
__kmp_str_split( var, '=', & name, & value );
|
__kmp_str_split( var, '=', & name, & value );
|
||||||
vars[ i ].name = name;
|
vars[ i ].name = name;
|
||||||
|
|
|
@ -1046,7 +1046,7 @@ FTN_SET_DEFAULTS( char const * str
|
||||||
{
|
{
|
||||||
#ifndef KMP_STUB
|
#ifndef KMP_STUB
|
||||||
#ifdef PASS_ARGS_BY_VALUE
|
#ifdef PASS_ARGS_BY_VALUE
|
||||||
int len = (int)strlen( str );
|
int len = (int)KMP_STRLEN( str );
|
||||||
#endif
|
#endif
|
||||||
__kmp_aux_set_defaults( str, len );
|
__kmp_aux_set_defaults( str, len );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -699,7 +699,7 @@ xexpand(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data, void (*copy_fu
|
||||||
(*copy_func)(task->shareds, data);
|
(*copy_func)(task->shareds, data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memcpy(task->shareds, data, arg_size);
|
KMP_MEMCPY(task->shareds, data, arg_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -864,7 +864,7 @@ __kmp_msg_error_code(
|
||||||
msg.type = kmp_mt_syserr;
|
msg.type = kmp_mt_syserr;
|
||||||
msg.num = code;
|
msg.num = code;
|
||||||
msg.str = sys_error( code );
|
msg.str = sys_error( code );
|
||||||
msg.len = strlen( msg.str );
|
msg.len = KMP_STRLEN( msg.str );
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
} // __kmp_msg_error_code
|
} // __kmp_msg_error_code
|
||||||
|
@ -880,7 +880,7 @@ __kmp_msg_error_mesg(
|
||||||
msg.type = kmp_mt_syserr;
|
msg.type = kmp_mt_syserr;
|
||||||
msg.num = 0;
|
msg.num = 0;
|
||||||
msg.str = __kmp_str_format( "%s", mesg );
|
msg.str = __kmp_str_format( "%s", mesg );
|
||||||
msg.len = strlen( msg.str );
|
msg.len = KMP_STRLEN( msg.str );
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
} // __kmp_msg_error_mesg
|
} // __kmp_msg_error_mesg
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* kmp_io.c -- RTL IO
|
* KMP_IO.c -- RTL IO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,9 +169,9 @@ __kmp_vprintf( enum kmp_io __kmp_io, char const * format, va_list ap )
|
||||||
int chars = 0;
|
int chars = 0;
|
||||||
|
|
||||||
#ifdef KMP_DEBUG_PIDS
|
#ifdef KMP_DEBUG_PIDS
|
||||||
chars = sprintf( db, "pid=%d: ", (kmp_int32)getpid() );
|
chars = KMP_SNPRINTF( db, __kmp_debug_buf_chars, "pid=%d: ", (kmp_int32)getpid() );
|
||||||
#endif
|
#endif
|
||||||
chars += vsprintf( db, format, ap );
|
chars += KMP_VSNPRINTF( db, __kmp_debug_buf_chars, format, ap );
|
||||||
|
|
||||||
if ( chars + 1 > __kmp_debug_buf_chars ) {
|
if ( chars + 1 > __kmp_debug_buf_chars ) {
|
||||||
if ( chars + 1 > __kmp_debug_buf_warn_chars ) {
|
if ( chars + 1 > __kmp_debug_buf_warn_chars ) {
|
||||||
|
|
|
@ -1130,9 +1130,9 @@ __kmp_set_ticket_lock_flags( kmp_ticket_lock_t *lck, kmp_lock_flags_t flags )
|
||||||
#define TRACE_BUF_ELE 1024
|
#define TRACE_BUF_ELE 1024
|
||||||
static char traces[TRACE_BUF_ELE][128] = { 0 }
|
static char traces[TRACE_BUF_ELE][128] = { 0 }
|
||||||
static int tc = 0;
|
static int tc = 0;
|
||||||
#define TRACE_LOCK(X,Y) sprintf( traces[tc++ % TRACE_BUF_ELE], "t%d at %s\n", X, Y );
|
#define TRACE_LOCK(X,Y) KMP_SNPRINTF( traces[tc++ % TRACE_BUF_ELE], 128, "t%d at %s\n", X, Y );
|
||||||
#define TRACE_LOCK_T(X,Y,Z) sprintf( traces[tc++ % TRACE_BUF_ELE], "t%d at %s%d\n", X,Y,Z );
|
#define TRACE_LOCK_T(X,Y,Z) KMP_SNPRINTF( traces[tc++ % TRACE_BUF_ELE], 128, "t%d at %s%d\n", X,Y,Z );
|
||||||
#define TRACE_LOCK_HT(X,Y,Z,Q) sprintf( traces[tc++ % TRACE_BUF_ELE], "t%d at %s %d,%d\n", X, Y, Z, Q );
|
#define TRACE_LOCK_HT(X,Y,Z,Q) KMP_SNPRINTF( traces[tc++ % TRACE_BUF_ELE], 128, "t%d at %s %d,%d\n", X, Y, Z, Q );
|
||||||
|
|
||||||
static void
|
static void
|
||||||
__kmp_dump_queuing_lock( kmp_info_t *this_thr, kmp_int32 gtid,
|
__kmp_dump_queuing_lock( kmp_info_t *this_thr, kmp_int32 gtid,
|
||||||
|
@ -2035,9 +2035,9 @@ FILE * __kmp_open_stats_file()
|
||||||
if (strcmp (__kmp_speculative_statsfile, "-") == 0)
|
if (strcmp (__kmp_speculative_statsfile, "-") == 0)
|
||||||
return stdout;
|
return stdout;
|
||||||
|
|
||||||
size_t buffLen = strlen( __kmp_speculative_statsfile ) + 20;
|
size_t buffLen = KMP_STRLEN( __kmp_speculative_statsfile ) + 20;
|
||||||
char buffer[buffLen];
|
char buffer[buffLen];
|
||||||
snprintf (&buffer[0], buffLen, __kmp_speculative_statsfile,
|
KMP_SNPRINTF (&buffer[0], buffLen, __kmp_speculative_statsfile,
|
||||||
(kmp_int32)getpid());
|
(kmp_int32)getpid());
|
||||||
FILE * result = fopen(&buffer[0], "w");
|
FILE * result = fopen(&buffer[0], "w");
|
||||||
|
|
||||||
|
@ -3147,7 +3147,7 @@ __kmp_insert_indirect_lock(kmp_indirect_lock_t *lck)
|
||||||
kmp_lock_index_t size = __kmp_indirect_lock_table_size;
|
kmp_lock_index_t size = __kmp_indirect_lock_table_size;
|
||||||
kmp_indirect_lock_t **old_table = __kmp_indirect_lock_table;
|
kmp_indirect_lock_t **old_table = __kmp_indirect_lock_table;
|
||||||
__kmp_indirect_lock_table = (kmp_indirect_lock_t **)__kmp_allocate(2*next*sizeof(kmp_indirect_lock_t *));
|
__kmp_indirect_lock_table = (kmp_indirect_lock_t **)__kmp_allocate(2*next*sizeof(kmp_indirect_lock_t *));
|
||||||
memcpy(__kmp_indirect_lock_table, old_table, next*sizeof(kmp_indirect_lock_t *));
|
KMP_MEMCPY(__kmp_indirect_lock_table, old_table, next*sizeof(kmp_indirect_lock_t *));
|
||||||
__kmp_free(old_table);
|
__kmp_free(old_table);
|
||||||
__kmp_indirect_lock_table_size = 2*next;
|
__kmp_indirect_lock_table_size = 2*next;
|
||||||
}
|
}
|
||||||
|
@ -3826,7 +3826,7 @@ __kmp_lock_table_insert( kmp_user_lock_p lck )
|
||||||
size = __kmp_user_lock_table.allocated * 2;
|
size = __kmp_user_lock_table.allocated * 2;
|
||||||
}
|
}
|
||||||
table = (kmp_user_lock_p *)__kmp_allocate( sizeof( kmp_user_lock_p ) * size );
|
table = (kmp_user_lock_p *)__kmp_allocate( sizeof( kmp_user_lock_p ) * size );
|
||||||
memcpy( table + 1, __kmp_user_lock_table.table + 1, sizeof( kmp_user_lock_p ) * ( __kmp_user_lock_table.used - 1 ) );
|
KMP_MEMCPY( table + 1, __kmp_user_lock_table.table + 1, sizeof( kmp_user_lock_p ) * ( __kmp_user_lock_table.used - 1 ) );
|
||||||
table[ 0 ] = (kmp_user_lock_p)__kmp_user_lock_table.table;
|
table[ 0 ] = (kmp_user_lock_p)__kmp_user_lock_table.table;
|
||||||
// We cannot free the previos table now, sinse it may be in use by other
|
// We cannot free the previos table now, sinse it may be in use by other
|
||||||
// threads. So save the pointer to the previous table in in the first element of the
|
// threads. So save the pointer to the previous table in in the first element of the
|
||||||
|
|
|
@ -850,3 +850,6 @@ enum kmp_warnings_level {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
#endif /* KMP_OS_H */
|
#endif /* KMP_OS_H */
|
||||||
|
// Safe C API
|
||||||
|
#include "kmp_safe_c_api.h"
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ __kmp_print_storage_map_gtid( int gtid, void *p1, void *p2, size_t size, char co
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start( ap, format);
|
va_start( ap, format);
|
||||||
sprintf( buffer, "OMP storage map: %p %p%8lu %s\n", p1, p2, (unsigned long) size, format );
|
KMP_SNPRINTF( buffer, sizeof(buffer), "OMP storage map: %p %p%8lu %s\n", p1, p2, (unsigned long) size, format );
|
||||||
__kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
|
__kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
|
||||||
__kmp_vprintf( kmp_err, buffer, ap );
|
__kmp_vprintf( kmp_err, buffer, ap );
|
||||||
#if KMP_PRINT_DATA_PLACEMENT
|
#if KMP_PRINT_DATA_PLACEMENT
|
||||||
|
@ -387,7 +387,7 @@ __kmp_warn( char const * format, ... )
|
||||||
|
|
||||||
va_start( ap, format );
|
va_start( ap, format );
|
||||||
|
|
||||||
snprintf( buffer, sizeof(buffer) , "OMP warning: %s\n", format );
|
KMP_SNPRINTF( buffer, sizeof(buffer) , "OMP warning: %s\n", format );
|
||||||
__kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
|
__kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
|
||||||
__kmp_vprintf( kmp_err, buffer, ap );
|
__kmp_vprintf( kmp_err, buffer, ap );
|
||||||
__kmp_release_bootstrap_lock( & __kmp_stdio_lock );
|
__kmp_release_bootstrap_lock( & __kmp_stdio_lock );
|
||||||
|
@ -1458,7 +1458,7 @@ __kmp_fork_call(
|
||||||
if ( __kmp_stkpadding > 0 && __kmp_root[gtid] != NULL ) {
|
if ( __kmp_stkpadding > 0 && __kmp_root[gtid] != NULL ) {
|
||||||
/* Some systems prefer the stack for the root thread(s) to start with */
|
/* Some systems prefer the stack for the root thread(s) to start with */
|
||||||
/* some gap from the parent stack to prevent false sharing. */
|
/* some gap from the parent stack to prevent false sharing. */
|
||||||
void *dummy = alloca(__kmp_stkpadding);
|
void *dummy = KMP_ALLOCA(__kmp_stkpadding);
|
||||||
/* These 2 lines below are so this does not get optimized out */
|
/* These 2 lines below are so this does not get optimized out */
|
||||||
if ( __kmp_stkpadding > KMP_MAX_STKPADDING )
|
if ( __kmp_stkpadding > KMP_MAX_STKPADDING )
|
||||||
__kmp_stkpadding += (short)((kmp_int64)dummy);
|
__kmp_stkpadding += (short)((kmp_int64)dummy);
|
||||||
|
@ -1604,7 +1604,7 @@ __kmp_fork_call(
|
||||||
#if KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64)
|
#if KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64)
|
||||||
void * args[ argc ];
|
void * args[ argc ];
|
||||||
#else
|
#else
|
||||||
void * * args = (void**) alloca( argc * sizeof( void * ) );
|
void * * args = (void**) KMP_ALLOCA( argc * sizeof( void * ) );
|
||||||
#endif /* KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) */
|
#endif /* KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) */
|
||||||
|
|
||||||
__kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
|
__kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
|
||||||
|
@ -2745,7 +2745,7 @@ __kmp_reallocate_team_arrays(kmp_team_t *team, int max_nth) {
|
||||||
#endif
|
#endif
|
||||||
__kmp_allocate_team_arrays(team, max_nth);
|
__kmp_allocate_team_arrays(team, max_nth);
|
||||||
|
|
||||||
memcpy(team->t.t_threads, oldThreads, team->t.t_nproc * sizeof (kmp_info_t*));
|
KMP_MEMCPY(team->t.t_threads, oldThreads, team->t.t_nproc * sizeof (kmp_info_t*));
|
||||||
|
|
||||||
__kmp_free(oldThreads);
|
__kmp_free(oldThreads);
|
||||||
}
|
}
|
||||||
|
@ -3257,8 +3257,8 @@ __kmp_expand_threads(int nWish, int nNeed) {
|
||||||
} while(newCapacity < minimumRequiredCapacity);
|
} while(newCapacity < minimumRequiredCapacity);
|
||||||
newThreads = (kmp_info_t**) __kmp_allocate((sizeof(kmp_info_t*) + sizeof(kmp_root_t*)) * newCapacity + CACHE_LINE);
|
newThreads = (kmp_info_t**) __kmp_allocate((sizeof(kmp_info_t*) + sizeof(kmp_root_t*)) * newCapacity + CACHE_LINE);
|
||||||
newRoot = (kmp_root_t**) ((char*)newThreads + sizeof(kmp_info_t*) * newCapacity );
|
newRoot = (kmp_root_t**) ((char*)newThreads + sizeof(kmp_info_t*) * newCapacity );
|
||||||
memcpy(newThreads, __kmp_threads, __kmp_threads_capacity * sizeof(kmp_info_t*));
|
KMP_MEMCPY(newThreads, __kmp_threads, __kmp_threads_capacity * sizeof(kmp_info_t*));
|
||||||
memcpy(newRoot, __kmp_root, __kmp_threads_capacity * sizeof(kmp_root_t*));
|
KMP_MEMCPY(newRoot, __kmp_root, __kmp_threads_capacity * sizeof(kmp_root_t*));
|
||||||
memset(newThreads + __kmp_threads_capacity, 0,
|
memset(newThreads + __kmp_threads_capacity, 0,
|
||||||
(newCapacity - __kmp_threads_capacity) * sizeof(kmp_info_t*));
|
(newCapacity - __kmp_threads_capacity) * sizeof(kmp_info_t*));
|
||||||
memset(newRoot + __kmp_threads_capacity, 0,
|
memset(newRoot + __kmp_threads_capacity, 0,
|
||||||
|
@ -5783,8 +5783,8 @@ __kmp_register_library_startup(
|
||||||
if ( tail != NULL ) {
|
if ( tail != NULL ) {
|
||||||
long * flag_addr = 0;
|
long * flag_addr = 0;
|
||||||
long flag_val = 0;
|
long flag_val = 0;
|
||||||
sscanf( flag_addr_str, "%p", & flag_addr );
|
KMP_SSCANF( flag_addr_str, "%p", & flag_addr );
|
||||||
sscanf( flag_val_str, "%lx", & flag_val );
|
KMP_SSCANF( flag_val_str, "%lx", & flag_val );
|
||||||
if ( flag_addr != 0 && flag_val != 0 && strcmp( file_name, "" ) != 0 ) {
|
if ( flag_addr != 0 && flag_val != 0 && strcmp( file_name, "" ) != 0 ) {
|
||||||
// First, check whether environment-encoded address is mapped into addr space.
|
// First, check whether environment-encoded address is mapped into addr space.
|
||||||
// If so, dereference it to see if it still has the right value.
|
// If so, dereference it to see if it still has the right value.
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.txt for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef KMP_SAFE_C_API_H
|
||||||
|
#define KMP_SAFE_C_API_H
|
||||||
|
|
||||||
|
//
|
||||||
|
// Replacement for banned C API
|
||||||
|
//
|
||||||
|
|
||||||
|
// Not every unsafe call listed here is handled now, but keeping everything
|
||||||
|
// in one place should be handy for future maintenance.
|
||||||
|
#if KMP_OS_WINDOWS
|
||||||
|
|
||||||
|
# define RSIZE_MAX_STR ( 4UL << 10 ) // 4KB
|
||||||
|
|
||||||
|
// _malloca was suggested, but it is not a drop-in replacement for _alloca
|
||||||
|
// TODO: test performance and replace with _alloca (as below)
|
||||||
|
# define KMP_ALLOCA alloca
|
||||||
|
//# define KMP_ALLOCA _alloca
|
||||||
|
|
||||||
|
# define KMP_MEMCPY_S memcpy_s
|
||||||
|
# define KMP_SNPRINTF sprintf_s
|
||||||
|
# define KMP_SSCANF sscanf_s
|
||||||
|
# define KMP_STRCPY_S strcpy_s
|
||||||
|
# define KMP_STRNCPY_S strncpy_s
|
||||||
|
|
||||||
|
// Use this only when buffer size is unknown
|
||||||
|
# define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
|
||||||
|
|
||||||
|
# define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
|
||||||
|
|
||||||
|
// Use this only when buffer size is unknown
|
||||||
|
# define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
|
||||||
|
|
||||||
|
// _TRUNCATE insures buffer size > max string to print.
|
||||||
|
# define KMP_VSNPRINTF(dst, cnt, fmt, arg) vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg)
|
||||||
|
|
||||||
|
#else // KMP_OS_WINDOWS
|
||||||
|
|
||||||
|
// For now, these macros use the existing API.
|
||||||
|
|
||||||
|
# define KMP_ALLOCA alloca
|
||||||
|
# define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt)
|
||||||
|
# define KMP_SNPRINTF snprintf
|
||||||
|
# define KMP_SSCANF sscanf
|
||||||
|
# define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src)
|
||||||
|
# define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt)
|
||||||
|
# define KMP_VSNPRINTF vsnprintf
|
||||||
|
# define KMP_STRNCPY strncpy
|
||||||
|
# define KMP_STRLEN strlen
|
||||||
|
# define KMP_MEMCPY memcpy
|
||||||
|
|
||||||
|
#endif // KMP_OS_WINDOWS
|
||||||
|
|
||||||
|
#endif // KMP_SAFE_C_API_H
|
|
@ -37,7 +37,7 @@ __kmp_convert_to_double( char const * s )
|
||||||
{
|
{
|
||||||
double result;
|
double result;
|
||||||
|
|
||||||
if ( sscanf( s, "%lf", &result ) < 1 ) {
|
if ( KMP_SSCANF( s, "%lf", &result ) < 1 ) {
|
||||||
result = 0.0;
|
result = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ __kmp_convert_to_seconds( char const * data )
|
||||||
if (data == NULL) return (0);
|
if (data == NULL) return (0);
|
||||||
value = 0;
|
value = 0;
|
||||||
mult = '\0';
|
mult = '\0';
|
||||||
nvalues = sscanf (data, "%d%c%c", &value, &mult, &extra);
|
nvalues = KMP_SSCANF (data, "%d%c%c", &value, &mult, &extra);
|
||||||
if (nvalues < 1) return (0);
|
if (nvalues < 1) return (0);
|
||||||
if (nvalues == 1) mult = '\0';
|
if (nvalues == 1) mult = '\0';
|
||||||
if (nvalues == 3) return (-1);
|
if (nvalues == 3) return (-1);
|
||||||
|
@ -221,7 +221,7 @@ __kmp_convert_to_milliseconds( char const * data )
|
||||||
if ( __kmp_str_match( "infinit", -1, data)) return (INT_MAX);
|
if ( __kmp_str_match( "infinit", -1, data)) return (INT_MAX);
|
||||||
value = (double) 0.0;
|
value = (double) 0.0;
|
||||||
mult = '\0';
|
mult = '\0';
|
||||||
nvalues = sscanf (data, "%lf%c%c", &value, &mult, &extra);
|
nvalues = KMP_SSCANF (data, "%lf%c%c", &value, &mult, &extra);
|
||||||
if (nvalues < 1) return (-1);
|
if (nvalues < 1) return (-1);
|
||||||
if (nvalues == 1) mult = '\0';
|
if (nvalues == 1) mult = '\0';
|
||||||
if (nvalues == 3) return (-1);
|
if (nvalues == 3) return (-1);
|
||||||
|
@ -272,7 +272,7 @@ __kmp_convert_to_nanoseconds( // R: Time in nanoseconds, or ~0 in case o
|
||||||
if ( str == NULL || str[ 0 ] == 0 ) { // No string or empty string.
|
if ( str == NULL || str[ 0 ] == 0 ) { // No string or empty string.
|
||||||
return 0; // Default value.
|
return 0; // Default value.
|
||||||
}; // if
|
}; // if
|
||||||
rc = sscanf( str, "%lf%c%c", &value, &unit, &extra );
|
rc = KMP_SSCANF( str, "%lf%c%c", &value, &unit, &extra );
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
case 0: { // Value is not parsed.
|
case 0: { // Value is not parsed.
|
||||||
return ~ 0;
|
return ~ 0;
|
||||||
|
@ -545,9 +545,9 @@ __kmp_stg_parse_par_range(
|
||||||
int * out_lb,
|
int * out_lb,
|
||||||
int * out_ub
|
int * out_ub
|
||||||
) {
|
) {
|
||||||
size_t len = strlen( value + 1 );
|
size_t len = KMP_STRLEN( value + 1 );
|
||||||
par_range_to_print = (char *) KMP_INTERNAL_MALLOC( len +1 );
|
par_range_to_print = (char *) KMP_INTERNAL_MALLOC( len +1 );
|
||||||
strncpy( par_range_to_print, value, len + 1);
|
KMP_STRNCPY_S( par_range_to_print, len + 1, value, len + 1);
|
||||||
__kmp_par_range = +1;
|
__kmp_par_range = +1;
|
||||||
__kmp_par_range_lb = 0;
|
__kmp_par_range_lb = 0;
|
||||||
__kmp_par_range_ub = INT_MAX;
|
__kmp_par_range_ub = INT_MAX;
|
||||||
|
@ -585,7 +585,7 @@ __kmp_stg_parse_par_range(
|
||||||
if (( ! __kmp_strcasecmp_with_sentinel( "range", value, '=' ))
|
if (( ! __kmp_strcasecmp_with_sentinel( "range", value, '=' ))
|
||||||
|| ( ! __kmp_strcasecmp_with_sentinel( "incl_range", value, '=' ))) {
|
|| ( ! __kmp_strcasecmp_with_sentinel( "incl_range", value, '=' ))) {
|
||||||
value = strchr( value, '=' ) + 1;
|
value = strchr( value, '=' ) + 1;
|
||||||
if ( sscanf( value, "%d:%d", out_lb, out_ub ) != 2 ) {
|
if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub ) != 2 ) {
|
||||||
goto par_range_error;
|
goto par_range_error;
|
||||||
}
|
}
|
||||||
*out_range = +1;
|
*out_range = +1;
|
||||||
|
@ -597,7 +597,7 @@ __kmp_stg_parse_par_range(
|
||||||
}
|
}
|
||||||
if ( ! __kmp_strcasecmp_with_sentinel( "excl_range", value, '=' )) {
|
if ( ! __kmp_strcasecmp_with_sentinel( "excl_range", value, '=' )) {
|
||||||
value = strchr( value, '=' ) + 1;
|
value = strchr( value, '=' ) + 1;
|
||||||
if ( sscanf( value, "%d:%d", out_lb, out_ub) != 2 ) {
|
if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub) != 2 ) {
|
||||||
goto par_range_error;
|
goto par_range_error;
|
||||||
}
|
}
|
||||||
*out_range = -1;
|
*out_range = -1;
|
||||||
|
@ -1972,7 +1972,7 @@ __kmp_parse_affinity_proc_id_list( const char *var, const char *env,
|
||||||
{
|
{
|
||||||
int len = next - env;
|
int len = next - env;
|
||||||
char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
|
char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
|
||||||
memcpy(retlist, env, len * sizeof(char));
|
KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
|
||||||
retlist[len] = '\0';
|
retlist[len] = '\0';
|
||||||
*proclist = retlist;
|
*proclist = retlist;
|
||||||
}
|
}
|
||||||
|
@ -2833,7 +2833,7 @@ __kmp_parse_place_list( const char *var, const char *env, char **place_list )
|
||||||
{
|
{
|
||||||
int len = scan - env;
|
int len = scan - env;
|
||||||
char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
|
char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
|
||||||
memcpy(retlist, env, len * sizeof(char));
|
KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
|
||||||
retlist[len] = '\0';
|
retlist[len] = '\0';
|
||||||
*place_list = retlist;
|
*place_list = retlist;
|
||||||
}
|
}
|
||||||
|
@ -3507,7 +3507,7 @@ static void
|
||||||
__kmp_stg_parse_schedule( char const * name, char const * value, void * data ) {
|
__kmp_stg_parse_schedule( char const * name, char const * value, void * data ) {
|
||||||
|
|
||||||
if ( value != NULL ) {
|
if ( value != NULL ) {
|
||||||
size_t length = strlen( value );
|
size_t length = KMP_STRLEN( value );
|
||||||
if ( length > INT_MAX ) {
|
if ( length > INT_MAX ) {
|
||||||
KMP_WARNING( LongValue, name );
|
KMP_WARNING( LongValue, name );
|
||||||
} else {
|
} else {
|
||||||
|
@ -3581,7 +3581,7 @@ __kmp_stg_parse_omp_schedule( char const * name, char const * value, void * data
|
||||||
{
|
{
|
||||||
size_t length;
|
size_t length;
|
||||||
if( value ) {
|
if( value ) {
|
||||||
length = strlen( value );
|
length = KMP_STRLEN( value );
|
||||||
if( length ) {
|
if( length ) {
|
||||||
char *comma = (char *) strchr( value, ',' );
|
char *comma = (char *) strchr( value, ',' );
|
||||||
if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'')
|
if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'')
|
||||||
|
@ -5315,7 +5315,7 @@ __kmp_env_print() {
|
||||||
char const * name = block.vars[ i ].name;
|
char const * name = block.vars[ i ].name;
|
||||||
char const * value = block.vars[ i ].value;
|
char const * value = block.vars[ i ].value;
|
||||||
if (
|
if (
|
||||||
( strlen( name ) > 4 && strncmp( name, "KMP_", 4 ) == 0 )
|
( KMP_STRLEN( name ) > 4 && strncmp( name, "KMP_", 4 ) == 0 )
|
||||||
|| strncmp( name, "OMP_", 4 ) == 0
|
|| strncmp( name, "OMP_", 4 ) == 0
|
||||||
#ifdef KMP_GOMP_COMPAT
|
#ifdef KMP_GOMP_COMPAT
|
||||||
|| strncmp( name, "GOMP_", 5 ) == 0
|
|| strncmp( name, "GOMP_", 5 ) == 0
|
||||||
|
|
|
@ -54,7 +54,7 @@ double tsc_tick_count::tick_time()
|
||||||
for (;*start == ' '; start++)
|
for (;*start == ' '; start++)
|
||||||
;
|
;
|
||||||
|
|
||||||
char * end = brand + strlen(brand) - 3;
|
char * end = brand + KMP_STRLEN(brand) - 3;
|
||||||
uint64_t multiplier;
|
uint64_t multiplier;
|
||||||
|
|
||||||
if (*end == 'M') multiplier = 1000LL*1000LL;
|
if (*end == 'M') multiplier = 1000LL*1000LL;
|
||||||
|
|
|
@ -112,7 +112,7 @@ __kmp_str_buf_reserve(
|
||||||
if ( buffer->str == NULL ) {
|
if ( buffer->str == NULL ) {
|
||||||
KMP_FATAL( MemoryAllocFailed );
|
KMP_FATAL( MemoryAllocFailed );
|
||||||
}; // if
|
}; // if
|
||||||
memcpy( buffer->str, buffer->bulk, buffer->used + 1 );
|
KMP_MEMCPY_S( buffer->str, buffer->size, buffer->bulk, buffer->used + 1 );
|
||||||
} else {
|
} else {
|
||||||
buffer->str = (char *) KMP_INTERNAL_REALLOC( buffer->str, buffer->size );
|
buffer->str = (char *) KMP_INTERNAL_REALLOC( buffer->str, buffer->size );
|
||||||
if ( buffer->str == NULL ) {
|
if ( buffer->str == NULL ) {
|
||||||
|
@ -142,7 +142,7 @@ __kmp_str_buf_detach(
|
||||||
if ( buffer->str == NULL ) {
|
if ( buffer->str == NULL ) {
|
||||||
KMP_FATAL( MemoryAllocFailed );
|
KMP_FATAL( MemoryAllocFailed );
|
||||||
}; // if
|
}; // if
|
||||||
memcpy( buffer->str, buffer->bulk, buffer->used + 1 );
|
KMP_MEMCPY_S( buffer->str, buffer->size, buffer->bulk, buffer->used + 1 );
|
||||||
}; // if
|
}; // if
|
||||||
|
|
||||||
} // __kmp_str_buf_detach
|
} // __kmp_str_buf_detach
|
||||||
|
@ -173,7 +173,7 @@ __kmp_str_buf_cat(
|
||||||
KMP_DEBUG_ASSERT( str != NULL );
|
KMP_DEBUG_ASSERT( str != NULL );
|
||||||
KMP_DEBUG_ASSERT( len >= 0 );
|
KMP_DEBUG_ASSERT( len >= 0 );
|
||||||
__kmp_str_buf_reserve( buffer, buffer->used + len + 1 );
|
__kmp_str_buf_reserve( buffer, buffer->used + len + 1 );
|
||||||
memcpy( buffer->str + buffer->used, str, len );
|
KMP_MEMCPY( buffer->str + buffer->used, str, len );
|
||||||
buffer->str[ buffer->used + len ] = 0;
|
buffer->str[ buffer->used + len ] = 0;
|
||||||
buffer->used += len;
|
buffer->used += len;
|
||||||
KMP_STR_BUF_INVARIANT( buffer );
|
KMP_STR_BUF_INVARIANT( buffer );
|
||||||
|
@ -211,7 +211,7 @@ __kmp_str_buf_vprint(
|
||||||
__va_copy( _args, args ); // Make copy of args.
|
__va_copy( _args, args ); // Make copy of args.
|
||||||
#define args _args // Substitute args with its copy, _args.
|
#define args _args // Substitute args with its copy, _args.
|
||||||
#endif // KMP_OS_WINDOWS
|
#endif // KMP_OS_WINDOWS
|
||||||
rc = vsnprintf( buffer->str + buffer->used, free, format, args );
|
rc = KMP_VSNPRINTF( buffer->str + buffer->used, free, format, args );
|
||||||
#if ! KMP_OS_WINDOWS
|
#if ! KMP_OS_WINDOWS
|
||||||
#undef args // Remove substitution.
|
#undef args // Remove substitution.
|
||||||
va_end( _args );
|
va_end( _args );
|
||||||
|
@ -502,7 +502,7 @@ __kmp_str_format( // Allocated string.
|
||||||
|
|
||||||
// Try to format string.
|
// Try to format string.
|
||||||
va_start( args, format );
|
va_start( args, format );
|
||||||
rc = vsnprintf( buffer, size, format, args );
|
rc = KMP_VSNPRINTF( buffer, size, format, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
|
|
||||||
// No errors, string has been formatted.
|
// No errors, string has been formatted.
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
#if KMP_OS_WINDOWS
|
#if KMP_OS_WINDOWS
|
||||||
# define strdup _strdup
|
# define strdup _strdup
|
||||||
# define snprintf _snprintf
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* some macros to replace ctype.h functions */
|
/* some macros to replace ctype.h functions */
|
||||||
|
|
|
@ -1978,8 +1978,9 @@ __kmp_realloc_task_threads_data( kmp_info_t *thread, kmp_task_team_t *task_team
|
||||||
new_data = (kmp_thread_data_t *)
|
new_data = (kmp_thread_data_t *)
|
||||||
__kmp_allocate( nthreads * sizeof(kmp_thread_data_t) );
|
__kmp_allocate( nthreads * sizeof(kmp_thread_data_t) );
|
||||||
// copy old data to new data
|
// copy old data to new data
|
||||||
memcpy( (void *) new_data, (void *) old_data,
|
KMP_MEMCPY_S( (void *) new_data, nthreads * sizeof(kmp_thread_data_t),
|
||||||
maxthreads * sizeof(kmp_taskdata_t *) );
|
(void *) old_data,
|
||||||
|
maxthreads * sizeof(kmp_taskdata_t *) );
|
||||||
|
|
||||||
#ifdef BUILD_TIED_TASK_STACK
|
#ifdef BUILD_TIED_TASK_STACK
|
||||||
// GEH: Figure out if this is the right thing to do
|
// GEH: Figure out if this is the right thing to do
|
||||||
|
|
|
@ -114,7 +114,7 @@ __kmp_init_common_data( void *pc_addr, size_t pc_size )
|
||||||
for (i = pc_size; i > 0; --i) {
|
for (i = pc_size; i > 0; --i) {
|
||||||
if (*p++ != '\0') {
|
if (*p++ != '\0') {
|
||||||
d->data = __kmp_allocate( pc_size );
|
d->data = __kmp_allocate( pc_size );
|
||||||
memcpy( d->data, pc_addr, pc_size );
|
KMP_MEMCPY( d->data, pc_addr, pc_size );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ __kmp_copy_common_data( void *pc_addr, struct private_data *d )
|
||||||
if (d->data == 0)
|
if (d->data == 0)
|
||||||
memset( & addr[ offset ], '\0', d->size );
|
memset( & addr[ offset ], '\0', d->size );
|
||||||
else
|
else
|
||||||
memcpy( & addr[ offset ], d->data, d->size );
|
KMP_MEMCPY( & addr[ offset ], d->data, d->size );
|
||||||
offset += d->size;
|
offset += d->size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,12 +314,12 @@ __kmp_expand_host_name( char *buffer, size_t size )
|
||||||
DWORD s = size;
|
DWORD s = size;
|
||||||
|
|
||||||
if (! GetComputerNameA( buffer, & s ))
|
if (! GetComputerNameA( buffer, & s ))
|
||||||
strcpy( buffer, unknown );
|
KMP_STRCPY_S( buffer, size, unknown );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
buffer[size - 2] = 0;
|
buffer[size - 2] = 0;
|
||||||
if (gethostname( buffer, size ) || buffer[size - 2] != 0)
|
if (gethostname( buffer, size ) || buffer[size - 2] != 0)
|
||||||
strcpy( buffer, unknown );
|
KMP_STRCPY_S( buffer, size, unknown );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ __kmp_expand_file_name( char *result, size_t rlen, char *pattern )
|
||||||
case 'h':
|
case 'h':
|
||||||
{
|
{
|
||||||
__kmp_expand_host_name( buffer, sizeof( buffer ) );
|
__kmp_expand_host_name( buffer, sizeof( buffer ) );
|
||||||
strncpy( pos, buffer, end - pos + 1);
|
KMP_STRNCPY( pos, buffer, end - pos + 1);
|
||||||
if(*end == 0) {
|
if(*end == 0) {
|
||||||
while ( *pos )
|
while ( *pos )
|
||||||
++pos;
|
++pos;
|
||||||
|
@ -386,7 +386,7 @@ __kmp_expand_file_name( char *result, size_t rlen, char *pattern )
|
||||||
case 'P':
|
case 'P':
|
||||||
case 'p':
|
case 'p':
|
||||||
{
|
{
|
||||||
snp_result = snprintf( pos, end - pos + 1, "%0*d", cpu_width, __kmp_dflt_team_nth );
|
snp_result = KMP_SNPRINTF( pos, end - pos + 1, "%0*d", cpu_width, __kmp_dflt_team_nth );
|
||||||
if(snp_result >= 0 && snp_result <= end - pos) {
|
if(snp_result >= 0 && snp_result <= end - pos) {
|
||||||
while ( *pos )
|
while ( *pos )
|
||||||
++pos;
|
++pos;
|
||||||
|
@ -399,7 +399,7 @@ __kmp_expand_file_name( char *result, size_t rlen, char *pattern )
|
||||||
case 'i':
|
case 'i':
|
||||||
{
|
{
|
||||||
pid_t id = getpid();
|
pid_t id = getpid();
|
||||||
snp_result = snprintf( pos, end - pos + 1, "%0*d", width, id );
|
snp_result = KMP_SNPRINTF( pos, end - pos + 1, "%0*d", width, id );
|
||||||
if(snp_result >= 0 && snp_result <= end - pos) {
|
if(snp_result >= 0 && snp_result <= end - pos) {
|
||||||
while ( *pos )
|
while ( *pos )
|
||||||
++pos;
|
++pos;
|
||||||
|
|
|
@ -101,7 +101,7 @@ static kmp_mutex_align_t __kmp_wait_mx;
|
||||||
static void
|
static void
|
||||||
__kmp_print_cond( char *buffer, kmp_cond_align_t *cond )
|
__kmp_print_cond( char *buffer, kmp_cond_align_t *cond )
|
||||||
{
|
{
|
||||||
sprintf( buffer, "(cond (lock (%ld, %d)), (descr (%p)))",
|
KMP_SNPRINTF( buffer, 128, "(cond (lock (%ld, %d)), (descr (%p)))",
|
||||||
cond->c_cond.__c_lock.__status, cond->c_cond.__c_lock.__spinlock,
|
cond->c_cond.__c_lock.__status, cond->c_cond.__c_lock.__spinlock,
|
||||||
cond->c_cond.__c_waiting );
|
cond->c_cond.__c_waiting );
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ __kmp_affinity_bind_thread( int which )
|
||||||
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
|
KMP_ASSERT2(KMP_AFFINITY_CAPABLE(),
|
||||||
"Illegal set affinity operation when not capable");
|
"Illegal set affinity operation when not capable");
|
||||||
|
|
||||||
kmp_affin_mask_t *mask = (kmp_affin_mask_t *)alloca(__kmp_affin_mask_size);
|
kmp_affin_mask_t *mask = (kmp_affin_mask_t *)KMP_ALLOCA(__kmp_affin_mask_size);
|
||||||
KMP_CPU_ZERO(mask);
|
KMP_CPU_ZERO(mask);
|
||||||
KMP_CPU_SET(which, mask);
|
KMP_CPU_SET(which, mask);
|
||||||
__kmp_set_system_affinity(mask, TRUE);
|
__kmp_set_system_affinity(mask, TRUE);
|
||||||
|
@ -732,7 +732,7 @@ __kmp_launch_worker( void *thr )
|
||||||
|
|
||||||
#if KMP_OS_LINUX || KMP_OS_FREEBSD
|
#if KMP_OS_LINUX || KMP_OS_FREEBSD
|
||||||
if ( __kmp_stkoffset > 0 && gtid > 0 ) {
|
if ( __kmp_stkoffset > 0 && gtid > 0 ) {
|
||||||
padding = alloca( gtid * __kmp_stkoffset );
|
padding = KMP_ALLOCA( gtid * __kmp_stkoffset );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2300,7 +2300,7 @@ __kmp_is_address_mapped( void * addr ) {
|
||||||
if ( rc == EOF ) {
|
if ( rc == EOF ) {
|
||||||
break;
|
break;
|
||||||
}; // if
|
}; // if
|
||||||
KMP_ASSERT( rc == 3 && strlen( perms ) == 4 ); // Make sure all fields are read.
|
KMP_ASSERT( rc == 3 && KMP_STRLEN( perms ) == 4 ); // Make sure all fields are read.
|
||||||
|
|
||||||
// Ending address is not included in the region, but beginning is.
|
// Ending address is not included in the region, but beginning is.
|
||||||
if ( ( addr >= beginning ) && ( addr < ending ) ) {
|
if ( ( addr >= beginning ) && ( addr < ending ) ) {
|
||||||
|
@ -2475,7 +2475,7 @@ __kmp_get_load_balance( int max )
|
||||||
|
|
||||||
// Construct task_path.
|
// Construct task_path.
|
||||||
task_path.used = task_path_fixed_len; // Reset task_path to "/proc/".
|
task_path.used = task_path_fixed_len; // Reset task_path to "/proc/".
|
||||||
__kmp_str_buf_cat( & task_path, proc_entry->d_name, strlen( proc_entry->d_name ) );
|
__kmp_str_buf_cat( & task_path, proc_entry->d_name, KMP_STRLEN( proc_entry->d_name ) );
|
||||||
__kmp_str_buf_cat( & task_path, "/task", 5 );
|
__kmp_str_buf_cat( & task_path, "/task", 5 );
|
||||||
|
|
||||||
task_dir = opendir( task_path.str );
|
task_dir = opendir( task_path.str );
|
||||||
|
@ -2510,7 +2510,7 @@ __kmp_get_load_balance( int max )
|
||||||
// __kmp_str_buf_print( & stat_path, "%s/%s/stat", task_path.str, task_entry->d_name );
|
// __kmp_str_buf_print( & stat_path, "%s/%s/stat", task_path.str, task_entry->d_name );
|
||||||
// but seriae of __kmp_str_buf_cat works a bit faster.
|
// but seriae of __kmp_str_buf_cat works a bit faster.
|
||||||
stat_path.used = stat_path_fixed_len; // Reset stat path to its fixed part.
|
stat_path.used = stat_path_fixed_len; // Reset stat path to its fixed part.
|
||||||
__kmp_str_buf_cat( & stat_path, task_entry->d_name, strlen( task_entry->d_name ) );
|
__kmp_str_buf_cat( & stat_path, task_entry->d_name, KMP_STRLEN( task_entry->d_name ) );
|
||||||
__kmp_str_buf_cat( & stat_path, "/stat", 5 );
|
__kmp_str_buf_cat( & stat_path, "/stat", 5 );
|
||||||
|
|
||||||
// Note: Low-level API (open/read/close) is used. High-level API
|
// Note: Low-level API (open/read/close) is used. High-level API
|
||||||
|
|
|
@ -1190,7 +1190,7 @@ __kmp_launch_worker( void *arg )
|
||||||
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
|
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
|
||||||
|
|
||||||
if ( __kmp_stkoffset > 0 && gtid > 0 ) {
|
if ( __kmp_stkoffset > 0 && gtid > 0 ) {
|
||||||
padding = _alloca( gtid * __kmp_stkoffset );
|
padding = KMP_ALLOCA( gtid * __kmp_stkoffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
KMP_FSYNC_RELEASING( &this_thr -> th.th_info.ds.ds_alive );
|
KMP_FSYNC_RELEASING( &this_thr -> th.th_info.ds.ds_alive );
|
||||||
|
|
Loading…
Reference in New Issue