]> git.saurik.com Git - apple/libc.git/blob - gen.subproj/zone.c
0f4610f91ed26d1b1f322d6f0ec7df31abfae17c
[apple/libc.git] / gen.subproj / zone.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #import <objc/zone.h>
24 #import <stdio.h>
25 #import <libc.h>
26
27 /********* NX functions ************/
28
29 malloc_zone_t *NXDefaultMallocZone() {
30 return malloc_default_zone();
31 }
32
33 malloc_zone_t *NXCreateZone(size_t startsize, size_t granularity, int canfree) {
34 return malloc_create_zone(startsize, 0);
35 }
36
37 void NXNameZone(malloc_zone_t *z, const char *name) {
38 malloc_set_zone_name(z, name);
39 }
40
41 void *NXZoneMalloc(malloc_zone_t *zone, size_t size) {
42 return malloc_zone_malloc(zone, size);
43 }
44
45 void *NXZoneRealloc(malloc_zone_t *zone, void *ptr, size_t size) {
46 return malloc_zone_realloc(zone, ptr, size);
47 }
48
49 void *NXZoneCalloc(malloc_zone_t *zone, size_t num_items, size_t size) {
50 return malloc_zone_calloc(zone, num_items, size);
51 }
52
53 void NXZoneFree(malloc_zone_t *zone, void *ptr) {
54 malloc_zone_free(zone, ptr);
55 }
56
57 void NXDestroyZone(malloc_zone_t *zone) {
58 if (zone == malloc_default_zone()) return; // we avoid destroying child zones
59 malloc_destroy_zone(zone);
60 }
61
62 NXZone *NXZoneFromPtr(void *ptr) {
63 NXZone *zone = malloc_zone_from_ptr(ptr);
64 if (!zone) {
65 fprintf(stderr, "*** malloc[%d]: NXZoneFromPtr() did not find any zone for %p; returning default\n", getpid(), ptr);
66 zone = NX_NOZONE;
67 }
68 return zone;
69 }
70
71 void NXAddRegion(void *start, size_t size, malloc_zone_t *zone) {
72 fprintf(stderr, "*** malloc[%d]: OBSOLETE: NXAddRegion()\n", getpid());
73 }
74
75 void NXRemoveRegion(void *start) {
76 fprintf(stderr, "*** malloc[%d]: OBSOLETE: NXRemoveRegion()\n", getpid());
77 }
78
79 void NXZonePtrInfo(void *ptr) {
80 malloc_zone_print_ptr_info(ptr);
81 }
82
83 int NXMallocCheck(void) {
84 malloc_zone_check(NULL);
85 return 1;
86 }
87
88 void _NXMallocDumpZones(void) {
89 malloc_zone_print(NULL, 0);
90 }
91
92 /***************** UNIMPLEMENTED ENTRY POINTS ********************/
93
94 void NXMergeZone(malloc_zone_t *z) {
95 static char warned = 0;
96 if (!warned) {
97 fprintf(stderr, "*** malloc[%d]: NXMergeZone() now obsolete, does nothing\n", getpid());
98 warned = 1;
99 }
100 }
101
102 boolean_t NXProtectZone(malloc_zone_t *zone, int protection) {
103 fprintf(stderr, "*** malloc[%d]: NXProtectZone() is obsolete\n", getpid());
104 return 0;
105 }
106
107 malloc_zone_t *NXCreateChildZone(malloc_zone_t *parentzone, size_t startsize, size_t granularity, int canfree) {
108 // We can not remove this one as it is still used by IndexingKit
109 static char warned = 0;
110 if (!warned) {
111 fprintf(stderr, "*** malloc[%d]: NXCreateChildZone() now obsolete, has been defined to create new zone\n", getpid());
112 warned = 1;
113 }
114 return NXCreateZone(startsize, granularity, canfree);
115 }
116
117 void _NXMallocDumpFrees(void) {
118 fprintf(stderr, "*** malloc[%d]: OBSOLETE: _NXMallocDumpFrees()\n", getpid());
119 }
120