This is the first of two rather big changes to clean up includes throughout the project. In this commit, the implicit semi-dependency on libc that bonnibel adds to every module is removed. Previously, I was sloppy with includes of libc headers and include directory order. Now, the freestanding headers from libc are split out into libc_free, and an implicit real dependency is added onto this module, unless `no_libc` is set to `True`. The full libc needs to be explicitly specified as a dependency to be used. Several things needed to change in order to do this: - Many places use `memset` or `memcpy` that cannot depend on libc. The kernel has basic implementations of them itself for this reason. Now those functions are moved into the lower-level `j6/memutils.h`, and libc merely references them. Other modules are now free to reference those functions from libj6 instead. - The kernel's `assert.h` was renamed kassert.h (matching its `kassert` function) so that the new `util/assert.h` can use `__has_include` to detect it and make sure the `assert` macro is usable in libutil code. - Several implementation header files under `__libj6/` also moved under the new libc_free. - A new `include_phase` property has been added to modules for Bonnibel, which can be "normal" (default) or "late" which uses `-idirafter` instead of `-I` for includes. - Since `<utility>` and `<new>` are not freestanding, implementations of `remove_reference`, `forward`, `move`, and `swap` were added to the `util` namespace to replace those from `std`, and `util/new.h` was added to declare `operator new` and `operator delete`.
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#include <j6/errors.h>
|
|
#include <j6/types.h>
|
|
|
|
#include "kassert.h"
|
|
#include "logger.h"
|
|
#include "objects/kobject.h"
|
|
#include "objects/thread.h"
|
|
|
|
namespace obj {
|
|
|
|
static constexpr unsigned types_count = static_cast<unsigned>(kobject::type::max);
|
|
|
|
static uint32_t next_oids [types_count] = { 0 };
|
|
|
|
static_assert(types_count <= (1 << kobject::koid_type_bits),
|
|
"kobject::koid_type_bits cannot represent all kobject types");
|
|
|
|
static const char *type_names[] = {
|
|
#define OBJECT_TYPE( name ) #name ,
|
|
#include <j6/tables/object_types.inc>
|
|
#undef OBJECT_TYPE
|
|
nullptr
|
|
};
|
|
|
|
static uint32_t
|
|
oid_generate(kobject::type t)
|
|
{
|
|
kassert(t < kobject::type::max, "Object type out of bounds");
|
|
unsigned type_int = static_cast<unsigned>(t);
|
|
return __atomic_fetch_add(&next_oids[type_int], 1, __ATOMIC_RELAXED);
|
|
}
|
|
|
|
kobject::kobject(type t) :
|
|
m_handle_count {0},
|
|
m_type {t},
|
|
m_obj_id {oid_generate(t)}
|
|
{
|
|
log::spam(logs::objs, "%s[%02lx] created @ 0x%lx", type_name(m_type), m_obj_id, this);
|
|
}
|
|
|
|
kobject::~kobject()
|
|
{
|
|
log::spam(logs::objs, "%s[%02lx] deleted", type_name(m_type), m_obj_id);
|
|
}
|
|
|
|
const char *
|
|
kobject::type_name(type t)
|
|
{
|
|
return type_names[static_cast<int>(t)];
|
|
}
|
|
|
|
void
|
|
kobject::on_no_handles()
|
|
{
|
|
log::verbose(logs::objs, "Deleting %s[%02lx] on no handles", type_name(m_type), m_obj_id);
|
|
delete this;
|
|
}
|
|
|
|
} // namespace obj
|