On Wed, May 21, 2025 at 11:23:12PM +0000, Brooks Davis wrote:
> On Wed, May 21, 2025 at 11:07:09AM -0600, Warner Losh wrote:
> > In short, I'd love to widen the interface, but there's a number of practical
> > issues in the way.
> 
> I think caching something in the kernel of later retrieval or adding a
> new return path to the ABI is the wrong way around.  Instead I think the
> right solution is for each thread to register a userspace buffer.  You
> end up adding one or two entries to struct thread (pointer to a
> structure or pointer to an buffer and length) and if the pointer is
> non-NULL you copyout a string to the buffer.  This avoids signficant
> new storage in the kernel and means programs that won't use this data
> don't see it.  It also means that the debugger can access it without
> needing a new PT_ argument.
> 
> As a minor downside you would introduce some new error conditions if the
> programmer messes up registration, but we'd probably just have libthr do
> it in most cases (that would be more debugger friendly since you
> could hang it off a known location in userspace).

I mostly agree with this proposal, and can implement it.
I strongly object against blowing the kernel with MBs of strings.

Userspace can register per-thread extended errno location, and kernel
can copyout the ext-errno when returning error.

We already have a similar mechanism for fast signals blocking, so I
am talking with relatively good experience about related machanism.
There is no problem with userspace not registering or messing up the
registration: after the first failure the mechanism stops working, until
the next registration attempt. Since registration must be per-thread,
some libc/libthr wrapper would be provided to fetch the value for C
runtime.  Go would handle it on its own, as it already does for vdso.
I do not see a problem with Rust/Java/Nodejs, since they play well
with C runtime.

All this is quite doable, and the biggest work is to adjust kernel to
record additional metadata to places where it identifies an error
condition.

Reply via email to