Last active
July 26, 2025 04:09
-
-
Save ericdennisforever/34f32cb2a1b4fc90353e1a08e3d439a0 to your computer and use it in GitHub Desktop.
How to compile a Linux kernel module for Android Emulator(LDPLAYER/NOX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- LDPlayer ver 9.0.45(9) | |
Android version 9 | |
Kernel 4.4.146 #1 Thu Apr27 10:42:33 (ST 2023) | |
Build Number PQ3A 190705.003 release keys | |
$modinfo vboxsf.ko | |
vermagic: 4.4.146 SMP preempt mod_unload modversions | |
- To compile a linux kernel module: | |
git clone https://android.googlesource.com/kernel/goldfish/ -b android-goldfish-4.4-dev | |
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9 | |
cd x86_64-linux-android-4.9 | |
git checkout pie-b4s4-release | |
cd goldfish | |
export CROSS_COMPILE=x86_64-linux-android- | |
export ARCH=x86_64 | |
export PATH=$PATH:/path/to/x86_64-linux-android-4.9/bin | |
make x86_64_ranchu_defconfig | |
make menuconfig # enable overlayfs and namespaces support here | |
make -j8 | |
- hello.c | |
#include <linux/module.h> /* Needed by all modules */ | |
#include <linux/kernel.h> /* Needed for KERN_ALERT */ | |
#include<linux/init.h> | |
MODULE_LICENSE("GPL"); | |
MODULE_AUTHOR("dambo, 2023"); | |
MODULE_DESCRIPTION("Demo module"); | |
static int __init hello_start(void) | |
{ | |
printk("hello to the world from module"); | |
return 0; | |
} | |
static void __exit hello_end(void) | |
{ | |
printk("hello exit"); | |
} | |
module_init(hello_start); | |
module_exit(hello_end); | |
-Makefile | |
KDIR=~/Workspace/android-sdks/goldfish-4.4-dev/ | |
PWD := $(shell pwd) | |
obj-m += hello.o | |
CCPATH := ~/Workspace/android-sdks/x86_64-linux-android-4.9/bin/ | |
CCPATH_EXT := $(CCPATH)x86_64-linux-android- | |
ARCH=x86_64 | |
default: | |
make -C $(KDIR) CFLAGS_MODULE=-fno-pic ARCH=$(ARCH) CROSS_COMPILE=$(CCPATH_EXT) $(KERNEL_DIR) M=$(PWD) modules | |
clean: | |
make -C $(KERNEL_DIR) M=$(PWD) clean | |
- compile | |
$ make | |
- outputs | |
make -C ~/Workspace/android-sdks/goldfish-4.4-dev/ CFLAGS_MODULE=-fno-pic ARCH=x86_64 CROSS_COMPILE=~/Workspace/android-sdks/x86_64-linux-android-4.9/bin/x86_64-linux-android- M=/home/ubuntu/Workspace/android-sdks/custom_modules/hello modules | |
make[1]: Entering directory '/home/ubuntu/Workspace/android-sdks/goldfish-4.4-dev' | |
Building modules, stage 2. | |
MODPOST 1 modules | |
LD [M] /home/ubuntu/Workspace/android-sdks/custom_modules/hello/hello.ko | |
- adb shell | |
/data/local/tmp # modinfo hello.ko | |
modinfo hello.ko | |
filename: hello.ko | |
author: dambo, 2023 | |
license: GPL | |
depends: | |
vermagic: 4.4.302+ SMP preempt mod_unload modversions | |
- goldfish/Makefile | |
VERSION = 4 | |
PATCHLEVEL = 4 | |
SUBLEVEL = 146 | |
EXTRAVERSION = | |
make -j8 LOCALVERSION="" |
Hello everyone
i have same issue and getting same error
disagrees about version of symbol module_layout
KSNS8I4:~/ldplayer_module$ modinfo hello.ko
filename: /home/i/ldplayer_module/hello.ko
description: LDPlayer9 Demo Module
author: dambo, 2023
license: GPL
depends:
retpoline: Y
vermagic: 4.4.146 SMP preempt mod_unload modversions
KSNS8I4:~/ldplayer_module$ modinfo vboxsf.ko
filename: /home/i/ldplayer_module/vboxsf.ko
version: 6.1.36 r152435
alias: fs-vboxsf
license: GPL and additional rights
author: Oracle Corporation
description: Oracle VM VirtualBox VFS Module for Host File System Access
srcversion: 2E5DC49B1A7F01FC78BAC88
depends: vboxguest
vermagic: 4.4.146 SMP preempt mod_unload modversions
parm: follow_symlinks:Let host resolve symlinks rather than showing them (int)
LOGS:
[ 108.229351] hello: disagrees about version of symbol module_layout
[ 108.239316] type=1400 audit(1753502806.994:473): avc: denied { module_load } for pid=4104 comm="insmod" path="/data/local/tmp/hello.ko" dev="sdb2" ino=131304 scontext=u:r:su:s0 tcontext=u:object_r:shell_data_file:s0 tclass=system permissive=1
[ 108.248559] type=1400 audit(1753502806.994:473): avc: denied { module_load } for pid=4104 comm="insmod" path="/data/local/tmp/hello.ko" dev="sdb2" ino=131304 scontext=u:r:su:s0 tcontext=u:object_r:shell_data_file:s0 tclass=system permissive=1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi my friend :) i can't run hello on ld 9.0.45(9)
can u help me? and i can't undestand that u use git checkout pie-b4s4-release branch :)