zalloc_malloc.c (39672) | zalloc_malloc.c (39863) |
---|---|
1/* 2 * This module derived from code donated to the FreeBSD Project by 3 * Matthew Dillon <dillon@backplane.com> 4 * 5 * Copyright (c) 1998 The FreeBSD Project 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/* 2 * This module derived from code donated to the FreeBSD Project by 3 * Matthew Dillon <dillon@backplane.com> 4 * 5 * Copyright (c) 1998 The FreeBSD Project 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $Id: zalloc_malloc.c,v 1.1 1998/09/26 01:42:39 msmith Exp $ | 29 * $Id: zalloc_malloc.c,v 1.2 1998/09/26 10:48:50 dfr Exp $ |
30 */ 31 32/* 33 * MALLOC.C - malloc equivalent, runs on top of zalloc and uses sbrk 34 */ 35 36#include "zalloc_defs.h" 37 | 30 */ 31 32/* 33 * MALLOC.C - malloc equivalent, runs on top of zalloc and uses sbrk 34 */ 35 36#include "zalloc_defs.h" 37 |
38static MemPool MallocPool = INITPOOL("malloc", panic, znot); | 38static MemPool MallocPool; |
39 40#ifdef DMALLOCDEBUG 41static int MallocMax; 42static int MallocCount; 43 44void mallocstats(void); 45#endif 46 --- 40 unchanged lines hidden (view full) --- 87free(void *ptr) 88{ 89 size_t bytes; 90 91 if (ptr != NULL) { 92 Guard *res = (void *)((char *)ptr - MALLOCALIGN); 93 94#ifdef USEGUARD | 39 40#ifdef DMALLOCDEBUG 41static int MallocMax; 42static int MallocCount; 43 44void mallocstats(void); 45#endif 46 --- 40 unchanged lines hidden (view full) --- 87free(void *ptr) 88{ 89 size_t bytes; 90 91 if (ptr != NULL) { 92 Guard *res = (void *)((char *)ptr - MALLOCALIGN); 93 94#ifdef USEGUARD |
95 if (res->ga_Magic != GAMAGIC) { 96#ifdef USEPANIC 97 panic("free(): guard1 fail @ %08lx\n", ptr); 98#else 99 *(char *)0 = 1; 100#endif 101 } | 95 if (res->ga_Magic != GAMAGIC) 96 panic("free: guard1 fail @ %p", ptr); |
102 res->ga_Magic = -1; 103#endif 104#ifdef USEENDGUARD | 97 res->ga_Magic = -1; 98#endif 99#ifdef USEENDGUARD |
105 if (*((char *)res + res->ga_Bytes - 1) != -2) { 106#ifdef USEPANIC 107 panic("free(): guard2 fail @ %08lx + %d\n", ptr, res->ga_Bytes - MALLOCALIGN); 108#else 109 *(char *)0 = 1; 110#endif 111 } | 100 if (*((char *)res + res->ga_Bytes - 1) != -2) 101 panic("free: guard2 fail @ %p + %d", ptr, res->ga_Bytes - MALLOCALIGN); |
112 *((char *)res + res->ga_Bytes - 1) = -1; 113#endif 114 115 bytes = res->ga_Bytes; 116 zfree(&MallocPool, res, bytes); 117#ifdef DMALLOCDEBUG 118 --MallocCount; 119#endif --- 79 unchanged lines hidden --- | 102 *((char *)res + res->ga_Bytes - 1) = -1; 103#endif 104 105 bytes = res->ga_Bytes; 106 zfree(&MallocPool, res, bytes); 107#ifdef DMALLOCDEBUG 108 --MallocCount; 109#endif --- 79 unchanged lines hidden --- |