如何取消映射这是使用remap_pfn_range存储器映射() [英] how to unmap the memory which is mapped using remap_pfn_range()

查看:498
本文介绍了如何取消映射这是使用remap_pfn_range存储器映射()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有映射内核内存到用户空间多种方法。
有人说用拼接()的mmap()

There are multiple approaches to map kernel memory to user space. Some say use splice(), mmap(), etc.

我打电话的mmap()像'的/ dev / MEM。

I am calling mmap() with a descriptor of our own pseudo char device file like '/dev/mem'.

致电时的mmap()用我们自己的伪字符设备文件,在内部登记 file_operation 函数指针的mmap我们可以调用 remap_pfn_range()映射内存..

When calling mmap() with with our own pseudo char device file, internally in mmap registered file_operation function pointer, we can invoke remap_pfn_range() for mapping memory..

现在这个过程可能就终止/杀/清洁的exit()。
如何删除从内核空间的映射。我工作的ARMv7-A。

Now that process might have got terminated/killed/clean exit(). How to remove those mappings from kernel space. I am working on ARMv7-A.

任何人能解释发生了什么什么时候这个过程就会被杀死这些内存映射/终止?请问内核本身删除映射或我们是否需要取消映射明确?

Can anyone explain what happens about these memory mappings when the process gets killed/terminated? Does kernel remove the mappings by itself or do we need to unmap explicitly?

推荐答案

MMAP 映射外部(的进程)的内存空间的进程调用的虚拟地址空间它。内存可能是共享内存段,文件......不像物理内存段映射到 MMAP 只是创建一个链接到该段,并返回一个地址可以看到和从调用方法中。

mmap maps an external (to the process) memory space to the virtual address space of the process calling it. Memory maybe a shared memory segment, a file... Unlike the physical memory segment it maps to, mmap just creates a "link" to that segment, and returns an address that can be seen and used from the calling process.

在该 MMAP 调用进程终止(当然,杀..)它创建的映射是自动映射的。

When the mmap calling process terminates (naturally, killed..) the mappings it created are automatically unmapped.

但是被映射,并且可以由其他进程(或没有)所用的物理存储器区域中,仍然可用。

The physical memory region that was mapped, however, and that may be used by other processes (or no), remains available.

男人MMAP

您可以从程序关闭映射它死之前,

You may close the mapping from the program before it dies,

int munmap(void *addr, size_t length);

这篇关于如何取消映射这是使用remap_pfn_range存储器映射()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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