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*/
40int
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
50void
51umem_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
60void
61umem_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
70int
71umem_vsnprintf(char *s, size_t n, const char *format, va_list ap)
72{
73	return (mdb_iob_vsnprintf(s, n, format, ap));
74}
75
76int
77umem_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 */
90uint32_t
91umem_atomic_add_32_nv(uint32_t *target, int32_t delta)
92{
93	return (*target = *target + delta);
94}
95
96void
97umem_atomic_add_64(uint64_t *target, int64_t delta)
98{
99	*target = *target + delta;
100}
101
102uint64_t
103umem_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 */
113void
114mdb_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 */
124int
125mdb_umem_add(caddr_t base, size_t len)
126{
127	return (umem_add(base, len));
128}
129