kernel: Fix error for dup2 if the new file descriptor is out of bounds.

According to POSIX, when using fcntl()'s F_DUPFD or F_DUPFD_CLOEXEC
commands and the new file descriptor is out of bounds, EINVAL must be
returned. But if it is out of bounds when using dup2(), EBADF must be
returned.

So add detection of whether kern_dup() was called from kern_fcntl() or
from sys_dup2() and act accordingly.
kernel/kern_dup(): Fix comment.