Page MenuHomeFreeBSD

Extended errors from kernel
Needs ReviewPublic

Authored by kib on Fri, May 23, 6:42 AM.
Tags
None
Referenced Files
F118467615: D50483.diff
Thu, May 29, 6:24 PM
F118394614: D50483.diff
Wed, May 28, 9:05 PM
Unknown Object (File)
Tue, May 27, 3:59 PM
Unknown Object (File)
Tue, May 27, 4:27 AM

Details

Reviewers
brooks

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib requested review of this revision.Fri, May 23, 6:42 AM

Not tested, but at least it compiles.
The formatting of the errors to display them to user is not implemented: uexterr_gettext() is a stub.
I only added two places for mmap() to demonstrate use of the kernel interface.

Make it possible to infer that there were no extended error reported.

Over all this looks great.

I'm on the fence about extending struct pthread on vs adding avoid additional mallocs. It's certainly simplifying, but people might want it off in some cases (e.g., if the kernel doesn't include messages or the developer isn't using APIs they think would benefit from extra explanations.)

sys/kern/sys_generic.c
2239

Enforce uap->flags == 0?

2244

I wonder if it makes more sense to encode the version in the flags and not try to dance around its presence in the structure.

2257

IMO this shouldn't exist. If part of the thread's execution doesn't know where the buffer is that should be respected. If we want to leak the pointer for diagnostic purposes let's do it without provenance via kinfo_proc.

I'd almost certainly disable this on CheriABI.

sys/kern/syscalls.master
3356

There annotation should probably be _Inout_updates_bytes_opt_(sizeof(struct uexterror)), but you might need to hardcode the value rather than using sizeof.

sys/sys/exterrvar.h
28

I wonder if EXTERR_CATEGORY is the right name. It's effectively the file in this design.

kib marked 4 inline comments as done.Sat, May 24, 3:47 AM

Over all this looks great.

I'm on the fence about extending struct pthread on vs adding avoid additional mallocs. It's certainly simplifying, but people might want it off in some cases (e.g., if the kernel doesn't include messages or the developer isn't using APIs they think would benefit from extra explanations.)

Then how would it disabled?
FWIW, I indeed can do 'malloc; exterrctl(); if error {free}' in libthr. But I do not see a good option for the libc.

sys/kern/sys_generic.c
2239

Flags are used in the current version, I added the check for valid bits.

2244

IMO signatures are useful. If only for debugging.

sys/kern/syscalls.master
3356

No, I do not think so. I changed it to _In_reads_bytes_(4), this is all what this syscall does. Assuming the direct reading the spec as plain english is correct.

And there is similar annotation bug for sigfastblock(2), I suspect.

sys/sys/exterrvar.h
28

I wanted to automatically convert the source path of the compiled files (perhaps with everything before sys/ trimmed) into some identifier, easily mapped back. I was not able to create a scheme that did not require an additional build artifact to be consulted afterward. So I renamed that to category. For instance, I imagined that kern_descrip.c and sys_generic.c fall into same EXTERR_CAT_FILEDESC name.

I certainly can rename this to EXTERR_FILEID or use a different scheme of generating something to match source lines.

kib marked 3 inline comments as done.

Fix hand-off from libc to libthr.
Generate SIGSEGV on EFAULT from copyout of the exterr.
Remove getptr.
Report exterr address through kinfo_proc.

Still not tested.

Fix fork and exec.
Add sysconf() to get max exterr buffer
Provide real exterr format procedure
Fixed flags handling in syscall

This version works.

I'm still not a big fan of putting the strings in the kernel syscall ABI (as i guarantee someone's gonna end up writing stuff that depends upon the content of the strings!), but I /am/ a fan of how the kernel source is being updated with errors. We can at least grep for the macro use to see what they're doing, and they're a no-op if it's not compiled in.