mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 20:44:26 +01:00
rename include to lkmc
This commit is contained in:
16
README.adoc
16
README.adoc
@@ -2608,7 +2608,7 @@ traps: ring0.out[55] general protection ip:40054c sp:7fffffffec20 error:0 in rin
|
|||||||
Sources:
|
Sources:
|
||||||
|
|
||||||
* link:kernel_modules/ring0.c[]
|
* link:kernel_modules/ring0.c[]
|
||||||
* link:include/ring0.h[]
|
* link:lkmc/ring0.h[]
|
||||||
* link:userland/ring0.c[]
|
* link:userland/ring0.c[]
|
||||||
|
|
||||||
In both cases, we attempt to run the exact same code which is shared on the `ring0.h` header file.
|
In both cases, we attempt to run the exact same code which is shared on the `ring0.h` header file.
|
||||||
@@ -6425,7 +6425,7 @@ Outcome: the test passes:
|
|||||||
Sources:
|
Sources:
|
||||||
|
|
||||||
* link:kernel_modules/ioctl.c[]
|
* link:kernel_modules/ioctl.c[]
|
||||||
* link:include/ioctl.h[]
|
* link:lkmc/ioctl.h[]
|
||||||
* link:userland/kernel_modules/ioctl.c[]
|
* link:userland/kernel_modules/ioctl.c[]
|
||||||
* link:rootfs_overlay/lkmc/ioctl.sh[]
|
* link:rootfs_overlay/lkmc/ioctl.sh[]
|
||||||
|
|
||||||
@@ -6510,7 +6510,7 @@ Outcome: the test passes:
|
|||||||
Sources:
|
Sources:
|
||||||
|
|
||||||
* link:kernel_modules/anonymous_inode.c[]
|
* link:kernel_modules/anonymous_inode.c[]
|
||||||
* link:include/anonymous_inode.h[]
|
* link:lkmc/anonymous_inode.h[]
|
||||||
* link:userland/kernel_modules/anonymous_inode.c[]
|
* link:userland/kernel_modules/anonymous_inode.c[]
|
||||||
* link:rootfs_overlay/lkmc/anonymous_inode.sh[]
|
* link:rootfs_overlay/lkmc/anonymous_inode.sh[]
|
||||||
|
|
||||||
@@ -6538,7 +6538,7 @@ Outcome: the test passes:
|
|||||||
Sources:
|
Sources:
|
||||||
|
|
||||||
* link:kernel_modules/netlink.c[]
|
* link:kernel_modules/netlink.c[]
|
||||||
* link:include/netlink.h[]
|
* link:lkmc/netlink.h[]
|
||||||
* link:userland/kernel_modules/netlink.c[]
|
* link:userland/kernel_modules/netlink.c[]
|
||||||
* link:rootfs_overlay/lkmc/netlink.sh[]
|
* link:rootfs_overlay/lkmc/netlink.sh[]
|
||||||
|
|
||||||
@@ -13481,11 +13481,13 @@ git -C "$(./getvar buildroot_source_dir)" checkout -
|
|||||||
|
|
||||||
=== Directory structure
|
=== Directory structure
|
||||||
|
|
||||||
==== include directory
|
==== lkmc directory
|
||||||
|
|
||||||
link:include/[] contains headers that are shared across both kernel modules and userland structures.
|
link:lkmc/[] contains sources and headers that are shared across kernel modules, userland and baremetal examples.
|
||||||
|
|
||||||
They contain data structs and magic constant for kernel to userland communication.
|
We chose this awkward name so that our includes will have an `lkmc/` prefix.
|
||||||
|
|
||||||
|
Another option would have been to name it as `includes/lkmc`, but that would make paths longer, and we might want to store source code in that directory as well in the future.
|
||||||
|
|
||||||
==== buildroot_packages directory
|
==== buildroot_packages directory
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import distutils.dir_util
|
import distutils.dir_util
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import common
|
import common
|
||||||
@@ -80,14 +81,18 @@ Place the modules on a separate magic directory from non --host builds.
|
|||||||
cc = '{} {}'.format(ccache, gcc)
|
cc = '{} {}'.format(ccache, gcc)
|
||||||
else:
|
else:
|
||||||
cc = gcc
|
cc = gcc
|
||||||
if self.env['verbose']:
|
|
||||||
verbose = ['V=1']
|
|
||||||
else:
|
|
||||||
verbose = []
|
|
||||||
if self.env['host']:
|
if self.env['host']:
|
||||||
linux_dir = os.path.join('/lib', 'modules', platform.uname().release, 'build')
|
linux_dir = os.path.join('/lib', 'modules', platform.uname().release, 'build')
|
||||||
else:
|
else:
|
||||||
linux_dir = self.env['linux_build_dir']
|
linux_dir = self.env['linux_build_dir']
|
||||||
|
ccflags = [
|
||||||
|
'-I', self.env['root_dir'], LF,
|
||||||
|
]
|
||||||
|
make_args_extra = []
|
||||||
|
if self.env['verbose']:
|
||||||
|
make_args_extra.extend(['V=1', LF])
|
||||||
|
if self.env['force_rebuild']:
|
||||||
|
make_args_extra.extend(['-B', LF])
|
||||||
self.sh.run_cmd(
|
self.sh.run_cmd(
|
||||||
(
|
(
|
||||||
[
|
[
|
||||||
@@ -95,13 +100,14 @@ Place the modules on a separate magic directory from non --host builds.
|
|||||||
'-j', str(self.env['nproc']), LF,
|
'-j', str(self.env['nproc']), LF,
|
||||||
'ARCH={}'.format(self.env['linux_arch']), LF,
|
'ARCH={}'.format(self.env['linux_arch']), LF,
|
||||||
'CC={}'.format(cc), LF,
|
'CC={}'.format(cc), LF,
|
||||||
|
'CCFLAGS={}'.format(self.sh.cmd_to_string(ccflags)), LF,
|
||||||
'CROSS_COMPILE={}'.format(prefix), LF,
|
'CROSS_COMPILE={}'.format(prefix), LF,
|
||||||
'LINUX_DIR={}'.format(linux_dir), LF,
|
'LINUX_DIR={}'.format(linux_dir), LF,
|
||||||
'M={}'.format(build_subdir), LF,
|
'M={}'.format(build_subdir), LF,
|
||||||
'OBJECT_FILES={}'.format(' '.join(object_files)), LF,
|
'OBJECT_FILES={}'.format(' '.join(object_files)), LF,
|
||||||
] +
|
] +
|
||||||
self.sh.shlex_split(self.env['make_args']) +
|
make_args_extra +
|
||||||
verbose
|
self.sh.shlex_split(self.env['make_args'])
|
||||||
),
|
),
|
||||||
cwd=os.path.join(self.env['kernel_modules_build_subdir']),
|
cwd=os.path.join(self.env['kernel_modules_build_subdir']),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ consts['userland_subdir'] = 'userland'
|
|||||||
consts['userland_source_dir'] = os.path.join(consts['root_dir'], consts['userland_subdir'])
|
consts['userland_source_dir'] = os.path.join(consts['root_dir'], consts['userland_subdir'])
|
||||||
consts['userland_source_arch_dir'] = os.path.join(consts['userland_source_dir'], 'arch')
|
consts['userland_source_arch_dir'] = os.path.join(consts['userland_source_dir'], 'arch')
|
||||||
consts['userland_build_ext'] = '.out'
|
consts['userland_build_ext'] = '.out'
|
||||||
consts['include_subdir'] = 'include'
|
consts['include_subdir'] = 'lkmc'
|
||||||
consts['include_source_dir'] = os.path.join(consts['root_dir'], consts['include_subdir'])
|
consts['include_source_dir'] = os.path.join(consts['root_dir'], consts['include_subdir'])
|
||||||
consts['submodules_dir'] = os.path.join(consts['root_dir'], 'submodules')
|
consts['submodules_dir'] = os.path.join(consts['root_dir'], 'submodules')
|
||||||
consts['buildroot_source_dir'] = os.path.join(consts['submodules_dir'], 'buildroot')
|
consts['buildroot_source_dir'] = os.path.join(consts['submodules_dir'], 'buildroot')
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
https://github.com/cirosantilli/linux-kernel-module-cheat#include-directory
|
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
ifeq ($(OBJECT_FILES),)
|
|
||||||
# Hardcoding LKMC_MODULE_SUBDIRS here because is not defined.
|
|
||||||
obj-m += $(addsuffix .o, $(notdir $(basename $(filter-out %.mod.c, $(wildcard $(BR2_EXTERNAL_LKMC_PATH)/kernel_modules/*.c)))))
|
|
||||||
else
|
|
||||||
# Trying to do:
|
# Trying to do:
|
||||||
# $(MAKE) -C '$(LINUX_DIR)' M='$(M)' hello.ko hello2.ko
|
# $(MAKE) -C '$(LINUX_DIR)' M='$(M)' hello.ko hello2.ko
|
||||||
# to restrict which modules are built leads to failures
|
# to restrict which modules are built leads to failures
|
||||||
# when doing parallel builds. The only solution I could find
|
# when doing parallel builds. The only solution I could find
|
||||||
# was to let the host select obj-m itself.
|
# was to let the host select obj-m itself.
|
||||||
obj-m += $(OBJECT_FILES)
|
obj-m += $(OBJECT_FILES)
|
||||||
endif
|
ccflags-y := \
|
||||||
ccflags-y := -DDEBUG -g -std=gnu99 -Werror -Wno-declaration-after-statement -Wframe-larger-than=1000000000
|
-DDEBUG \
|
||||||
|
-ggdb3 \
|
||||||
|
-std=gnu99 \
|
||||||
|
-Werror \
|
||||||
|
-Wframe-larger-than=1000000000 \
|
||||||
|
-Wno-declaration-after-statement \
|
||||||
|
$(CCFLAGS)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <linux/printk.h> /* printk */
|
#include <linux/printk.h> /* printk */
|
||||||
#include <linux/uaccess.h> /* copy_from_user */
|
#include <linux/uaccess.h> /* copy_from_user */
|
||||||
|
|
||||||
#include "../include/anonymous_inode.h"
|
#include <lkmc/anonymous_inode.h>
|
||||||
|
|
||||||
static struct dentry *debugfs_file;
|
static struct dentry *debugfs_file;
|
||||||
static u32 myval = 1;
|
static u32 myval = 1;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <linux/printk.h> /* printk */
|
#include <linux/printk.h> /* printk */
|
||||||
#include <linux/uaccess.h> /* copy_from_user, copy_to_user */
|
#include <linux/uaccess.h> /* copy_from_user, copy_to_user */
|
||||||
|
|
||||||
#include "../include/ioctl.h"
|
#include <lkmc/ioctl.h>
|
||||||
|
|
||||||
static struct dentry *debugfs_file;
|
static struct dentry *debugfs_file;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <net/sock.h>
|
#include <net/sock.h>
|
||||||
|
|
||||||
#include "../include/netlink.h"
|
#include <lkmc/netlink.h>
|
||||||
|
|
||||||
struct sock *nl_sk = NULL;
|
struct sock *nl_sk = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
|
||||||
#include "../include/ring0.h"
|
#include <lkmc/ring0.h>
|
||||||
|
|
||||||
static int myinit(void)
|
static int myinit(void)
|
||||||
{
|
{
|
||||||
|
|||||||
1
lkmc/README.adoc
Normal file
1
lkmc/README.adoc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://github.com/cirosantilli/linux-kernel-module-cheat#lkmc-directory
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#ifndef IOCTL_H
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#anonymous-inode */
|
||||||
#define IOCTL_H
|
|
||||||
|
#ifndef LKMC_ANONYMOUS_INODE_H
|
||||||
|
#define LKMC_ANONYMOUS_INODE_H
|
||||||
|
|
||||||
#include <linux/ioctl.h>
|
#include <linux/ioctl.h>
|
||||||
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#ifndef IOCTL_H
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#ioctl */
|
||||||
#define IOCTL_H
|
|
||||||
|
#ifndef LKMC_IOCTL_H
|
||||||
|
#define LKMC_IOCTL_H
|
||||||
|
|
||||||
#include <linux/ioctl.h>
|
#include <linux/ioctl.h>
|
||||||
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#ifndef NETLINK_H
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#netlink-sockets */
|
||||||
#define NETLINK_H
|
|
||||||
|
#ifndef LKMC_NETLINK_H
|
||||||
|
#define LKMC_NETLINK_H
|
||||||
|
|
||||||
/* Socket identifier, matches userland. TODO can be anything?
|
/* Socket identifier, matches userland. TODO can be anything?
|
||||||
* Is there a more scalable way to do it? E.g. ioctl device,
|
* Is there a more scalable way to do it? E.g. ioctl device,
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#ring0 */
|
||||||
|
|
||||||
|
#ifndef LKMC_RING0_H
|
||||||
|
#define LKMC_RING0_H
|
||||||
|
|
||||||
#if defined(__x86_64__) || defined(__i386__)
|
#if defined(__x86_64__) || defined(__i386__)
|
||||||
|
|
||||||
#ifdef THIS_MODULE
|
#ifdef THIS_MODULE
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <include/ring0.h>
|
#include <lkmc/ring0.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
LkmcRing0Regs ring0_regs;
|
LkmcRing0Regs ring0_regs;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h> /* sleep */
|
#include <unistd.h> /* sleep */
|
||||||
|
|
||||||
#include <include/anonymous_inode.h>
|
#include <lkmc/anonymous_inode.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <include/ioctl.h>
|
#include <lkmc/ioctl.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char *ioctl_path;
|
char *ioctl_path;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <include/netlink.h>
|
#include <lkmc/netlink.h>
|
||||||
|
|
||||||
#define MAX_PAYLOAD 1024
|
#define MAX_PAYLOAD 1024
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user