Linux android mmap 失败:参数无效(错误号 22)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5780524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:49:05  来源:igfitidea点击:

android mmap failed: invalid argument (errno 22)

androidlinuxshared-memory

提问by rouble

I was porting/compiling androidvncserverfor my android device, but when I run it (as root) I keep getting mmap errors.

我正在为我的 android 设备移植/编译androidvncserver,但是当我(以 root 身份)运行它时,我不断收到 mmap 错误。

The offending code looks like this:

违规代码如下所示:

/* Android does not use /dev/fb0. */
#define FB_DEVICE "/dev/graphics/fb0"

if ((fbfd = open(FB_DEVICE, O_RDONLY)) == -1)
{
    printf("cannot open fb device %s\n", FB_DEVICE);
    exit(EXIT_FAILURE);
}

<SNIP>

fbmmap = mmap(NULL, pixels * bytespp, PROT_READ, MAP_SHARED, fbfd, 0);
if (fbmmap == MAP_FAILED)
{
    printf("mmap failed errno = %d\n", errno);
    exit(EXIT_FAILURE);
}

I am looking for thoughts on how to debug this further.

我正在寻找有关如何进一步调试的想法。

For the record, pixels=614400 and bytespp=4. Also, /dev/graphics/fb0 is owned by root (group=graphics), and has permissions of 660.

作为记录,像素 = 614400 和字节数 = 4。此外,/dev/graphics/fb0 归 root (group=graphics) 所有,权限为 660。

采纳答案by Will Tate

prmatta,

普玛塔,

Error code 22 is EINVAL.

错误代码 22 是EINVAL.

From the mmap()documentation that tells you...

mmap()告诉您的文档中...

EINVAL We don't like start or length or offset. (E.g., they are too large, or not aligned on a page boundary.)

EINVAL 我们不喜欢开始、长度或偏移。(例如,它们太大,或未在页面边界上对齐。)

Perhaps you didn't page align your memory?

也许你没有页面对齐你的记忆?