get rid of lkmc package, move userland and kernel-modules to top

Rationale: we already had a non buildroot build system,
maintaining both will be hard, and having short paths is more awesome.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-10-25 00:00:01 +00:00
parent 98d2c83317
commit ca231b82f6
99 changed files with 184 additions and 181 deletions

1
include/README.adoc Normal file
View File

@@ -0,0 +1 @@
https://github.com/cirosantilli/linux-kernel-module-cheat#include-directory

View File

@@ -0,0 +1,9 @@
#ifndef IOCTL_H
#define IOCTL_H
#include <linux/ioctl.h>
#define LKMC_ANONYMOUS_INODE_MAGIC 0x33
#define LKMC_ANONYMOUS_INODE_GET_FD _IOR(LKMC_ANONYMOUS_INODE_MAGIC, 0, int)
#endif

42
include/ioctl.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef IOCTL_H
#define IOCTL_H
#include <linux/ioctl.h>
/* Structs are the way to pass multiple arguments. */
typedef struct {
int i;
int j;
} lkmc_ioctl_struct;
/* TODO some random number I can't understand how to choose. */
#define LKMC_IOCTL_MAGIC 0x33
/* I think those number do not *need* to be unique across, that is just to help debugging:
* https://stackoverflow.com/questions/22496123/what-is-the-meaning-of-this-macro-iormy-macig-0-int
*
* However, the ioctl syscall highjacks several low values at do_vfs_ioctl, e.g.
* This "forces" use to use the _IOx macros...
* https://stackoverflow.com/questions/10071296/ioctl-is-not-called-if-cmd-2
*
* Some of those magic low values are used for fnctl, which can also be used on regular files:
* e.g. FIOCLEX for close-on-exec:
* https://stackoverflow.com/questions/6125068/what-does-the-fd-cloexec-fcntl-flag-do
*
* TODO are the W or R of _IOx and type functional, or only to help with uniqueness?
*
* Documentation/ioctl/ioctl-number.txt documents:
*
* ....
* _IO an ioctl with no parameters
* _IOW an ioctl with write parameters (copy_from_user)
* _IOR an ioctl with read parameters (copy_to_user)
* _IOWR an ioctl with both write and read parameters.
* ....
*/
/* Take an int, increment it. */
#define LKMC_IOCTL_INC _IOWR(LKMC_IOCTL_MAGIC, 0, int)
/* Take a struct with two ints, increment the first, and decrement the second. */
#define LKMC_IOCTL_INC_DEC _IOWR(LKMC_IOCTL_MAGIC, 1, lkmc_ioctl_struct)
#endif

10
include/netlink.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef NETLINK_H
#define NETLINK_H
/* Socket identifier, matches userland. TODO can be anything?
* Is there a more scalable way to do it? E.g. ioctl device,
* kernel generates one on the fly, then give it back and connect?
* https://stackoverflow.com/questions/32898173/can-i-have-more-than-32-netlink-sockets-in-kernelspace */
#define NETLINK_USER 31
#endif

58
include/ring0.h Normal file
View File

@@ -0,0 +1,58 @@
#if defined(__x86_64__) || defined(__i386__)
#ifdef THIS_MODULE
#include <linux/kernel.h>
#if defined(__x86_64__)
typedef u64 T;
#elif defined(__i386__)
typedef u32 T;
#endif
#else
#include <stdint.h>
#if defined(__x86_64__)
typedef uint64_t T;
#elif defined(__i386__)
typedef uint32_t T;
#endif
#endif
typedef struct {
T cr0;
T cr2;
T cr3;
} Ring0Regs;
void ring0_get_control_regs(Ring0Regs *ring0_regs)
{
#if defined(__x86_64__)
__asm__ __volatile__ (
"mov %%cr0, %%rax;"
"mov %%eax, %0;"
"mov %%cr2, %%rax;"
"mov %%eax, %1;"
"mov %%cr3, %%rax;"
"mov %%eax, %2;"
: "=m" (ring0_regs->cr0),
"=m" (ring0_regs->cr2),
"=m" (ring0_regs->cr3)
:
: "%rax"
);
#elif defined(__i386__)
__asm__ __volatile__ (
"mov %%cr0, %%eax;"
"mov %%eax, %0;"
"mov %%cr2, %%eax;"
"mov %%eax, %1;"
"mov %%cr3, %%eax;"
"mov %%eax, %2;"
: "=m" (ring0_regs->cr0),
"=m" (ring0_regs->cr2),
"=m" (ring0_regs->cr3)
:
: "%eax"
);
#endif
}
#endif