| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | * All rights reserved. | 
|  | 4 | * | 
|  | 5 | * Redistribution and use in source and binary forms, with or without | 
|  | 6 | * modification, are permitted provided that the following conditions | 
|  | 7 | * are met: | 
|  | 8 | *  * Redistributions of source code must retain the above copyright | 
|  | 9 | *    notice, this list of conditions and the following disclaimer. | 
|  | 10 | *  * Redistributions in binary form must reproduce the above copyright | 
|  | 11 | *    notice, this list of conditions and the following disclaimer in | 
|  | 12 | *    the documentation and/or other materials provided with the | 
|  | 13 | *    distribution. | 
|  | 14 | * | 
|  | 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|  | 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|  | 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 
|  | 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 
|  | 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|  | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 
|  | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 
|  | 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 
|  | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
|  | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | 
|  | 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
|  | 26 | * SUCH DAMAGE. | 
|  | 27 | */ | 
|  | 28 |  | 
| Elliott Hughes | cbc80ba | 2018-02-13 14:26:29 -0800 | [diff] [blame] | 29 | #pragma once | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | #include <stdint.h> | 
|  | 32 | #include <string.h> | 
|  | 33 |  | 
|  | 34 | #include <vector> | 
|  | 35 |  | 
|  | 36 | #include <private/bionic_macros.h> | 
|  | 37 |  | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 38 | #include "OptionData.h" | 
|  | 39 |  | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 40 | // Forward declarations. | 
|  | 41 | class DebugData; | 
|  | 42 | struct Header; | 
| Christopher Ferris | 2b2b25b | 2017-04-05 19:13:03 -0700 | [diff] [blame] | 43 | class Config; | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 44 |  | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 45 | class GuardData : public OptionData { | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 46 | public: | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 47 | GuardData(DebugData* debug_data, int init_value, size_t num_bytes); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 48 | virtual ~GuardData() = default; | 
|  | 49 |  | 
|  | 50 | bool Valid(void* data) { return memcmp(data, cmp_mem_.data(), cmp_mem_.size()) == 0; } | 
|  | 51 |  | 
|  | 52 | void LogFailure(const Header* header, const void* pointer, const void* data); | 
|  | 53 |  | 
|  | 54 | protected: | 
|  | 55 | std::vector<uint8_t> cmp_mem_; | 
|  | 56 |  | 
|  | 57 | virtual const char* GetTypeName() = 0; | 
|  | 58 |  | 
| Elliott Hughes | 5e62b34 | 2018-10-25 11:00:00 -0700 | [diff] [blame] | 59 | BIONIC_DISALLOW_COPY_AND_ASSIGN(GuardData); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 60 | }; | 
|  | 61 |  | 
|  | 62 | class FrontGuardData : public GuardData { | 
|  | 63 | public: | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 64 | FrontGuardData(DebugData* debug_data, const Config& config, size_t* offset); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 65 | virtual ~FrontGuardData() = default; | 
|  | 66 |  | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 67 | bool Valid(const Header* header); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 68 |  | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 69 | void LogFailure(const Header* header); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 70 |  | 
|  | 71 | size_t offset() { return offset_; } | 
|  | 72 |  | 
|  | 73 | private: | 
|  | 74 | const char* GetTypeName() override { return "FRONT"; } | 
|  | 75 |  | 
|  | 76 | size_t offset_ = 0; | 
|  | 77 |  | 
| Elliott Hughes | 5e62b34 | 2018-10-25 11:00:00 -0700 | [diff] [blame] | 78 | BIONIC_DISALLOW_COPY_AND_ASSIGN(FrontGuardData); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 79 | }; | 
|  | 80 |  | 
|  | 81 | class RearGuardData : public GuardData { | 
|  | 82 | public: | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 83 | RearGuardData(DebugData* debug_data, const Config& config); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 84 | virtual ~RearGuardData() = default; | 
|  | 85 |  | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 86 | bool Valid(const Header* header); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 87 |  | 
| Christopher Ferris | 55a89a4 | 2016-04-07 17:14:53 -0700 | [diff] [blame] | 88 | void LogFailure(const Header* header); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 89 |  | 
|  | 90 | private: | 
|  | 91 | const char* GetTypeName() override { return "REAR"; } | 
|  | 92 |  | 
| Elliott Hughes | 5e62b34 | 2018-10-25 11:00:00 -0700 | [diff] [blame] | 93 | BIONIC_DISALLOW_COPY_AND_ASSIGN(RearGuardData); | 
| Christopher Ferris | 63860cb | 2015-11-16 17:30:32 -0800 | [diff] [blame] | 94 | }; |