blob: 58e33e917c4ff3f051dd1bfced9e6c68ac3f2047 [file] [log] [blame]
Christopher Ferris63860cb2015-11-16 17:30:32 -08001/*
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 Hughescbc80ba2018-02-13 14:26:29 -080029#pragma once
Christopher Ferris63860cb2015-11-16 17:30:32 -080030
31#include <stdint.h>
32#include <string.h>
33
34#include <vector>
35
Josh Gao4956c372019-12-19 16:35:51 -080036#include <platform/bionic/macros.h>
Christopher Ferris63860cb2015-11-16 17:30:32 -080037
Christopher Ferris55a89a42016-04-07 17:14:53 -070038#include "OptionData.h"
39
Christopher Ferris63860cb2015-11-16 17:30:32 -080040// Forward declarations.
41class DebugData;
42struct Header;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070043class Config;
Christopher Ferris63860cb2015-11-16 17:30:32 -080044
Christopher Ferris55a89a42016-04-07 17:14:53 -070045class GuardData : public OptionData {
Christopher Ferris63860cb2015-11-16 17:30:32 -080046 public:
Christopher Ferris55a89a42016-04-07 17:14:53 -070047 GuardData(DebugData* debug_data, int init_value, size_t num_bytes);
Christopher Ferris63860cb2015-11-16 17:30:32 -080048 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 Hughes5e62b342018-10-25 11:00:00 -070059 BIONIC_DISALLOW_COPY_AND_ASSIGN(GuardData);
Christopher Ferris63860cb2015-11-16 17:30:32 -080060};
61
62class FrontGuardData : public GuardData {
63 public:
Christopher Ferris55a89a42016-04-07 17:14:53 -070064 FrontGuardData(DebugData* debug_data, const Config& config, size_t* offset);
Christopher Ferris63860cb2015-11-16 17:30:32 -080065 virtual ~FrontGuardData() = default;
66
Christopher Ferris55a89a42016-04-07 17:14:53 -070067 bool Valid(const Header* header);
Christopher Ferris63860cb2015-11-16 17:30:32 -080068
Christopher Ferris55a89a42016-04-07 17:14:53 -070069 void LogFailure(const Header* header);
Christopher Ferris63860cb2015-11-16 17:30:32 -080070
71 size_t offset() { return offset_; }
72
73 private:
74 const char* GetTypeName() override { return "FRONT"; }
75
76 size_t offset_ = 0;
77
Elliott Hughes5e62b342018-10-25 11:00:00 -070078 BIONIC_DISALLOW_COPY_AND_ASSIGN(FrontGuardData);
Christopher Ferris63860cb2015-11-16 17:30:32 -080079};
80
81class RearGuardData : public GuardData {
82 public:
Christopher Ferris55a89a42016-04-07 17:14:53 -070083 RearGuardData(DebugData* debug_data, const Config& config);
Christopher Ferris63860cb2015-11-16 17:30:32 -080084 virtual ~RearGuardData() = default;
85
Christopher Ferris55a89a42016-04-07 17:14:53 -070086 bool Valid(const Header* header);
Christopher Ferris63860cb2015-11-16 17:30:32 -080087
Christopher Ferris55a89a42016-04-07 17:14:53 -070088 void LogFailure(const Header* header);
Christopher Ferris63860cb2015-11-16 17:30:32 -080089
90 private:
91 const char* GetTypeName() override { return "REAR"; }
92
Elliott Hughes5e62b342018-10-25 11:00:00 -070093 BIONIC_DISALLOW_COPY_AND_ASSIGN(RearGuardData);
Christopher Ferris63860cb2015-11-16 17:30:32 -080094};