xref: /titanic_44/usr/src/lib/libtnfprobe/probe_mem.c (revision 9dd0f810214fdc8e1af881a9a5c4b6927629ff9e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * Includes
30  */
31 
32 #include "prb_internals.h"
33 
34 
35 /*
36  * Globals
37  *	Memory that prex uses to store combinations in target process
38  */
39 
40 #define	INITMEMSZ 2048
41 
42 static char	initial_memory[INITMEMSZ];
43 static tnf_memseg_t	initial_memseg = {
44 					initial_memory,
45 					initial_memory + INITMEMSZ,
46 					DEFAULTMUTEX,
47 					0
48 				};
49 
50 tnf_memseg_t *	__tnf_probe_memseg_p = &initial_memseg;
51 
52 
53 /*
54  * __tnf_probe_alloc() - allocates memory from the global pool
55  */
56 
57 char *
58 __tnf_probe_alloc(size_t size)
59 {
60 	tnf_memseg_t *	memseg_p = __tnf_probe_memseg_p;
61 	char *		ptr;
62 
63 	ptr = NULL;
64 
65 	mutex_lock(&memseg_p->i_lock);
66 
67 	memseg_p->i_reqsz = size;
68 
69 	if ((memseg_p->min_p + size) <= memseg_p->max_p) {
70 	    ptr = memseg_p->min_p;
71 	    memseg_p->min_p += size;
72 	}
73 
74 	memseg_p->i_reqsz = 0;
75 
76 	mutex_unlock(&memseg_p->i_lock);
77 
78 	return (ptr);
79 
80 }   /* end __tnf_probe_alloc */
81