mmap(2) 与 mmap(3)
有谁知道 mmap(2)
和 mmap(3)
之间有什么区别? Man第3节被描述为“本章描述了除第2章中描述的实现系统调用的库函数之外的所有库函数”。 mmap(3)
不执行系统调用吗?
阅读这两个手册页,我发现 mmap(2)
似乎比 mmap(3)
接受更广泛的标志,并且声称能够映射设备 I/O 空间。 mmap(3)
声称除了文件之外还能够映射“共享内存对象”和“类型化内存对象”,但没有提及设备 I/O。
由于这两个函数具有相同的名称,我什至不确定如何选择一个而不是另一个。
Does anyone know what the difference between mmap(2)
and mmap(3)
is? Man section 3 is described as "This chapter describes all library functions excluding the library functions described in chapter 2, which implement system calls." Doesn't mmap(3)
perform a system call?
Reading the two man pages, I see that mmap(2)
seems to accept a much wider variety of flags than mmap(3)
does, and claims to be able to map device I/O spaces. mmap(3)
claims to be able to map "shared memory objects" and "typed memory objects" in addtion to files, but doesn't mention device I/O.
Since the two functions have the same name, I'm not even sure how I can choose one rather than the other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mmap(3)
应该是 POSIX 函数< /a>.它应该在所有方面提供 POSIX 所要求的语义,即使这偏离了 Linux“本机”所做的事情。mmap(2)
是系统调用,提供了 Linus 认为重要的所有功能。 C库函数当然是使用系统调用来实现的。要按字面意思调用系统调用(绕过 C 库),可以使用
。mmap(3) 的实际实现可以在 C 库。正如您所看到的,它通常将控制权直接转移到 mmap(2),除非在(glibc 的)编译时,选择 mmap2(2) 作为“后端”。
mmap(3)
is supposed to be the POSIX function. It should in all respect provide the very semantics that POSIX mandates, even if that deviates from what Linux does "natively".mmap(2)
is the system call, and provides all bells and whistles that Linus considers important. The C library function is, of course, implemented using the system call.To invoke the system call literally (bypassing the C library), you can use
<sys/syscall.h>
.The actual implementation of mmap(3) can be found in the C library. As you can see, it usually transfers control directly to mmap(2), unless, at compile time (of glibc), mmap2(2) was selected as the "back-end".