xref: /titanic_41/usr/src/cmd/mdb/common/kmdb/kmdb_umemglue.c (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <mdb/mdb_debug.h>
30 #include <mdb/mdb_err.h>
31 #include <mdb/mdb_io.h>
32 
33 #define	UMEM_STANDALONE
34 #include <umem_impl.h>
35 
36 /*
37  * The standalone umem requires that kmdb provide some error-handling
38  * services.  These are them.
39  */
40 
41 /*ARGSUSED*/
42 int
43 __umem_assert_failed(const char *assertion, const char *file, int line)
44 {
45 #ifdef DEBUG
46 	(void) mdb_dassert(assertion, file, line);
47 	/*NOTREACHED*/
48 #endif
49 	return (0);
50 }
51 
52 void
53 umem_panic(const char *format, ...)
54 {
55 	va_list alist;
56 
57 	va_start(alist, format);
58 	vfail(format, alist);
59 	va_end(alist);
60 }
61 
62 void
63 umem_err_recoverable(const char *format, ...)
64 {
65 	va_list alist;
66 
67 	va_start(alist, format);
68 	vwarn(format, alist);
69 	va_end(alist);
70 }
71 
72 int
73 umem_vsnprintf(char *s, size_t n, const char *format, va_list ap)
74 {
75 	return (mdb_iob_vsnprintf(s, n, format, ap));
76 }
77 
78 int
79 umem_snprintf(char *s, size_t n, const char *format, ...)
80 {
81 	va_list ap;
82 	int rc;
83 
84 	va_start(ap, format);
85 	rc = umem_vsnprintf(s, n, format, ap);
86 	va_end(ap);
87 
88 	return (rc);
89 }
90 
91 /* These aren't atomic, but we're not MT, so it doesn't matter */
92 uint32_t
93 umem_atomic_add_32_nv(uint32_t *target, int32_t delta)
94 {
95 	return (*target = *target + delta);
96 }
97 
98 void
99 umem_atomic_add_64(uint64_t *target, int64_t delta)
100 {
101 	*target = *target + delta;
102 }
103 
104 /*
105  * Standalone umem must be manually initialized
106  */
107 void
108 mdb_umem_startup(caddr_t base, size_t len, size_t pgsize)
109 {
110 	umem_startup(base, len, pgsize, base, base + len);
111 }
112 
113 /*
114  * The kernel will tell us when there's more memory available for us to use.
115  * This is most common on amd64, which boots with only 4G of VA available, and
116  * later expands to the full 64-bit address space.
117  */
118 int
119 mdb_umem_add(caddr_t base, size_t len)
120 {
121 	return (umem_add(base, len));
122 }
123