115b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes/* 215b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * Copyright (C) 2008 The Android Open Source Project 315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * 415b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 515b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * you may not use this file except in compliance with the License. 615b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * You may obtain a copy of the License at 715b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * 815b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 915b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * 1015b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * Unless required by applicable law or agreed to in writing, software 1115b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 1215b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * See the License for the specific language governing permissions and 1415b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes * limitations under the License. 1515b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes */ 1615b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 17989725940e765f0065b2bc06b881cde864b62595Dan Albert#include <errno.h> 1815b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes#include <new> 1915b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes#include <stdlib.h> 2015b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 21989725940e765f0065b2bc06b881cde864b62595Dan Albert#include "private/libc_logging.h" 22989725940e765f0065b2bc06b881cde864b62595Dan Albert 2315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughesconst std::nothrow_t std::nothrow = {}; 2415b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 2515b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughesvoid* operator new(std::size_t size) { 2615b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes void* p = malloc(size); 2715b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes if (p == NULL) { 28989725940e765f0065b2bc06b881cde864b62595Dan Albert __libc_fatal("new failed to allocate %zu bytes", size); 2915b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes } 3015b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes return p; 3115b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 3215b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 3315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughesvoid* operator new[](std::size_t size) { 3415b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes void* p = malloc(size); 3515b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes if (p == NULL) { 36989725940e765f0065b2bc06b881cde864b62595Dan Albert __libc_fatal("new[] failed to allocate %zu bytes", size); 3715b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes } 3815b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes return p; 3915b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 4015b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 41ae558d6b4bcee740f7e61434982eb5f2c999fb97Chih-Hung Hsiehvoid operator delete(void* ptr) throw() { 4215b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes free(ptr); 4315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 4415b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 45ae558d6b4bcee740f7e61434982eb5f2c999fb97Chih-Hung Hsiehvoid operator delete[](void* ptr) throw() { 4615b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes free(ptr); 4715b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 4815b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 4915b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughesvoid* operator new(std::size_t size, const std::nothrow_t&) { 5015b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes return malloc(size); 5115b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 5215b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 5315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughesvoid* operator new[](std::size_t size, const std::nothrow_t&) { 5415b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes return malloc(size); 5515b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 5615b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 57ae558d6b4bcee740f7e61434982eb5f2c999fb97Chih-Hung Hsiehvoid operator delete(void* ptr, const std::nothrow_t&) throw() { 5815b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes free(ptr); 5915b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 6015b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes 61ae558d6b4bcee740f7e61434982eb5f2c999fb97Chih-Hung Hsiehvoid operator delete[](void* ptr, const std::nothrow_t&) throw() { 6215b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes free(ptr); 6315b641a26731a7e42455c3ed22e1e9bdf31ea79cElliott Hughes} 64