将-1作为文件描述符传递给mmap [英] passing -1 as file descriptor to mmap
本文介绍了将-1作为文件描述符传递给mmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在FC17 Linux中对"ls"命令进行了跟踪.
I did an strace on the "ls" command in FC17 Linux.
以下是输出.
execve("/usr/bin/ls", ["ls"], [/* 48 vars */]) = 0
brk(0) = 0x27c1000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc765fa6000
...
我没有得到将-1作为文件描述符传递给mmap调用的目的和结果,有人可以对此有所了解吗?
I am not getting the purpose and result of passing -1 as the file descriptor to the mmap call, can some one shed some light on this ?
推荐答案
有两种映射(将虚拟内存区域映射到进程):文件支持的映射和匿名(非文件支持的)映射.有两种方法可以请求匿名映射:
There are two kinds of mappings (areas of virtual memory mapped to a process): file-backed mappings, and anonymous (non file-backed) mappings. There are two ways to request an anonymous mapping:
- (BSD)将
MAP_ANONYMOUS
(以前称为MAP_ANON
)传递到mmap()
.没有关联的文件,因此您应该将-1作为file
参数传递.一些操作系统会忽略file
参数,其他操作系统则将其设为-1(BSD IIRC). - (Sys V)映射
/dev/zero
.在这种情况下,file
显然是有意义的.
- (BSD) Pass
MAP_ANONYMOUS
(formerlyMAP_ANON
) tommap()
. There is no associated file, so you should pass -1 asfile
parameter. Some OSes ignore thefile
parameter, others require it to be -1 (BSD IIRC). - (Sys V) Map
/dev/zero
. In this case,file
is obviously meaningful.
这篇关于将-1作为文件描述符传递给mmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文