Files
jsix/src/kernel/cpprt.cpp
Justin C. Miller f5208d1641 [all] Remove dependencies on non-freestanding libc
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`.
2023-07-12 19:38:31 -07:00

38 lines
729 B
C++

#include "kassert.h"
using __exit_func = void (*)(void *);
extern "C" {
void *__dso_handle __attribute__ ((__weak__));
int __cxa_atexit(__exit_func, void *, void *);
void __cxa_pure_virtual();
}
struct __exit_func_entry
{
__exit_func func;
void *obj;
void *dso;
};
static int __num_exit_funcs = 0;
static const int __max_exit_funcs = 64;
__exit_func_entry __exit_funcs[__max_exit_funcs];
int
__cxa_atexit(__exit_func f, void *o, void *dso)
{
int i = __num_exit_funcs++;
if (i >= __max_exit_funcs) return -1;
__exit_funcs[i].func = f;
__exit_funcs[i].obj = o;
__exit_funcs[i].dso = dso;
return 0;
}
void __cxa_pure_virtual()
{
kassert(0, "Pure virtual function call");
}