signature.hpp (1784B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /* Relacy Race Detector * Copyright (c) 2008-2010, Dmitry S. Vyukov * All rights reserved. * This software is provided AS-IS with no warranty, either express or implied. * This software is distributed under a license and may not be copied, * modified or distributed except as expressly authorized under the * terms of the license contained in the file LICENSE.TXT in this distribution. */ #ifndef RL_SIGNATURE_HPP #define RL_SIGNATURE_HPP #ifdef _MSC_VER # pragma once #endif #include "base.hpp" #include "test_result.hpp" #include "context_base.hpp" namespace rl { template<unsigned magic> class signature { public: signature() : magic_(magic) { } signature(signature const&) : magic_(magic) { } ~signature() { check(RL_INFO); magic_ = 0; } void check(debug_info_param info) const { if ( ((uintptr_t)this <= (uintptr_t)-1 - 4096) && ((uintptr_t)this >= 4096) && ((uintptr_t)this % sizeof(unsigned) == 0) && (magic == magic_)) { return; } else { fail(info); } } private: unsigned magic_; struct fault_event { void const* addr_; void output(std::ostream& s) const { s << "<" << std::hex << addr_ << std::dec << ">" << " access to freed memory"; } }; RL_NOINLINE void fail(debug_info_param info) const { context& c = ctx(); RL_HIST(fault_event) {this} RL_HIST_END(); rl::ctx().fail_test("access to freed memory", test_result_access_to_freed_memory, info); } }; } #endif |