|
| 1 | +// This file is a part of the IncludeOS unikernel - www.includeos.org |
| 2 | +// |
| 3 | +// Copyright 2015 Oslo and Akershus University College of Applied Sciences |
| 4 | +// and Alfred Bratterud |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | + |
| 18 | +#include <common> |
| 19 | +#include <util/crc32.hpp> |
| 20 | +#include <kernel/elf.hpp> |
| 21 | +#include <kernel/syscalls.hpp> |
| 22 | +#include <cstdint> |
| 23 | +#include <kprint> |
| 24 | + |
| 25 | +// Global constructors |
| 26 | +static int gconstr_value = 0; |
| 27 | +__attribute__((constructor)) |
| 28 | +static void self_test_gconstr() { |
| 29 | + gconstr_value = 1; |
| 30 | +} |
| 31 | + |
| 32 | +extern "C" |
| 33 | +void __init_sanity_checks() noexcept |
| 34 | +{ |
| 35 | +} |
| 36 | + |
| 37 | +extern "C" |
| 38 | +void kernel_sanity_checks() |
| 39 | +{ |
| 40 | + // verify that Elf symbols were not overwritten |
| 41 | + bool symbols_verified = Elf::verify_symbols(); |
| 42 | + if (!symbols_verified) |
| 43 | + panic("Sanity checks: Consistency of Elf symbols and string areas"); |
| 44 | + |
| 45 | + // global constructor self-test |
| 46 | + if (gconstr_value != 1) { |
| 47 | + kprintf("Sanity checks: Global constructors not working (or modified during run-time)!\n"); |
| 48 | + panic("Sanity checks: Global constructors verification failed"); |
| 49 | + } |
| 50 | +} |
0 commit comments