|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
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 OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1990 NeXT, Inc.
27: *
28: * HISTORY
29: * 29-Jun-90 Morris Meyer (mmeyer) at NeXT
30: * Created.
31: */
32:
33: #import <mallocdebug.h>
34:
35: #if MALLOCDEBUG
36:
37: #import <sys/types.h>
38: #import <mach/boolean.h>
39: #import <kern/malloc_debug.h>
40: #import <sys/uio.h>
41: #import <sys/user.h>
42: #import <sys/vfs.h>
43: #import <sys/vnode.h>
44: #import <vm/vm_kern.h>
45: #import <vm/vm_pager.h>
46: #import <kern/lock.h>
47: #ifdef m68k
48: #import <machdep/m68k/eventc.h>
49: #endif m68k
50:
51: int mallocdebug = FALSE;
52: int malloc_dropped = 0;
53: int malloc_curbuf = 0;
54: int malloc_buflim = 0;
55: char *malloctypes[] = { "MTYPE_KALLOC", "MTYPE_ZALLOC", "MTYPE_KMEM_ALLOC" };
56: struct vnode *mallocvp;
57: int mallocoffset;
58: struct mallocbuf {
59: int numstamps;
60: struct malloc_info mallocbufs[2048];
61: } mallocbuf [2];
62: static void malloc_debug_syncbufs (int nstamps, int whichbuf);
63:
64: lock_data_t malloc_lock_data;
65:
66: #define malloc_lock() lock_write(&malloc_lock_data)
67: #define malloc_unlock() lock_write_done(&malloc_lock_data)
68:
69: mallocdebuginit()
70: {
71: malloc_buflim = 2048;
72: lock_init(&malloc_lock_data, TRUE);
73: }
74:
75: void malloc_debug (void *addr, void *pc, int size, int which, int type)
76: {
77: struct malloc_info mi, *mip;
78: int write_buf;
79: int numstamps = mallocbuf[malloc_curbuf].numstamps;
80:
81: if (mallocdebug) {
82: mip = &mallocbuf[malloc_curbuf].mallocbufs[numstamps++];
83: mi.type = type;
84: mi.which = which;
85: mi.addr = addr;
86: mi.pc = pc;
87: mi.size = size;
88: #if m68k
89: event_set_ts(&mi.time);
90: #endif m68k
91: *(struct malloc_info *)mip = mi;
92:
93: if (numstamps >= malloc_buflim) {
94: write_buf = malloc_curbuf;
95: malloc_curbuf ^= 1;
96: malloc_debug_syncbufs(numstamps, write_buf);
97: numstamps = 0;
98: }
99: mallocbuf[malloc_curbuf].numstamps = numstamps;
100: }
101: }
102:
103: static void malloc_debug_syncbufs (int nstamps, int whichbuf)
104: {
105: extern struct ucred *rootcred;
106: struct vattr vattr;
107: struct uio auio;
108: struct iovec aiov;
109: int error;
110:
111: if (mallocvp == (struct vnode *)0) {
112: u.u_error = 0;
113: vattr_null (&vattr);
114: vattr.va_type = VREG;
115: vattr.va_mode = 0644;
116: vattr.va_size = 0;
117: error = vn_create ("/mallocinfo", UIO_SYSSPACE,
118: &vattr, NONEXCL, VWRITE, &mallocvp, rootcred);
119: if (error)
120: panic ("vn_create: malloc_debug_syncbufs");
121: (void) VOP_SETATTR(mallocvp, &vattr, rootcred);
122: }
123:
124: error = vn_rdwr(UIO_WRITE, mallocvp,
125: &mallocbuf[whichbuf].mallocbufs,
126: nstamps * sizeof (struct malloc_info), mallocoffset,
127: UIO_SYSSPACE, IO_UNIT | IO_SYNC, (int *) 0);
128:
129: malloc_lock();
130: mallocoffset += nstamps * sizeof (struct malloc_info);
131: malloc_unlock();
132: }
133:
134: /*
135: * FIXME...
136: */
137: #if m88k
138: void *get_return_pc(void)
139: {
140: return 0;
141: }
142: #endif m88k
143: #endif MALLOCDEBUG
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.