kernel headers for svc - MarekBykowski/readme GitHub Wiki
HOME » kernel headers for svc
Exporting kernel headers for use by userspace is here https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt.
Kernel header files are used by intermediate libraries (such as glibc or uClibc) and not usually directly by the apps. Here are further details:
- for
make headers_install INSTALL_HDR_PATH=install-directorysee here https://www.gnu.org/software/libc/manual/html_node/Linux.html - for configuring and compiling the glibc
--with-headers=directorysee here https://www.gnu.org/software/libc/manual/html_node/Configuring-and-compiling.html
- First, add your kernel header to
UAPI(user api) dir, eg.include/uapi/linux/avery_doe.h. Only those headers are copied over withmake headers_install - Generate headers from the kernel
make headers_install ARCH=x86 INSTALL_HDR_PATH=/home/xxbykowm/repos/cxl_run_qemu/workdir/linux-cxl/linux-cxl-apps
-
UAPIstructs must use__uXX/__sXX, notuXX/sXX. So if needed edit your kernelUAPIheader, not the userspace copy, eg.include/uapi/linux/avery_doe.hand change
u32 type;
u32 offset;
u32 value;
s32 status;
``
to
__u32 type; __u32 offset; __u32 value; __s32 status;
These will compile perfectly fine in kernel and user-spcace.
### ~How to use the kernel headers directly from the app~
> But if you really want to/have to use it directly here is a workaround, of course one of many available to use:
> 1. `make headers_install ARCH=x86 INSTALL_HDR_PATH=/home/xxbykowm/repos/cxl_run_qemu/workdir/linux-cxl/linux-cxl-apps`
> 2. Kernel installed header files to install dir. See below
> ```
> $ ls
> Makefile README.md cscope.files cscope.out cxl_app cxl_app.c cxl_app.o include
> ```
> 3. A file, `include/linux/cxl_mem.h`, implementing the symbols for CXL IOCTL includes `<linux/types.h>` that is for the kernel, not user-space so that work it around by `#ifdef __KERNEL__` separating from user and kernel-specific code and adding in our own header for the types, such as `__u32` the kernel uses. Also add an include path `-I./include_wa_kernel_headers` to the Makefile for the header `kernel_types.h` to be searched for.
> ```
> xxbykowm@ubuntu:~/repos/cxl_run_qemu/workdir/linux-cxl/linux-cxl-apps$ git diff include/linux/cxl_mem.h
> diff --git a/include/linux/cxl_mem.h b/include/linux/cxl_mem.h
> index 836bc7d..f9ab469 100644
> --- a/include/linux/cxl_mem.h
> +++ b/include/linux/cxl_mem.h
> @@ -6,7 +6,11 @@
> #ifndef _CXL_MEM_H_
> #define _CXL_MEM_H_
>
> +#ifdef __KERNEL__
> #include <linux/types.h>
> +#else
> +#include <kernel_types.h>
> +#endif
>
> /**
> * DOC: UAPI
> ```
> ```
> $ cat ./include_wa_kernel_headers/kernel_types.h
> #ifndef __KERNEL_TYPES_H
> #define __KERNEL_TYPES_H
> #include <stdint.h>
> typedef uint8_t u8;
> typedef uint16_t u16;
> typedef uint32_t u32;
> typedef uint64_t u64;
> typedef uint8_t __u8;
> typedef uint16_t __u16;
> typedef uint32_t __u32;
> typedef uint64_t __u64;
> #endif
> ```
> 4. Finally, include the kernel header file `#include "include/linux/cxl_mem.h` to the app