link(2) and EFAULT
Oliver Fromme
check+jltyok00rsxcmfu5 at fromme.com
Fri Jul 27 02:18:37 PDT 2007
Dave Hayes wrote:
> Under what conditions does link() return EFAULT? The man
> page says:
>
> [EFAULT] One of the pathnames specified is outside the
> process's allocated address space.
>
> However I would think that if I had a (char *) pointing
> outside the address space that I would get a segfault
> somewhere before getting this error.
As others have pointed out, only userland applications
can generate a segfault (SIGSEGV). If an illegal access
happens inside the kernel, it would normally panic the
machine. Of course that would be undesirable so the
syscalls take precautions and return EFAULT in such cases.
> How would you even
> handle this error, should your code get it?
It's clearly an application bug to pass an invalid pointer
to a syscall. The most sensible thing would be to print
an error message (along the line "internal error, please
report this bug to the author") and abort(2), dropping a
core dump that can be useful for debugging.
However, if the failed syscall is not critical for the
application, it might choose to continue anyway. But a
warning should still be printed so the bug doesn't stay
unnoticed.
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.
More information about the Kernel
mailing list