1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include <cstddef>
16 #include <cstdlib>
17 #include <new>
18
operator new(size_t size)19 void* operator new(size_t size) { return malloc(size); }
20
operator new[](size_t size)21 void* operator new[](size_t size) { return malloc(size); }
22
operator new(size_t size,std::align_val_t alignment)23 void* operator new(size_t size, std::align_val_t alignment) {
24 return aligned_alloc(static_cast<size_t>(alignment), size);
25 }
26
operator new[](size_t size,std::align_val_t alignment)27 void* operator new[](size_t size, std::align_val_t alignment) {
28 return aligned_alloc(static_cast<size_t>(alignment), size);
29 }
30
operator new(size_t size,const std::nothrow_t &)31 void* operator new(size_t size, const std::nothrow_t&) noexcept {
32 return ::operator new(size);
33 }
34
operator new[](size_t size,const std::nothrow_t &)35 void* operator new[](size_t size, const std::nothrow_t&) noexcept {
36 return ::operator new[](size);
37 }
38
operator new(size_t size,std::align_val_t alignment,const std::nothrow_t &)39 void* operator new(size_t size,
40 std::align_val_t alignment,
41 const std::nothrow_t&) noexcept {
42 return ::operator new(size, alignment);
43 }
44
operator new[](size_t size,std::align_val_t alignment,const std::nothrow_t &)45 void* operator new[](size_t size,
46 std::align_val_t alignment,
47 const std::nothrow_t&) noexcept {
48 return ::operator new[](size, alignment);
49 }
50