liblinux++

A hosted C++ runtime without any libc.
git clone git://henryandlizzy.uk/liblinux++
Log | Files | Refs

new.cpp (415B)


      1 #include "linux.hpp"
      2 
      3 namespace std {
      4 
      5 struct nothrow_t {};
      6 constexpr nothrow_t nothrow;
      7 
      8 }
      9 
     10 void* operator new(size_t size, std::nothrow_t const&) noexcept
     11 {
     12 	return *mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, {}, 0);
     13 }
     14 
     15 void operator delete(void* p, size_t size) noexcept
     16 {
     17 	*munmap(p, size);
     18 }
     19 
     20 int main()
     21 {
     22 	auto p = new (std::nothrow) int{5};
     23 	int x = *p;
     24 	delete p;
     25 	return x;
     26 }