/*1* Copyright (C) 2017-2019 Lyude Paul2* Copyright (C) 2017-2019 Alyssa Rosenzweig3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23*/2425#ifndef __PAN_DECODE_H__26#define __PAN_DECODE_H__2728#include "wrap.h"2930extern FILE *pandecode_dump_stream;3132void pandecode_dump_file_open(void);3334struct pandecode_mapped_memory {35size_t length;36void *addr;37uint64_t gpu_va;38bool ro;39char name[32];40};4142char *pointer_as_memory_reference(uint64_t ptr);4344struct pandecode_mapped_memory *pandecode_find_mapped_gpu_mem_containing(uint64_t addr);4546void pandecode_map_read_write(void);4748static inline void *49__pandecode_fetch_gpu_mem(const struct pandecode_mapped_memory *mem,50uint64_t gpu_va, size_t size,51int line, const char *filename)52{53if (!mem)54mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);5556if (!mem) {57fprintf(stderr, "Access to unknown memory %" PRIx64 " in %s:%d\n",58gpu_va, filename, line);59assert(0);60}6162assert(mem);63assert(size + (gpu_va - mem->gpu_va) <= mem->length);6465return mem->addr + gpu_va - mem->gpu_va;66}6768#define pandecode_fetch_gpu_mem(mem, gpu_va, size) \69__pandecode_fetch_gpu_mem(mem, gpu_va, size, __LINE__, __FILE__)7071/* Returns a validated pointer to mapped GPU memory with the given pointer type,72* size automatically determined from the pointer type73*/74#define PANDECODE_PTR(mem, gpu_va, type) \75((type*)(__pandecode_fetch_gpu_mem(mem, gpu_va, sizeof(type), \76__LINE__, __FILE__)))7778/* Usage: <variable type> PANDECODE_PTR_VAR(name, mem, gpu_va) */79#define PANDECODE_PTR_VAR(name, mem, gpu_va) \80name = __pandecode_fetch_gpu_mem(mem, gpu_va, sizeof(*name), \81__LINE__, __FILE__)8283#endif /* __MMAP_TRACE_H__ */848586