Print this page
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/ptools/pmap/pmap_common.c
+++ new/usr/src/cmd/ptools/pmap/pmap_common.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26 /*
27 27 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
28 28 */
29 29
|
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
30 30 #include <fcntl.h>
31 31 #include <libproc.h>
32 32 #include <limits.h>
33 33 #include <stdio.h>
34 34 #include <strings.h>
35 35 #include <sys/mkdev.h>
36 36 #include <sys/stat.h>
37 37 #include <sys/types.h>
38 38
39 39 #include "pmap_common.h"
40 +#include "ptools_common.h"
40 41
41 42 /*
42 43 * We compare the high memory addresses since stacks are faulted in from
43 44 * high memory addresses to low memory addresses, and our prmap_t
44 45 * structures identify only the range of addresses that have been faulted
45 46 * in so far.
46 47 */
47 48 int
48 49 cmpstacks(const void *ap, const void *bp)
49 50 {
50 51 const lwpstack_t *as = ap;
51 52 const lwpstack_t *bs = bp;
52 53 uintptr_t a = (uintptr_t)as->lwps_stack.ss_sp + as->lwps_stack.ss_size;
53 54 uintptr_t b = (uintptr_t)bs->lwps_stack.ss_sp + bs->lwps_stack.ss_size;
54 55
55 56 if (a < b)
56 57 return (1);
57 58 if (a > b)
58 59 return (-1);
59 60 return (0);
60 61 }
61 62
62 63 /*
63 64 * Create labels for non-anon, non-heap mappings
64 65 */
65 66 char *
66 67 make_name(struct ps_prochandle *Pr, int lflag, uintptr_t addr,
67 68 const char *mapname, char *buf, size_t bufsz)
68 69 {
69 70 const pstatus_t *Psp = Pstatus(Pr);
70 71 struct stat statb;
71 72 char path[PATH_MAX];
72 73 int len;
73 74
74 75 if (lflag || Pstate(Pr) == PS_DEAD) {
75 76 if (Pobjname(Pr, addr, buf, bufsz) != NULL)
76 77 return (buf);
77 78 } else {
78 79 if (Pobjname_resolved(Pr, addr, buf, bufsz) != NULL) {
79 80 /* Verify that the path exists */
80 81 if ((len = resolvepath(buf, buf, bufsz)) > 0) {
|
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
81 82 buf[len] = '\0';
82 83 return (buf);
83 84 }
84 85 }
85 86 }
86 87
87 88 if (Pstate(Pr) == PS_DEAD || *mapname == '\0')
88 89 return (NULL);
89 90
90 91 /* first see if we can find a path via /proc */
91 - (void) snprintf(path, sizeof (path), "/proc/%d/path/%s",
92 + (void) proc_snprintf(path, sizeof (path), "/proc/%d/path/%s",
92 93 (int)Psp->pr_pid, mapname);
93 94 len = readlink(path, buf, bufsz - 1);
94 95 if (len >= 0) {
95 96 buf[len] = '\0';
96 97 return (buf);
97 98 }
98 99
99 100 /* fall back to object information reported by /proc */
100 - (void) snprintf(path, sizeof (path),
101 + (void) proc_snprintf(path, sizeof (path),
101 102 "/proc/%d/object/%s", (int)Psp->pr_pid, mapname);
102 103 if (stat(path, &statb) == 0) {
103 104 dev_t dev = statb.st_dev;
104 105 ino_t ino = statb.st_ino;
105 106 (void) snprintf(buf, bufsz, "dev:%lu,%lu ino:%lu",
106 107 (ulong_t)major(dev), (ulong_t)minor(dev), ino);
107 108 return (buf);
108 109 }
109 110
110 111 return (NULL);
111 112 }
112 113
113 114 /*
114 115 * Create label for anon mappings
115 116 */
116 117 char *
117 118 anon_name(char *name, const pstatus_t *Psp, lwpstack_t *stacks, uint_t nstacks,
118 119 uintptr_t vaddr, size_t size, int mflags, int shmid, int *mtypesp)
119 120 {
120 121 int mtypes = 0;
121 122
122 123 if (mflags & MA_ISM) {
123 124 if (shmid == -1)
124 125 (void) snprintf(name, PATH_MAX, " [ %s shmid=null ]",
125 126 (mflags & MA_NORESERVE) ? "ism" : "dism");
126 127 else
127 128 (void) snprintf(name, PATH_MAX, " [ %s shmid=0x%x ]",
128 129 (mflags & MA_NORESERVE) ? "ism" : "dism", shmid);
129 130 mtypes |= (1 << AT_SHARED);
130 131 } else if (mflags & MA_SHM) {
131 132 if (shmid == -1)
132 133 (void) sprintf(name, " [ shmid=null ]");
133 134 else
134 135 (void) sprintf(name, " [ shmid=0x%x ]", shmid);
135 136 mtypes |= (1 << AT_SHARED);
136 137 } else if (vaddr + size > Psp->pr_stkbase &&
137 138 vaddr < Psp->pr_stkbase + Psp->pr_stksize) {
138 139 (void) strcpy(name, " [ stack ]");
139 140 mtypes |= (1 << AT_STACK);
140 141 } else if ((mflags & MA_ANON) &&
141 142 vaddr + size > Psp->pr_brkbase &&
142 143 vaddr < Psp->pr_brkbase + Psp->pr_brksize) {
143 144 (void) strcpy(name, " [ heap ]");
144 145 mtypes |= (1 << AT_HEAP);
145 146 } else {
146 147 lwpstack_t key, *stk;
147 148
148 149 key.lwps_stack.ss_sp = (void *)vaddr;
149 150 key.lwps_stack.ss_size = size;
150 151 if (nstacks > 0 &&
151 152 (stk = bsearch(&key, stacks, nstacks, sizeof (stacks[0]),
152 153 cmpstacks)) != NULL) {
153 154 (void) snprintf(name, PATH_MAX, " [ %s tid=%d ]",
154 155 (stk->lwps_stack.ss_flags & SS_ONSTACK) ?
155 156 "altstack" : "stack",
156 157 stk->lwps_lwpid);
157 158 mtypes |= (1 << AT_STACK);
158 159 } else {
159 160 (void) strcpy(name, " [ anon ]");
160 161 mtypes |= (1 << AT_PRIVM);
161 162 }
162 163 }
163 164
164 165 if (mtypesp)
165 166 *mtypesp = mtypes;
166 167 return (name);
167 168 }
|
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX