Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/kernel/rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <cstdint>
#include <delegate>
#include <smp_utils>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

// Incorporate seed data into the system RNG state
extern void rng_absorb(const void* input, size_t bytes);
Expand Down
3 changes: 3 additions & 0 deletions api/net/buffer_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <vector>
#include <smp>
#include <likely>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

namespace net
{
Expand Down
42 changes: 22 additions & 20 deletions api/posix/tcp_fd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,30 @@

#include "sockfd.hpp"

struct TCP_FD_Conn;
struct TCP_FD_Listen;

struct TCP_FD_Conn
{
TCP_FD_Conn(net::tcp::Connection_ptr c);
~TCP_FD_Conn() = default;

void retrieve_buffer();
void set_default_read();

ssize_t send(const void *, size_t, int fl);
ssize_t recv(void*, size_t, int fl);
int close();
int shutdown(int);

std::string to_string() const { return conn->to_string(); }

net::tcp::Connection_ptr conn;
net::tcp::buffer_t buffer;
size_t buf_offset;
bool recv_disc = false;
};


class TCP_FD : public SockFD {
public:
using id_t = int;
Expand Down Expand Up @@ -68,25 +89,6 @@ class TCP_FD : public SockFD {
friend struct TCP_FD_Listen;
};

struct TCP_FD_Conn
{
TCP_FD_Conn(net::tcp::Connection_ptr c);

void retrieve_buffer();
void set_default_read();

ssize_t send(const void *, size_t, int fl);
ssize_t recv(void*, size_t, int fl);
int close();
int shutdown(int);

std::string to_string() const { return conn->to_string(); }

net::tcp::Connection_ptr conn;
net::tcp::buffer_t buffer;
size_t buf_offset;
bool recv_disc = false;
};

struct TCP_FD_Listen
{
Expand Down
42 changes: 33 additions & 9 deletions api/util/delegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <type_traits>
#include <functional>
#include <memory>
#include <new> // std::launder

// ----- SYNOPSIS -----

Expand Down Expand Up @@ -68,6 +69,20 @@ class empty_delegate_error : public std::bad_function_call
}
};

template<std::size_t Size, std::size_t Align>
struct sbo_storage {
alignas(Align) std::byte data[Size];

template<class T>
constexpr T& as() noexcept {
return *std::launder(reinterpret_cast<T*>(data));
}
template<class T>
constexpr const T& as() const noexcept {
return *std::launder(reinterpret_cast<const T*>(data));
}
};

// ----- IMPLEMENTATION -----

namespace detail
Expand Down Expand Up @@ -163,7 +178,7 @@ template<
> class inplace_triv
{
public:
using storage_t = std::aligned_storage_t<size, align>;
using storage_t = sbo_storage<size, align>;
using invoke_ptr_t = R(*)(storage_t&, Args&&...);

explicit inplace_triv() noexcept :
Expand All @@ -178,7 +193,10 @@ template<
> explicit inplace_triv(T&& closure) :
invoke_ptr_{ static_cast<invoke_ptr_t>(
[](storage_t& storage, Args&&... args) -> R
{ return reinterpret_cast<C&>(storage)(std::forward<Args>(args)...); }
{
auto& closure = storage.template as<C>();
return closure(std::forward<Args>(args)...);
}
)}
{
static_assert(sizeof(C) <= size,
Expand Down Expand Up @@ -211,12 +229,12 @@ template<

bool empty() const noexcept
{
return reinterpret_cast<std::nullptr_t&>(storage_) == nullptr;
return storage_.template as <std::nullptr_t&>() == nullptr;
}

template<typename T> T* target() const noexcept
{
return reinterpret_cast<T*>(&storage_);
return &storage_.template as<T*>();
}

private:
Expand All @@ -233,7 +251,7 @@ template<
> class inplace
{
public:
using storage_t = std::aligned_storage_t<size, align>;
using storage_t = sbo_storage<size, align>;

using invoke_ptr_t = R(*)(storage_t&, Args&&...);
using copy_ptr_t = void(*)(storage_t&, storage_t&);
Expand All @@ -251,12 +269,18 @@ template<
> explicit inplace(T&& closure) noexcept :
invoke_ptr_{ static_cast<invoke_ptr_t>(
[](storage_t& storage, Args&&... args) -> R
{ return reinterpret_cast<C&>(storage)(std::forward<Args>(args)...); }
{
auto& closure = storage.template as<C>();
return closure(std::forward<Args>(args)...);
}
) },
copy_ptr_{ copy_op<C, storage_t>() },
destructor_ptr_{ static_cast<destructor_ptr_t>(
[](storage_t& storage) noexcept -> void
{ reinterpret_cast<C&>(storage).~C(); }
{
auto& closure = storage.template as<C>();
closure.~C();
}
) }
{
static_assert(sizeof(C) <= size,
Expand Down Expand Up @@ -337,7 +361,7 @@ template<

template<typename T> T* target() const noexcept
{
return reinterpret_cast<T*>(&storage_);
return &storage_.template as <T>();
}

private:
Expand All @@ -357,7 +381,7 @@ template<
{
return [](S& dst, S& src) noexcept -> void
{
new(&dst)T{ reinterpret_cast<T&>(src) };
new(&dst)T{ src.template as<T>() };
};
}

Expand Down
32 changes: 18 additions & 14 deletions api/util/fixed_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cassert>
#include <type_traits>
#include <iterator>
#include <new>

enum class Fixedvector_Init {
UNINIT
Expand All @@ -54,14 +55,14 @@ class Fixed_vector {
T& push_back(const T& e) noexcept {
assert(count < N);
(*this)[count] = e;
return (*this)[count++];
return reinterpret_raw()[count++];
}
// construct into
template <typename... Args>
T& emplace_back(Args&&... args) noexcept {
assert(count < N);
new (&element[count]) T(args...);
return (*this)[count++];
new (static_cast<void*>(reinterpret_raw() + count)) T(std::forward<Args>(args)...);
return reinterpret_raw()[count++];
}

/**
Expand Down Expand Up @@ -108,36 +109,36 @@ class Fixed_vector {
{ return capacity() - size(); }

T& operator[] (uint32_t i) noexcept {
return *(T*) (element + i);
return reinterpret_raw()[i];
}
T* at (uint32_t i) noexcept {
if (i >= size()) return nullptr;
return (T*) (element + i);
return reinterpret_raw() + i;
}

T* data() noexcept {
return (T*) &element[0];
return reinterpret_raw();
}
T* begin() noexcept {
return (T*) &element[0];
return reinterpret_raw();
}
T* end() noexcept {
return (T*) &element[count];
return reinterpret_raw() + count;
}

const T* data() const noexcept {
return (T*) &element[0];
return reinterpret_raw();
}
const T* begin() const noexcept {
return (T*) &element[0];
return reinterpret_raw();
}
const T* end() const noexcept {
return (T*) &element[count];
return reinterpret_raw() + count;
}

T& back() noexcept {
assert(not empty());
return (T&)element[count-1];
return reinterpret_raw()[count-1];
}

constexpr int capacity() const noexcept {
Expand All @@ -151,7 +152,7 @@ class Fixed_vector {
// source of the same type T, with @size elements
// Note: size and capacity are not related, and they don't have to match
void copy(T* src, uint32_t size) {
memcpy(element, src, size * sizeof(T));
memcpy(reinterpret_raw(), src, size * sizeof(T));
count = size;
}

Expand All @@ -163,7 +164,10 @@ class Fixed_vector {

private:
uint32_t count;
typename std::aligned_storage<sizeof(T), alignof(T)>::type element[N];
alignas(T) std::byte storage[sizeof(T) * N];

T* reinterpret_raw() noexcept { return std::launder(reinterpret_cast< T*>(storage)); }
const T* reinterpret_raw() const noexcept { return std::launder(reinterpret_cast<const T*>(storage)); }
};


Expand Down
2 changes: 1 addition & 1 deletion cmake/includeos.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#includeos standard settings for compilation and linkers

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
4 changes: 2 additions & 2 deletions cmake/library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ if (debug)
endif()

if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "-m32 -MMD ${CAPABS} ${WARNS} -nostdlib -fno-omit-frame-pointer -c -std=c++20 -D_LIBCPP_HAS_NO_THREADS=1")
set(CMAKE_CXX_FLAGS "-m32 -MMD ${CAPABS} ${WARNS} -nostdlib -fno-omit-frame-pointer -c -std=c++23 -D_LIBCPP_HAS_NO_THREADS=1")
set(CMAKE_C_FLAGS "-m32 -MMD ${CAPABS} ${WARNS} -nostdlib -fno-omit-frame-pointer -c")
else()
# these kinda work with llvm
set(CMAKE_CXX_FLAGS "-MMD ${CAPABS} ${OPTIMIZE} ${WARNS} -nostdlib -nostdlibinc -fno-omit-frame-pointer -c -std=c++20 -fno-threadsafe-statics -D_LIBCPP_HAS_NO_THREADS=1")
set(CMAKE_CXX_FLAGS "-MMD ${CAPABS} ${OPTIMIZE} ${WARNS} -nostdlib -nostdlibinc -fno-omit-frame-pointer -c -std=c++23 -fno-threadsafe-statics -D_LIBCPP_HAS_NO_THREADS=1")
set(CMAKE_C_FLAGS "-MMD ${CAPABS} ${OPTIMIZE} ${WARNS} -nostdlib -nostdlibinc -fno-omit-frame-pointer -c")
endif()

Expand Down
4 changes: 2 additions & 2 deletions cmake/linux.service.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Linux Userspace CMake script #
####################################

#set(CMAKE_CXX_STANDARD 20)
#set(CMAKE_CXX_STANDARD 23)
set(COMMON "-g -O2 -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 ${COMMON}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23 ${COMMON}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON}")

option(BUILD_PLUGINS "Build all plugins as libraries" OFF)
Expand Down
2 changes: 1 addition & 1 deletion cmake/os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD 23)
set (CMAKE_CXX_STANDARD_REQUIRED ON)


Expand Down
2 changes: 1 addition & 1 deletion lib/LiveUpdate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

project(includeos C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
3 changes: 3 additions & 0 deletions src/kernel/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <smp>
#include <arch.hpp>
//#define DEBUG_SMP
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

static SMP::Array<Events> managers;
static Spinlock em_lock_;
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <statman>
#include <map>
#include <vector>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

using namespace std::chrono;
typedef Timers::duration_t duration_t;
Expand Down
3 changes: 3 additions & 0 deletions src/net/buffer_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <smp>
#include <cstddef>
#include <likely>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

#ifdef __MACH__
extern void* aligned_alloc(size_t alignment, size_t size);
Expand Down
3 changes: 3 additions & 0 deletions src/platform/x86_pc/acpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <cstddef>
#include <vector>
#include <smp_utils>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

namespace x86 {

Expand Down
1 change: 1 addition & 0 deletions src/platform/x86_pc/apic_revenant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <os.hpp>
#include <kernel/rng.hpp>
#include <kprint>
#include <mutex>

namespace x86 {
extern void initialize_cpu_tables_for_cpu(int);
Expand Down
3 changes: 3 additions & 0 deletions src/platform/x86_pc/x2apic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <expects>
#include <debug>
#include <info>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif

/// x2APIC MSR offsets ///
#define x2APIC_ID 0x02
Expand Down
Loading