66
66
#include < sys/types.h>
67
67
#include < sys/sysctl.h>
68
68
#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>
69
75
#include < sys/loadavg.h>
70
76
#endif
71
77
@@ -418,15 +424,14 @@ void __kmp_terminate_thread(int gtid) {
418
424
KMP_YIELD (TRUE );
419
425
} //
420
426
421
- /* Set thread stack info according to values returned by pthread_getattr_np() .
427
+ /* Set thread stack info.
422
428
If values are unreasonable, assume call failed and use incremental stack
423
429
refinement method instead. Returns TRUE if the stack parameters could be
424
430
determined exactly, FALSE if incremental refinement is necessary. */
425
431
static kmp_int32 __kmp_set_stack_info (int gtid, kmp_info_t *th) {
426
432
int stack_data;
427
433
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
428
434
KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
429
- pthread_attr_t attr;
430
435
int status;
431
436
size_t size = 0 ;
432
437
void *addr = 0 ;
@@ -436,6 +441,19 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
436
441
pthread_attr_getstack may cause thread gtid aliasing */
437
442
if (!KMP_UBER_GTID (gtid)) {
438
443
444
+ #if KMP_OS_SOLARIS
445
+ stack_t s;
446
+ if ((status = thr_stksegment (&s)) < 0 ) {
447
+ KMP_CHECK_SYSFAIL (" thr_stksegment" , status);
448
+ }
449
+
450
+ addr = s.ss_sp ;
451
+ size = s.ss_size ;
452
+ KA_TRACE (60 , (" __kmp_set_stack_info: T#%d thr_stksegment returned size:"
453
+ " %lu, low addr: %p\n " ,
454
+ gtid, size, addr));
455
+ #else
456
+ pthread_attr_t attr;
439
457
/* Fetch the real thread attributes */
440
458
status = pthread_attr_init (&attr);
441
459
KMP_CHECK_SYSFAIL (" pthread_attr_init" , status);
@@ -454,6 +472,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
454
472
gtid, size, addr));
455
473
status = pthread_attr_destroy (&attr);
456
474
KMP_CHECK_SYSFAIL (" pthread_attr_destroy" , status);
475
+ #endif
457
476
}
458
477
459
478
if (size != 0 && addr != 0 ) { // was stack parameter determination successful?
@@ -2175,6 +2194,56 @@ int __kmp_is_address_mapped(void *addr) {
2175
2194
}
2176
2195
2177
2196
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
2178
2247
#elif KMP_OS_DARWIN
2179
2248
2180
2249
/* On OS X*, /proc pseudo filesystem is not available. Try to read memory
@@ -2253,9 +2322,9 @@ int __kmp_is_address_mapped(void *addr) {
2253
2322
}
2254
2323
#elif KMP_OS_WASI
2255
2324
found = (int )addr < (__builtin_wasm_memory_size (0 ) * PAGESIZE);
2256
- #elif KMP_OS_SOLARIS || KMP_OS_AIX
2325
+ #elif KMP_OS_AIX
2257
2326
2258
- // FIXME(Solaris, AIX): Implement this
2327
+ // FIXME(AIX): Implement this
2259
2328
found = 1 ;
2260
2329
2261
2330
#else
0 commit comments