]>
git.saurik.com Git - apple/dyld.git/blob - src/dyldNew.cpp
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
26 #include <malloc/malloc.h>
31 // dyld does not use malloc anywhere, instead C++ new is used.
32 // All dyld allocations go in dyld-only zone so as to be not co-mingled with target proccess's allocations
37 static malloc_zone_t
* sZone
= NULL
; // could be initialized to malloc_create_zone, but that would require careful ordering of initializers
40 void* operator new(std::size_t len
) throw (std::bad_alloc
)
42 if ( sZone
== NULL
) {
43 sZone
= malloc_create_zone(40960, 0);
44 malloc_set_zone_name(sZone
, "dyld heap");
46 //fprintf(stderr, "new(%d)\n", len);
47 return malloc_zone_malloc(sZone
, len
);
50 void* operator new[](std::size_t len
) throw (std::bad_alloc
)
52 if ( sZone
== NULL
) {
53 sZone
= malloc_create_zone(40960, 0);
54 malloc_set_zone_name(sZone
, "dyld heap");
56 //fprintf(stderr, "new[](%d)\n", len);
57 return malloc_zone_malloc(sZone
, len
);
61 void operator delete(void* obj
) throw()
63 //fprintf(stderr, "delete(%p)\n", obj);
64 malloc_zone_free(sZone
, obj
);
68 void operator delete[](void* obj
) throw()
70 //fprintf(stderr, "delete[](%p)\n", obj);
71 malloc_zone_free(sZone
, obj
);