[kernel] Run global constructors
Look up the global constructor list that the linker outputs, and run them all. Required creation of the `kutil::no_construct` template for objects that are constructed before the global constructors are run. Also split the `memory_initialize` function into two - one for just those objects that need to happen before the global ctors, and one after. Tags: memory c++
This commit is contained in:
@@ -18,11 +18,18 @@ enum class level : uint8_t {
|
||||
class logger
|
||||
{
|
||||
public:
|
||||
/// Callback type for immediate-mode logging
|
||||
typedef void (*immediate)(area_t, level, const char *);
|
||||
|
||||
/// Default constructor. Creates a logger without a backing store.
|
||||
logger();
|
||||
/// \arg output Immediate-mode logging output function
|
||||
logger(immediate output = nullptr);
|
||||
|
||||
/// Constructor. Logs are written to the given buffer.
|
||||
logger(uint8_t *buffer, size_t size);
|
||||
/// \arg buffer Buffer to which logs are written
|
||||
/// \arg size Size of `buffer`, in bytes
|
||||
/// \arg output Immediate-mode logging output function
|
||||
logger(uint8_t *buffer, size_t size, immediate output = nullptr);
|
||||
|
||||
/// Register a log area for future use.
|
||||
/// \arg area The key for the new area
|
||||
@@ -30,9 +37,6 @@ public:
|
||||
/// \arg verbosity What level of logs to print for this area
|
||||
void register_area(area_t area, const char *name, level verbosity);
|
||||
|
||||
/// Callback type for immediate-mode logging
|
||||
typedef void (*immediate)(area_t, level, const char *);
|
||||
|
||||
/// Register an immediate-mode log callback
|
||||
inline void set_immediate(immediate cb) { m_immediate = cb; }
|
||||
|
||||
|
||||
15
src/libraries/kutil/include/kutil/no_construct.h
Normal file
15
src/libraries/kutil/include/kutil/no_construct.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
/// \file no_construct.h
|
||||
/// Tools for creating objects witout running constructors
|
||||
|
||||
namespace kutil {
|
||||
|
||||
/// Helper template for creating objects witout running constructors
|
||||
template <typename T>
|
||||
union no_construct
|
||||
{
|
||||
T value;
|
||||
no_construct() {}
|
||||
};
|
||||
|
||||
} // namespace kutil
|
||||
@@ -21,9 +21,9 @@ using kutil::memcpy;
|
||||
logger *logger::s_log = nullptr;
|
||||
const char *logger::s_level_names[] = {"", "debug", "info", "warn", "error", "fatal"};
|
||||
|
||||
logger::logger() :
|
||||
logger::logger(logger::immediate output) :
|
||||
m_buffer(nullptr, 0),
|
||||
m_immediate(nullptr),
|
||||
m_immediate(output),
|
||||
m_sequence(0)
|
||||
{
|
||||
memset(&m_levels, 0, sizeof(m_levels));
|
||||
@@ -31,9 +31,9 @@ logger::logger() :
|
||||
s_log = this;
|
||||
}
|
||||
|
||||
logger::logger(uint8_t *buffer, size_t size) :
|
||||
logger::logger(uint8_t *buffer, size_t size, logger::immediate output) :
|
||||
m_buffer(buffer, size),
|
||||
m_immediate(nullptr),
|
||||
m_immediate(output),
|
||||
m_sequence(0)
|
||||
{
|
||||
memset(&m_levels, 0, sizeof(m_levels));
|
||||
|
||||
Reference in New Issue
Block a user