diff --git a/openmp/runtime/cmake/LibompHandleFlags.cmake b/openmp/runtime/cmake/LibompHandleFlags.cmake index eed98036dd51a6e..1aba1fbea829099 100644 --- a/openmp/runtime/cmake/LibompHandleFlags.cmake +++ b/openmp/runtime/cmake/LibompHandleFlags.cmake @@ -147,8 +147,11 @@ function(libomp_get_libflags libflags) if (${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly") libomp_append(libflags_local "-lkvm") endif() - elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|Solaris") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|SunOS") libomp_append(libflags_local -lm) + if (${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") + libomp_append(libflags_local "-lproc") + endif() endif() set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS}) libomp_setup_flags(libflags_local) diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp index 3636266677d99e8..a8e5a9e6bbb0b84 100644 --- a/openmp/runtime/src/z_Linux_util.cpp +++ b/openmp/runtime/src/z_Linux_util.cpp @@ -66,6 +66,9 @@ #include #include #elif KMP_OS_SOLARIS +#include +#include +#include #include #endif @@ -418,7 +421,7 @@ void __kmp_terminate_thread(int gtid) { KMP_YIELD(TRUE); } // -/* Set thread stack info according to values returned by pthread_getattr_np(). +/* Set thread stack info. If values are unreasonable, assume call failed and use incremental stack refinement method instead. Returns TRUE if the stack parameters could be determined exactly, FALSE if incremental refinement is necessary. */ @@ -426,7 +429,6 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) { int stack_data; #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \ KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX - pthread_attr_t attr; int status; size_t size = 0; void *addr = 0; @@ -436,6 +438,19 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) { pthread_attr_getstack may cause thread gtid aliasing */ if (!KMP_UBER_GTID(gtid)) { +#if KMP_OS_SOLARIS + stack_t s; + if ((status = thr_stksegment(&s)) < 0) { + KMP_CHECK_SYSFAIL("thr_stksegment", status); + } + + addr = s.ss_sp; + size = s.ss_size; + KA_TRACE(60, ("__kmp_set_stack_info: T#%d thr_stksegment returned size:" + " %lu, low addr: %p\n", + gtid, size, addr)); +#else + pthread_attr_t attr; /* Fetch the real thread attributes */ status = pthread_attr_init(&attr); KMP_CHECK_SYSFAIL("pthread_attr_init", status); @@ -454,6 +469,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) { gtid, size, addr)); status = pthread_attr_destroy(&attr); KMP_CHECK_SYSFAIL("pthread_attr_destroy", status); +#endif } if (size != 0 && addr != 0) { // was stack parameter determination successful? @@ -2175,6 +2191,54 @@ int __kmp_is_address_mapped(void *addr) { } kvm_close(fd); +#elif KMP_OS_SOLARIS + prmap_t *cur, *map; + void *buf; + uintptr_t uaddr; + ssize_t rd; + int err; + int file; + + pid_t pid = getpid(); + struct ps_prochandle *fd = Pgrab(pid, PGRAB_RDONLY, &err); + ; + + if (!fd) { + return 0; + } + + char *name = __kmp_str_format("/proc/%d/map", pid); + size_t sz = (1 << 20); + file = open(name, O_RDONLY); + if (file == -1) { + KMP_INTERNAL_FREE(name); + return 0; + } + + buf = kmpc_malloc(sz); + + while (sz > 0 && (rd = pread(file, buf, sz, 0)) == sz) { + void *newbuf; + sz <<= 1; + newbuf = kmpc_realloc(buf, sz); + buf = newbuf; + } + + map = reinterpret_cast(buf); + uaddr = reinterpret_cast(addr); + + for (cur = map; rd > 0; cur++, rd = -sizeof(*map)) { + if ((uaddr >= cur->pr_vaddr) && (uaddr < cur->pr_vaddr)) { + if ((cur->pr_mflags & MA_READ) != 0 && (cur->pr_mflags & MA_WRITE) != 0) { + found = 1; + break; + } + } + } + + kmpc_free(map); + close(file); + KMP_INTERNAL_FREE(name); #elif KMP_OS_DARWIN /* On OS X*, /proc pseudo filesystem is not available. Try to read memory @@ -2253,9 +2317,9 @@ int __kmp_is_address_mapped(void *addr) { } #elif KMP_OS_WASI found = (int)addr < (__builtin_wasm_memory_size(0) * PAGESIZE); -#elif KMP_OS_SOLARIS || KMP_OS_AIX +#elif KMP_OS_AIX - // FIXME(Solaris, AIX): Implement this + // FIXME(AIX): Implement this found = 1; #else