“mmap() 失败:参数无效” Graphics_drm.cpp 出错,如何解决?

发布于 2025-01-13 16:43:14 字数 2662 浏览 6 评论 0原文

当我调试小米拿铁平板电脑的恢复时,在该函数中出现错误“mmap() faileder: Invalid argument”,我不知道是什么原因造成的。希望有人能帮助我,谢谢!

我检查了相关值并写在注释中:surface->base.height = 2048,surface->base.row_bytes = 3072,drm_fd=0,map_dumb.offset=0,并且我检查了所有关于drm_fd的脚本cpp,都已经正常执行了。

static drm_surface *drm_create_surface(int width, int height) {
    struct drm_surface *surface;
    struct drm_mode_create_dumb create_dumb;
    uint32_t format;
    int ret;
 
    surface = (struct drm_surface*)calloc(1, sizeof(*surface));
    if (!surface) {
        printf("Can't allocate memory\n");
        return NULL;
    }
 
#if defined(RECOVERY_ABGR)
    format = DRM_FORMAT_RGBA8888;
#elif defined(RECOVERY_BGRA)
    format = DRM_FORMAT_ARGB8888;     //This is my tablet's argument
#elif defined(RECOVERY_RGBX)
    format = DRM_FORMAT_XBGR8888;
#else
    format = DRM_FORMAT_RGB565;
#endif
 
    memset(&create_dumb, 0, sizeof(create_dumb));
    create_dumb.height = height;
    create_dumb.width = width;
    create_dumb.bpp = drm_format_to_bpp(format);
    create_dumb.flags = 0;
 
    ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
    if (ret) {
        printf("DRM_IOCTL_MODE_CREATE_DUMB failed ret=%d\n",ret);
        drm_destroy_surface(surface);
        return NULL;
    }
    surface->handle = create_dumb.handle;
 
    uint32_t handles[4], pitches[4], offsets[4];
 
    handles[0] = surface->handle;
    pitches[0] = create_dumb.pitch;
    offsets[0] = 0;
 
    ret = drmModeAddFB2(drm_fd, width, height,
            format, handles, pitches, offsets,
            &(surface->fb_id), 0);
    if (ret) {
        printf("DRM_IOCTL_MODE_MAP_DUMB failed ret=%d\n",ret);
        drm_destroy_surface(surface);
        return NULL;;
    }
 
    surface->base.height = height;
    surface->base.width = width;
    surface->base.row_bytes = create_dumb.pitch;
    surface->base.pixel_bytes = create_dumb.bpp / 8;

    surface->base.data = (unsigned char*)
                         mmap(NULL,
                              surface->base.height * surface->base.row_bytes,
                              PROT_READ | PROT_WRITE, MAP_SHARED,
                              drm_fd, map_dumb.offset);     //I checked the values: surface->base.height = 2048,surface->base.row_bytes = 3072,drm_fd=0, map_dumb.offset=0,and I checked all scripts about drm_fd int the cpp, they all been executed normally.
    if (surface->base.data == MAP_FAILED) {
        perror("mmap() failed");     //Get error here: “mmap() failer: Invalid argument”
        drm_destroy_surface(surface);
        return NULL;
    }
 
    return surface;
...

When I debug my xiaomi latte tablet's recovery,get error “mmap() failer: Invalid argument” in this function,I don't know what causes it. Hope somebody can help me, thank you!

I checked the related values and writed them in the comments: surface->base.height = 2048,surface->base.row_bytes = 3072,drm_fd=0, map_dumb.offset=0,and I checked all scripts about drm_fd in the cpp, they've all been executed normally.

static drm_surface *drm_create_surface(int width, int height) {
    struct drm_surface *surface;
    struct drm_mode_create_dumb create_dumb;
    uint32_t format;
    int ret;
 
    surface = (struct drm_surface*)calloc(1, sizeof(*surface));
    if (!surface) {
        printf("Can't allocate memory\n");
        return NULL;
    }
 
#if defined(RECOVERY_ABGR)
    format = DRM_FORMAT_RGBA8888;
#elif defined(RECOVERY_BGRA)
    format = DRM_FORMAT_ARGB8888;     //This is my tablet's argument
#elif defined(RECOVERY_RGBX)
    format = DRM_FORMAT_XBGR8888;
#else
    format = DRM_FORMAT_RGB565;
#endif
 
    memset(&create_dumb, 0, sizeof(create_dumb));
    create_dumb.height = height;
    create_dumb.width = width;
    create_dumb.bpp = drm_format_to_bpp(format);
    create_dumb.flags = 0;
 
    ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
    if (ret) {
        printf("DRM_IOCTL_MODE_CREATE_DUMB failed ret=%d\n",ret);
        drm_destroy_surface(surface);
        return NULL;
    }
    surface->handle = create_dumb.handle;
 
    uint32_t handles[4], pitches[4], offsets[4];
 
    handles[0] = surface->handle;
    pitches[0] = create_dumb.pitch;
    offsets[0] = 0;
 
    ret = drmModeAddFB2(drm_fd, width, height,
            format, handles, pitches, offsets,
            &(surface->fb_id), 0);
    if (ret) {
        printf("DRM_IOCTL_MODE_MAP_DUMB failed ret=%d\n",ret);
        drm_destroy_surface(surface);
        return NULL;;
    }
 
    surface->base.height = height;
    surface->base.width = width;
    surface->base.row_bytes = create_dumb.pitch;
    surface->base.pixel_bytes = create_dumb.bpp / 8;

    surface->base.data = (unsigned char*)
                         mmap(NULL,
                              surface->base.height * surface->base.row_bytes,
                              PROT_READ | PROT_WRITE, MAP_SHARED,
                              drm_fd, map_dumb.offset);     //I checked the values: surface->base.height = 2048,surface->base.row_bytes = 3072,drm_fd=0, map_dumb.offset=0,and I checked all scripts about drm_fd int the cpp, they all been executed normally.
    if (surface->base.data == MAP_FAILED) {
        perror("mmap() failed");     //Get error here: “mmap() failer: Invalid argument”
        drm_destroy_surface(surface);
        return NULL;
    }
 
    return surface;
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文