Skip to content

Commit 6c03b09

Browse files
authored
Merge pull request #1400 from fwsGonzo/dev
Custom sanity checks for solo5
2 parents 0f66f55 + 470075a commit 6c03b09

8 files changed

Lines changed: 73 additions & 19 deletions

File tree

cmake/post.service.cmake

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ endif()
99

1010
set(INSTALL_LOC $ENV{INCLUDEOS_PREFIX}/includeos)
1111

12-
1312
message(STATUS "Target CPU architecture ${ARCH}")
1413
set(TRIPLE "${ARCH}-pc-linux-elf")
1514
set(CMAKE_CXX_COMPILER_TARGET ${TRIPLE})
@@ -37,17 +36,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/settings.cmake)
3736
set(CAPABS "${CAPABS} -mno-red-zone -fstack-protector-strong -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE -DSERVICE=\"\\\"${BINARY}\\\"\" -DSERVICE_NAME=\"\\\"${SERVICE_NAME}\\\"\"")
3837
set(WARNS "-Wall -Wextra") #-pedantic
3938

40-
# configure options
41-
option(debug "Build with debugging symbols (OBS: increases binary size)" OFF)
42-
option(minimal "Build for minimal size" OFF)
43-
option(stripped "Strip symbols to further reduce size" OFF)
44-
45-
add_definitions(-DARCH_${ARCH})
46-
add_definitions(-DARCH="${ARCH}")
47-
if (single_threaded)
48-
add_definitions(-DINCLUDEOS_SINGLE_THREADED)
49-
endif()
50-
5139
# Compiler optimization
5240
set(OPTIMIZE "-O2")
5341
if (minimal)

cmake/pre.service.cmake

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@ if (NOT DEFINED PLATFORM)
1515
endif()
1616
endif()
1717

18+
# configure options
19+
option(debug "Build with debugging symbols (OBS: increases binary size)" OFF)
20+
option(minimal "Build for minimal size" OFF)
21+
option(stripped "Strip symbols to further reduce size" OFF)
22+
option(single_threaded "Compile without SMP support" ON)
1823

24+
# arch and platform defines
1925
message(STATUS "Building for arch ${ARCH}, platform ${PLATFORM}")
20-
2126
set(TRIPLE ${ARCH}) #-pc-linux-elf
2227
set(DCMAKE_CXX_COMPILER_TARGET ${TRIPLE})
2328
set(DCMAKE_C_COMPILER_TARGET ${TRIPLE})
2429

25-
option(single_threaded "Compile without SMP support" ON)
30+
add_definitions(-DARCH_${ARCH})
31+
add_definitions(-DARCH="${ARCH}")
32+
add_definitions(-DPLATFORM="${PLATFORM}")
33+
add_definitions(-DPLATFORM_${PLATFORM})
34+
35+
if (single_threaded)
36+
add_definitions(-DINCLUDEOS_SINGLE_THREADED)
37+
endif()
2638

2739
# include toolchain for arch
2840
include($ENV{INCLUDEOS_PREFIX}/includeos/${ARCH}-elf-toolchain.cmake)

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ include_directories(${BOTAN_DIR})
3232

3333
# TODO: i wanted to use a glob, but then found out that not everything is included
3434
set(OS_OBJECTS
35-
kernel/kernel_start.cpp kernel/sanity_checks.cpp kernel/syscalls.cpp
35+
kernel/kernel_start.cpp kernel/syscalls.cpp
3636
kernel/irq_manager.cpp kernel/multiboot.cpp
3737
kernel/os.cpp kernel/cpuid.cpp kernel/memmap.cpp kernel/pci_manager.cpp
3838
kernel/heap.cpp kernel/service_stub.cpp kernel/main_call.cpp

src/platform/x86_nano/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(PLATFORM_OBJECTS
1111
../x86_pc/os.cpp
1212
../x86_pc/block.cpp
1313
../x86_pc/softreset.cpp
14+
../x86_pc/sanity_checks.cpp
1415
platform.cpp
1516
kernel_start.cpp
1617
)

src/platform/x86_pc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(X86_PC_OBJECTS
1616
serial1.cpp
1717
pic.cpp
1818
softreset.cpp
19+
sanity_checks.cpp
1920
)
2021

2122
add_custom_command(
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525

2626
// NOTE: crc_to MUST NOT be initialized to zero
2727
static uint32_t crc_ro = CRC32_BEGIN();
28-
extern char _TEXT_START_;
29-
extern char _TEXT_END_;
30-
extern char _RODATA_START_;
31-
extern char _RODATA_END_;
3228
const auto* LOW_CHECK_SIZE = (volatile int*) 0x200;
3329

3430
// Global constructors
@@ -40,6 +36,10 @@ static void self_test_gconstr() {
4036

4137
static uint32_t generate_ro_crc() noexcept
4238
{
39+
extern char _TEXT_START_;
40+
extern char _TEXT_END_;
41+
extern char _RODATA_START_;
42+
extern char _RODATA_END_;
4343
return crc32_fast(&_TEXT_START_, &_RODATA_END_ - &_TEXT_START_);
4444
}
4545

@@ -68,6 +68,7 @@ void kernel_sanity_checks()
6868
kprintf("Memory at %p was not zeroed: %#x\n", lowmem, *lowmem);
6969
panic("Sanity checks: Low-memory zero test");
7070
}
71+
7172
// verify that Elf symbols were not overwritten
7273
bool symbols_verified = Elf::verify_symbols();
7374
if (!symbols_verified)

src/platform/x86_solo5/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(PLATFORM_OBJECTS
55
start.asm
66
platform.cpp
77
kernel_start.cpp
8+
sanity_checks.cpp
89
)
910

1011
add_library(x86_solo5 STATIC ${PLATFORM_OBJECTS})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)