6666#include < sys/types.h>
6767#include < sys/sysctl.h>
6868#elif KMP_OS_SOLARIS
69+ #include < libproc.h>
70+ #include < procfs.h>
71+ #include < thread.h>
6972#include < sys/loadavg.h>
7073#endif
7174
@@ -418,15 +421,14 @@ void __kmp_terminate_thread(int gtid) {
418421 KMP_YIELD (TRUE );
419422} //
420423
421- /* Set thread stack info according to values returned by pthread_getattr_np() .
424+ /* Set thread stack info.
422425 If values are unreasonable, assume call failed and use incremental stack
423426 refinement method instead. Returns TRUE if the stack parameters could be
424427 determined exactly, FALSE if incremental refinement is necessary. */
425428static kmp_int32 __kmp_set_stack_info (int gtid, kmp_info_t *th) {
426429 int stack_data;
427430#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
428431 KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
429- pthread_attr_t attr;
430432 int status;
431433 size_t size = 0 ;
432434 void *addr = 0 ;
@@ -436,6 +438,19 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
436438 pthread_attr_getstack may cause thread gtid aliasing */
437439 if (!KMP_UBER_GTID (gtid)) {
438440
441+ #if KMP_OS_SOLARIS
442+ stack_t s;
443+ if ((status = thr_stksegment (&s)) < 0 ) {
444+ KMP_CHECK_SYSFAIL (" thr_stksegment" , status);
445+ }
446+
447+ addr = s.ss_sp ;
448+ size = s.ss_size ;
449+ KA_TRACE (60 , (" __kmp_set_stack_info: T#%d thr_stksegment returned size:"
450+ " %lu, low addr: %p\n " ,
451+ gtid, size, addr));
452+ #else
453+ pthread_attr_t attr;
439454 /* Fetch the real thread attributes */
440455 status = pthread_attr_init (&attr);
441456 KMP_CHECK_SYSFAIL (" pthread_attr_init" , status);
@@ -454,6 +469,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
454469 gtid, size, addr));
455470 status = pthread_attr_destroy (&attr);
456471 KMP_CHECK_SYSFAIL (" pthread_attr_destroy" , status);
472+ #endif
457473 }
458474
459475 if (size != 0 && addr != 0 ) { // was stack parameter determination successful?
@@ -2175,6 +2191,54 @@ int __kmp_is_address_mapped(void *addr) {
21752191 }
21762192
21772193 kvm_close (fd);
2194+ #elif KMP_OS_SOLARIS
2195+ prmap_t *cur, *map;
2196+ void *buf;
2197+ uintptr_t uaddr;
2198+ ssize_t rd;
2199+ int err;
2200+ int file;
2201+
2202+ pid_t pid = getpid ();
2203+ struct ps_prochandle *fd = Pgrab (pid, PGRAB_RDONLY, &err);
2204+ ;
2205+
2206+ if (!fd) {
2207+ return 0 ;
2208+ }
2209+
2210+ char *name = __kmp_str_format (" /proc/%d/map" , pid);
2211+ size_t sz = (1 << 20 );
2212+ file = open (name, O_RDONLY);
2213+ if (file == -1 ) {
2214+ KMP_INTERNAL_FREE (name);
2215+ return 0 ;
2216+ }
2217+
2218+ buf = kmpc_malloc (sz);
2219+
2220+ while (sz > 0 && (rd = pread (file, buf, sz, 0 )) == sz) {
2221+ void *newbuf;
2222+ sz <<= 1 ;
2223+ newbuf = kmpc_realloc (buf, sz);
2224+ buf = newbuf;
2225+ }
2226+
2227+ map = reinterpret_cast <prmap_t *>(buf);
2228+ uaddr = reinterpret_cast <uintptr_t >(addr);
2229+
2230+ for (cur = map; rd > 0 ; cur++, rd = -sizeof (*map)) {
2231+ if ((uaddr >= cur->pr_vaddr ) && (uaddr < cur->pr_vaddr )) {
2232+ if ((cur->pr_mflags & MA_READ) != 0 && (cur->pr_mflags & MA_WRITE) != 0 ) {
2233+ found = 1 ;
2234+ break ;
2235+ }
2236+ }
2237+ }
2238+
2239+ kmpc_free (map);
2240+ close (file);
2241+ KMP_INTERNAL_FREE (name);
21782242#elif KMP_OS_DARWIN
21792243
21802244 /* On OS X*, /proc pseudo filesystem is not available. Try to read memory
@@ -2253,9 +2317,9 @@ int __kmp_is_address_mapped(void *addr) {
22532317 }
22542318#elif KMP_OS_WASI
22552319 found = (int )addr < (__builtin_wasm_memory_size (0 ) * PAGESIZE);
2256- #elif KMP_OS_SOLARIS || KMP_OS_AIX
2320+ #elif KMP_OS_AIX
22572321
2258- // FIXME(Solaris, AIX): Implement this
2322+ // FIXME(AIX): Implement this
22592323 found = 1 ;
22602324
22612325#else
0 commit comments