Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2007-2010 The Android Open Source Project |
| 2 | ** |
| 3 | ** This software is licensed under the terms of the GNU General Public |
| 4 | ** License version 2, as published by the Free Software Foundation, and |
| 5 | ** may be copied, distributed, and modified under those terms. |
| 6 | ** |
| 7 | ** This program is distributed in the hope that it will be useful, |
| 8 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | ** GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * Contains declarations of memchecker external variables and routines, used by |
| 15 | * other qemu components. |
| 16 | */ |
| 17 | |
| 18 | #ifndef QEMU_MEMCHECK_MEMCHECK_API_H |
| 19 | #define QEMU_MEMCHECK_MEMCHECK_API_H |
| 20 | |
| 21 | /* This file should compile iff qemu is built with memory checking |
| 22 | * configuration turned on. */ |
| 23 | #ifndef CONFIG_MEMCHECK |
| 24 | #error CONFIG_MEMCHECK is not defined. |
| 25 | #endif // CONFIG_MEMCHECK |
| 26 | |
| 27 | /* Global flag, indicating whether or not memchecking has been enabled |
| 28 | * for the current emulator session. 1 means that memchecking has been |
| 29 | * enabled, 0 means that memchecking has not been enabled. The variable |
| 30 | * is declared in memchec/memcheck.c */ |
| 31 | extern int memcheck_enabled; |
| 32 | |
| 33 | /* Flags wether or not mmu instrumentation is enabled by memchecker. |
| 34 | * 1 - enabled, 0 - is not enabled. */ |
| 35 | extern int memcheck_instrument_mmu; |
| 36 | |
| 37 | /* Global flag, indicating whether or not memchecker is collecting call stack. |
| 38 | * 1 - call stack is being collected, 0 means that stack is not being |
| 39 | * collected. The variable is declared in memchec/memcheck.c */ |
| 40 | extern int memcheck_watch_call_stack; |
| 41 | |
| 42 | /* Array of (tb_pc, guest_pc) pairs, big enough for all translations. This |
| 43 | * array is used to obtain guest PC address from a translated PC address. |
| 44 | * tcg_gen_code_common will fill it up when memchecker is enabled. The array is |
| 45 | * declared in ./translate_all.c */ |
David 'Digit' Turner | d9b6cb9 | 2010-10-20 19:07:28 +0200 | [diff] [blame] | 46 | extern void** gen_opc_tpc2gpc_ptr; |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 47 | |
| 48 | /* Number of (tb_pc, guest_pc) pairs stored in gen_opc_tpc2gpc array. |
| 49 | * The variable is declared in ./translate_all.c */ |
| 50 | extern unsigned int gen_opc_tpc2gpc_pairs; |
| 51 | |
| 52 | /* Checks if given address range in the context of the current process is |
| 53 | * under surveillance by memchecker. |
| 54 | * Param: |
| 55 | * addr - Starting address of a range. |
| 56 | * size - Range size. |
| 57 | * Return: |
| 58 | * boolean: 1 if address range contains memory that requires access |
| 59 | * violation detection, or 0 if given address range is in no interest to |
| 60 | * the memchecker. */ |
| 61 | int memcheck_is_checked(target_ulong addr, uint32_t size); |
| 62 | |
| 63 | /* Validates __ldx_mmu operations. |
| 64 | * Param: |
| 65 | * addr - Virtual address in the guest space where memory is read. |
| 66 | * data_size - Size of the read. |
| 67 | * retaddr - Code address (in TB) that accesses memory. |
| 68 | * Return: |
| 69 | * 1 Address should be invalidated in TLB cache, in order to ensure that |
| 70 | * subsequent attempts to read from that page will launch __ld/__stx_mmu. |
| 71 | * If this routine returns zero, no page invalidation is requried. |
| 72 | */ |
| 73 | int memcheck_validate_ld(target_ulong addr, |
| 74 | uint32_t data_size, |
| 75 | target_ulong retaddr); |
| 76 | |
| 77 | /* Validates __stx_mmu operations. |
| 78 | * Param: |
| 79 | * addr - Virtual address in the guest space where memory is written. |
| 80 | * data_size - Size of the write. |
| 81 | * value - Value to be written. Note that we typecast all values to 64 bits, |
| 82 | * since this will fit all data sizes. |
| 83 | * retaddr - Code address (in TB) that accesses memory. |
| 84 | * Return: |
| 85 | * 1 Address should be invalidated in TLB cache, in order to ensure that |
| 86 | * subsequent attempts to read from that page will launch __ld/__stx_mmu. |
| 87 | * If this routine returns zero, no page invalidation is requried. |
| 88 | */ |
| 89 | int memcheck_validate_st(target_ulong addr, |
| 90 | uint32_t data_size, |
| 91 | uint64_t value, |
| 92 | target_ulong retaddr); |
| 93 | |
| 94 | /* Memchecker's handler for on_call callback. |
| 95 | * Param: |
| 96 | * pc - Guest address where call has been made. |
| 97 | * ret - Guest address where called routine will return. |
| 98 | */ |
| 99 | void memcheck_on_call(target_ulong pc, target_ulong ret); |
| 100 | |
| 101 | /* Memchecker's handler for on_ret callback. |
| 102 | * Param: |
| 103 | * pc - Guest address where routine has returned. |
| 104 | */ |
| 105 | void memcheck_on_ret(target_ulong pc); |
| 106 | |
| 107 | #endif // QEMU_MEMCHECK_MEMCHECK_API_H |