Skip to content

Commit 444ec06

Browse files
committed
[OpenMP] Implements __kmp_is_address_mapped for Solaris/Illumos.
Also fixing OpenMP build itself for this platform.
1 parent 2c5a688 commit 444ec06

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ function(libomp_get_libflags libflags)
147147
if (${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly")
148148
libomp_append(libflags_local "-lkvm")
149149
endif()
150-
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|Solaris")
150+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|SunOS")
151151
libomp_append(libflags_local -lm)
152+
if (${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
153+
libomp_append(libflags_local "-lproc")
154+
endif()
152155
endif()
153156
set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS})
154157
libomp_setup_flags(libflags_local)

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
#include <sys/types.h>
6767
#include <sys/sysctl.h>
6868
#elif KMP_OS_SOLARIS
69+
#if defined(__LP64__)
70+
#define _STRUCTURED_PROC 1
71+
#include <sys/procfs.h>
72+
#include <libproc.h>
73+
#endif
74+
#include <thread.h>
6975
#include <sys/loadavg.h>
7076
#endif
7177

@@ -426,7 +432,6 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
426432
int stack_data;
427433
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
428434
KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
429-
pthread_attr_t attr;
430435
int status;
431436
size_t size = 0;
432437
void *addr = 0;
@@ -436,6 +441,8 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
436441
pthread_attr_getstack may cause thread gtid aliasing */
437442
if (!KMP_UBER_GTID(gtid)) {
438443

444+
#if !KMP_OS_SOLARIS
445+
pthread_attr_t attr;
439446
/* Fetch the real thread attributes */
440447
status = pthread_attr_init(&attr);
441448
KMP_CHECK_SYSFAIL("pthread_attr_init", status);
@@ -454,6 +461,18 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
454461
gtid, size, addr));
455462
status = pthread_attr_destroy(&attr);
456463
KMP_CHECK_SYSFAIL("pthread_attr_destroy", status);
464+
#else
465+
stack_t s;
466+
if ((status = thr_stksegment(&s)) < 0) {
467+
KMP_CHECK_SYSFAIL("thr_stksegment", status);
468+
}
469+
470+
addr = s.ss_sp;
471+
size = s.ss_size;
472+
KA_TRACE(60, ("__kmp_set_stack_info: T#%d thr_stksegment returned size:"
473+
" %lu, low addr: %p\n",
474+
gtid, size, addr));
475+
#endif
457476
}
458477

459478
if (size != 0 && addr != 0) { // was stack parameter determination successful?
@@ -2175,6 +2194,56 @@ int __kmp_is_address_mapped(void *addr) {
21752194
}
21762195

21772196
kvm_close(fd);
2197+
#elif KMP_OS_SOLARIS
2198+
#if defined(__LP64__)
2199+
prmap_t *cur, *map;
2200+
void *buf;
2201+
uintptr_t uaddr;
2202+
ssize_t rd;
2203+
int err;
2204+
int file;
2205+
2206+
pid_t pid = getpid();
2207+
struct ps_prochandle *fd = Pgrab(pid, PGRAB_RDONLY, &err);
2208+
;
2209+
2210+
if (!fd) {
2211+
return 0;
2212+
}
2213+
2214+
char *name = __kmp_str_format("/proc/%d/map", pid);
2215+
size_t sz = (1 << 20);
2216+
file = open(name, O_RDONLY);
2217+
if (file == -1) {
2218+
KMP_INTERNAL_FREE(name);
2219+
return 0;
2220+
}
2221+
2222+
buf = kmpc_malloc(sz);
2223+
2224+
while (sz > 0 && (rd = pread(file, buf, sz, 0)) == sz) {
2225+
void *newbuf;
2226+
sz <<= 1;
2227+
newbuf = kmpc_realloc(buf, sz);
2228+
buf = newbuf;
2229+
}
2230+
2231+
map = reinterpret_cast<prmap_t *>(buf);
2232+
uaddr = reinterpret_cast<uintptr_t>(addr);
2233+
2234+
for (cur = map; rd > 0; cur++, rd = -sizeof(*map)) {
2235+
if ((uaddr >= cur->pr_vaddr) && (uaddr < cur->pr_vaddr)) {
2236+
if ((cur->pr_mflags & MA_READ) != 0 && (cur->pr_mflags & MA_WRITE) != 0) {
2237+
found = 1;
2238+
break;
2239+
}
2240+
}
2241+
}
2242+
2243+
kmpc_free(map);
2244+
close(file);
2245+
KMP_INTERNAL_FREE(name);
2246+
#endif
21782247
#elif KMP_OS_DARWIN
21792248

21802249
/* On OS X*, /proc pseudo filesystem is not available. Try to read memory
@@ -2253,9 +2322,9 @@ int __kmp_is_address_mapped(void *addr) {
22532322
}
22542323
#elif KMP_OS_WASI
22552324
found = (int)addr < (__builtin_wasm_memory_size(0) * PAGESIZE);
2256-
#elif KMP_OS_SOLARIS || KMP_OS_AIX
2325+
#elif KMP_OS_AIX
22572326

2258-
// FIXME(Solaris, AIX): Implement this
2327+
// FIXME(AIX): Implement this
22592328
found = 1;
22602329

22612330
#else

0 commit comments

Comments
 (0)