kernel headers for svc - MarekBykowski/readme GitHub Wiki

HOME » kernel headers for svc

Exporting kernel headers for use in 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:

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
  1. 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
  1. Finally, include the kernel header file #include "include/linux/cxl_mem.h to the app
⚠️ **GitHub.com Fallback** ⚠️