The kldstat(2) syscall supports two different structures, identified by
their size, which the application stores in the version field before the
call. Since one is a prefix of the other, instead of calling different
functions to fill each one in like modstat(2) does, we fill in the
larger of the two and simply don't copy out the extra fields if the
smaller one was requested. As a side effect, we failed to fill out the
version field in either case. This causes application code that sets
the version field once and calls kldstat(2) repeatedly to fail since the
version field is now incorrect for subsequent calls, whereas the same
pattern works fine for modstat(2) because it copies the same version
value back out. Fix this by setting the version field immediately
before copying the struct out.
While here, amend the manual pages for both kldstat(2) and modstat(2) to
clarify that the version field is unchanged on return and remove bad
advice about rebuilding world if either syscall returns EINVAL.
MFC after: 1 week