我正在试图找到最快的方式将大的数据从内核移动到用户空间。现在我正在尝试GKH的调试器,但我很难让blob包装正常工作。
到目前为止,我得到的是:
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/debugfs.h>
MODULE_AUTHOR("CREED0R");
MODULE_LICENSE("GPL");
struct dentry *dfs;
struct debugfs_blob_wrapper *myblob;
int my_init(void)
{
int stats[10];
int i;
for (i = 0; i < 10; i++)
stats[i] = i;
myblob->data = (void *) stats;
myblob->size = (unsigned long) 10;
dfs = debugfs_create_blob("test", 0644, NULL, myblob);
if (dfs == NULL) {
printk("Could not create debugfs blob\n");
return 1;
}
printk("DebugFS file created\n");
return 0;
}
void my_exit(void)
{
printk("DebugFS file deleted\n\n");
debugfs_remove(dfs);
}
module_init(my_init);
module_exit(my_exit);它构建,但是如果我运行不顺畅,我的qemu实例就会可怕地死去。
不知道为什么。我遗漏了什么?
发布于 2013-02-03 09:14:25
谢谢你的帮助。我只是忘了为blob-结构获取mem,所以设置数据和大小指针不可避免地会扼杀它。
这是正确的版本,将32 K值的u32从内核注入到用户空间。它使用2.6.32.38内核构建:
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/debugfs.h>
#define SIZE 8192
MODULE_AUTHOR("CREED0R");
MODULE_LICENSE("GPL");
struct dentry *dfs;
struct debugfs_blob_wrapper *myblob;
u32 *stats; /* our blob of data */
int my_init(void)
{
int i;
int stats_size; /* size of our data */
int struct_size; /* size of the blob struct */
struct_size = sizeof(struct debugfs_blob_wrapper);
stats_size = SIZE * sizeof(u32);
/* get mem for data */
stats = kmalloc(stats_size, GFP_KERNEL);
if (stats == NULL) {
printk("Could not allocate mem for data\n");
return -ENOMEM;
}
/* fill datablob with dummy data */
for (i = 0; i < SIZE; i++)
stats[i] = i;
/* get mem for blob struct and init */
myblob = (struct debugfs_blob_wrapper *) kmalloc(struct_size, GFP_KERNEL);
if (myblob == NULL) {
printk("Could not allocate mem for blob\n");
kfree(stats);
return -ENOMEM;
}
/* only set data pointer and data size */
myblob->data = (void *) stats;
myblob->size = (unsigned long) stats_size;
/* create pseudo file under /sys/kernel/debug/ with name 'test' */
dfs = debugfs_create_blob("test", 0644, NULL, myblob);
if (dfs == NULL) {
printk("Could not create debugfs blob\n");
kfree(stats);
kfree(myblob);
return -EINVAL;
}
printk("DebugFS file created\n");
return 0;
}
void my_exit(void)
{
printk("DebugFS file deleted\n\n");
kfree(myblob);
kfree(stats);
debugfs_remove(dfs);
}
module_init(my_init);
module_exit(my_exit);https://stackoverflow.com/questions/14666991
复制相似问题