| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 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 |  | 
| Dan Albert | 9897259 | 2014-05-30 16:00:53 -0700 | [diff] [blame] | 17 | #include <errno.h> | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 18 | #include <new> | 
|  | 19 | #include <stdlib.h> | 
|  | 20 |  | 
| Dan Albert | 9897259 | 2014-05-30 16:00:53 -0700 | [diff] [blame] | 21 | #include "private/libc_logging.h" | 
|  | 22 |  | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 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) { | 
| Dan Albert | 9897259 | 2014-05-30 16:00:53 -0700 | [diff] [blame] | 28 | __libc_fatal("new failed to allocate %zu bytes", size); | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 29 | } | 
|  | 30 | return p; | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | void* operator new[](std::size_t size) { | 
|  | 34 | void* p = malloc(size); | 
|  | 35 | if (p == NULL) { | 
| Dan Albert | 9897259 | 2014-05-30 16:00:53 -0700 | [diff] [blame] | 36 | __libc_fatal("new[] failed to allocate %zu bytes", size); | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 37 | } | 
|  | 38 | return p; | 
|  | 39 | } | 
|  | 40 |  | 
| Chih-Hung Hsieh | ae558d6 | 2014-08-25 12:08:19 -0700 | [diff] [blame] | 41 | void  operator delete(void* ptr) throw() { | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 42 | free(ptr); | 
|  | 43 | } | 
|  | 44 |  | 
| Chih-Hung Hsieh | ae558d6 | 2014-08-25 12:08:19 -0700 | [diff] [blame] | 45 | void  operator delete[](void* ptr) throw() { | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 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 |  | 
| Chih-Hung Hsieh | ae558d6 | 2014-08-25 12:08:19 -0700 | [diff] [blame] | 57 | void  operator delete(void* ptr, const std::nothrow_t&) throw() { | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 58 | free(ptr); | 
|  | 59 | } | 
|  | 60 |  | 
| Chih-Hung Hsieh | ae558d6 | 2014-08-25 12:08:19 -0700 | [diff] [blame] | 61 | void  operator delete[](void* ptr, const std::nothrow_t&) throw() { | 
| Elliott Hughes | 15b641a | 2014-05-14 18:18:55 -0700 | [diff] [blame] | 62 | free(ptr); | 
|  | 63 | } |