Search code examples
unixfreebsdbsdnetbsd

Implementation of copyout() in FreeBSD


Where is the definition of function copyout() in FreeBSD for AMD64?

(http://www.unix.com/man-page/FreeBSD/9/copyout/)

The only place I can find is in sys/sys/systm.h.

The definition/declaration is:

int     copyout(const void * __restrict kaddr, void * __restrict udaddr,
        size_t len) __nonnull(1) __nonnull(2);

Is it a declaration or a definition? What does __nonnull(1) and __nonnull(2) mean?


Solution

  • That is a function prototype, otherwise known as a declaration. The implementation (definition if you choose) is in the kernel sources. You can find those online, or (if you chose to install sources) on your local FreeBSD machine (under /usr/src/sys). There are actually several copies, depending on the hardware for which the kernel is compiled. (The function names, by the way, are "old" — I encountered them in the mid-1980s, and they were well-known at that point in time).

    The kernel source contains several implementations of these functions, depending on the hardware platform. For instance, in FreeBSD 10, the amd64 version is written in assembly language (see SVN in /usr/src/sys/amd64/amd64/support.S for instance). In the same release, I found only one implementation written in C (under the powerpc subtree), and in current source, that has been rewritten. So, to know "where" is the source, you must do some research and find the corresponding source for your hardware platform and release of FreeBSD.

    __nonnull is a compiler directive telling it to ensure that the given parameters are not obviously null-pointers. See for example these mailing list comments: