mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
virt_to_phys: fix multiple read size
build-buildroot: add --make-args
This commit is contained in:
35
README.adoc
35
README.adoc
@@ -10989,10 +10989,43 @@ This directory has the following structure:
|
|||||||
|
|
||||||
==== include directory
|
==== include directory
|
||||||
|
|
||||||
link:include/[] contains headers that are shared acros both kernel modules and userland structures.
|
link:include/[] contains headers that are shared across both kernel modules and userland structures.
|
||||||
|
|
||||||
They contain data structs and magic constant for kernel to userland communication.
|
They contain data structs and magic constant for kernel to userland communication.
|
||||||
|
|
||||||
|
==== userland directory
|
||||||
|
|
||||||
|
Userland test programs.
|
||||||
|
|
||||||
|
It is possible to build and run those examples directly on your host:
|
||||||
|
|
||||||
|
....
|
||||||
|
cd userland
|
||||||
|
make
|
||||||
|
....
|
||||||
|
|
||||||
|
For usage in the guest, build with:
|
||||||
|
|
||||||
|
....
|
||||||
|
./build-userland
|
||||||
|
....
|
||||||
|
|
||||||
|
Source: link:build-userland[].
|
||||||
|
|
||||||
|
This makes them visible immediately on the 9P mount `/mnt/9p/out_root_overlay`.
|
||||||
|
|
||||||
|
In order to place them in the root filesystem image itself, you must also run:
|
||||||
|
|
||||||
|
....
|
||||||
|
./build-buildroot
|
||||||
|
....
|
||||||
|
|
||||||
|
To force rebuild all examples, pass the `-B` option to `make`:
|
||||||
|
|
||||||
|
....
|
||||||
|
./build-buildroot --make-args=-B
|
||||||
|
....
|
||||||
|
|
||||||
==== packages directory
|
==== packages directory
|
||||||
|
|
||||||
Every directory inside it is a Buildroot package.
|
Every directory inside it is a Buildroot package.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@@ -18,6 +19,10 @@ Indicate that a given package is present in the root filesystem, which
|
|||||||
allows us to build examples that rely on it.
|
allows us to build examples that rely on it.
|
||||||
''',
|
''',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--make-args',
|
||||||
|
default='',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'targets',
|
'targets',
|
||||||
default=[],
|
default=[],
|
||||||
@@ -27,7 +32,6 @@ Default: build all examples that have their package dependencies met.
|
|||||||
For example, an OpenBLAS example can only be built if the target root filesystem
|
For example, an OpenBLAS example can only be built if the target root filesystem
|
||||||
has the OpenBLAS libraries and headers installed.
|
has the OpenBLAS libraries and headers installed.
|
||||||
''',
|
''',
|
||||||
metavar='programs',
|
|
||||||
nargs='*',
|
nargs='*',
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ has the OpenBLAS libraries and headers installed.
|
|||||||
'OUT_DIR={}'.format(build_dir),
|
'OUT_DIR={}'.format(build_dir),
|
||||||
] +
|
] +
|
||||||
['HAS_{}=y'.format(package.upper()) for package in args.has_package] +
|
['HAS_{}=y'.format(package.upper()) for package in args.has_package] +
|
||||||
|
shlex.split(args.make_args) +
|
||||||
[os.path.join(build_dir, os.path.splitext(os.path.split(target)[1])[0]) + common.executable_ext for target in args.targets]
|
[os.path.join(build_dir, os.path.splitext(os.path.split(target)[1])[0]) + common.executable_ext for target in args.targets]
|
||||||
),
|
),
|
||||||
cwd=common.userland_src_dir,
|
cwd=common.userland_src_dir,
|
||||||
|
|||||||
1
kernel_modules/README.adoc
Normal file
1
kernel_modules/README.adoc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://github.com/cirosantilli/linux-kernel-module-cheat#your-first-kernel-module-hack
|
||||||
1
userland/README.adoc
Normal file
1
userland/README.adoc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://github.com/cirosantilli/linux-kernel-module-cheat#userland-directory
|
||||||
@@ -34,14 +34,16 @@ int pagemap_get_entry(PagemapEntry *entry, int pagemap_fd, uintptr_t vaddr)
|
|||||||
size_t nread;
|
size_t nread;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
uint64_t data;
|
uint64_t data;
|
||||||
|
uintptr_t vpn;
|
||||||
|
|
||||||
|
vpn = vaddr / sysconf(_SC_PAGE_SIZE);
|
||||||
nread = 0;
|
nread = 0;
|
||||||
while (nread < sizeof(data)) {
|
while (nread < sizeof(data)) {
|
||||||
ret = pread(
|
ret = pread(
|
||||||
pagemap_fd,
|
pagemap_fd,
|
||||||
&data,
|
&data,
|
||||||
sizeof(data),
|
sizeof(data) - nread,
|
||||||
(vaddr / sysconf(_SC_PAGE_SIZE)) * sizeof(data) + nread
|
vpn * sizeof(data) + nread
|
||||||
);
|
);
|
||||||
nread += ret;
|
nread += ret;
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
@@ -61,7 +63,7 @@ int pagemap_get_entry(PagemapEntry *entry, int pagemap_fd, uintptr_t vaddr)
|
|||||||
* @param[out] paddr physical address
|
* @param[out] paddr physical address
|
||||||
* @param[in] pid process to convert for
|
* @param[in] pid process to convert for
|
||||||
* @param[in] vaddr virtual address to get entry for
|
* @param[in] vaddr virtual address to get entry for
|
||||||
* @return 0 for success, 1 for failure
|
* @return 0 for success, 1 for failure
|
||||||
*/
|
*/
|
||||||
int virt_to_phys_user(uintptr_t *paddr, pid_t pid, uintptr_t vaddr)
|
int virt_to_phys_user(uintptr_t *paddr, pid_t pid, uintptr_t vaddr)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user