From 47266f5ed97a43fa504dbcbbd113cfe645934cba Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Thu, 25 Aug 2016 21:50:11 +0200 Subject: [PATCH] Ensure that tlib headers are not included in kernel --- cpp.mk | 10 +++++----- tlib/include/tlib/config.hpp | 33 +++++++++++++++++++++++++++++++++ tlib/include/tlib/file.hpp | 3 +++ tlib/include/tlib/graphics.hpp | 4 ++++ tlib/include/tlib/io.hpp | 3 +++ tlib/include/tlib/malloc.hpp | 3 +++ tlib/include/tlib/net.hpp | 5 ++++- tlib/include/tlib/print.hpp | 4 +++- tlib/include/tlib/system.hpp | 3 +++ 9 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 tlib/include/tlib/config.hpp diff --git a/cpp.mk b/cpp.mk index 320d66d9..6e63f9be 100644 --- a/cpp.mk +++ b/cpp.mk @@ -36,10 +36,10 @@ COMMON_LINK_FLAGS=-lgcc KERNEL_LINK_FLAGS=$(COMMON_LINK_FLAGS) -T linker.ld -LIB_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -ffunction-sections -fdata-sections -LIB_LINK_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -Wl,-gc-sections +TLIB_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -ffunction-sections -fdata-sections -DTHOR_TLIB=yes +TLIB_LINK_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -Wl,-gc-sections -PROGRAM_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -I../../tlib/include/ -I../../printf/include/ -static -L../../tlib/debug/ -ltlib -mcmodel=small -fPIC -DTHOR_PROGRAM +PROGRAM_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -I../../tlib/include/ -I../../printf/include/ -static -L../../tlib/debug/ -ltlib -mcmodel=small -fPIC -DTHOR_PROGRAM=yes PROGRAM_LINK_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) $(COMMON_LINK_FLAGS) -static -L../../tlib/debug/ -mcmodel=small -fPIC -z max-page-size=0x1000 -T ../linker.ld NO_COLOR=\x1b[0m @@ -133,12 +133,12 @@ define tlib_compile_cpp_folder debug/$(1)/%.cpp.d: $(1)/%.cpp @ mkdir -p debug/$(1)/ - @ $(CXX) $(LIB_FLAGS) -MM -MT debug/$(1)/$$*.cpp.o $(1)/$$*.cpp | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $$@ + @ $(CXX) $(TLIB_FLAGS) -MM -MT debug/$(1)/$$*.cpp.o $(1)/$$*.cpp | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $$@ debug/$(1)/%.cpp.o: $(1)/%.cpp @ mkdir -p debug/$(1)/ @ echo -e "$(MODE_COLOR)[debug]$(NO_COLOR) Compile (tlib) $(FILE_COLOR)$(1)/$$*.cpp$(NO_COLOR)" - @ $(CXX) $(LIB_FLAGS) -c $$< -o $$@ + @ $(CXX) $(TLIB_FLAGS) -c $$< -o $$@ folder_cpp_files := $(wildcard $(1)/*.cpp) folder_d_files := $$(folder_cpp_files:%.cpp=debug/%.cpp.d) diff --git a/tlib/include/tlib/config.hpp b/tlib/include/tlib/config.hpp new file mode 100644 index 00000000..6cffc128 --- /dev/null +++ b/tlib/include/tlib/config.hpp @@ -0,0 +1,33 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#ifndef TLIB_CONFIG_HPP +#define TLIB_CONFIG_HPP + +namespace tlib { + +constexpr bool is_thor_program(){ +#ifdef THOR_PROGRAM + return true; +#else + return false; +#endif +} + +constexpr bool is_thor_lib(){ +#ifdef THOR_TLIB + return true; +#else + return false; +#endif +} + +} // end of namespace tlib + +#define ASSERT_ONLY_THOR_PROGRAM static_assert(tlib::is_thor_program() || tlib::is_thor_lib(), __FILE__ " can only be used in Thor programs"); + +#endif diff --git a/tlib/include/tlib/file.hpp b/tlib/include/tlib/file.hpp index a810ead2..cff12324 100644 --- a/tlib/include/tlib/file.hpp +++ b/tlib/include/tlib/file.hpp @@ -14,6 +14,9 @@ #include "tlib/stat_info.hpp" #include "tlib/statfs_info.hpp" +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM namespace tlib { diff --git a/tlib/include/tlib/graphics.hpp b/tlib/include/tlib/graphics.hpp index 90bcdc95..58790ef6 100644 --- a/tlib/include/tlib/graphics.hpp +++ b/tlib/include/tlib/graphics.hpp @@ -10,6 +10,10 @@ #include +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM + namespace tlib { namespace graphics { diff --git a/tlib/include/tlib/io.hpp b/tlib/include/tlib/io.hpp index 9617f142..d2963ccc 100644 --- a/tlib/include/tlib/io.hpp +++ b/tlib/include/tlib/io.hpp @@ -12,6 +12,9 @@ #include #include "tlib/ioctl_codes.hpp" +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM namespace tlib { diff --git a/tlib/include/tlib/malloc.hpp b/tlib/include/tlib/malloc.hpp index 9fe91aa4..54589652 100644 --- a/tlib/include/tlib/malloc.hpp +++ b/tlib/include/tlib/malloc.hpp @@ -9,6 +9,9 @@ #define USERLIB_MALLOC_H #include "types.hpp" +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM void* operator new(uint64_t size); void operator delete(void* p); diff --git a/tlib/include/tlib/net.hpp b/tlib/include/tlib/net.hpp index 7ca7f0cc..b7ae781c 100644 --- a/tlib/include/tlib/net.hpp +++ b/tlib/include/tlib/net.hpp @@ -10,7 +10,10 @@ #include -#include "net_constants.hpp" +#include "tlib/net_constants.hpp" +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM namespace tlib { diff --git a/tlib/include/tlib/print.hpp b/tlib/include/tlib/print.hpp index 325d87cb..30f7bdcd 100644 --- a/tlib/include/tlib/print.hpp +++ b/tlib/include/tlib/print.hpp @@ -8,7 +8,9 @@ #ifndef USER_PRINT_HPP #define USER_PRINT_HPP -//TODO Rename in console +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM #include diff --git a/tlib/include/tlib/system.hpp b/tlib/include/tlib/system.hpp index eb185803..f435e9fb 100644 --- a/tlib/include/tlib/system.hpp +++ b/tlib/include/tlib/system.hpp @@ -14,6 +14,9 @@ #include #include "tlib/datetime.hpp" +#include "tlib/config.hpp" + +ASSERT_ONLY_THOR_PROGRAM namespace tlib {