Linux-在内核代码中映射用户空间内存 [英] Linux - Mapping user space memory in kernel code

查看:188
本文介绍了Linux-在内核代码中映射用户空间内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一段代码,该代码需要在SOC关闭之前存储位于特定物理地址中的10k内存.

i am writing a piece of code that needs to store 10k of memory located in specific physical address before the SOC shuts down.

我的问题是此物理地址不是内核空间的一部分,因此我必须创建一个临时内存映射,以便我可以访问此内存空间.

My problem is that this physical address is not part of kernel space so i have to create an ad -hoc memory mapping so i can access this memory space.

我尝试使用io-remap,但它(显然)不适用于非内核空间.

i tried using io-remap but it doesn't (apparently) work on non-kernel space.

是否有用于执行此操作的API? 我应该使用kmap吗?

is there any API for doing this ? should i used kmap ?

预先感谢

推荐答案

找到了答案

关键是使用vmap函数为给定的页表创建映射.问题是如何将页表结构初始化为某个物理地址,但似乎也存在针对该物理地址的API

the key is to use the vmap function which create a mapping for a given page table. the problem was how to initialize a page table structure to a certain physical address but it appears there exists an API for that as well

这是分配单个页面的示例

here is an example to allocate a single page

void *virt_addr_ptr
struct page **my_page = kmalloc(sizeof (*my_page), GFP_KERNEL);
my_page = phys_to_page(phys_addr_ptr);
virt_addr_ptr = vmap(my_page, 1, VM_MAP, PAGE_KERNEL);

/*now its possible to access this space */
memcpy(store_buffer, virt_addr_ptr, store_size);

这篇关于Linux-在内核代码中映射用户空间内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆