mmap()返回EINVAL [英] mmap() returns EINVAL

查看:193
本文介绍了mmap()返回EINVAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 mmap 功能.它返回 EINVAL 错误代码.

I can't get the mmap function to work. It returns the EINVAL error code.

void* mapped = 
        mmap((void*)(map_addr + slide),
             map_size,
             PROT_WRITE | PROT_READ,
             MAP_PRIVATE | MAP_ANON,
             bprm->file,
             map_offset);

我已经在我的平台( Darwin )上检查了此功能的文档,似乎没有什么错. mmap的手册页介绍了四种返回EINVAL的情况.

I've checked the documentation for this function on my platform (Darwin) and there doesn't seem to be anything wrong. The man page for mmap presents four cases under which EINVAL would be returned.

 [EINVAL]           MAP_FIXED was specified and the addr argument was not page
                    aligned, or part of the desired address space resides out of the
                    valid address space for a user process.

未指定MAP_FIXED,所以不是这个.

MAP_FIXED isn't specified so it isn't this.

 [EINVAL]           flags does not include either MAP_PRIVATE or MAP_SHARED.

存在MAP_PRIVATE.

MAP_PRIVATE is present.

 [EINVAL]           The len argument was negative.

调用时的len(map_size)参数为8192.

The len (map_size) argument at the time of the call is 8192.

 [EINVAL]           The offset argument was not page-aligned based on the page size as
                    returned by getpagesize(3).

offset参数(map_offset)为0,因此必须页面对齐. (也许我错了吗?)

The offset argument (map_offset) is 0 so it must be page aligned. (maybe I'm wrong?)

推荐答案

您确定要阅读第一个描述吗?也可以理解为描述两个不相交的情况:

Are you sure about your reading of the first description? It could also be read as describing two disjoint cases:

  1. 已指定MAP_FIXED,并且addr参数未页面对齐
  2. 或部分所需的地址空间位于用户进程的有效地址空间之外.

如果这样读取,则map_addr + slide表达式的实际值会变得有趣.

if read like this, the actual value of the the map_addr + slide expression becomes interesting.

这篇关于mmap()返回EINVAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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