xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kmdb_umemglue.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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 #include <mdb/mdb_debug.h>
28 #include <mdb/mdb_err.h>
29 #include <mdb/mdb_io.h>
30 
31 #define	UMEM_STANDALONE
32 #include <umem_impl.h>
33 
34 /*
35  * The standalone umem requires that kmdb provide some error-handling
36  * services.  These are them.
37  */
38 
39 /*ARGSUSED*/
40 int
41 __umem_assert_failed(const char *assertion, const char *file, int line)
42 {
43 #ifdef DEBUG
44 	(void) mdb_dassert(assertion, file, line);
45 	/*NOTREACHED*/
46 #endif
47 	return (0);
48 }
49 
50 void
51 umem_panic(const char *format, ...)
52 {
53 	va_list alist;
54 
55 	va_start(alist, format);
56 	vfail(format, alist);
57 	va_end(alist);
58 }
59 
60 void
61 umem_err_recoverable(const char *format, ...)
62 {
63 	va_list alist;
64 
65 	va_start(alist, format);
66 	vwarn(format, alist);
67 	va_end(alist);
68 }
69 
70 int
71 umem_vsnprintf(char *s, size_t n, const char *format, va_list ap)
72 {
73 	return (mdb_iob_vsnprintf(s, n, format, ap));
74 }
75 
76 int
77 umem_snprintf(char *s, size_t n, const char *format, ...)
78 {
79 	va_list ap;
80 	int rc;
81 
82 	va_start(ap, format);
83 	rc = umem_vsnprintf(s, n, format, ap);
84 	va_end(ap);
85 
86 	return (rc);
87 }
88 
89 /* These aren't atomic, but we're not MT, so it doesn't matter */
90 uint32_t
91 umem_atomic_add_32_nv(uint32_t *target, int32_t delta)
92 {
93 	return (*target = *target + delta);
94 }
95 
96 void
97 umem_atomic_add_64(uint64_t *target, int64_t delta)
98 {
99 	*target = *target + delta;
100 }
101 
102 uint64_t
103 umem_atomic_swap_64(volatile uint64_t *t, uint64_t v)
104 {
105 	uint64_t old = *t;
106 	*t = v;
107 	return (old);
108 }
109 
110 /*
111  * Standalone umem must be manually initialized
112  */
113 void
114 mdb_umem_startup(caddr_t base, size_t len, size_t pgsize)
115 {
116 	umem_startup(base, len, pgsize, base, base + len);
117 }
118 
119 /*
120  * The kernel will tell us when there's more memory available for us to use.
121  * This is most common on amd64, which boots with only 4G of VA available, and
122  * later expands to the full 64-bit address space.
123  */
124 int
125 mdb_umem_add(caddr_t base, size_t len)
126 {
127 	return (umem_add(base, len));
128 }
129