1/* 2 * Copyright (c) 2011 Apple Inc. All rights reserved. 3 * 4 * @APPLE_APACHE_LICENSE_HEADER_START@ 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * @APPLE_APACHE_LICENSE_HEADER_END@ 19 */ 20/* 21 Definitions.cpp 22 Global Definitions 23 Copyright (c) 2004-2011 Apple Inc. All rights reserved. 24 */ 25 26#include "Definitions.h" 27#include "Environment.h" 28#include "Zone.h" 29 30 31namespace Auto { 32 33 // 34 // Shadow malloc zone functions 35 // 36 void *aux_malloc(size_t size) { 37 ASSERTION(aux_zone); 38 void *new_ptr = malloc_zone_malloc(aux_zone, size); 39#if defined(DEBUG) 40 if (Environment::print_allocs) malloc_printf("malloc_zone_malloc @%p %d\n", new_ptr, size); 41#endif 42 return new_ptr; 43 } 44 void *aux_calloc(size_t count, size_t size) { 45 ASSERTION(aux_zone); 46 void *new_ptr = malloc_zone_calloc(aux_zone, count, size); 47#if defined(DEBUG) 48 if (Environment::print_allocs) malloc_printf("malloc_zone_calloc @%p %d\n", new_ptr, count * size); 49#endif 50 return new_ptr; 51 } 52 void *aux_valloc(size_t size) { 53 ASSERTION(aux_zone); 54 void *new_ptr = malloc_zone_valloc(aux_zone, size); 55#if defined(DEBUG) 56 if (Environment::print_allocs) malloc_printf("malloc_zone_valloc @%p %d\n", new_ptr, size); 57#endif 58 return new_ptr; 59 } 60 void *aux_realloc(void *ptr, size_t size) { 61 ASSERTION(aux_zone); 62 void *new_ptr = malloc_zone_realloc(aux_zone, ptr, size); 63#if defined(DEBUG) 64 if (Environment::print_allocs) malloc_printf("malloc_zone_realloc @%p %d\n", new_ptr, size); 65#endif 66 return new_ptr; 67 } 68 void aux_free(void *ptr) { 69 ASSERTION(aux_zone); 70#if defined(DEBUG) 71 if (Environment::print_allocs) malloc_printf("malloc_zone_free @%p\n", ptr); 72#endif 73 malloc_zone_free(aux_zone, ptr); 74 } 75 76 void uncommit_memory(void *address, usword_t size) { 77 madvise(address, size, MADV_FREE_REUSABLE); 78 } 79 80 void commit_memory(void *address, usword_t size) { 81 madvise(address, size, MADV_FREE_REUSE); 82 } 83}; 84