]> git.saurik.com Git - apple/libc.git/blame - gen/zone.c
Libc-498.1.1.tar.gz
[apple/libc.git] / gen / zone.c
CommitLineData
e9ce8d39
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
734aad71
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
e9ce8d39
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
e9ce8d39
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#import <objc/zone.h>
25#import <stdio.h>
26#import <libc.h>
224c7076
A
27#import <pthread.h>
28#import <stdlib.h>
29#import <unistd.h>
30
31#define OBSOLETED
32
33static pthread_mutex_t _zone_mutex = PTHREAD_MUTEX_INITIALIZER;
34
35enum {
36 nXDefaultMallocZone = 0,
37 nXCreateZone,
38 nXNameZone,
39 nXZoneMalloc,
40 nXZoneRealloc,
41 nXZoneCalloc,
42 nXZoneFree,
43 nXDestroyZone,
44 nXZoneFromPtr,
45 nXZonePtrInfo,
46 nXMallocCheck,
47 _nXMallocDumpZones
48};
49static char *once[] = {
50 "NXDefaultMallocZone",
51 "NXCreateZone",
52 "NXNameZone",
53 "NXZoneMalloc",
54 "NXZoneRealloc",
55 "NXZoneCalloc",
56 "NXZoneFree",
57 "NXDestroyZone",
58 "NXZoneFromPtr",
59 "NXZonePtrInfo",
60 "NXMallocCheck",
61 "_NXMallocDumpZones"
62};
63
64extern int __is_threaded;
e9ce8d39
A
65
66/********* NX functions ************/
67
224c7076
A
68static void
69_deprecated(int index)
70{
71 if(__is_threaded)
72 pthread_mutex_lock(&_zone_mutex);
73 if(once[index]) {
74 fprintf(stderr, "*** %s[%d]: %s() is deprecated and will be removed in the future\n", getprogname(), getpid(), once[index]);
75 once[index] = NULL;
76 }
77 if(__is_threaded)
78 pthread_mutex_unlock(&_zone_mutex);
79}
80
e9ce8d39 81malloc_zone_t *NXDefaultMallocZone() {
224c7076 82 _deprecated(nXDefaultMallocZone);
e9ce8d39
A
83 return malloc_default_zone();
84}
85
86malloc_zone_t *NXCreateZone(size_t startsize, size_t granularity, int canfree) {
224c7076 87 _deprecated(nXCreateZone);
e9ce8d39
A
88 return malloc_create_zone(startsize, 0);
89}
90
91void NXNameZone(malloc_zone_t *z, const char *name) {
224c7076 92 _deprecated(nXNameZone);
e9ce8d39
A
93 malloc_set_zone_name(z, name);
94}
95
96void *NXZoneMalloc(malloc_zone_t *zone, size_t size) {
224c7076 97 _deprecated(nXZoneMalloc);
e9ce8d39
A
98 return malloc_zone_malloc(zone, size);
99}
100
101void *NXZoneRealloc(malloc_zone_t *zone, void *ptr, size_t size) {
224c7076 102 _deprecated(nXZoneRealloc);
e9ce8d39
A
103 return malloc_zone_realloc(zone, ptr, size);
104}
105
106void *NXZoneCalloc(malloc_zone_t *zone, size_t num_items, size_t size) {
224c7076 107 _deprecated(nXZoneCalloc);
e9ce8d39
A
108 return malloc_zone_calloc(zone, num_items, size);
109}
110
111void NXZoneFree(malloc_zone_t *zone, void *ptr) {
224c7076 112 _deprecated(nXZoneFromPtr);
e9ce8d39
A
113 malloc_zone_free(zone, ptr);
114}
115
116void NXDestroyZone(malloc_zone_t *zone) {
224c7076 117 _deprecated(nXDestroyZone);
e9ce8d39
A
118 if (zone == malloc_default_zone()) return; // we avoid destroying child zones
119 malloc_destroy_zone(zone);
120}
121
122NXZone *NXZoneFromPtr(void *ptr) {
123 NXZone *zone = malloc_zone_from_ptr(ptr);
224c7076 124 _deprecated(nXZoneFromPtr);
e9ce8d39 125 if (!zone) {
59e0d9fe 126 malloc_printf("*** NXZoneFromPtr() did not find any zone for %p; returning default\n", ptr);
e9ce8d39
A
127 zone = NX_NOZONE;
128 }
129 return zone;
130}
131
224c7076 132#ifndef OBSOLETED
e9ce8d39 133void NXAddRegion(void *start, size_t size, malloc_zone_t *zone) {
59e0d9fe 134 malloc_printf("*** OBSOLETE: NXAddRegion()\n");
e9ce8d39
A
135}
136
137void NXRemoveRegion(void *start) {
59e0d9fe 138 malloc_printf("*** OBSOLETE: NXRemoveRegion()\n");
e9ce8d39 139}
224c7076 140#endif /* OBSOLETED */
e9ce8d39
A
141
142void NXZonePtrInfo(void *ptr) {
224c7076 143 _deprecated(nXZonePtrInfo);
e9ce8d39
A
144 malloc_zone_print_ptr_info(ptr);
145}
146
147int NXMallocCheck(void) {
224c7076 148 _deprecated(nXMallocCheck);
e9ce8d39
A
149 malloc_zone_check(NULL);
150 return 1;
151}
152
153void _NXMallocDumpZones(void) {
224c7076 154 _deprecated(_nXMallocDumpZones);
e9ce8d39
A
155 malloc_zone_print(NULL, 0);
156}
157
158/***************** UNIMPLEMENTED ENTRY POINTS ********************/
159
224c7076 160#ifndef OBSOLETED
e9ce8d39
A
161void NXMergeZone(malloc_zone_t *z) {
162 static char warned = 0;
163 if (!warned) {
59e0d9fe 164 malloc_printf("*** NXMergeZone() now obsolete, does nothing\n");
e9ce8d39
A
165 warned = 1;
166 }
167}
168
169boolean_t NXProtectZone(malloc_zone_t *zone, int protection) {
59e0d9fe 170 malloc_printf("*** NXProtectZone() is obsolete\n");
e9ce8d39
A
171 return 0;
172}
173
174malloc_zone_t *NXCreateChildZone(malloc_zone_t *parentzone, size_t startsize, size_t granularity, int canfree) {
175 // We can not remove this one as it is still used by IndexingKit
176 static char warned = 0;
177 if (!warned) {
59e0d9fe 178 malloc_printf("*** NXCreateChildZone() now obsolete, has been defined to create new zone\n");
e9ce8d39
A
179 warned = 1;
180 }
181 return NXCreateZone(startsize, granularity, canfree);
182}
183
184void _NXMallocDumpFrees(void) {
59e0d9fe 185 malloc_printf("*** OBSOLETE: _NXMallocDumpFrees()\n");
e9ce8d39 186}
224c7076 187#endif /* OBSOLETED */