This pr adds stdio (mostly stubs, but streams already work), proper handling of cdtors, the beginnings of a C++ stdlib, a cmake target to copy libc headers to the sysroot, a cmake flag to build libc for the native host, a better syscall interface for C and C++, support for native syscalls, malloc using a simple bump allocator, and the implementation of various other functions.
Implement part of stdio and improve libc in general #11
Sirraide/LensorOS:dev into main @ -25,2 +25,2 @@
# Use cross compiler.
set( CMAKE_TOOLCHAIN_FILE "../../kernel/lensor_gnu_toolchain.cmake" )
if (NOT LENSOR_OS_LIBC_BUILD_HOST)
Do -DLENSOR_OS_LIBC_BUILD_HOST=1 when invoking CMake to build libc for the native system. Currently, only linux is supported for obvious reasons.
@ -74,0 +96,4 @@
-fno-exceptions
-nostdlib
-nostdinc
-Wno-prio-ctor-dtor
This way, programs that link against libc via CMake have these set automatically.
Also, I'm gonna remove -Wno-prio-ctor-dtor later and replace it locally w/ a pragma.
@ -74,0 +104,4 @@
c
PRIVATE
-g
-O0
Force debug mode for now when compiling natively
@ -74,0 +130,4 @@
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/time.h" "${ROOT}/inc/time.h"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/unistd.h" "${ROOT}/inc/unistd.h"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/sys" "${ROOT}/inc/sys"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/bits" "${ROOT}/inc/bits"
You can probably improve this w/ a file(GLOB ...) + foreach()
@ -0,0 +28,4 @@
const char *file,
unsigned int line,
const char *func
);
Called by assert()
@ -0,0 +37,4 @@
const char *file,
unsigned int line,
const char *func
);
Called by __libc_assert()
@ -0,0 +21,4 @@
#define _LENSOROS_LIBC_CDTORS_H
#define _CDTOR_MALLOC 0
#define _CDTOR_STDIO 1
Global constructor/destructor order
@ -47,0 +259,4 @@
}
__attribute__((__noreturn__)) void _Exit(int status) {
/// TODO: call at_quick_exit handlers.
This comment is wrong.
Things are somewhat broken (has to do with write syscall), but it is most likely in the kernel somewhere. If not, we still want all the work from this PR done, so we are just calling it a known bug 😎
No due date set.
No dependencies set.
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?