diff --git a/kernel/src/Pledge.cpp b/kernel/src/Pledge.cpp index 0ecc0ed2..0f91474d 100644 --- a/kernel/src/Pledge.cpp +++ b/kernel/src/Pledge.cpp @@ -24,13 +24,16 @@ Result check_pledge(Thread* thread, Promise promise) // Thread::process_pending_signals(). thread->signal_handlers[SIGABRT - 1].sa_handler = SIG_DFL; + // Unblock SIGABRT. + thread->signal_mask.set(SIGABRT - 1, false); + // If there are any other pending signals, they might be processed before SIGABRT. Avoid that by resetting the // thread's pending signals. - thread->pending_signals = 0; + thread->pending_signals.clear(); thread->send_signal(SIGABRT); - // This should never arrive to userspace. + // This should never arrive to userspace, unless we're init and have ignored SIGABRT. return err(ENOSYS); } diff --git a/libluna/include/luna/Bitset.h b/libluna/include/luna/Bitset.h index a2755cfb..202949d9 100644 --- a/libluna/include/luna/Bitset.h +++ b/libluna/include/luna/Bitset.h @@ -1,27 +1,66 @@ +/** + * @file Bitset.h + * @author apio (cloudapio.eu) + * @brief A wrapper class to modify/inspect specific bits of an integer type. + * + * @copyright Copyright (c) 2023, the Luna authors. + * + */ + #pragma once #include +/** + * @brief A wrapper class to modify/inspect specific bits of an integer type, to avoid manual error-prone bit shifting. + * + * @tparam T The integer type to use. + */ template class Bitset { public: - Bitset() : m_value() + /** + * @brief Construct a new empty Bitset object. + */ + Bitset() : m_value(0) { } + /** + * @brief Construct a new Bitset object with a value. + * + * @param value The value to use. + */ Bitset(T value) : m_value(value) { } + /** + * @brief Construct a copy of another Bitset object. + * + * @param other The original object. + */ Bitset(const Bitset& other) : m_value(other.m_value) { } + /** + * @brief Update the internal value of this bitset. + * + * @param value The new value. + * @return Bitset& A reference to this itset. + */ Bitset& operator=(T value) { m_value = value; return *this; } + /** + * @brief Set this bitset to the same value as another bitset. + * + * @param other The pther bitset. + * @return Bitset& A reference to this bitset. + */ Bitset& operator=(const Bitset& other) { if (&other == this) return *this; @@ -29,11 +68,23 @@ template class Bitset return *this; } + /** + * @brief Return the value contained in this bitset. + * + * @return T The contained value. + */ T value() const { return m_value; } + /** + * @brief Modify one of the individual bits in this bitset. + * + * @param index The index of the bit (this will set/unset 1 << index). It must be less than the bit width of the + * underlying type. + * @param b The value to set the bit to. + */ void set(int index, bool b) { check((usize)index < (sizeof(T) * 8)); @@ -42,12 +93,22 @@ template class Bitset m_value &= ~(((T)1) << index); } + /** + * @brief Get the value of one of the individual bits in this bitset. + * + * @param index The index of the bit (this will read 1 << index). It must be less than the bit width of the + * underlying type. + * @return bool The value of the requested bit. + */ bool get(int index) { check((usize)index < (sizeof(T) * 8)); return m_value & (((T)1) << index); } + /** + * @brief Clear all the bits in this bitset. + */ void clear() { m_value = 0;