diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 17:01:22 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 17:01:22 +0100 |
| commit | 7b9df8bec5038e0316540d2397df632fb14c9169 (patch) | |
| tree | 3b5959510cbfd336479b97413427a35972e6e305 | |
| parent | b157e2c472d8bd67ac1656404a6a6ee821260f4b (diff) | |
| download | teachos-7b9df8bec5038e0316540d2397df632fb14c9169.tar.xz teachos-7b9df8bec5038e0316540d2397df632fb14c9169.zip | |
chore: configure clang-tidy
| -rw-r--r-- | .clang-tidy | 5 | ||||
| -rw-r--r-- | .vscode/settings.json | 11 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/region_allocator.hpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/crtc.hpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/text.hpp | 26 | ||||
| -rw-r--r-- | arch/x86_64/src/cpu/registers.cpp | 4 | ||||
| -rw-r--r-- | arch/x86_64/src/kapi/cio.cpp | 1 | ||||
| -rw-r--r-- | arch/x86_64/src/kapi/memory.cpp | 14 | ||||
| -rw-r--r-- | arch/x86_64/src/vga/text.cpp | 7 | ||||
| -rw-r--r-- | cmake/Platforms/x86_64.cmake | 1 | ||||
| -rw-r--r-- | kapi/include/kapi/cio.hpp | 3 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/address.hpp | 2 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/frame.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/frame_allocator.hpp | 2 | ||||
| -rw-r--r-- | kapi/src/cio.cpp | 3 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/asm_ptr | 42 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/bits/shared_ptr.hpp | 2 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/mutex | 17 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/stack | 32 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/vector | 9 | ||||
| -rw-r--r-- | libs/kstd/src/libc/stdlib.cpp | 5 |
21 files changed, 133 insertions, 69 deletions
diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..64699bf --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,5 @@ +Checks: + - '-clang-diagnostic-*' + - 'clang-analyzer-*' + - 'cppcoreguidelines-*' + - 'modernize-*'
\ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 91b307a..8cee879 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,5 +20,14 @@ "editor.rulers": [ 80 ] - } + }, + "cSpell.words": [ + "crtc", + "invlpg", + "kapi", + "kstd", + "NOLINTNEXTLINE", + "rvalues", + "TeachOS" + ] }
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/memory/region_allocator.hpp b/arch/x86_64/include/x86_64/memory/region_allocator.hpp index 913b0bb..4a18a0f 100644 --- a/arch/x86_64/include/x86_64/memory/region_allocator.hpp +++ b/arch/x86_64/include/x86_64/memory/region_allocator.hpp @@ -66,10 +66,10 @@ namespace teachos::memory::x86_64 frame m_next_frame; ///< The physical_frame after the last allocated one. std::optional<multiboot2::memory_map::region> m_current_region; ///< The memory region currently allocated from multiboot2::memory_map m_memory_map; ///< The boot loader supplied memory map. - frame const m_kernel_start; ///< The start address of the kernel code in memory. - frame const m_kernel_end; ///< The end address of the kernel code in memory. - frame const m_multiboot_start; ///< The start address of the multiboot code in memory. - frame const m_multiboot_end; ///< The end address of the multiboot code in memory. + frame m_kernel_start; ///< The start address of the kernel code in memory. + frame m_kernel_end; ///< The end address of the kernel code in memory. + frame m_multiboot_start; ///< The start address of the multiboot code in memory. + frame m_multiboot_end; ///< The end address of the multiboot code in memory. }; } // namespace teachos::memory::x86_64 diff --git a/arch/x86_64/include/x86_64/vga/crtc.hpp b/arch/x86_64/include/x86_64/vga/crtc.hpp index be72ac4..8bdc12d 100644 --- a/arch/x86_64/include/x86_64/vga/crtc.hpp +++ b/arch/x86_64/include/x86_64/vga/crtc.hpp @@ -10,12 +10,12 @@ namespace teachos::vga::x86_64::crtc /** * @brief The address port of the CRT Controller. */ - using address = io::x86_64::port<0x3d4, 1>; + using address = io::x86_64::port<0x3d4, 1>; // NOLINT(cppcoreguidelines-avoid-magic-numbers) /** * @brief The data port of the CRT Controller. */ - using data = io::x86_64::port<0x3d5, 1>; + using data = io::x86_64::port<0x3d5, 1>; // NOLINT(cppcoreguidelines-avoid-magic-numbers) namespace registers { diff --git a/arch/x86_64/include/x86_64/vga/text.hpp b/arch/x86_64/include/x86_64/vga/text.hpp index 858350f..d8919bf 100644 --- a/arch/x86_64/include/x86_64/vga/text.hpp +++ b/arch/x86_64/include/x86_64/vga/text.hpp @@ -54,7 +54,7 @@ namespace teachos::vga::x86_64::text { color foreground_color : 3; ///< The foreground color of the cell, e.g. the color of the code point. enum foreground_flag foreground_flag : 1; ///< The foreground color modification flag of the cell. - color bacground_color : 3; ///< The background color of the cell. + color background_color : 3; ///< The background color of the cell. enum background_flag background_flag : 1; ///< The background color modification flag of the cell. }; @@ -68,26 +68,34 @@ namespace teachos::vga::x86_64::text /** * @brief Make the affected cell display with a gray foreground and black background. */ - [[maybe_unused]] constexpr auto gray_on_black = - attribute{color::gray, foreground_flag::none, color::black, background_flag::none}; + [[maybe_unused]] constexpr auto gray_on_black = attribute{.foreground_color = color::gray, + .foreground_flag = foreground_flag::none, + .background_color = color::black, + .background_flag = background_flag::none}; /** * @brief Make the affected cell display with a green foreground and black background. */ - [[maybe_unused]] constexpr auto green_on_black = - attribute{color::green, foreground_flag::none, color::black, background_flag::none}; + [[maybe_unused]] constexpr auto green_on_black = attribute{.foreground_color = color::green, + .foreground_flag = foreground_flag::none, + .background_color = color::black, + .background_flag = background_flag::none}; /** * @brief Make the affected cell display with a green foreground and black background. */ - [[maybe_unused]] constexpr auto red_on_black = - attribute{color::red, foreground_flag::none, color::black, background_flag::none}; + [[maybe_unused]] constexpr auto red_on_black = attribute{.foreground_color = color::red, + .foreground_flag = foreground_flag::none, + .background_color = color::black, + .background_flag = background_flag::none}; /** * @brief Make the affected cell display with a white (gray + intense) foreground and red background. */ - [[maybe_unused]] constexpr auto white_on_red = - attribute{color::gray, foreground_flag::intense, color::red, background_flag::none}; + [[maybe_unused]] constexpr auto white_on_red = attribute{.foreground_color = color::gray, + .foreground_flag = foreground_flag::intense, + .background_color = color::red, + .background_flag = background_flag::none}; } // namespace common_attributes struct device final : teachos::cio::output_device diff --git a/arch/x86_64/src/cpu/registers.cpp b/arch/x86_64/src/cpu/registers.cpp index 8646829..d59776b 100644 --- a/arch/x86_64/src/cpu/registers.cpp +++ b/arch/x86_64/src/cpu/registers.cpp @@ -6,7 +6,7 @@ namespace teachos::cpu::x86_64 { auto read_control_register(control_register cr) -> uint64_t { - uint64_t current_value; + uint64_t current_value{}; switch (cr) { case control_register::cr0: @@ -59,6 +59,6 @@ namespace teachos::cpu::x86_64 auto set_cr0_bit(cr0_flags flag) -> void { auto const cr0 = read_control_register(control_register::cr0); - write_control_register(control_register::cr0, static_cast<std::underlying_type<cr0_flags>::type>(flag) | cr0); + write_control_register(control_register::cr0, static_cast<std::underlying_type_t<cr0_flags>>(flag) | cr0); } } // namespace teachos::cpu::x86_64 diff --git a/arch/x86_64/src/kapi/cio.cpp b/arch/x86_64/src/kapi/cio.cpp index eb0142a..456477a 100644 --- a/arch/x86_64/src/kapi/cio.cpp +++ b/arch/x86_64/src/kapi/cio.cpp @@ -5,6 +5,7 @@ namespace teachos::cio { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) auto static constinit vga_device = std::optional<vga::x86_64::text::device>{}; auto init() -> void diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp index 61d462f..e05fde9 100644 --- a/arch/x86_64/src/kapi/memory.cpp +++ b/arch/x86_64/src/kapi/memory.cpp @@ -19,19 +19,23 @@ namespace teachos::memory namespace { + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) auto constinit is_initialized = std::atomic_flag{}; auto constinit allocator = static_cast<frame_allocator *>(nullptr); + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) auto create_memory_information() -> x86_64::region_allocator::memory_information { auto const & mbi = boot::x86_64::multiboot_information_pointer.get(); auto map = mbi->memory_map(); - return {std::make_pair(physical_address{&boot::x86_64::_start_physical}, - physical_address{&boot::x86_64::_end_physical}), - std::make_pair(physical_address{std::bit_cast<std::byte *>(mbi)}, - physical_address{std::bit_cast<std::byte *>(mbi) + mbi->size_bytes()}), - map}; + // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic) + return {.image_range = std::make_pair(physical_address{&boot::x86_64::_start_physical}, + physical_address{&boot::x86_64::_end_physical}), + .mbi_range = std::make_pair(physical_address{std::bit_cast<std::byte *>(mbi)}, + physical_address{std::bit_cast<std::byte *>(mbi) + mbi->size_bytes()}), + .memory_map = map}; + // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic) }; auto create_early_frame_allocator() diff --git a/arch/x86_64/src/vga/text.cpp b/arch/x86_64/src/vga/text.cpp index 8aa809f..0e0d353 100644 --- a/arch/x86_64/src/vga/text.cpp +++ b/arch/x86_64/src/vga/text.cpp @@ -15,10 +15,12 @@ namespace teachos::vga::x86_64::text namespace { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) auto constinit buffer_offset = std::ptrdiff_t{}; constexpr auto DEFAULT_TEXT_BUFFER_WIDTH = 80U; constexpr auto DEFAULT_TEXT_BUFFER_HEIGHT = 25U; + constexpr auto CURSOR_ENABLED_BIT = 5U; auto write_char(char code_point, attribute attribute) -> void { @@ -29,12 +31,13 @@ namespace teachos::vga::x86_64::text auto device::clear(attribute attribute) -> void { buffer_offset = 0; - std::ranges::fill_n(vga_buffer_pointer.get(), 2000, std::pair{' ', std::bit_cast<std::byte>(attribute)}); + std::ranges::fill_n(vga_buffer_pointer.get(), DEFAULT_TEXT_BUFFER_WIDTH * DEFAULT_TEXT_BUFFER_HEIGHT, + std::pair{' ', std::bit_cast<std::byte>(attribute)}); } auto device::cursor(bool enabled) -> void { - auto cursor_disable_byte = std::byte{!enabled} << 5; + auto cursor_disable_byte = std::byte{!enabled} << CURSOR_ENABLED_BIT; crtc::address::write(crtc::registers::cursor_start); crtc::data::write(crtc::data::read() | cursor_disable_byte); diff --git a/cmake/Platforms/x86_64.cmake b/cmake/Platforms/x86_64.cmake index afdc0ec..23287de 100644 --- a/cmake/Platforms/x86_64.cmake +++ b/cmake/Platforms/x86_64.cmake @@ -19,6 +19,7 @@ set(CMAKE_CXX_FLAGS_INIT "-fno-pie" "-fno-rtti" "-fno-exceptions" + "-fno-use-cxa-atexit" "-ffunction-sections" "-fdata-sections" ) diff --git a/kapi/include/kapi/cio.hpp b/kapi/include/kapi/cio.hpp index 6b93638..a01af08 100644 --- a/kapi/include/kapi/cio.hpp +++ b/kapi/include/kapi/cio.hpp @@ -6,8 +6,11 @@ namespace teachos::cio { + // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct output_device { + virtual ~output_device() = default; + auto virtual write(std::string_view text [[maybe_unused]]) -> void {} auto virtual writeln(std::string_view text [[maybe_unused]]) -> void {} diff --git a/kapi/include/kapi/memory/address.hpp b/kapi/include/kapi/memory/address.hpp index 63301aa..359b5ec 100644 --- a/kapi/include/kapi/memory/address.hpp +++ b/kapi/include/kapi/memory/address.hpp @@ -34,7 +34,7 @@ namespace teachos::memory constexpr auto operator<=>(address const &) const noexcept -> std::strong_ordering = default; constexpr auto operator==(address const &) const noexcept -> bool = default; - constexpr auto raw() const noexcept -> std::uintptr_t + [[nodiscard]] constexpr auto raw() const noexcept -> std::uintptr_t { return m_value; } diff --git a/kapi/include/kapi/memory/frame.hpp b/kapi/include/kapi/memory/frame.hpp index a208f28..63b1e70 100644 --- a/kapi/include/kapi/memory/frame.hpp +++ b/kapi/include/kapi/memory/frame.hpp @@ -3,10 +3,8 @@ #include "kapi/memory/address.hpp" -#include <bit> #include <compare> #include <cstddef> -#include <cstdint> namespace teachos::memory { @@ -37,7 +35,7 @@ namespace teachos::memory * * @return Start address of the physical frame. */ - constexpr auto start_address() const noexcept -> physical_address + [[nodiscard]] constexpr auto start_address() const noexcept -> physical_address { return physical_address{m_number * PLATFORM_FRAME_SIZE}; } diff --git a/kapi/include/kapi/memory/frame_allocator.hpp b/kapi/include/kapi/memory/frame_allocator.hpp index f9393ee..22102a6 100644 --- a/kapi/include/kapi/memory/frame_allocator.hpp +++ b/kapi/include/kapi/memory/frame_allocator.hpp @@ -8,8 +8,10 @@ namespace teachos::memory { + // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct frame_allocator { + virtual ~frame_allocator() = default; virtual auto allocate() -> std::optional<frame> = 0; virtual auto release(frame frame) -> void = 0; }; diff --git a/kapi/src/cio.cpp b/kapi/src/cio.cpp index e8490e9..210e58e 100644 --- a/kapi/src/cio.cpp +++ b/kapi/src/cio.cpp @@ -5,8 +5,9 @@ namespace teachos::cio { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) auto constinit null_device = output_device{}; - + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) auto constinit active_device = &null_device; auto set_output_device(output_device & device) -> std::optional<output_device *> diff --git a/libs/kstd/include/kstd/asm_ptr b/libs/kstd/include/kstd/asm_ptr index e9072e2..e8636c3 100644 --- a/libs/kstd/include/kstd/asm_ptr +++ b/libs/kstd/include/kstd/asm_ptr @@ -23,28 +23,50 @@ namespace kstd asm_ptr() = delete; asm_ptr(asm_ptr const &) = delete; asm_ptr(asm_ptr &&) = delete; + ~asm_ptr() = delete; - auto constexpr operator=(asm_ptr const &) = delete; - auto constexpr operator=(asm_ptr &&) = delete; + constexpr auto operator=(asm_ptr const &) = delete; + constexpr auto operator=(asm_ptr &&) = delete; - auto get() const noexcept -> pointer { return m_ptr; } + auto get() const noexcept -> pointer + { + return m_ptr; + } - auto constexpr operator+(std::ptrdiff_t offset) const noexcept -> pointer + constexpr auto operator+(std::ptrdiff_t offset) const noexcept -> pointer { return std::bit_cast<pointer>(m_ptr) + offset; } - auto constexpr operator*() noexcept -> reference { return *(std::bit_cast<pointer>(m_ptr)); } + constexpr auto operator*() noexcept -> reference + { + return *(std::bit_cast<pointer>(m_ptr)); + } - auto constexpr operator*() const noexcept -> const_reference { return *(std::bit_cast<const_pointer>(m_ptr)); } + constexpr auto operator*() const noexcept -> const_reference + { + return *(std::bit_cast<const_pointer>(m_ptr)); + } - auto constexpr operator[](std::ptrdiff_t offset) noexcept -> reference { return *(*this + offset); } + constexpr auto operator[](std::ptrdiff_t offset) noexcept -> reference + { + return *(*this + offset); + } - auto constexpr operator[](std::ptrdiff_t offset) const noexcept -> const_reference { return *(*this + offset); } + constexpr auto operator[](std::ptrdiff_t offset) const noexcept -> const_reference + { + return *(*this + offset); + } - auto constexpr operator->() noexcept -> pointer { return m_ptr; } + constexpr auto operator->() noexcept -> pointer + { + return m_ptr; + } - auto constexpr operator->() const noexcept -> const_pointer { return m_ptr; } + constexpr auto operator->() const noexcept -> const_pointer + { + return m_ptr; + } private: pointer m_ptr; diff --git a/libs/kstd/include/kstd/bits/shared_ptr.hpp b/libs/kstd/include/kstd/bits/shared_ptr.hpp index 251c187..4bcf499 100644 --- a/libs/kstd/include/kstd/bits/shared_ptr.hpp +++ b/libs/kstd/include/kstd/bits/shared_ptr.hpp @@ -220,7 +220,7 @@ namespace kstd private: /** - * @brief Releases ownership and deletes the object if this was the last ereference to the owned managed object. + * @brief Releases ownership and deletes the object if this was the last reference to the owned managed object. */ [[gnu::section(".stl_text")]] auto cleanup() -> void diff --git a/libs/kstd/include/kstd/mutex b/libs/kstd/include/kstd/mutex index cf8549f..6ae3adf 100644 --- a/libs/kstd/include/kstd/mutex +++ b/libs/kstd/include/kstd/mutex @@ -24,12 +24,23 @@ namespace kstd /** * @brief Deleted copy constructor. */ - mutex(const mutex &) = delete; + mutex(mutex const &) = delete; /** - * @brief Deleted assignment operator. + * @brief Deleted move constructor. + * + */ + mutex(mutex &&) = delete; + + /** + * @brief Deleted copy assignment operator. + */ + auto operator=(mutex const &) -> mutex & = delete; + + /** + * @brief Deleted move assignment operator. */ - mutex & operator=(const mutex &) = delete; + auto operator=(mutex &&) -> mutex & = delete; /** * @brief Lock the mutex (blocks for as long as it is not available). diff --git a/libs/kstd/include/kstd/stack b/libs/kstd/include/kstd/stack index 8c702cf..8cd208a 100644 --- a/libs/kstd/include/kstd/stack +++ b/libs/kstd/include/kstd/stack @@ -1,8 +1,7 @@ #ifndef KSTD_STACK_HPP #define KSTD_STACK_HPP -#include "kstd/vector.hpp" - +#include "kstd/vector" #include <utility> namespace kstd @@ -29,8 +28,12 @@ namespace kstd */ stack() = default; + stack(stack const &) = delete; + stack(stack &&) = delete; + auto operator=(stack const &) -> stack & = delete; + auto operator=(stack &&) -> stack & = delete; /** - * @brief Constructs data with the given amount of elements containg the given value or alterantively the default + * @brief Constructs data with the given amount of elements containing the given value or alternatively the default * constructed value. * * @param n Amount of elements we want to create and set the given value for. @@ -61,11 +64,11 @@ namespace kstd /** * @brief Construct data by copying all elements from the initializer list. * - * @param initalizer_list List we want to copy all elements from. + * @param elements List we want to copy all elements from. */ [[gnu::section(".stl_text")]] - explicit stack(std::initializer_list<T> initalizer_list) - : _container(initalizer_list) + explicit stack(std::initializer_list<T> elements) + : _container(elements) { // Nothing to do. } @@ -86,21 +89,6 @@ namespace kstd } /** - * @brief Copy assignment operator. - * - * @note Allocates underlying data container with the same capacity as vector we are copying from and copies all - * elements from it. - * - * @param other Other instance of vector we want to copy the data from. - * @return Newly created copy. - */ - [[gnu::section(".stl_text")]] - stack<T> & operator=(stack<T> const & other) - { - _container = other; - } - - /** * @brief Destructor. */ ~stack() = default; @@ -194,7 +182,7 @@ namespace kstd } /** - * @brief Wheter there are currently any items this container or not. + * @brief Whether there are currently any items this container or not. * * @return True if there are no elements, false if there are. */ diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector index 1009e81..9d96eb8 100644 --- a/libs/kstd/include/kstd/vector +++ b/libs/kstd/include/kstd/vector @@ -29,7 +29,7 @@ namespace kstd vector() = default; /** - * @brief Constructs data with the given amount of elements containg the given value or alterantively the default + * @brief Constructs data with the given amount of elements containing the given value or alternatively the default * constructed value. * * @param n Amount of elements we want to create and set the given value for. @@ -99,7 +99,7 @@ namespace kstd * @return Newly created copy. */ [[gnu::section(".stl_text")]] - vector<value_type> & operator=(vector<value_type> const & other) + auto operator=(vector const & other) -> vector<value_type> & { delete[] _data; _size = other._size; @@ -112,7 +112,10 @@ namespace kstd /** * @brief Destructor. */ - ~vector() { delete[] _data; } + ~vector() + { + delete[] _data; + } /** * @brief Amount of elements currently contained in this vector, will fill up until we have reached the capacity. If diff --git a/libs/kstd/src/libc/stdlib.cpp b/libs/kstd/src/libc/stdlib.cpp index 752e616..a0f062a 100644 --- a/libs/kstd/src/libc/stdlib.cpp +++ b/libs/kstd/src/libc/stdlib.cpp @@ -9,6 +9,11 @@ namespace kstd::libc { kstd::os::abort(); } + + [[noreturn, gnu::weak]] auto free(void *) -> void + { + kstd::os::panic("Tried to call free."); + } } } // namespace kstd::libc
\ No newline at end of file |
