66
66
#include < sys/types.h>
67
67
#include < sys/sysctl.h>
68
68
#elif KMP_OS_SOLARIS
69
+ #include < libproc.h>
70
+ #include < procfs.h>
71
+ #include < thread.h>
69
72
#include < sys/loadavg.h>
70
73
#endif
71
74
@@ -418,15 +421,14 @@ void __kmp_terminate_thread(int gtid) {
418
421
KMP_YIELD (TRUE );
419
422
} //
420
423
421
- /* Set thread stack info according to values returned by pthread_getattr_np() .
424
+ /* Set thread stack info.
422
425
If values are unreasonable, assume call failed and use incremental stack
423
426
refinement method instead. Returns TRUE if the stack parameters could be
424
427
determined exactly, FALSE if incremental refinement is necessary. */
425
428
static kmp_int32 __kmp_set_stack_info (int gtid, kmp_info_t *th) {
426
429
int stack_data;
427
430
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
428
431
KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
429
- pthread_attr_t attr;
430
432
int status;
431
433
size_t size = 0 ;
432
434
void *addr = 0 ;
@@ -436,6 +438,19 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
436
438
pthread_attr_getstack may cause thread gtid aliasing */
437
439
if (!KMP_UBER_GTID (gtid)) {
438
440
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;
439
454
/* Fetch the real thread attributes */
440
455
status = pthread_attr_init (&attr);
441
456
KMP_CHECK_SYSFAIL (" pthread_attr_init" , status);
@@ -454,6 +469,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
454
469
gtid, size, addr));
455
470
status = pthread_attr_destroy (&attr);
456
471
KMP_CHECK_SYSFAIL (" pthread_attr_destroy" , status);
472
+ #endif
457
473
}
458
474
459
475
if (size != 0 && addr != 0 ) { // was stack parameter determination successful?
@@ -2175,6 +2191,54 @@ int __kmp_is_address_mapped(void *addr) {
2175
2191
}
2176
2192
2177
2193
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);
2178
2242
#elif KMP_OS_DARWIN
2179
2243
2180
2244
/* On OS X*, /proc pseudo filesystem is not available. Try to read memory
@@ -2253,9 +2317,9 @@ int __kmp_is_address_mapped(void *addr) {
2253
2317
}
2254
2318
#elif KMP_OS_WASI
2255
2319
found = (int )addr < (__builtin_wasm_memory_size (0 ) * PAGESIZE);
2256
- #elif KMP_OS_SOLARIS || KMP_OS_AIX
2320
+ #elif KMP_OS_AIX
2257
2321
2258
- // FIXME(Solaris, AIX): Implement this
2322
+ // FIXME(AIX): Implement this
2259
2323
found = 1 ;
2260
2324
2261
2325
#else
0 commit comments