Newer versions of our linux distributions had their includes revised: A lot of kernel structures that were previously exported to userspace now are not exported anymore. To take an example, definitions of page size (macro PAGE_SIZE), usually found on asm/page.h, that used to be available when one installed the kernel-headers (or equivalent) package.
I see the point of hiding internal kernel structures from most userspace programs, usually they shouldn’t mess with such structures. But if your userspace program is actually a test for a kernel feature? Tests that are designed to test the kernel should be able to access those structures, otherwise we won’t be accurate and portable on our tests.
Example: I am getting the cerberus testsuite to compile under ubuntu 9.04 and opensuse 11. They both don’t have asm/page.h anymore and some of the code of the cerberus test suite use the PAGE_SIZE macro. Doing a bit of research points out to the fact that I should be using the getpagesize() function from unistd.h. Should I really?
/* Return the number of bytes in a page. This is the system's page size,
which is not necessarily the same as the hardware page size. */
extern int getpagesize (void) __THROW __attribute__ ((__const__));
An inspection on the testsuite code shows me that the authors really meant to use the hardware page sizes:
/* Takes aligned buffers. Finds an arbitrary location in memory of a
* user process (must be passed as an array of ints) and translates
* it to physical memory location. All this without kernel support
* (besides /proc/kcore). Optionally specify a character alignment in
* case the memory buffer is not byte-aligned. */
/* Now compute the offset (in chars) of the error from the page
fail_page_offset = ((int) (&nbuf[offset])) % PAGE_SIZE
So, how do we handle ‘special’ userspace programs that are intended to test kernel and hardware? Do we still enforce this restriction of not being able to access kernel structures or we do have an alternative solution? Comments are very very much appreciated, I would like to get some ideas before I start to fix those suites…