2

I want to use something (header file, struct, function or macro) that is declared / defined under arch/XXX/asm/include (in my case, PAGE_TABLE) in a kernel module.

Is it possible to know if that thing is present on all architectures?

Phrased differently: what exactly is the arch-portable API that the kernel exposes to kernel space under asm/?

I could find . or grep -r into the kernel tree, but is there a better way to know that for every new architecture that comes out, that thing must be defined for the architecture to be supported? After all, even if something is furnished on all existing architectures, who guarantees that it is not just a coincidence that they all furnish those things, but that they are not mandatory?

Taking headers for example, in recent source snapshots, x86 contains acpi.h, but arm does not, but all architectures seem to have page.h. So how can I know that I can use #include <asm/page.h> but not acpi.h? page.h on the other hand, is expected to have an implementation on all archs since include/linux/ uses it in several points, and include/linux is meant to be portable to all architectures (please confirm this point).

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • *After all, even if something is furnished on all existing architectures, who guarantees that it is not just a coincidence that they all furnish those things, but that they are not mandatory?* This is a misunderstanding of how the kernel development process works. [Nothing in the kernel source is guaranteed to always remain the same or backwards compatible](https://www.kernel.org/doc/Documentation/stable_api_nonsense.txt). The only way to guarantee your code will work in future version is to get your module included in mainline. – tangrs Jan 01 '16 at 12:40

1 Answers1

0

You can check it by yourself:

Algorithm:

  1. Init array of all the possible ARCH's e.g. i386
  2. Init /tmp/include/name_of_arch directory for each arch
  3. Iterate for each ARCH: make headers_install ARCH=name_of_arch INSTALL_HDR_PATH=/tmp/include/name_or_arch/
  4. For each file in each arch folder: compute sha256sum
  5. Find the intersection of all the commons sha256 signatures.

You can find some the ARCH's in checkstack.pl script, e.g. m68k or in the main Makefile of the kernel.

Community
  • 1
  • 1
0x90
  • 39,472
  • 36
  • 165
  • 245
  • Thanks for the answer, but as I said in the question: 1) usage is on a kernel module. Or is it true that the asm headers that are exported to userspace are exactly the same as those that are available on all kernel modules? 2) If possible, I don't want to process the source and see what is defined on all archs (this is what I meant by not using find/grep), because if a new architecture comes out, who guarantees that this new architecture should furnish those headers? Maybe it was just a coincidence that all existing architectures are able to furnish those headers. – Ciro Santilli OurBigBook.com Jul 16 '13 at 11:52
  • making my first comment's point 1) clearer: the link given to headers_install doc says that it exports `in a form suitable for use by userspace programs`. – Ciro Santilli OurBigBook.com Jul 16 '13 at 11:56
  • 1
    @cirosantilli Some headers only make sense for certain architectures. That is, they are arch-specific. – Peter L. Jul 16 '13 at 16:44
  • 1
    @PeterL. I see what you mean, and I imagine that is the case for `acpi.h` in x86. But it seems that there are some which should be available to all architectures, since they are used extensively from `include/linux/` in important files sched.h via `#include asm/XXX.h`, and stuff under `include/linux/` should be architecture independant (please correct if this is not true).What I wanted to know in this question, is how to decide on which I can rely on when writting portable kernel code. – Ciro Santilli OurBigBook.com Jul 16 '13 at 17:05