kernel: use non-deprecated signatures for new/delete operators.

add posix_memalign(), needed for c++17.
This commit is contained in:
Jérôme Duval 2018-05-28 20:43:15 +02:00
parent b3e749b0c1
commit 9e75e900da
3 changed files with 41 additions and 16 deletions

View File

@ -23,14 +23,21 @@ typedef struct {} mynothrow_t;
extern const mynothrow_t mynothrow;
#ifndef __clang__
extern void* operator new(size_t size) throw (std::bad_alloc);
extern void* operator new[](size_t size) throw (std::bad_alloc);
extern void* operator new(size_t size, const std::nothrow_t &) throw ();
extern void* operator new[](size_t size, const std::nothrow_t &) throw ();
extern void* operator new(size_t size, const mynothrow_t &) throw ();
extern void* operator new[](size_t size, const mynothrow_t &) throw ();
extern void operator delete(void *ptr) throw ();
extern void operator delete[](void *ptr) throw ();
#if __cplusplus >= 201402L
#define _THROW(x)
#define _NOEXCEPT noexcept
#else
#define _THROW(x) throw (x)
#define _NOEXCEPT throw ()
#endif
extern void* operator new(size_t size) _THROW(std::bad_alloc);
extern void* operator new[](size_t size) _THROW(std::bad_alloc);
extern void* operator new(size_t size, const std::nothrow_t &) _NOEXCEPT;
extern void* operator new[](size_t size, const std::nothrow_t &) _NOEXCEPT;
extern void* operator new(size_t size, const mynothrow_t &) _NOEXCEPT;
extern void* operator new[](size_t size, const mynothrow_t &) _NOEXCEPT;
extern void operator delete(void *ptr) _NOEXCEPT;
extern void operator delete[](void *ptr) _NOEXCEPT;
#endif
#if __cplusplus >= 201402L

View File

@ -220,6 +220,16 @@ memalign_etc(size_t alignment, size_t size, uint32 flags)
}
int
posix_memalign(void** _pointer, size_t alignment, size_t size)
{
if ((alignment & (sizeof(void*) - 1)) != 0 || _pointer == NULL)
return B_BAD_VALUE;
*_pointer = block_alloc(size, alignment, 0);
return 0;
}
void
free_etc(void *address, uint32 flags)
{

View File

@ -40,6 +40,14 @@ const nothrow_t std::nothrow = {};
# endif
#endif
#if __cplusplus >= 201402L
#define _THROW(x)
#define _NOEXCEPT noexcept
#else
#define _THROW(x) throw (x)
#define _NOEXCEPT throw ()
#endif
const mynothrow_t mynothrow = {};
#if __GNUC__ == 2
@ -76,7 +84,7 @@ __cxa_finalize(void* dsoHandle)
// full C++ support in the kernel
#if (defined(_KERNEL_MODE) || defined(_LOADER_MODE))
void *
operator new(size_t size) throw (std::bad_alloc)
operator new(size_t size) _THROW(std::bad_alloc)
{
// we don't actually throw any exceptions, but we have to
// keep the prototype as specified in <new>, or else GCC 3
@ -86,49 +94,49 @@ operator new(size_t size) throw (std::bad_alloc)
void *
operator new[](size_t size) throw (std::bad_alloc)
operator new[](size_t size)
{
return malloc(size);
}
void *
operator new(size_t size, const std::nothrow_t &) throw ()
operator new(size_t size, const std::nothrow_t &) _NOEXCEPT
{
return malloc(size);
}
void *
operator new[](size_t size, const std::nothrow_t &) throw ()
operator new[](size_t size, const std::nothrow_t &) _NOEXCEPT
{
return malloc(size);
}
void *
operator new(size_t size, const mynothrow_t &) throw ()
operator new(size_t size, const mynothrow_t &) _NOEXCEPT
{
return malloc(size);
}
void *
operator new[](size_t size, const mynothrow_t &) throw ()
operator new[](size_t size, const mynothrow_t &) _NOEXCEPT
{
return malloc(size);
}
void
operator delete(void *ptr) throw ()
operator delete(void *ptr) _NOEXCEPT
{
free(ptr);
}
void
operator delete[](void *ptr) throw ()
operator delete[](void *ptr) _NOEXCEPT
{
free(ptr);
}