I would be surprised if the size argument was the issue. That comes right out out of the create IOCTL unmodified. Here is the full source that I am using.
// Clear the arg buffers.
memset(&create_arg, 0, sizeof(create_arg));
memset(&map_arg, 0, sizeof(map_arg));
// ------------------------------------------------------------------------
// Allocate
// Fill in the arguments for the IOCTL. Note that we only support 32bpp
// dumb buffers so that is hard coded here.
create_arg.width = width;
create_arg.height = height;
create_arg.bpp = 32;
// Allocate the dumb buffer
if (drmIoctl(gpu->fd(), DRM_IOCTL_MODE_CREATE_DUMB, &create_arg))
{
svWarning(0) << "Failed: DRM_IOCTL_MODE_CREATE_DUMB - " << strerror(errno);
return;
}
// Store the dumb buffer properties.
mSize = create_arg.size;
mStride = create_arg.pitch;
mHandle = create_arg.handle;
// ------------------------------------------------------------------------
// Map
// Fill in the arguments for the IOCTL.
map_arg.handle = mHandle;
// Allocate the dumb buffer
if (drmIoctl(gpu->fd(), DRM_IOCTL_MODE_MAP_DUMB, &map_arg))
{
svWarning(0) << "Failed: DRM_IOCTL_MODE_MAP_DUMB - " << strerror(errno);
return;
}
// Store the mapped memory
if ((mVaddr = (svuint32 *)mmap(0, mSize, PROT_READ | PROT_WRITE, MAP_SHARED, gpu->fd(), map_arg.offset)) == MAP_FAILED)
{
// Need to clear out the address so that we don't try to use it.
mVaddr = NULL;
// Error out.
svWarning(0) << "Failed: Dumb Buffer mmap - " << strerror(errno);
return;
}