Page MenuHomeFreeBSD

Improve error handling for posix file syscalls
ClosedPublic

Authored by markj on Feb 24 2016, 8:17 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 20, 3:45 AM
Unknown Object (File)
Oct 2 2024, 7:34 AM
Unknown Object (File)
Sep 29 2024, 11:26 PM
Unknown Object (File)
Sep 9 2024, 3:25 AM
Unknown Object (File)
Sep 1 2024, 12:56 PM
Unknown Object (File)
Aug 17 2024, 9:30 PM
Unknown Object (File)
Jun 30 2024, 9:19 AM
Unknown Object (File)
Jun 30 2024, 9:19 AM
Subscribers

Details

Summary

At the moment, both syscalls store the error number in td_retval[0] and
return 0, indicating success. This has two problems:

  • td_errno is not set, so errors are not made visible to ktrace and dtrace in the usual way
  • negative error numbers such as ERESTART, which are supposed to be interpreted by the kernel, are returned to userland

Thus, set td_errno and use TDP_NERRNO to ensure that it is not set by
the kernel syscall layer, and return negative errors directly.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 2654
Build 2672: arc lint + arc unit

Event Timeline

markj retitled this revision from to Improve error handling for posix file syscalls.
markj edited the test plan for this revision. (Show Details)
markj updated this object.
markj added a subscriber: kib.
markj removed a subscriber: kib.

You also need to fix freebsd32_posix_f*() wrappers from sys/compat/freebsd32/freebsd32_misc.c

sys/kern/vfs_syscalls.c
4461

posix_ret_error() might be better. For some reason this function should be non-static anyway, and I expect that more posix functions with this interface would come.

markj edited edge metadata.

Fixups based on feedback.

sys/kern/vfs_syscalls.c
4461

Perhaps syscall_posix_ret(), to fit in with the kern_syscalls.c namespace?

kib edited edge metadata.
kib added inline comments.
sys/kern/kern_syscalls.c
234 ↗(On Diff #13693)

kern_syscalls.c is somewhat unnatural place as well, the file is for stuff related to the syscall registration and syscall module loading. Might be sys_generic.c is better place.

sys/kern/vfs_syscalls.c
4461

Good name.

sys/sys/sysent.h
273 ↗(On Diff #13693)

sysent.h is unsuitable, I think. syscallsubr.h is the good place IMO, it is the place for syscall-related helpers.

This revision is now accepted and ready to land.Feb 24 2016, 9:34 PM
sys/sys/sysent.h
273 ↗(On Diff #13693)

Ok. I had looked at syscallsubr.h (which sounds like the right place), but it's currently only used for the kern_* syscall implementation routines; sysent.h is used for various ad-hoc helpers.

sys/sys/sysent.h
273 ↗(On Diff #13693)

sysent.h is for the ABI vectors related declarations.

sys/kern/vfs_syscalls.c
4461

Call it kern_posix_error(), it is both more regular and match the syscallsubr.h namespace conventions.

markj edited edge metadata.
  • More fixups
This revision now requires review to proceed.Feb 25 2016, 6:40 PM
kib edited edge metadata.
This revision is now accepted and ready to land.Feb 25 2016, 6:47 PM

This was committed... not sure why that's not happening automatically anymore.