glave: Fix locking of mem_info entries in UnmapMemory
authorJon Ashburn <jon@lunarg.com>
Wed, 25 Feb 2015 20:51:07 +0000 (13:51 -0700)
committerJon Ashburn <jon@lunarg.com>
Wed, 25 Feb 2015 23:53:17 +0000 (16:53 -0700)
The retruned entry pointer could change after lock released in the case the mem info list was realloc.

glave-generate.py

index 9d5b2f6..f284418 100755 (executable)
@@ -321,7 +321,8 @@ class Subcommand(object):
         um_body.append('    SEND_ENTRYPOINT_PARAMS("xglUnmapMemory(mem %p)\\n", mem);')
         um_body.append('    // insert into packet the data that was written by CPU between the xglMapMemory call and here')
         um_body.append('    // Note must do this prior to the real xglUnMap() or else may get a FAULT')
-        um_body.append('    entry = find_mem_info_entry_lock(mem);')
+        um_body.append('    glv_enter_critical_section(&g_memInfoLock);')
+        um_body.append('    entry = find_mem_info_entry(mem);')
         um_body.append('    CREATE_TRACE_PACKET(xglUnmapMemory, (entry) ? entry->size : 0);')
         um_body.append('    pPacket = interpret_body_as_xglUnmapMemory(pHeader);')
         um_body.append('    if (entry)')
@@ -334,6 +335,7 @@ class Subcommand(object):
         um_body.append('    {')
         um_body.append('         glv_LogError("Failed to copy app memory into trace packet (idx = %u) on xglUnmapMemory\\n", pHeader->global_packet_index);')
         um_body.append('    }')
+        um_body.append('    glv_leave_critical_section(&g_memInfoLock);')
         um_body.append('    result = real_xglUnmapMemory(mem);')
         um_body.append('    pPacket->mem = mem;')
         um_body.append('    pPacket->result = result;')