if (bo_fake->is_static)
return 0;
- /* Allow recursive mapping, which is used internally in relocation. */
+ /* Allow recursive mapping. Mesa may recursively map buffers with
+ * nested display loops, and it is used internally in bufmgr_fake
+ * for relocation.
+ */
if (bo_fake->map_count++ != 0)
return 0;
dri_bo bo;
int refcount;
+ unsigned int map_count;
drmBO drm_bo;
const char *name;
uint64_t flags;
unsigned int hint;
- ttm_buf = malloc(sizeof(*ttm_buf));
+ ttm_buf = calloc(1, sizeof(*ttm_buf));
if (!ttm_buf)
return NULL;
dri_bo_ttm *ttm_buf;
int ret;
- ttm_buf = malloc(sizeof(*ttm_buf));
+ ttm_buf = calloc(1, sizeof(*ttm_buf));
if (!ttm_buf)
return NULL;
if (--ttm_buf->refcount == 0) {
int ret;
+ assert(ttm_buf->map_count == 0);
+
if (ttm_buf->reloc_buf_data) {
int i;
if (write_enable)
flags |= DRM_BO_FLAG_WRITE;
+ /* Allow recursive mapping. Mesa may recursively map buffers with
+ * nested display loops.
+ */
+ if (ttm_buf->map_count++ != 0)
+ return 0;
+
assert(buf->virtual == NULL);
DBG("bo_map: %p (%s)\n", &ttm_buf->bo, ttm_buf->name);
if (buf == NULL)
return 0;
+ assert(ttm_buf->map_count != 0);
+ if (--ttm_buf->map_count != 0)
+ return 0;
+
bufmgr_ttm = (dri_bufmgr_ttm *)buf->bufmgr;
assert(buf->virtual != NULL);