2

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?

WindChaser
  • 960
  • 1
  • 10
  • 30

1 Answers1

3

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:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Do you know where is the actual function body of copyout() for AMD64, FreeBSD 10.1? I know it must be in some files, but cannot locate it. – WindChaser Jun 05 '15 at 08:43
  • 1
    It's in `sys/amd64/amd64/support.S` , See e.g. here http://fxr.watson.org/fxr/source/amd64/amd64/support.S#L227 – nos Jun 05 '15 at 08:44
  • Any easy way to intercept (record or change the copied bytes) function `copyout()`? It seems hard to intercept it in the assembly language (%rdi, %rsi, %rdx). – WindChaser Jun 05 '15 at 21:30
  • If you are able to compile your own kernel, you could rename the entrypoints in the `.S` file, and interpose a c-language function that calls the renamed entrypoints. – Thomas Dickey Jun 05 '15 at 22:24