return NULL;
}
+static void
+pandecode_add_name(struct pandecode_mapped_memory *mem, uint64_t gpu_va, const char *name)
+{
+ if (!name) {
+ /* If we don't have a name, assign one */
+
+ snprintf(mem->name, ARRAY_SIZE(mem->name) - 1,
+ "memory_%" PRIx64, gpu_va);
+ } else {
+ assert((strlen(name) + 1) < ARRAY_SIZE(mem->name));
+ memcpy(mem->name, name, strlen(name) + 1);
+ }
+}
+
void
pandecode_inject_mmap(uint64_t gpu_va, void *cpu, unsigned sz, const char *name)
{
+ /* First, search if we already mapped this and are just updating an address */
+
+ list_for_each_entry(struct pandecode_mapped_memory, pos, &mmaps.node, node) {
+ if (pos->gpu_va == gpu_va) {
+ /* TODO: Resizing weirdness. Only applies to tracing
+ * the legacy driver, not for native traces */
+
+ pos->length = sz;
+ pos->addr = cpu;
+ pandecode_add_name(pos, gpu_va, name);
+
+ return;
+ }
+ }
+
+ /* Otherwise, add a fresh mapping */
struct pandecode_mapped_memory *mapped_mem = NULL;
mapped_mem = malloc(sizeof(*mapped_mem));
mapped_mem->gpu_va = gpu_va;
mapped_mem->length = sz;
mapped_mem->addr = cpu;
-
- if (!name) {
- /* If we don't have a name, assign one */
-
- snprintf(mapped_mem->name, ARRAY_SIZE(mapped_mem->name) - 1,
- "memory_%" PRIx64, gpu_va);
- } else {
- assert((strlen(name) + 1) < ARRAY_SIZE(mapped_mem->name));
- memcpy(mapped_mem->name, name, strlen(name) + 1);
- }
+ pandecode_add_name(mapped_mem, gpu_va, name);
list_add(&mapped_mem->node, &mmaps.node);
}