KernelPatch icon indicating copy to clipboard operation
KernelPatch copied to clipboard

当我使用kp_malloc或者vmalloc时模块加载失败

Open SoyBeanMilkx opened this issue 1 year ago • 0 comments

Currently, there is no immediate solution. You need to troubleshoot it yourself or provide the device to me for further investigation. 代码时kpms里的demo #include <compiler.h> #include <kpmodule.h> #include <linux/printk.h> #include <common.h> #include <kputils.h> #include <linux/string.h> #include <kpmalloc.h>

KPM_NAME("kpm-hello-demo"); KPM_VERSION("1.0.0"); KPM_LICENSE("GPL v2"); KPM_AUTHOR("bmax121"); KPM_DESCRIPTION("KernelPatch Module Example");

static long hello_init(const char *args, const char *event, void *__user reserved) { pr_info("kpm hello init, event: %s, args: %s\n", event, args); pr_info("kernelpatch version: %x\n", kpver); return 0; }

static long hello_control0(const char *args, char *__user out_msg, int outlen) { pr_info("kpm hello control0, args: %s\n", args); char echo[64] = "echo: "; strncat(echo, args, 48); compat_copy_to_user(out_msg, echo, sizeof(echo)); return 0; }

static long hello_control1(void a1, void a2, void a3) { /char str = (char)kp_malloc(sizeof(char) * 10); kp_free(str);/ int arr = kp_malloc(sizeof(int) * 10); kp_free(arr); pr_info("kpm hello control1, a1: %llx, a2: %llx, a3: %llx\n", a1, a2, a3); return 0; }

static long hello_exit(void *__user reserved) { pr_info("kpm hello exit\n"); return 0; }

KPM_INIT(hello_init); KPM_CTL0(hello_control0); KPM_CTL1(hello_control1); KPM_EXIT(hello_exit);

只是加了这段,模块就无法加载了 /char str = (char*)kp_malloc(sizeof(char) * 10); kp_free(str);/ int arr = kp_malloc(sizeof(int) * 10); kp_free(arr); 请问这个是什么原因呢?

SoyBeanMilkx avatar Oct 25 '24 16:10 SoyBeanMilkx