[libc-commits] [libc] [libc] Add pthread_getstack_np extension (PR #217049)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Aug 31 07:57:59 PDT 2026


================
@@ -130,10 +132,20 @@ static TLSDescriptor tls;
     case AT_HWCAP2:
       hwcap2 = aux_entry.val;
       break;
+    case AT_EXECFN:
+      execfn = reinterpret_cast<const char *>(aux_entry.val);
+      break;
     default:
       break; // TODO: Read other useful entries from the aux vector.
     }
   }
+  // AT_EXECFN is typically the last thing on the stack. Round it up to the
+  // next page boundary.
+  uintptr_t stack_addr =
----------------
labath wrote:

What would you all say to this returning a `(stack_low, stack_high)` pair instead of `base+size`?

The thing I like about this is that it can neatly handle both grows-down and grows-up stack (just change which value you return as DYNAMIC).

The thing I don't like about it is it breaks symmetry with `pthread_attr_getstack`, although you could say that this is already done via PTHREAD_STACK_DYNAMIC_NP. OTOH, if we want to break symmetry then the space of possible solutions gets pretty open. For instance one could return three values (e.g., in a struct): stack_low+stack_high+flags. flags could say which of the other two values are valid (or dynamic), which would let us say something like "stack_low current value is `X`, but it can change in the future".

https://github.com/llvm/llvm-project/pull/217049


More information about the libc-commits mailing list