Introduce std::nothrow
Let's make sure we explicitly tell new that we don't want exceptions
This commit is contained in:
parent
32c8869973
commit
d759058b80
@ -5,12 +5,18 @@
|
|||||||
#include "memory/KernelVM.h"
|
#include "memory/KernelVM.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include <luna/Alignment.h>
|
#include <luna/Alignment.h>
|
||||||
|
#include <luna/Alloc.h>
|
||||||
#include <luna/LinkedList.h>
|
#include <luna/LinkedList.h>
|
||||||
#include <luna/SafeArithmetic.h>
|
#include <luna/SafeArithmetic.h>
|
||||||
#include <luna/ScopeGuard.h>
|
#include <luna/ScopeGuard.h>
|
||||||
#include <luna/String.h>
|
#include <luna/String.h>
|
||||||
#include <luna/SystemError.h>
|
#include <luna/SystemError.h>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
const std::nothrow_t nothrow;
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr int BLOCK_USED = 1 << 0;
|
static constexpr int BLOCK_USED = 1 << 0;
|
||||||
static constexpr int BLOCK_START_MEM = 1 << 1;
|
static constexpr int BLOCK_START_MEM = 1 << 1;
|
||||||
static constexpr int BLOCK_END_MEM = 1 << 2;
|
static constexpr int BLOCK_END_MEM = 1 << 2;
|
||||||
@ -354,12 +360,12 @@ void dump_heap_usage()
|
|||||||
kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used);
|
kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new(usize size) noexcept
|
void* operator new(usize size, const std::nothrow_t&) noexcept
|
||||||
{
|
{
|
||||||
return kmalloc(size).value_or(nullptr);
|
return kmalloc(size).value_or(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new[](usize size) noexcept
|
void* operator new[](usize size, const std::nothrow_t&) noexcept
|
||||||
{
|
{
|
||||||
return kmalloc(size).value_or(nullptr);
|
return kmalloc(size).value_or(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,36 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
struct nothrow_t
|
||||||
|
{
|
||||||
|
explicit nothrow_t() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const nothrow_t nothrow;
|
||||||
|
|
||||||
|
enum class align_val_t : usize
|
||||||
|
{
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
[[nodiscard]] void* raw_malloc(usize);
|
[[nodiscard]] void* raw_malloc(usize);
|
||||||
void raw_free(void*);
|
void raw_free(void*);
|
||||||
|
|
||||||
|
void* operator new(usize size, const std::nothrow_t&) noexcept;
|
||||||
|
void* operator new[](usize size, const std::nothrow_t&) noexcept;
|
||||||
|
|
||||||
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
||||||
{
|
{
|
||||||
T* const result = new T(args...);
|
T* const result = new (std::nothrow) T(args...);
|
||||||
if (!result) return err(ENOMEM);
|
if (!result) return err(ENOMEM);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
|
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
|
||||||
{
|
{
|
||||||
T* const result = new T[count];
|
T* const result = new (std::nothrow) T[count];
|
||||||
if (!result) return err(ENOMEM);
|
if (!result) return err(ENOMEM);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user