diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index e6974b707c4ede..03871a500808f6 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -104,7 +104,7 @@ if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS add_definitions(-D__APPLE_USE_RFC_3542) endif () -if (CLR_CMAKE_TARGET_LINUX) +if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_ANDROID) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") endif () diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index 9dfc9dbcc6fb69..648ad60dd0494a 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -514,7 +514,7 @@ #cmakedefine GLIBC_BEFORE_2_3_4_SCHED_SETAFFINITY 1 /* GLIBC has CPU_COUNT macro in sched.h */ -#cmakedefine GLIBC_HAS_CPU_COUNT 1 +#cmakedefine HAVE_GNU_CPU_COUNT /* Have large file support */ #cmakedefine HAVE_LARGE_FILE_SUPPORT 1 diff --git a/src/mono/cmake/configure.cmake b/src/mono/cmake/configure.cmake index 695c1c582ec944..e8e9fb9e67d799 100644 --- a/src/mono/cmake/configure.cmake +++ b/src/mono/cmake/configure.cmake @@ -125,18 +125,36 @@ check_type_size("long" SIZEOF_LONG) check_type_size("long long" SIZEOF_LONG_LONG) check_type_size("size_t" SIZEOF_SIZE_T) -set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +if (HOST_LINUX OR HOST_ANDROID) + set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +endif() + +check_c_source_compiles( + " + #include + int main(void) + { + char buffer[1]; + char c = *strerror_r(0, buffer, 0); + return 0; + } + " + HAVE_GNU_STRERROR_R) + check_c_source_compiles( - " - #include - int main(void) - { - char buffer[1]; - char c = *strerror_r(0, buffer, 0); - return 0; - } - " - HAVE_GNU_STRERROR_R) + " + #include + int main(void) + { + CPU_COUNT((void *) 0); + return 0; + } + " + HAVE_GNU_CPU_COUNT) + +if (HOST_LINUX OR HOST_ANDROID) + set(CMAKE_REQUIRED_DEFINITIONS) +endif() # ICONV set(ICONV_LIB) @@ -145,14 +163,6 @@ if(NOT LIBICONV_FOUND STREQUAL "LIBICONV_FOUND-NOTFOUND") set(ICONV_LIB "iconv") endif() -file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c - "#include \n" - "void main () { CPU_COUNT((void *) 0); }\n" -) -try_compile(GLIBC_HAS_CPU_COUNT ${CMAKE_BINARY_DIR}/CMakeTmp SOURCES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c" - COMPILE_DEFINITIONS "-D_GNU_SOURCE") - - if(HOST_WIN32) # checking for this doesn't work for some reason, hardcode result set(HAVE_WINTERNL_H 1) diff --git a/src/mono/mono/utils/mono-proclib.c b/src/mono/mono/utils/mono-proclib.c index 1fe731d9fe0f59..9a33fc2924e6bc 100644 --- a/src/mono/mono/utils/mono-proclib.c +++ b/src/mono/mono/utils/mono-proclib.c @@ -69,7 +69,7 @@ # define kinfo_name_member p_comm #elif defined(__OpenBSD__) // Can not figure out how to get the proc's start time on OpenBSD -# undef kinfo_starttime_member +# undef kinfo_starttime_member # define kinfo_pid_member p_pid # define kinfo_name_member p_comm #else @@ -81,7 +81,7 @@ #endif #ifdef HAVE_SCHED_GETAFFINITY -# ifndef GLIBC_HAS_CPU_COUNT +# ifndef HAVE_GNU_CPU_COUNT static int CPU_COUNT(cpu_set_t *set) { @@ -430,7 +430,7 @@ mono_process_get_times (gpointer pid, gint64 *start_time, gint64 *user_time, gin /* * /proc/pid/stat format: - * pid (cmdname) S + * pid (cmdname) S * [0] ppid pgid sid tty_nr tty_pgrp flags min_flt cmin_flt maj_flt cmaj_flt * [10] utime stime cutime cstime prio nice threads 0 start_time vsize * [20] rss rsslim start_code end_code start_stack esp eip pending blocked sigign @@ -445,7 +445,7 @@ mono_process_get_times (gpointer pid, gint64 *start_time, gint64 *user_time, gin static gint64 get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error) { -#if defined(__APPLE__) +#if defined(__APPLE__) double process_user_time = 0, process_system_time = 0;//, process_percent = 0; task_t task; struct task_basic_info t_info; @@ -479,16 +479,16 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error) do { ret = task_threads (task, &th_array, &th_count); } while (ret == KERN_ABORTED); - + if (ret != KERN_SUCCESS) { if (pid != getpid ()) mach_port_deallocate (mach_task_self (), task); RET_ERROR (MONO_PROCESS_ERROR_OTHER); } - + for (i = 0; i < th_count; i++) { double thread_user_time, thread_system_time;//, thread_percent; - + struct thread_basic_info th_info; mach_msg_type_number_t th_info_count = THREAD_BASIC_INFO_COUNT; do { @@ -499,13 +499,13 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error) thread_user_time = th_info.user_time.seconds + th_info.user_time.microseconds / 1e6; thread_system_time = th_info.system_time.seconds + th_info.system_time.microseconds / 1e6; //thread_percent = (double)th_info.cpu_usage / TH_USAGE_SCALE; - + process_user_time += thread_user_time; process_system_time += thread_system_time; //process_percent += th_percent; } } - + for (i = 0; i < th_count; i++) mach_port_deallocate(task, th_array[i]); @@ -514,14 +514,14 @@ get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error) process_user_time += t_info.user_time.seconds + t_info.user_time.microseconds / 1e6; process_system_time += t_info.system_time.seconds + t_info.system_time.microseconds / 1e6; - + if (pos == 10 && sum == TRUE) return (gint64)((process_user_time + process_system_time) * 10000000); else if (pos == 10) return (gint64)(process_user_time * 10000000); else if (pos == 11) return (gint64)(process_system_time * 10000000); - + return 0; #else char buf [512]; @@ -604,7 +604,7 @@ get_pid_status_item (int pid, const char *item, MonoProcessError *error, int mul { #if defined(__APPLE__) // ignore the multiplier - + gint64 ret; task_t task; task_vm_info_data_t t_info; @@ -661,7 +661,7 @@ get_pid_status_item (int pid, const char *item, MonoProcessError *error, int mul if (pid != getpid ()) mach_port_deallocate (mach_task_self (), task); - + return ret; #else char buf [64]; @@ -905,7 +905,7 @@ get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *s } else { continue; } - + user_ticks = strtoull (data, &data, 10); nice_ticks = strtoull (data, &data, 10); system_ticks = strtoull (data, &data, 10);