1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <errno.h> 18 #include <new> 19 #include <stdlib.h> 20 21 #include "private/libc_logging.h" 22 23 const std::nothrow_t std::nothrow = {}; 24 25 void* operator new(std::size_t size) { 26 void* p = malloc(size); 27 if (p == NULL) { 28 __libc_fatal("new failed to allocate %zu bytes", size); 29 } 30 return p; 31 } 32 33 void* operator new[](std::size_t size) { 34 void* p = malloc(size); 35 if (p == NULL) { 36 __libc_fatal("new[] failed to allocate %zu bytes", size); 37 } 38 return p; 39 } 40 41 void operator delete(void* ptr) throw() { 42 free(ptr); 43 } 44 45 void operator delete[](void* ptr) throw() { 46 free(ptr); 47 } 48 49 void* operator new(std::size_t size, const std::nothrow_t&) { 50 return malloc(size); 51 } 52 53 void* operator new[](std::size_t size, const std::nothrow_t&) { 54 return malloc(size); 55 } 56 57 void operator delete(void* ptr, const std::nothrow_t&) throw() { 58 free(ptr); 59 } 60 61 void operator delete[](void* ptr, const std::nothrow_t&) throw() { 62 free(ptr); 63 } 64